{
  "id": "huggingface/peft-4bit-inference-mode",
  "signature": "RuntimeError: You are trying to train a 4-bit model but you have set `inference_mode=True`. Set `inference_mode=False` for training.",
  "signature_zh": "RuntimeError：您正在尝试训练一个 4-bit 模型，但您设置了 `inference_mode=True`。请将 `inference_mode=False` 设置为训练模式。",
  "regex": "You are trying to train a 4-bit model but you have set `inference_mode=True`",
  "domain": "huggingface",
  "category": "config_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "当使用 PEFT 与 4-bit 量化基础模型时，LoRA 配置中的 `inference_mode` 标志在训练时必须为 False，但被设置为 True。",
  "versions": [
    {
      "version": "peft>=0.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "transformers>=4.31.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "bitsandbytes>=0.41.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The error is specifically about the LoRA `inference_mode` parameter, not the model loading quantization. The LoRA config must be explicitly updated.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "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.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set `inference_mode=False` in the LoRA configuration: `lora_config = LoraConfig(r=8, lora_alpha=32, inference_mode=False)`",
      "success_rate": 0.98,
      "how": "Set `inference_mode=False` in the LoRA configuration: `lora_config = LoraConfig(r=8, lora_alpha=32, inference_mode=False)`",
      "condition": "",
      "sources": []
    },
    {
      "action": "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.",
      "success_rate": 0.95,
      "how": "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.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在 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` 再创建模型。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/peft/v0.6.0/en/developer_guides/quantization#4-bit-models",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.98,
  "resolvable": "true",
  "first_seen": "2023-09-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}