{
  "id": "huggingface/quantization-dtype-mismatch-bnb",
  "signature": "ValueError: You passed `quantization_config` with `bnb_4bit_compute_dtype=torch.float16` but the model weights are loaded in `torch.bfloat16`. This is incompatible.",
  "signature_zh": "ValueError：您传递了 `bnb_4bit_compute_dtype=torch.float16` 的量化配置，但模型权重以 `torch.bfloat16` 加载。两者不兼容。",
  "regex": "bnb_4bit_compute_dtype.*incompatible",
  "domain": "huggingface",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Bitsandbytes quantization config compute dtype does not match the model's native weight dtype, causing a type cast failure during forward pass.",
  "root_cause_type": "generic",
  "root_cause_zh": "Bitsandbytes 量化配置的计算数据类型与模型的原始权重数据类型不匹配，导致前向传播时类型转换失败。",
  "versions": [
    {
      "version": "bitsandbytes 0.43.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "transformers 4.44.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "torch 2.3.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "If the model was saved in bfloat16, casting to float16 may cause overflow or underflow; the root mismatch remains if model weights are bfloat16.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Bitsandbytes checks for exact dtype match; this combination will still raise the same error.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set `bnb_4bit_compute_dtype=torch.bfloat16` to match the model weight dtype: `quantization_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.bfloat16)`.",
      "success_rate": 0.95,
      "how": "Set `bnb_4bit_compute_dtype=torch.bfloat16` to match the model weight dtype: `quantization_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.bfloat16)`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Load model with `torch_dtype=torch.float16` and set `bnb_4bit_compute_dtype=torch.float16`.",
      "success_rate": 0.8,
      "how": "Load model with `torch_dtype=torch.float16` and set `bnb_4bit_compute_dtype=torch.float16`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Set `bnb_4bit_compute_dtype=torch.bfloat16` to match the model weight dtype: `quantization_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.bfloat16)`.",
    "Load model with `torch_dtype=torch.float16` and set `bnb_4bit_compute_dtype=torch.float16`."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/bitsandbytes/en/quantization#dtype-mismatch",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-03-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}