{
  "id": "huggingface/quantization-config-bnb-compute-dtype-mismatch",
  "signature": "ValueError: You passed `quantization_config` with `bnb_4bit_compute_dtype=torch.float16` but the model weights are loaded in torch.float32. This may cause unexpected behavior.",
  "signature_zh": "ValueError：您传递了 `bnb_4bit_compute_dtype=torch.float16` 的 `quantization_config`，但模型权重以 torch.float32 加载。这可能导致意外行为。",
  "regex": "ValueError: You passed `quantization_config` with `bnb_4bit_compute_dtype=.*` but the model weights are loaded in torch\\..*",
  "domain": "huggingface",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Mismatch between the compute dtype specified in quantization config and the actual dtype of the loaded model weights, causing precision inconsistencies.",
  "root_cause_type": "generic",
  "root_cause_zh": "量化配置中指定的计算 dtype 与实际加载的模型权重的 dtype 不匹配，导致精度不一致。",
  "versions": [
    {
      "version": "transformers>=4.36.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"
    },
    {
      "version": "torch>=2.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "If quantization config specifies float16 but model weights are float32, the error persists.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The mismatch causes incorrect computations, especially in mixed-precision training.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set torch_dtype='auto' in from_pretrained to match the quantization config: model = AutoModel.from_pretrained('model', quantization_config=quant_config, torch_dtype='auto')",
      "success_rate": 0.9,
      "how": "Set torch_dtype='auto' in from_pretrained to match the quantization config: model = AutoModel.from_pretrained('model', quantization_config=quant_config, torch_dtype='auto')",
      "condition": "",
      "sources": []
    },
    {
      "action": "Explicitly set bnb_4bit_compute_dtype to match the model's dtype: quant_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.float32)",
      "success_rate": 0.85,
      "how": "Explicitly set bnb_4bit_compute_dtype to match the model's dtype: quant_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.float32)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在 from_pretrained 中设置 torch_dtype='auto' 以匹配量化配置：model = AutoModel.from_pretrained('model', quantization_config=quant_config, torch_dtype='auto')",
    "明确设置 bnb_4bit_compute_dtype 以匹配模型的 dtype：quant_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.float32)"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/transformers/main/en/quantization#bitsandbytes",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-03-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}