You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[REGRESSION] #4140: loading models that keep some parameters in fp32 now raises "model load left a corrupted state" #4170
Severity: high — valid models fail to load Version: 7.11.0 @ 6c3421c. Regression from 67ebd21 (#4140); the parent commit loads fine.
Summary
assert_loaded_model_state(..., require_uniform_dtype=True, expected_dtype=...) (utils/hf.py:~390-450) is now called from:
models/loader.py:1884 (native load);
models/loader.py:2090 (quantize-path load with offload_to_disk=False).
It requires every floating parameter to have one dtype. Transformers deliberately keeps modules listed in _keep_in_fp32_modules_strict (any half dtype) and _keep_in_fp32_modules (fp16) in fp32.
importtorchfromtransformersimportErnie4_5_MoeConfig, Ernie4_5_MoeForCausalLMcfg=Ernie4_5_MoeConfig(vocab_size=128256, hidden_size=64, intermediate_size=64, moe_intermediate_size=32,
num_hidden_layers=2, num_attention_heads=4, num_key_value_heads=2,
moe_num_experts=4, moe_k=2, moe_layer_start_index=1)
cfg.dtype=torch.bfloat16Ernie4_5_MoeForCausalLM(cfg).to(torch.bfloat16).save_pretrained("ernie_tiny") # + save a tokenizerfromgptqmodelimportGPTQModelGPTQModel.load("ernie_tiny")
# RuntimeError: model load left a corrupted state ... floating parameters have mixed dtypes:# {'torch.bfloat16': 22, 'torch.float32': 2}
Plain AutoModelForCausalLM.from_pretrained loads the same directory fine.
GPTQModel.load(path, QuantizeConfig(offload_to_disk=False), dtype=torch.bfloat16) fails with not all torch.bfloat16: {'torch.float32': 2}.
A tiny GPT-OSS loaded with dtype=torch.float16 fails with not all torch.float16: {'torch.float32': 5}.
Suggested fix
Exclude parameters owned by modules matched by the model's _keep_in_fp32_modules / _keep_in_fp32_modules_strict (walk submodules too) from the uniform-dtype and expected-dtype checks. Add tests with a keep-in-fp32 architecture.
Found during an AI-assisted review (Claude Code) of 6c3421c; repros were run on RTX 4090/5090 (CUDA 13) and Radeon AI PRO R9700 (ROCm) unless marked static/suspected.
Activity
fix(models): exempt declared keep-in-fp32 modules from the load dtype…