Repository navigation
fix(models): honor third-party checkpoint filters and layouts (#4053) - #4061
Merged
Merged
Conversation
…4053) - Fold AutoAWQ modules_to_not_convert and llm-compressor ignore into -: dynamic exclusions; apply Optimum modules_in_block_to_quantize as an inclusion filter so dense in-layer modules stay dense. - Validate qweight presence for AWQ and shared Marlin/BitBLAS formats instead of leaving zero placeholders that produce NaN. - Record the on-disk qzero layout at load and convert v1<->v2 qzeros on a format-changing re-save; refuse every other format change before writing. - Emit checkpoint-layout qzeros from save_pretrained for v2 runtime kernels, and fail closed for Marlin/ExLlamaV2 whose runtime weight permutation cannot be reversed. - Add docs/checkpoint-interop.md and the issue regression tests.
# Conflicts: # README.md # docs/checkpoint-interop.md
This was referenced Nov 14, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 15, 2026
…ng (#4070) (#4085) Items 1-2 are regressions from #4061. state_dict() emits checkpoint-layout v1 qzeros while Torch/Triton decode v2, so load_state_dict() must convert a self round-trip and must not relabel the runtime layout on a partial load. Serialize export_quant_method() so RTN AWQ exports publish quant_method: awq, publish packed GGUF under the non-colliding gptqmodel_gguf name with a refusing HF quantizer, and drop the compiled dequantize_weight from TorchLinear's pickle state.
This was referenced Nov 15, 2026
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.
Part of #4053 (items 1-3). Items 4-8 are in #4059.
TL;DR
Third-party checkpoints now declare which modules are dense, a format-changing re-save converts the qzeros exactly (or refuses), and
save_pretrained()writes checkpoint-layout qzeros while Marlin/ExLlamaV2 fail closed. Net diff: 11 files, +~700 lines including the reference page and regressions.1. The problem
Item 1: producer exclusions were ignored
The loader decided what to quantize from the module tree plus
dynamic(gptqmodel/models/loader.py:2223-2266on39cd57a85). It never read AutoAWQ/HFmodules_to_not_convert, llm-compressorignore, or Optimummodules_in_block_to_quantize.validate_checkpoint_qweightsreturned early for non-GPTQ formats (gptqmodel/utils/model.py:2592), so a never-loaded AWQ placeholder stayed zero-filled and the model produced NaN without an error.Item 2: a format change copied stale qzeros
get_model_with_quantize(gptqmodel/models/writer.py:2269-2351) reloaded the raw source tensors and wrote them unchanged. It never calledconvert_gptq_v1_to_v2_format/convert_gptq_v2_to_v1_format(gptqmodel/utils/model.py:925 / 1043), somodel.quantize_config.format = X; model.save()wrote v1 words under agptq_v2label.Item 3:
save_pretrained()serialized the runtime layouttransformers'save_pretrained()callsstate_dict()on the live modules. v2-requiring kernels keep v2 qzeros whilecheckpoint_formatstaysgptq; Marlin repacksqweightand emptiesqzeros/g_idxinpost_init; ExLlamaV2 shufflesqweightin place and recorded that only in torch_metadata(gptqmodel/nn_modules/qlinear/exllamav2.py:189), which safetensors drops. The reload was NaN, garbage, or a shape crash.2. The new flow
Producer filters
flowchart TD A["config.json quantization_config"] --> B["from_quant_config"] B --> C{"modules_to_not_convert or ignore"} C -- yes --> D["-: suffix regex rule"] C -- no --> E["keep declared dynamic"] D --> F["config.dynamic"] E --> F B --> G{"modules_in_block_to_quantize"} G -- yes --> H["external_module_inclusions()"] G -- no --> I["all declared modules eligible"] F --> J["loader module filter"] H --> J I --> J J --> K["create_quant_module"] K -- "dynamic match is False" --> L["module stays dense"] K -- "no exclusion" --> M["quantized module"] M --> N["validate_checkpoint_qweights"] L --> NFormat-changing re-save
flowchart TD A["from_quantized"] --> B["record _checkpoint_format_on_disk<br/>and layout snapshot"] B --> C["quantize_config.format = X"] C --> D["save_quantized"] D --> E{"resolve_resave_format_conversion"} E -- "same format" --> F["copy source tensors"] E -- "GPTQ v1 <-> v2" --> G["convert qzeros"] E -- "other layout" --> H["raise before writing"] G --> I["get_model_with_quantize"] I --> J["convert_loaded_qzeros_for_format_change"] J --> K["write target checkpoint"] style H fill:#f8d7da,stroke:#b02a37save_pretrained()flowchart TD A["model.save_pretrained"] --> B["nn.Module.state_dict"] B --> C["GPTQQuantLinear._save_to_state_dict"] C --> D{"runtime qzeros == checkpoint qzeros"} D -- yes --> E["write live buffers"] D -- no --> F["write converted copy"] B --> G["Marlin / ExLlamaV2 hook"] G --> H{"runtime layout applied"} H -- yes --> I["raise RuntimeError"] H -- no --> E style I fill:#f8d7da,stroke:#b02a37The full reference page is
docs/checkpoint-interop.md(linked fromREADME.md). It also contains the items 4-8 flows landed in #4059; both sections are preserved.3. What changed
gptqmodel/quantization/config.pymodules_to_not_convert/ignoreinto-:rules; record Optimum inclusions; preserve original spellings on writegptqmodel/models/loader.pygptqmodel/utils/model.pyqweightfor AWQ and shared Marlin/BitBLAS formatsgptqmodel/models/writer.py,gptqmodel/utils/model.pygptqmodel/nn_modules/qlinear/__init__.py_save_to_state_dictgptqmodel/nn_modules/qlinear/{marlin,marlin_awq,exllamav2,exllamav2_awq}.pygptqmodel/utils/hf_load.pydocs/checkpoint-interop.md,README.md,tests/test_checkpoint_interop_4053.py4. Before / after evidence
Item 1 (synthetic AutoAWQ Llama-3.2-1B-shaped checkpoint,
modules_to_not_convert: ["down_proj"])The fixture keeps
down_projdense and uses an independent dense oracle(code - zero) * scale; no GPT-QModel dequantizer is used as the reference.39cd57a85)RuntimeError: Cannot restore checkpoint buffers missing from checkpoint: model.layers.0.mlp.down_proj.scales(the issue's AUTO path was NaN)down_projisnn.Linear; logits finite; rel max error vs oracle 2.25e-4 (< 2e-3)Real
AWQ-Llama-3.2-1B-g128-gemmstill loads after the new AWQ validation: finite,absmax=13.6640625.Missing AWQ
qweightafter the fix raisesValueError: Missing required quantized weights in checkpoint ...; before it failed with the unrelateddown_proj.scalesrestore error.Item 2 (real checkpoints)
Llama-3.2-1B-Instruct-GPTQ-bit4-g128-symFasle-descFalsegptq->gptq_v2Llama-3.2-1B-Instruct-HF-GPTQV2gptq_v2->gptqItem 3 (real
Qwen2.5-0.5B-Instruct-gptq-4bit, Triton)Marlin / AWQ Marlin / ExLlamaV2 / AWQ ExLlamaV2 now raise from
_save_to_state_dictwith a message naming the kernel;GPTQModel.save()is unaffected because it rebuilds the shell from the source checkpoint.5. Tests
Hardware: CUDA 4090
GPU-50a20676-a7a4-8bb3-eb3d-f191fdc9fa42; ROCm R9700 viaHIP_VISIBLE_DEVICES=0(in this containerHIP_VISIBLE_DEVICES=4exposes zero devices;0is the single visible R9700).CUDA_VISIBLE_DEVICES=GPU-50a20676... pytest -q tests/test_checkpoint_interop_4053.pyCUDA_VISIBLE_DEVICES=GPU-50a20676... pytest -q tests/test_serialization.py tests/test_required_qweight.py tests/test_checkpoint_compat.py tests/test_save_loaded_quantized_model_dtype.pyCUDA_VISIBLE_DEVICES=GPU-50a20676... pytest -q tests/test_model_dequant_dynamic_bits.py tests/test_export.py tests/test_config_only_export.pyHIP_VISIBLE_DEVICES=0 pytest -q tests/test_checkpoint_interop_4053.py(ROCm)HIP_VISIBLE_DEVICES=0 pytest -q tests/test_required_qweight.py tests/test_checkpoint_compat.py(ROCm)HIP_VISIBLE_DEVICES=0 pytest -q tests/test_serialization.py::TestSerialization::test_gptq_v1_serialization(ROCm)ruff check gptqmodel docs/eora tests setup.pyAll 7 new tests fail on
39cd57a85and pass on this branch.tests/test_q4_marlin.pycannot collect on the CUDA venv (ModuleNotFoundError: parameterized, pre-existing).tests/test_serialization.py's Marlin/ExLlamaV2 cases are CUDA-only and fail on ROCm by design.6. Risks / limits
save_pretrained()is now fail-closed. Users who relied on writing the runtime layout will get a clearRuntimeError;GPTQModel.save()remains the supported export path.