Skip to content

fix(diffusion_gemma): never alias untied encoder/decoder parameters (#5411) - #5483

Merged
Qubitium merged 1 commit into
mainfrom
fix/5411-diffusion-gemma-untied
Nov 19, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5411-diffusion-gemma-untied

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5411.

Root cause

DiffusionGemmaConfig.tie_word_embeddings=False is 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 and setattr'd the encoder's Parameter onto the decoder, so quantization replaced the decoder's trained values.
  • _refresh_tied_weight_metadata() republished the class-level map (plus storage-inferred layer ties), so save_pretrained would drop the decoder copies it treats as aliases.
  • _sync_decoder_quantized_modules() shared encoder QuantLinear modules with an independent decoder.

Reproduced on pristine 181cd0185 with a tiny untied stub (tie_word_embeddings=False, encoder norm 0.0, decoder norm 0.5):

tied= False synced= 1
decoder value before: 0.5 after: 0.0
REPLACED
tie map after refresh: 2

On this branch the same probe prints synced= 0, 0.5 kept, tie map after refresh: 0.

Fix

  • New _encoder_decoder_tied(model) reads tie_word_embeddings from the model config (top level, then text_config); unknown means tied, preserving today's behaviour.
  • Both sync helpers return early when untied; _refresh_tied_weight_metadata() publishes an empty tie map for an untied model so a save keeps both stacks.
  • Only the encoder stack is quantized and the decoder is filled in by sharing those modules, so quantizing an untied checkpoint would leave a dense decoder. pre_quantize_generate_hook_start() now refuses it with NotImplementedError before any layer weight is replaced, naming tie_word_embeddings=False and the supported options (load without quantizing, or use a tied checkpoint).
  • The released checkpoint declares 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):

  • the predicate reads tied/untied from the config;
  • untied: the sync returns 0 and the decoder values and storage are unchanged;
  • untied: the published tie map is empty;
  • tied control: the sync still aliases and the layer tie is still recorded;
  • untied: encoder quantized modules are not shared into the decoder;
  • untied: pre_quantize_generate_hook_start raises before touching weights.

The new file cannot even import on main (_encoder_decoder_tied does 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.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] DiffusionGemma quantization replaces independent decoder weights with encoder weights

1 participant