Repository navigation
Description
Summary
Two official checkpoints no longer load through the dense path at HEAD:
GPTQModel.load("tencent/Hunyuan-A13B-Instruct")GPTQModel.load("Zyphra/Zamba-7B-v1")
The same failure hits the quantization load when QuantizeConfig(offload_to_disk=False) is used. Both raise:
RuntimeError: HunYuanMoEV1QModel.from_pretrained: model load left a corrupted state: floating parameters have mixed dtypes: {'torch.bfloat16': ..., 'torch.float32': ...}
RuntimeError: ZambaQModel.from_pretrained: model load left a corrupted state: floating parameters have mixed dtypes: {'torch.bfloat16': 708, 'torch.float32': 76}
Both vendored ports allocate one parameter in fp32 on purpose, exactly as upstream Transformers does:
- Hunyuan-MoE router:
self.wg = nn.Linear(..., dtype=torch.float32), with an fp32 fast path inforward. - Zamba
mamba.A_log: built fromtorch.arange(..., dtype=torch.float32).
For Hunyuan-A13B, the hub checkpoint itself stores mlp.gate.wg.weight as F32. For Zamba, the BF16 A_log is loaded into the fp32 parameter. The values are not corrupted; the guard simply rejects the load. Plain transformers AutoModelForCausalLM.from_pretrained(..., dtype=torch.bfloat16) loads the same Hunyuan directory fine ({'torch.bfloat16': 28, 'torch.float32': 2}).
Before #4620 this case was handled generically. _record_construction_dtypes (patched post_init) recorded each parameter's construction dtype, and assert_loaded_model_state exempted a parameter that was still in its construction fp32 dtype (the #4888 / #5021 fix). #4620 removed that mechanism. It replaced it with a Hymba-only declaration, _keep_in_fp32_modules_strict = ["A_log"] in ports/hymba/modeling_hymba.py:416. No other port got an equivalent declaration, so every other port that builds an fp32 parameter now fails the guard.
I scanned all ~180 text-only hub configs I tested: each was built in bf16 on meta and checked for fp32 parameters not covered by a keep-in-fp32 declaration. Only these two families hit it:
- Hunyuan-A13B:
model.layers.N.mlp.gate.wg.weight, 32 params. - Zamba-7B-v1:
model.layers.N.mamba.A_log/mamba_decoder.mamba.A_log, 76 params.
Introduced by
d2dfb9385 / #4620. It removed CONSTRUCTION_DTYPES_ATTR / _record_construction_dtypes and the matching exemption in gptqmodel/utils/hf.py, which #5021 (fix of #4888) had added.
Location
HEAD d81ad345e:
gptqmodel/utils/hf.py:394-430: only_keep_in_fp32_modules(_strict)matches are exempted:keep_in_fp32 = _compile_keep_in_fp32_matcher(model) ... if (parameter.dtype is torch.float32 and keep_in_fp32 is not None and keep_in_fp32(name)): continue ... elif require_uniform_dtype and len(dtypes) > 1: problems.append("floating parameters have mixed dtypes: " ...)
gptqmodel/models/loader.py:2966-2972(densefrom_pretrained,require_uniform_dtype=True) and:3187(quantize load withoffload_to_disk=False).gptqmodel/models/ports/native/hunyuan_v1_moe/modeling_hunyuan_v1_moe.py:233:self.wg = nn.Linear(config.hidden_size, self.num_experts, bias=False, dtype=torch.float32). There is no_keep_in_fp32_modules*in the port.gptqmodel/models/ports/native/zamba/modeling_zamba.py:471-473:A = torch.arange(1, self.ssm_state_size + 1, dtype=torch.float32)...; self.A_log = nn.Parameter(torch.log(A)...). There is no_keep_in_fp32_modules*in the port.
Reproduction
I ran these reproductions; the checkpoints contain no weights.
-
Zamba, real hub config/tokenizer plus header-only shards:
config.json, the tokenizer files, and sparse*.safetensorsfiles whose headers match the hub headers. All 784 tensors are BF16.from gptqmodel import GPTQModel GPTQModel.load("<dir of Zyphra/Zamba-7B-v1>", device="cpu") # RuntimeError: ZambaQModel.from_pretrained: model load left a corrupted state: # floating parameters have mixed dtypes: {'torch.bfloat16': 708, 'torch.float32': 76}
The 76 fp32 parameters are exactly
model.layers.*.mamba.A_logandmodel.layers.*.mamba_decoder.mamba.A_log. -
Hunyuan-A13B: the hub
config.jsontruncated to 2 layers and 8 experts, plus a random BF16model.safetensorswith the hub key names and shapes.GPTQModel.load(tiny_dir, device="cpu") # RuntimeError: HunYuanMoEV1QModel.from_pretrained: model load left a corrupted state: # floating parameters have mixed dtypes: {'torch.bfloat16': 28, 'torch.float32': 2} GPTQModel.load(tiny_dir, quantize_config=QuantizeConfig(bits=4, group_size=128, offload_to_disk=False)) # RuntimeError: ... floating parameters have mixed dtypes: {'torch.bfloat16': 72, 'torch.float32': 2}
The same directory loads without error on
d2dfb9385^, the parent of Port every supported model onto the Transformers 5.23 ABI; never patch Transformers #4620.
Expected vs actual
- Expected: both checkpoints load, as they do with Transformers and as they did before Port every supported model onto the Transformers 5.23 ABI; never patch Transformers #4620 (verified for the Hunyuan directory on
d2dfb9385^). A parameter the model's own constructor allocates in fp32 is intentional. - Actual: the dense load, and the quantize load with
offload_to_disk=False, raiseRuntimeError ... corrupted state. Passingdtype=torch.bfloat16instead fails withfloating parameters are not all torch.bfloat16.
Suggested fix
Restore a generic exemption instead of a per-port opt-in. For example, record the dtype each parameter has when the shell is constructed, and accept an fp32 parameter that is still in its construction dtype, as #5021 did. Alternatively, declare _keep_in_fp32_modules_strict in the affected ports:
["gate.wg"]for the Hunyuan-MoE port.["A_log"]for the Zamba port.
Add a regression test that loads every vendored port in bf16 and checks that no undeclared fp32 parameter remains.
Activity
fix(loader/save): exempt ported fp32 parameters and keep ported remot…