Repository navigation
fix(diffusion_gemma): never alias untied encoder/decoder parameters (#5411) - #5483
Merged
Merged
Conversation
…5411) DiffusionGemma supports `tie_word_embeddings=False` and stores independent encoder and decoder text parameters, but the definition aliased them anyway: - `_sync_decoder_tied_parameters` matched encoder and decoder parameters by name and shape without consulting the config, so quantization replaced the decoder's trained values with the encoder's. - `_refresh_tied_weight_metadata` republished the class-level tie map, so a save would drop the decoder copies it considered aliases. - `_sync_decoder_quantized_modules` shared encoder QuantLinear modules with the decoder even though the two stacks are independent. Consult `tie_word_embeddings` (top level, then `text_config`): untied models keep their own parameters, publish an empty tie map, and do not share modules. Only the encoder stack is quantized, so quantizing an untied checkpoint would leave the decoder dense; refuse that at the start of `pre_quantize_generate_hook_start`, before any layer weight is replaced, and point at the supported options. The released checkpoint declares `tie_word_embeddings=true`, so its behaviour is unchanged.
This was referenced Nov 19, 2026
Closed
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.
Fixes #5411.
Root cause
DiffusionGemmaConfig.tie_word_embeddings=Falseis supported and stores two independent copies of the text parameters. The definition aliased them anyway, because the tie map is a class-level constant and nothing consulted the config:_sync_decoder_tied_parameters()matched encoder and decoder parameters by name and shape andsetattr'd the encoder'sParameteronto the decoder, so quantization replaced the decoder's trained values._refresh_tied_weight_metadata()republished the class-level map (plus storage-inferred layer ties), sosave_pretrainedwould drop the decoder copies it treats as aliases._sync_decoder_quantized_modules()shared encoderQuantLinearmodules with an independent decoder.Reproduced on pristine
181cd0185with a tiny untied stub (tie_word_embeddings=False, encoder norm 0.0, decoder norm 0.5):On this branch the same probe prints
synced= 0,0.5 kept,tie map after refresh: 0.Fix
_encoder_decoder_tied(model)readstie_word_embeddingsfrom the model config (top level, thentext_config); unknown means tied, preserving today's behaviour._refresh_tied_weight_metadata()publishes an empty tie map for an untied model so a save keeps both stacks.pre_quantize_generate_hook_start()now refuses it withNotImplementedErrorbefore any layer weight is replaced, namingtie_word_embeddings=Falseand the supported options (load without quantizing, or use a tied checkpoint).tie_word_embeddings=true(verified against/monster/data/model/diffusiongemma-26B-A4B-it), so its path is unchanged.Tests
New
tests/test_diffusion_gemma_untied_5411.py(6 tests):pre_quantize_generate_hook_startraises before touching weights.The new file cannot even import on
main(_encoder_decoder_tieddoes not exist), so the red evidence is the behavioural probe above rather than a failing pytest run.Regression
tests/test_diffusion_gemma_support.py+ the new file -> 23 passed;uvx [email protected] check gptqmodel docs/eora tests setup.py-> clean. CPU-only.