Skip to content

[Audit][writer] Re-saving a loaded quantized model skips after_make_quant; DiffusionGemma re-save hits the #5514 guard #5716

Closed

Description

@Qubitium

Summary

The fix for #5514 added the after_make_quant hook so the loader can reattach the tied DiffusionGemma decoder leaves before the unmaterialized-parameter guard runs (gptqmodel/models/loader.py:3496-3498). The writer's export shell, get_model_with_quantize, rebuilds the same quantized model from config and fills it through the same load_checkpoint_in_model_then_tie_weights guard, but it never calls after_make_quant. Re-saving a loaded quantized model of a definition that relies on the hook (currently DiffusionGemmaQModel) therefore hits the #5514 failure again on the save side. This covers a plain GPTQModel.load(q).save(out) and also re-saving with a format change.

Impact

  • Saving (correctness / availability): medium, for affected definitions. The save raises RuntimeError: Loader: the checkpoint ... does not provide tensors for N non-quantized parameter(s) for every tied decoder parameter. No checkpoint is written, so a v1<->v2 format conversion or a re-shard of a loaded DiffusionGemma checkpoint is impossible.
  • No silent accuracy loss: the guard fails closed.

Location (85caf6c)

  • Loader calls the hook: gptqmodel/models/loader.py:3496-3498
    after_make_quant = getattr(cls, "after_make_quant", None)
    if callable(after_make_quant):
        model = after_make_quant(model)
  • Writer shell does not call it: gptqmodel/models/writer.py:2871-2952 (make_quant(...) is followed directly by load_checkpoint_in_model_then_tie_weights(model, ..., checkpoint=self.checkpoint_file_name, ...)).
  • The guard: gptqmodel/utils/model.py:4529-4533 -> _raise_on_unmaterialized_checkpoint_parameters (model.py:3442).
  • The hook implementation: gptqmodel/models/definitions/diffusion_gemma.py:274-284.

Mechanism

  1. A quantized DiffusionGemma checkpoint stores only the encoder owner. The decoder leaves are the same QuantLinear objects at save time, so get_state_dict_for_save dedups them.
  2. get_model_with_quantize builds from_config. make_quant replaces only the encoder leaves named by module_tree. The decoder q_proj/k_proj/... stay dense nn.Linear with torch.empty storage, because init is suspended.
  3. load_checkpoint_in_model_then_tie_weights finds no checkpoint tensors for those decoder weights. tie_weights cannot alias them either, because the tie source is now a QuantLinear with no weight. The guard therefore raises, exactly as described in [BUG] Quantized DiffusionGemma checkpoints cannot be reloaded: GPTQModel.load raises 'does not provide tensors' for every tied decoder parameter (after_model_load decoder sync runs after the loader guard) #5514 for the loader.

Reproduction / Validation

Not executed: on the audit host import gptqmodel is blocked by the torch dev-build version gate. The script is CPU-only and extends the existing tests/models/test_diffusion_gemma.py::test_quantized_checkpoint_reloads_with_tied_decoder with the load -> save round trip:

import sys, tempfile, pathlib, torch
sys.path.insert(0, "tests/models")
from transformers import AutoModelForMultimodalLM
from gptqmodel import GPTQModel, GPTQConfig, CalibrationConfig
from gptqmodel.models.definitions.diffusion_gemma import DiffusionGemmaQModel
from test_diffusion_gemma import _tiny_diffusion_gemma_config

DiffusionGemmaQModel.require_load_processor = False
tmp = pathlib.Path(tempfile.mkdtemp()); src, q1, q2 = tmp/"src", tmp/"q1", tmp/"q2"
AutoModelForMultimodalLM.from_config(_tiny_diffusion_gemma_config(), dtype=torch.bfloat16).save_pretrained(src)
rows = [{"input_ids": list(range(1+i, 49+i)), "attention_mask": [1]*48} for i in range(8)]
m = GPTQModel.load(str(src), GPTQConfig(bits=4, group_size=32), dtype=torch.bfloat16)
m.quantize(CalibrationConfig(dataset=rows, batch_size=1)); m.save(str(q1))
loaded = GPTQModel.load(str(q1), device="cpu")  # passes since #5514
loaded.save(str(q2))                             # expected: RuntimeError from the guard

Suggested fix

Apply the same hook in the export shell, right after make_quant and before the checkpoint fill:

             make_quant(
                 model,
                 ...
                 bias_dtype=model_dtype,
             )
+
+        after_make_quant = getattr(type(self), "after_make_quant", None)
+        if callable(after_make_quant):
+            model = after_make_quant(model)

Add the load -> save -> load round trip above to tests/models/test_diffusion_gemma.py.

Notes

Found by automated code audit (Claude Code).

Activity

  1. added
    bug
    on Nov 20, 2026
  2. added
    scanned
    safe
    on Nov 20, 2026
  3. Qubitium commented on Nov 20, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-24e6fcac08d0 finished this issue.

    Pull request: #5745

    Applying after_make_quant in the writer export shell and extending the DiffusionGemma load-save-load round trip

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

    bugsafescanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions