Repository navigation
fix(diffusion_gemma): reload quantized checkpoints with tied decoder - #5554
Merged
Merged
Conversation
…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.
This was referenced Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is wrong
A quantized DiffusionGemma checkpoint cannot be reloaded.
DiffusionGemmaQModelquantizes onlymodel.encoder.language_model.layers.#, and the weight-tied decoder shares thoseQuantLinearinstances.save()therefore writes only the encoder leaves; on reload,make_quantreplaces only the encoder leaves, leaving the decoder as densenn.Linearlayers withtorch.emptystorage.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 fromBaseQModel.__init__, after the loader has already raised.Fix
BaseQModel.after_make_quant(model)definition hook.make_quantand before the checkpoint load / unmaterialized-parameter guard.DiffusionGemmaQModelby 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_loadstill refreshes the tie metadata after the load.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
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 withGPTQModel.load, asserts every decoder quantized leaf is the encoderQuantLinearinstance, and runs a forward pass.upstream/mainwith the expecteddoes not provide tensors for 61 non-quantized parameter(s)error and passes with the fix.tests/test_diffusion_gemma_untied_5411.py(6 passed) andtests/test_diffusion_gemma_support.py(17 passed).uvx [email protected] check gptqmodel tests: All checks passed.Fixes #5514.