Skip to content

fix(writer): apply after_make_quant in the export shell (#5716) - #5745

Merged
Qubitium merged 1 commit into
mainfrom
fix/5716-writer-after-make-quant
Nov 20, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5716-writer-after-make-quant

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

ModelWriter's export shell (get_model_with_quantize) rebuilds the quantized model with
make_quant() and then fills it from the checkpoint under the same unmaterialized-parameter
guard the loader uses (load_checkpoint_in_model_then_tie_weights). The loader applies a
definition's after_make_quant hook to reattach runtime modules that make_quant() does not
replace; the export shell did not. Re-saving a loaded DiffusionGemma checkpoint therefore
raised before writing anything:

RuntimeError: Loader: the checkpoint '.../quantized/model.safetensors' does not provide
tensors for 61 non-quantized parameter(s): model.decoder.layers.0.self_attn.q_proj.weight, ...

Fixes #5716

What Changed

  • gptqmodel/models/writer.py: call the model definition's after_make_quant hook (when
    callable) immediately after make_quant() in the export shell, before the checkpoint fill.
    This mirrors the load path and lets tied/shared modules be reattached first.
  • tests/models/test_diffusion_gemma.py: extended the existing tied-decoder test to cover
    load → re-save → reload → forward. Extracted _assert_tied_decoder_is_quantized so both the
    first load and the reload assert the decoder shares the encoder's quantized leaves.
  • No API or behavior changes beyond the hook invocation; no follow-up work required.

Tests

The new assertions fail on origin/main at the re-save:

tests/models/test_diffusion_gemma.py:169: in test_quantized_checkpoint_reloads_with_tied_decoder
gptqmodel/models/base.py:4500: in save
gptqmodel/models/writer.py:2448: in save_quantized
gptqmodel/models/writer.py:2931: in get_model_with_quantize
gptqmodel/utils/model.py:4529: in load_checkpoint_in_model_then_tie_weights
E   RuntimeError: Loader: the checkpoint '.../quantized/model.safetensors' does not provide
    tensors for 61 non-quantized parameter(s): ...

and pass with the fix:

# targeted regression (green)
PYTHONPATH=$PWD /Users/diegostudioone/GPTQModel-5713/.venv/bin/python -m pytest \
  tests/models/test_diffusion_gemma.py::test_quantized_checkpoint_reloads_with_tied_decoder -x -q
# 1 passed

# writer suites (green)
PYTHONPATH=$PWD /Users/diegostudioone/GPTQModel-5713/.venv/bin/python -m pytest \
  tests/test_writer_instance_attrs.py tests/test_writer_attention.py \
  tests/test_writer_dynamic_order.py tests/test_writer_quant_log.py \
  tests/test_writer_state_overlay.py -q
# 47 passed

# lint (green)
uvx [email protected] check gptqmodel/models/writer.py tests/models/test_diffusion_gemma.py
# All checks passed!

Notes on the test environment: this run is on an Apple/MPS host, so the quantize load pins
device="cpu" in GPTQConfig; that pin only keeps the CPU test deterministic and is not part
of the fix. CUDA-only suites were not run because no CUDA device is available.

  • Unit tests have been executed and passed, or the reason they are not applicable is documented.
  • I added a new simple/fast unit test for this change, or documented why that is not applicable.

Model Support / Module Plan

Not applicable: no new model, alias, or definition change; this is a localized writer hook call.

Model test node IDs and results (or "not applicable"): not applicable.

@Qubitium
Qubitium merged commit 72b9097 into main Nov 20, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/5716-writer-after-make-quant branch November 20, 2026 08:11
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.

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

1 participant