Skip to content

fix(diffusion_gemma): reload quantized checkpoints with tied decoder - #5554

Merged
Qubitium merged 1 commit into
mainfrom
fix/5514-diffusiongemma-reload
Nov 19, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5514-diffusiongemma-reload

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

What is wrong

A quantized DiffusionGemma checkpoint cannot be reloaded. DiffusionGemmaQModel quantizes only model.encoder.language_model.layers.#, and the weight-tied decoder shares those QuantLinear instances. save() therefore writes only the encoder leaves; on reload, make_quant replaces only the encoder leaves, leaving the decoder as dense nn.Linear layers with torch.empty storage.

load_checkpoint_in_model_then_tie_weights → _raise_on_unmaterialized_checkpoint_parameters (guard from #4810) then raises for every decoder parameter. The code that would fix this up, DiffusionGemmaQModel.after_model_load → _sync_decoder_quantized_modules / _sync_decoder_tied_parameters, only runs from BaseQModel.__init__, after the loader has already raised.

Fix

  • Add a BaseQModel.after_make_quant(model) definition hook.
  • Call it in the quantized loader right after make_quant and before the checkpoint load / unmaterialized-parameter guard.
  • Implement it for DiffusionGemmaQModel by running the existing decoder module and dense-parameter sync, so the decoder no longer owns empty tensors by the time the guard runs. after_model_load still refreshes the tie metadata after the load.
  • The untied case (tie_word_embeddings=False, [BUG] DiffusionGemma quantization replaces independent decoder weights with encoder weights #5411) is still refused at quantization time and is a no-op in the new hook.

Tests

  • New CPU regression test tests/models/test_diffusion_gemma.py::test_quantized_checkpoint_reloads_with_tied_decoder: builds a tiny tied DiffusionGemma config, quantizes GPTQ 4-bit, saves, reloads with GPTQModel.load, asserts every decoder quantized leaf is the encoder QuantLinear instance, and runs a forward pass.
  • Verified the new test fails on upstream/main with the expected does not provide tensors for 61 non-quantized parameter(s) error and passes with the fix.
  • tests/test_diffusion_gemma_untied_5411.py (6 passed) and tests/test_diffusion_gemma_support.py (17 passed).
  • uvx [email protected] check gptqmodel tests: All checks passed.

Fixes #5514.

…nt load

A quantized DiffusionGemma checkpoint stores only the encoder text stack.
On reload, make_quant replaced only the encoder leaves, so the tied decoder
kept dense nn.Linear parameters with torch.empty storage. The unmaterialized
parameter guard in load_checkpoint_in_model_then_tie_weights then raised
before after_model_load could reattach the decoder.

Add a definition hook (after_make_quant) that the quantized loader runs right
after make_quant and before the checkpoint load, and implement it for
DiffusionGemma by reusing the existing decoder module/parameter sync. The
untied case stays refused as before.

Add a CPU regression test that quantizes a tiny tied DiffusionGemma, saves,
reloads, checks the decoder leaves are the encoder QuantLinear instances, and
runs a forward pass.

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

Labels

None yet

Projects

None yet

1 participant