Skip to content

[REGRESSION] #4140: loading models that keep some parameters in fp32 now raises "model load left a corrupted state" #4170

Closed

Description

@Qubitium

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.

Affected examples:

  • Ernie4.5-MoE gate.weight / moe_statics (default bf16 load)
  • GPT-OSS norms (fp16)
  • T5/mT5 wo (fp16)
  • DeepSeek-V3.2 / glm_moe_dsa indexer.weights_proj (fp16)

Reproduce

import torch
from transformers import Ernie4_5_MoeConfig, Ernie4_5_MoeForCausalLM
cfg = 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.bfloat16
Ernie4_5_MoeForCausalLM(cfg).to(torch.bfloat16).save_pretrained("ernie_tiny")  # + save a tokenizer
from gptqmodel import GPTQModel
GPTQModel.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions