huggingface
config_error
ai_generated
true
RuntimeError: You are trying to train a 4-bit model but you have set `inference_mode=True`. Set `inference_mode=False` for training.
ID: huggingface/peft-4bit-inference-mode
98%Fix Rate
88%Confidence
1Evidence
2023-09-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| peft>=0.5.0 | active | — | — | — |
| transformers>=4.31.0 | active | — | — | — |
| bitsandbytes>=0.41.0 | active | — | — | — |
Root Cause
When using PEFT with a 4-bit quantized base model, the `inference_mode` flag in LoRA configuration must be False for training, but was set to True.
generic中文
当使用 PEFT 与 4-bit 量化基础模型时,LoRA 配置中的 `inference_mode` 标志在训练时必须为 False,但被设置为 True。
Official Documentation
https://huggingface.co/docs/peft/v0.6.0/en/developer_guides/quantization#4-bit-modelsWorkarounds
-
98% success Set `inference_mode=False` in the LoRA configuration: `lora_config = LoraConfig(r=8, lora_alpha=32, inference_mode=False)`
Set `inference_mode=False` in the LoRA configuration: `lora_config = LoraConfig(r=8, lora_alpha=32, inference_mode=False)`
-
95% success If using the PEFT model directly, call `model.train()` and ensure the config was created with `inference_mode=False`. Example: `peft_config = LoraConfig.from_pretrained('path')` then modify `peft_config.inference_mode = False` before creating the model.
If using the PEFT model directly, call `model.train()` and ensure the config was created with `inference_mode=False`. Example: `peft_config = LoraConfig.from_pretrained('path')` then modify `peft_config.inference_mode = False` before creating the model.
中文步骤
在 LoRA 配置中设置 `inference_mode=False`:`lora_config = LoraConfig(r=8, lora_alpha=32, inference_mode=False)`
如果直接使用 PEFT 模型,调用 `model.train()` 并确保配置初始时设置了 `inference_mode=False`。示例:`peft_config = LoraConfig.from_pretrained('path')` 然后修改 `peft_config.inference_mode = False` 再创建模型。
Dead Ends
Common approaches that don't work:
-
85% fail
The error is specifically about the LoRA `inference_mode` parameter, not the model loading quantization. The LoRA config must be explicitly updated.
-
90% fail
The `inference_mode` flag in the LoRA config is separate from the model's training state. `model.train()` does not affect PEFT's internal configuration.