Skip to content

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

Closed

Description

@Qubitium

Describe the bug

Native DiffusionGemma supports tie_word_embeddings=False and can store independent encoder and decoder text parameters. GPT-QModel's finalizer synchronizes them by matching names and shapes even with an empty tie map. Calibration and quantization can complete successfully after replacing the decoder's trained values.

To reproduce

At 2c8717e1 with Transformers 5.23.0, initialize a tiny native DiffusionGemma with ties disabled. Set an encoder layer norm and its corresponding decoder norm to differing values and save both to safetensors. In the local pretokenized CPU fixture, processor construction was disabled to isolate the real model loader and GPTQ quantization.

The initial load preserves separate parameters and values. After quantization, the decoder norm becomes the exact encoder parameter and its value changes by 0.5. Calling the production finalizer on the native model produces the same replacement. Untied parameters should keep their separate values, or the configuration should be rejected before weights change. Unconditional synchronization, load and quantize hooks.

Suggested mitigation

One option is to drive aliasing and lazy sourcing from actual checkpoint-owned ties and retain independent decoder weights where present. If the algorithm currently requires tied text stacks, an early explicit validation would protect untied models while dedicated support is added. A regression can pair tied and untied native fixtures and check tensor identity and values through quantization and reload.

Activity

  1. added
    bug
    on Nov 19, 2026
  2. Qubitium commented on Nov 19, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-4e3a0639ecaf is working on this issue now.

    Started 2026-11-19T08:25:00Z. The claim expires 4.0h after this comment is last edited (heartbeat). Other agents: do not start this issue while the claim is live.

    Gate the encoder/decoder synchronization on the checkpoint's actual ties so untied DiffusionGemma parameters keep their trained values, with a tied/untied regression pair.

  3. Qubitium commented on Nov 19, 2026

    @Qubitium
    CollaboratorAuthor

    Released: #5483 merged as 47b1bf969.

    What changed

    • New _encoder_decoder_tied(model) reads tie_word_embeddings from the config (top level, then text_config); unknown means tied, preserving prior behaviour.
    • _sync_decoder_tied_parameters() and _sync_decoder_quantized_modules() return early for an untied model, so the decoder keeps its own trained parameters and does not share encoder QuantLinear modules.
    • _refresh_tied_weight_metadata() publishes an empty tie map for an untied model, so save_pretrained keeps both stacks instead of dropping the decoder copies as aliases.
    • pre_quantize_generate_hook_start() refuses to quantize an untied checkpoint (NotImplementedError naming tie_word_embeddings=False) before any layer weight is replaced, because only the encoder stack is quantized and the decoder would otherwise be left dense.
    • The released checkpoint declares tie_word_embeddings=true, so its path is unchanged.

    Verification

    • New tests/test_diffusion_gemma_untied_5411.py (6 tests). Behavioural probe on 181cd0185: untied stub showed synced= 1, decoder norm 0.5 -> 0.0, tie map 2. On the fix: synced= 0, 0.5 kept, tie map 0.
    • tests/test_diffusion_gemma_support.py + the new file -> 23 passed; ruff clean.
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions