Repository navigation
fix(checkpoint): repair v1 state_dict loads, HF quant methods, pickling (#4070) - #4085
Merged
Merged
Conversation
…ng (#4070) 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.
# Conflicts: # README.md # gptqmodel/__init__.py # gptqmodel/models/writer.py
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.
Fixes #4070
Items 1-2 are regressions from #4061.
TL;DR
Five checkpoint-interop fixes, 13 files, +484/-16. The worst one was silent:
load_state_dict(model.state_dict())copied v1 qzeros into a v2 kernel andcorrupted every GPTQ v1 model while
strict=Truereported success. The newflow converts a self round-trip in place and leaves the runtime layout alone
when a partial load carries no
qzeros.1. The problem
_save_to_state_dictemits checkpoint v1 words, but_load_from_state_dictcopied them into the v2 buffer and set_qzeros_format = 1without convertinggptqmodel/nn_modules/qlinear/__init__.py:1285(save) and:1300(load) before this PR_load_from_state_dictreset_qzeros_formatfromself.formateven whenqzeroswas not loadedgptqmodel/nn_modules/qlinear/__init__.py:1300to_dict()wrotequant_method: self.methodinstead ofexport_quant_method()gptqmodel/quantization/config.py:5192quant_method: "gguf", which transformers routes to its ownGgufHfQuantizergptqmodel/quantization/config.py:5192+gptqmodel/models/writer.py:215optimize()storedtorch_compile(bound method)on the instance; pickle cannot serialize itgptqmodel/nn_modules/qlinear/torch.py:3932. The new flow
GPTQQuantLinear._load_from_state_dictnow keys off the layout the loaderactually recorded (
_checkpoint_format_on_disk), converts a v1 checkpoint intothe v2 runtime layout for
REQUIRES_FORMAT_V2kernels, and skips the formatupdate entirely when
prefix + "qzeros"is absent.flowchart TD A["model.load_state_dict(state_dict)"] --> B["GPTQQuantLinear._load_from_state_dict"] B --> C["super()._load_from_state_dict<br/>copies the words"] C --> D{"prefix + qzeros<br/>in state_dict?"} D -- no --> E["keep _qzeros_format<br/>partial load, no relabel"] D -- yes --> F{"_checkpoint_format_on_disk"} F -- "GPTQ / gemm" --> G{"REQUIRES_FORMAT_V2?"} G -- yes --> H["convert_gptq_v1_to_v2_format_module<br/>_qzeros_format = 2"] G -- no --> I["_qzeros_format = 1"] F -- "GPTQ_V2" --> J["_qzeros_format = 2"] F -- "unset (export shell)" --> K["restore from self.format<br/>caller owns conversion"] E --> L["_clear_runtime_weight_cache"] H --> L I --> L J --> L K --> L style E fill:#d9f2d9,stroke:#2e7d32 style H fill:#d9f2d9,stroke:#2e7d32The
unsetbranch is deliberate:get_model_with_quantize()builds an exportshell from the target
qcfg, and accelerate fills it through_load_from_state_dictbefore the writer appliesconvert_loaded_qzeros_for_format_change. Keeping the historical restore thereavoids double-converting the shell.
to_dict()now publishesexport_quant_method(), andquant_method(adeprecated alias) can no longer override the canonical
methodkey. Packed GGUFpublishes
gptqmodel_ggufand registers a refusing HF quantizer.flowchart TD A["BaseQuantizeConfig.to_dict"] --> B["export_quant_method()"] B --> C["_serialize_export_quant_method"] C -- "METHOD.GGUF" --> D["quant_method: gptqmodel_gguf"] C -- "METHOD.AWQ" --> E["quant_method: awq"] C -- "METHOD.GPTQ" --> F["quant_method: gptq"] D --> G["transformers get_hf_quantizer"] G --> H["GPTQModelGGUFHfQuantizer.__init__<br/>raise ValueError"] E --> I["AwqHfQuantizer"] F --> J["GptqHfQuantizer"] style H fill:#f8d7da,stroke:#b02a37 style I fill:#d9f2d9,stroke:#2e7d32 style J fill:#d9f2d9,stroke:#2e7d32TorchLinear.__getstate__drops the compileddequantize_weightinstanceattribute; the class method is the eager fallback.
flowchart TD A["TorchLinear.optimize()"] --> B["self.dequantize_weight =<br/>torch_compile(bound method)"] B --> C["torch.save(model)"] C --> D["TorchLinear.__getstate__"] D --> E["pop dequantize_weight"] E --> F["pickle succeeds"] F --> G["torch.load restores the class method"] G --> H["eager dequantize_weight fallback"] style H fill:#d9f2d9,stroke:#2e7d32The committed reference page is
docs/checkpoint-interop.mdsections 9-11,linked from
README.md.3. Before / after measurements
Hardware: RTX 4090
GPU-50a20676-a7a4-8bb3-eb3d-f191fdc9fa42(CUDA) andR9700
HIP_VISIBLE_DEVICES=2(ROCm). Real model:/monster/data/model/Llama-3.2-1B-Instruct-GPTQ-4bits-gp128(v1, g128,gptq_tritonandgptq_torch).Item 1:
load_state_dict(model.state_dict())identityBefore (
main):After this PR:
The absolute PPL depends on the eval text, so it differs from the issue's
9.82 / 1856980.9; the failure mode and next token are identical(
' Berlin'->'imid'). The synthetic fixture's logits moved by relative0.406before the fix and0.0after it.gptq_torchandgptq_tritonproduced the same numbers on CUDA. On ROCm
gptq_torchthe same identityholds: before/after
[20.1685, 6.1908, 8.4766],' Berlin'both times, andthe partial-load round trip stayed at
6.1908 ' Berlin'.Item 2: partial load
Before (
main):After this PR:
Item 3: RTN AWQ export method
RTNConfig(bits=4, group_size=128, format=FORMAT.GEMM).to_dict():method: gptq,quant_method: gptq,format: gemmmethod: gptq,quant_method: awq,format: gemmtransformers.quantizers.AutoQuantizationConfig.from_dict(payload)now selectsAwqConfigfor GEMM/GEMV/GEMV_FAST/LLM_AWQ andGPTQConfigfor GPTQ/GPTQ_V2.The generic
QuantizeConfig.from_quant_config(payload)round-trips toRTNConfigwithexport_quant_method() == METHOD.AWQ; the deprecatedquant_methodalias no longer switches the quantizer back to GPTQ.Item 4: packed GGUF
quant_methodquant_method: "gguf"-> transformersGgufHfQuantizer-> random weightsquant_method: "gptqmodel_gguf"-> registeredGPTQModelGGUFHfQuantizerraisesAlready-published checkpoints with
quant_method: "gguf"(plusmethod: "gguf") still load throughGPTQModel.load;ggufremains acceptedby
_normalize_quant_method.Item 5: pickling
Before:
PicklingError: Can't pickle <function TorchLinear.dequantize_weight ...>.After:
torch.savewrote 41,861 bytes andtorch.loadrestored a workingLlamaForCausalLM; logits after reload are identical to the live model.4. Failure and ambiguity contract
load_state_dict(state_dict())on a v1 modelqzeros_qzeros_formatflipped to 1, next save garbage_checkpoint_format_on_diskunset)self.formatformat="gemm"quant_method: gptq+format: gemmquant_method: awqggufcollision, random weightsgptqmodel_ggufrefuses loudlygguf, random weightstorch.save(model)afteroptimize()PicklingError5. Tests
New regression tests:
test_load_state_dict_round_trip_preserves_v1_model(Torch + Triton),
test_partial_load_state_dict_keeps_runtime_qzeros_layout,test_optimized_torch_linear_model_pickles,test_hf_from_pretrained_refuses_packed_gguf,test_rtn_config_serializes_export_quant_method,test_gguf_config_publishes_non_colliding_quant_method,test_legacy_gguf_quant_method_still_loads, andtest_hf_compat_warning_for_packed_gguf.6. Reviewer notes
GPTQMODEL_*switches; the new behavior is driven by the module'srecorded checkpoint format and the config object.
gptqmodel/models/writer.py::hf_compat_warningsis shared with the [BUG] Real MoE/VL: GPTQModel MoE ckpts load in HF transformers as garbage (experts MISSING, PPL 39570), legacy-layout VL GPTQ ckpts (Qwen2-VL Int8) fail GPTQModel.load, AWQ crashes when in_features % group_size != 0, dangling auto_map after trust_remote_code override #4073 and[BUG] Features: GPTQ dynamic -: exclusions load as garbage in HF (PPL 690), requantize embeddings + post-quant EoRA crash under default auto_nf12 (repo e2e test fails), EoRA KeyError with dynamic, rotation half-applies then asserts on Qwen2.5, GSQ fp16 loss overflow #4077 workers. This PR only appends a self-contained GGUF warning; the
-:exclusion warning and the new per-expert MoE warning fromorigin/mainare preserved. Merged
origin/main@323673e99after opening the PR; theupstream removal of
_patch_transformers_paroquant_quantizer_compat([BUG] Real-model matrix: AWQ Gemma-3 bf16 offset-gain fold cancels (PPL 39.8 -> 486, #3973 incomplete), QQQ bf16 in-memory model raises (#4001 incomplete), ParoQuant ckpt crashes HF from_pretrained, QQQ default damp 0.005 too low #4074)was kept removed, not re-added.
4032308cf(fix) and71b93ca7a(merge oforigin/main).ValueError. A process that uses plaintransformerswithout importinggptqmodelstill hits transformers'supports_quant_methodfallback (logwarning, dense random init) because transformers 5.22 does not raise for
unknown methods; the save-time warning and the docs page direct users to
GPTQModel.load/vLLM. Legacyggufcheckpoints remain readable byGPT-QModel but cannot be made loud after publication.
_checkpoint_format_on_diskisunset so
convert_loaded_qzeros_for_format_changedoes not double-convert;tests/test_checkpoint_interop_4053.py::test_resave_v1_to_v2_converts_qzerospins that.