huggingface
config_error
ai_generated
true
ValueError: 您传递的 `quantization_config` 中 `bnb_4bit_compute_dtype=torch.float16`,但模型权重以 torch.float32 加载。这可能导致数值不稳定。
ValueError: You passed `quantization_config` with `bnb_4bit_compute_dtype=torch.float16` but the model weights are loaded in torch.float32. This may cause numerical instability.
ID: huggingface/quantization-config-dtype-mismatch
88%修复率
86%置信度
1证据数
2024-04-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| transformers>=4.30.0 | active | — | — | — |
| bitsandbytes>=0.41.0 | active | — | — | — |
根因分析
量化配置中指定的计算数据类型与实际模型权重数据类型不匹配,可能导致数值问题。
English
Mismatch between the compute dtype specified in quantization config and the actual model weight dtype leads to potential numerical issues.
官方文档
https://huggingface.co/docs/transformers/main/en/quantization/bitsandbytes解决方案
-
Set `bnb_4bit_compute_dtype` to match the model weight dtype: `quantization_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=model.dtype)`
-
Load the model with the correct torch_dtype: `model = AutoModelForCausalLM.from_pretrained('model-name', torch_dtype=torch.float16, quantization_config=quantization_config)`
无效尝试
常见但无效的做法:
-
Setting `bnb_4bit_compute_dtype` to `torch.float32` without changing model weights
70% 失败
This only silences the warning but does not fix the underlying dtype mismatch if the model is in float16.
-
Ignoring the warning and proceeding with training
60% 失败
Numerical instability can lead to NaN loss or diverging gradients, especially in mixed-precision training.