Skip to content

[BUG] Quantized DiffusionGemma checkpoints cannot be reloaded: GPTQModel.load raises 'does not provide tensors' for every tied decoder parameter (after_model_load decoder sync runs after the loader guard) #5514

Closed

Description

@Qubitium

Found on main @ c2e23c4, CPU, transformers 5.23.0. The same failure occurs at c1807f8 and at 47b1bf969^ (before #5483), so it is not a regression from #5483. #5483 did not fix it either.

What is wrong

A quantized DiffusionGemma checkpoint written by GPTQModel.save() cannot be loaded back with GPTQModel.load(). The load always raises before the model is returned.

  • DiffusionGemmaQModel quantizes only the encoder text stack (module_tree = model.encoder.language_model.layers.#) and shares those QuantLinears with the weight-tied decoder. save() therefore writes only model.encoder.language_model.layers.* quantized tensors. For the decoder layers it writes only layer_scalar (expected, because they are tied).
  • On from_quantized, the shell replaces only the encoder leaves with QuantLinear. The decoder layers keep dense nn.Linear / expert weights with torch.empty storage.
  • load_checkpoint_in_model_then_tie_weights → _raise_on_unmaterialized_checkpoint_parameters (gptqmodel/utils/model.py:4485, guard added in fix(omni): save and load Qwen2.5-Omni checkpoints in the source HF key layout (#4758) #4810) then rejects every decoder parameter.
  • The code that would fix this up, DiffusionGemmaQModel.after_model_load(load_quantized_model=True) → _sync_decoder_quantized_modules / _sync_decoder_tied_parameters (gptqmodel/models/definitions/diffusion_gemma.py:273-283), only runs from BaseQModel.__init__ (base.py:1431). That is after the loader has already raised, so it never gets a chance to run.

As a result, every quantized DiffusionGemma checkpoint (GPTQ, and every other method that uses the same save/load path) can only be used in the session that produced it. tests/models/test_diffusion_gemma.py quantizes and generates in-session only (need_eval=False, no reload), so this was never exercised.

Repro

On the real google/diffusiongemma-26B-A4B-it, truncated to 6 text layers so the last decoder layer is full_attention, GPTQ 4-bit quantization and save() succeed. GPTQModel.load(saved) then fails with:

RuntimeError: Loader: the checkpoint '.../model.safetensors.index.json' does not provide tensors for 2417 non-quantized parameter(s): model.decoder.layers.0.self_attn.q_proj.weight, model.decoder.layers.0.self_attn.k_proj.weight, model.decoder.layers.0.self_attn.v_proj.weight, ...

A tiny random model reproduces it in about 1 minute on CPU:

import json, os, shutil, torch
from transformers import AutoConfig, AutoModelForMultimodalLM
from gptqmodel import GPTQModel
from gptqmodel.quantization.config import GPTQConfig, CalibrationConfig

SRC = "google/diffusiongemma-26B-A4B-it"   # local copy; only config/tokenizer/processor files are used
D, OUT = "dg_tiny", "dg_tiny_q"
c = json.load(open(os.path.join(SRC, "config.json")))
c["text_config"].update(hidden_size=64, intermediate_size=128, moe_intermediate_size=32, num_experts=4, top_k_experts=2,
    num_attention_heads=2, num_key_value_heads=1, num_global_key_value_heads=1, head_dim=32, global_head_dim=64,
    num_hidden_layers=2, layer_types=["sliding_attention", "full_attention"])
c["vision_config"].update(hidden_size=32, intermediate_size=64, num_hidden_layers=1, num_attention_heads=2,
    num_key_value_heads=2, head_dim=16, global_head_dim=16)
os.makedirs(D, exist_ok=True)
for f in os.listdir(SRC):
    if f.endswith((".json", ".jinja")) and not f.startswith("model") and f != "config.json":
        shutil.copy(os.path.join(SRC, f), D)
json.dump(c, open(os.path.join(D, "config.json"), "w"))
torch.manual_seed(0)
AutoModelForMultimodalLM.from_config(AutoConfig.from_pretrained(D)).to(torch.bfloat16).save_pretrained(D)  # tied, release layout

rows = [{"input_ids": list(range(100 + i, 148 + i)), "attention_mask": [1] * 48} for i in range(8)]
q = GPTQModel.load(D, GPTQConfig(bits=4, group_size=32), dtype=torch.bfloat16)
q.quantize(CalibrationConfig(dataset=rows, batch_size=1))
q.save(OUT)
GPTQModel.load(OUT, device="cpu")

Output:

saved keys: decoder.layers.* = 2 (layer_scalar only), encoder.language_model.layers.* = 174 (qweight/qzeros/scales/g_idx ...)
RuntimeError: Loader: the checkpoint 'dg_tiny_q/model.safetensors' does not provide tensors for 61 non-quantized parameter(s): model.decoder.layers.0.self_attn.q_proj.weight, model.decoder.layers.0.self_attn.k_proj.weight, ...

Same result at c1807f8 and at the parent of 47b1bf9 (#5483).

Suggested fix

Reattach the decoder before the checkpoint load and its unmaterialized-parameter guard run. For example, add a definition hook that the quantized loader calls right after the QuantLinear replacement (make_quant) and before load_checkpoint_in_model_then_tie_weights. In that hook, run _sync_decoder_quantized_modules(model) and alias the dense decoder parameters to the encoder ones (_sync_decoder_tied_parameters), so the decoder no longer owns separate empty tensors. Alternatively, have the guard honor the model's tied-weights map (decoder.layers.* <- encoder.language_model.layers.* for a tied checkpoint) and let after_model_load alias them. Keep the untied case (#5411) refused as it is today.

Test that should have caught it

tests/models/test_diffusion_gemma.py never reloads the saved checkpoint. A tiny-config quantize → save → GPTQModel.load → forward test (like the snippet above) would have caught this. It should also check that the decoder leaves are the encoder QuantLinear instances after reload.

Severity

High for this family. Every quantized DiffusionGemma checkpoint fails to load, so the quantized output cannot be distributed or reused.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 19, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-5514-diffusiongemma is working on this issue now.

    Started 2026-11-19T11:09:21Z. This claim expires 4.0h after this comment was last edited (heartbeat). Other agents: do not start this issue while the claim is live.

    Reattach the tied decoder before the checkpoint load guard so saved DiffusionGemma checkpoints reload

  2. Qubitium commented on Nov 19, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-5514-diffusiongemma is working on this issue now.

  3. Qubitium commented on Nov 19, 2026

    @Qubitium
    CollaboratorAuthor

    Agent release: agent-root-5514-diffusiongemma finished this issue; merged in #5554 as 4ac8e97f4.

    The regression test added by that PR now guards the fix.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions