Repository navigation
fix(checkpoint): accept 5.4.x gptaq booleans and quantize untied lm_head (#4013) - #4034
Merged
Merged
Conversation
…ead (#4013) Four checkpoint-compatibility defects, all in the load/quantize/save path: 1. `_normalize_gptaq` accepted only None/dict/GPTAQConfig, so every 5.4.x checkpoint (`meta.gptaq: false|true`) raised ValueError. Map False to None and True to GPTAQConfig, folding the legacy `gptaq_alpha` / `gptaq_memory_device` siblings into the object. `_normalize_foem` takes the same shapes. 2. `lm_head=True` crashed on untied models: subset planning replaces the live head with the AUTO_NF12 forward wrapper, leaving the stage's `module` reference detached from the tree, so direct-state materialization raised "Could not find the given module within the target model" (utils/structure.py:542). Re-read the head from the tree after planning and keep the head out of the calibration-source pack. Tied heads now reach the explicit NotImplementedError via `_lm_head_is_tied`, which also consults the checkpoint for a missing `lm_head.weight`. 3. AWQ `-:` exclusions are written to `modules_to_not_convert` so HF and vLLM AutoAWQ skip those modules instead of building uninitialized layers. A quantized lm_head and 8-bit AWQ now log their loadability caveats at save time. 4. 8-bit AWQ keeps natural lane order as GPT-QModel's canonical layout and warns on export: vLLM `awq_marlin` undoes a `[0,2,1,3]` interleave that this layout never applied. Tests: tests/test_checkpoint_compat.py (14 cases, CUDA + ROCm). Docs: docs/checkpoint-compat.md, docs/awq-packed-layout.md, README.
# Conflicts: # README.md
…mplicit (fall through) returns' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
This was referenced Nov 14, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 18, 2026
…5027) (#5041) `WeightOnlyLooper` refused `lm_head=True` on a tied model with `find_tied_parameters(model)`, which only compares materialized parameters. With the default `offload_to_disk=True` the model is a lazy shell whose `lm_head.weight` and `embed_tokens.weight` are independent META parameters, so the guard never fired: the run quantized every layer and then died on the head's meta tensor (`Cannot copy out of meta tensor; no data!`), an error that points away from the real cause. The module looper had already been fixed in #4034. Move `ModuleLooper._lm_head_is_tied` into `utils.tied_weights.lm_head_quantization_is_tied()` and call it from both loopers, so one check decides the answer: real storage identity, then accelerate's tied report, then the lazy-shell checkpoint evidence, then the resolved tie snapshot, then the root config declaration. Fixes #5027
This was referenced Nov 28, 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 #4013
TL;DR
Four checkpoint-compatibility defects in the load/quantize/save path, fixed
with +735/-8 lines: 229 lines of source, 273 lines of tests, and 233 lines of
documentation. The architectural consequence: a checkpoint's producer is now explicit
about what a non-GPT-QModel loader can and cannot consume, and the
lm_headpseudo-layer no longer holds a stale module reference after subset planning.
_normalize_gptaqrejected 5.4.x booleans (gptqmodel/quantization/config.py:3513on the parent commit)FalsetoNone,TruetoGPTAQConfig, folding the legacygptaq_alpha/gptaq_memory_devicesiblingsHookedLinearthat subset planning had replaced with the AUTO_NF12 wrapper, so_get_qualified_namefailed (utils/structure.py:542)-:exclusions never reachedmodules_to_not_convert(config.py:5200)lm_headand 8-bit AWQawq_marlinundoes1. The problem
1a. Legacy
meta.gptaqflowchart TD A["quantize_config.json<br/>meta.gptaq = false or true"] --> B["_normalize_gptaq"] B -.->|"parent commit"| X["ValueError: gptaq must be a<br/>GPTAQConfig, dict, or None"]:::fail classDef fail fill:#ffdddd,stroke:#cc0000,color:#660000Real 5.4.2-produced checkpoints hit this, e.g.
Llama-3.2-1B-Instruct-GPTQ-4bits-gp128.1b. Untied
lm_headflowchart TD A["run_layer_stage<br/>step kind = lm_head"] --> B["module = get_module<br/>model, lm_head"] B --> C["build_layer_subset_plans"] C --> D["_maybe_auto_dtype_cast_forward_module<br/>replaces the live head"] D -.->|"stage keeps the old object"| X["_get_qualified_name<br/>utils/structure.py:542<br/>ValueError"]:::fail classDef fail fill:#ffdddd,stroke:#cc0000,color:#660000With
offload_to_disk=Falsethe same detach surfaced asRuntimeError: Lazy forward direct-state materialization left META tensors.For a tied head the identity check missed lazily loaded shells, so the run
continued until
Cannot reload quantization source: missing checkpoint tensors ['weight'](models/base.py:3607) instead of the explicitNotImplementedErroratmodule_looper.py:1801.2. The new flow
flowchart TD A["run_layer_stage<br/>step kind = lm_head"] --> B["module = get_module<br/>model, lm_head"] B --> C["build_layer_subset_plans"] C --> D{"live head replaced?"} D -->|"yes"| E["re-read module from the model tree<br/>stage_layer.py"] D -->|"no"| F["module unchanged"] E --> G["refresh full and cur_layer_device"] F --> H["_prepare_layer_direct_state_for_forward"] G --> H H --> I["calibration forward + quantize"] I --> J["submodule_finalize<br/>create_quant_module"] J --> K["post_quantize moves the head to CPU"]The head is also excluded from AUTO_NF12 calibration packing
(
models/base.py:3938): the head is its own quantization stage, its densesource is required as the quant source, and packing it detached it from the tree
that
post_quantizewalks.3. Tied-head detection
flowchart TD A["_lm_head_is_tied"] --> B{"find_tied_parameters<br/>matches lm_head.weight?"} B -->|"yes"| R["tied"]:::warn B -->|"no"| C{"config.tie_word_embeddings?"} C -->|"no"| N["untied"] C -->|"yes"| D{"head weight is META?"} D -->|"no"| N D -->|"yes"| E["LazyTurtle.has_checkpoint_tensor"] E --> F{"checkpoint owns lm_head.weight?"} F -->|"no"| R F -->|"yes"| N R --> Z["NotImplementedError:<br/>tied lm_head quantization is unsupported"]:::warn classDef warn fill:#fff3cd,stroke:#cc8800,color:#664400has_checkpoint_tensorresolves the same runtime-to-checkpoint aliases as thematerializers but never loads a tensor, so the check stays cheap on large
checkpoints.
4. Per-subsystem detail
4a. Legacy config normalization
_normalize_gptaqand_normalize_foemnow accept a boolean.from_quant_configfolds the legacy sibling keys into the object form before the target class is
resolved, so
gptaq_alphaandgptaq_memory_deviceare no longer dropped asunknown keys.
4b. AWQ exclusions and loadability metadata
flowchart LR A["quantize_config"] --> B{"method == AWQ?"} B -->|"yes"| C["excluded_module_patterns"] C --> D["-: dynamic rules<br/>+ declared list"] D --> E["modules_to_not_convert"] B -->|"no"| F["no key written"] A --> G["hf_compat_warnings"] G --> H{"lm_head quantized?"} H -->|"yes"| I["warn: HF random-initializes the head"]:::warn G --> J{"8-bit AWQ?"} J -->|"yes"| K["warn: vLLM awq_marlin decodes the wrong lane order"]:::warn classDef warn fill:#fff3cd,stroke:#cc8800,color:#664400modules_to_not_convertis a mirror, not a second source of truth: the-:rules in
dynamicstay authoritative and the mirror is recomputed on everysave.
4c. 8-bit AWQ lane order — decision
Natural lane order stays canonical for GPT-QModel; exporting 8-bit AWQ logs a
warning. I did not flip the packer to
[0, 2, 1, 3]because (a) it wouldsilently change the meaning of every 8-bit AWQ checkpoint published since #3993,
with no version marker to distinguish the layouts, and (b) the
awq_marlinsideof that decision lives in a compiled extension
(
gptqmodel_ext/marlin/awq_marlin_repack.cu), so it cannot be validated herewithout rebuilding and re-qualifying that kernel on every supported
architecture.
Measured with an independent FP64 oracle (
out_features=64,in_features=128,group_size=32, 8-bit codes, max absolute weight error):[0, 2, 1, 3]order5. Failure and ambiguity contract
meta.gptaq: falseValueErrorat config parsemeta.gptaq: trueValueErrorGPTAQConfigwith the recorded alpha/devicelm_head=TrueValueError: Could not find the given modulelm_head=TrueRuntimeError: missing checkpoint tensors ['weight']NotImplementedError: ... tied weights is not supported-:exclusionsmodules_to_not_convertlm_headsaved6. Change inventory
gptqmodel/quantization/config.pygptqmodel/looper/stage_layer.pygptqmodel/looper/module_looper.py_lm_head_is_tiedgptqmodel/models/base.pygptqmodel/models/writer.pyhf_compat_warnings+ save-time logginggptqmodel/utils/structure.pyLazyTurtle.has_checkpoint_tensortests/test_checkpoint_compat.pydocs/checkpoint-compat.md,docs/awq-packed-layout.md,README.md7. Tests
test_legacy_boolean_gptaq_false_disables_gptaqfalsemaps to no GPTAQtest_legacy_boolean_gptaq_true_keeps_alpha_and_devicetruekeeps alpha and devicetest_legacy_boolean_gptaq_true_without_alpha_uses_defaulttest_legacy_boolean_foem_metatest_boolean_gptaq_and_foem_accepted_by_the_constructortest_awq_dynamic_exclusions_are_written_to_modules_to_not_convert-:rules reach the key and survive reloadtest_awq_without_exclusions_writes_no_modules_to_not_converttest_hf_compat_warning_for_quantized_lm_headtest_hf_compat_warning_for_8bit_awqtest_awq_8bit_lane_order_is_naturaltest_awq_8bit_vllm_order_would_swap_lanes_one_and_twotest_untied_lm_head_quantizes_and_reloadstest_tied_lm_head_is_rejected_with_the_explicit_errorNotImplementedErrorFail-before / pass-after on the same file (RTX 4090, CUDA 13.0 venv):
8. Validation
Hardware: RTX 4090 (
GPU-1892aea4-cc09-827c-b9a5-93d4eef7f5ae) and the R9700via
HIP_VISIBLE_DEVICES=0. The RTX 5090 was never used.Item 1 against a real 5.4.2 checkpoint
(
/monster/data/model/Llama-3.2-1B-Instruct-GPTQ-4bits-gp128,meta.gptaq: false):Item 2 on the repo's own scenario (Qwen1.5-1.8B-Chat, 128 x 1024-token c4
samples,
QuantizeConfig(bits=4, group_size=32, lm_head=True)):The same flow also passes on a tiny untied Qwen2 with
offload_to_disk=False,saving and reloading to
MarlinLinearwith finite logits.9. Reviewer notes
tests/test_lm_head.py::TestLmHeadQuant::test_quant_lm_headcannot becollected in these venvs: neither CUDA nor ROCm has
datasets, and the test'seval half needs
lm_eval. I ran its quantization half unchanged (via a localJSON-lines stand-in for
datasets.load_dataset) on the real model, shownabove. The tiny-model regression in
tests/test_checkpoint_compat.pycoversthe same path without either dependency.
tests/test_awq_dynamic_group_size.py::test_dynamic_group_size_selects_compatible_kernel_and_packsfails on
maintoo (AttributeError: 'Stub' object has no attribute '_module_format'); it is pre-existing and unrelated.fixes the metadata that caused them but does not re-measure HF logits.
loadable by vLLM
awq_marlin. That limitation is now loud at save time anddocumented, not silent.