Repository navigation
fix(packing): restore GPTQ runtime zeros and preserve repack buffer dtypes - #3845
Merged
Merged
Conversation
…types - hf_post_init restores the v2 runtime zero-point layout for GPTQ kernels that require it, matching hf_pack_layer(post_init=True) after a split pack/initialize lifecycle. - hf_repack_layer keeps floating checkpoint buffers at the source storage width instead of narrowing them into FP16 target allocations; dtype only selects the activation/output dtype. - hf_pack_layer routes kernels that declare METHOD.AWQ to their AWQ packer, so AllSpark (QUANT_TYPE="allspark") is no longer rejected for lacking pack_original.
ZX-ModelCloud
force-pushed
the
fix/3822-hf-packing-helpers
branch
from
November 13, 2026 09:02
f7e546f to
92167ad
Compare
ZX-ModelCloud
added a commit
that referenced
this pull request
Nov 13, 2026
Restore the import order required by ruff after #3845 so the repository lint gate passes again.
Qubitium
pushed a commit
that referenced
this pull request
Nov 13, 2026
…ough (#3846) * fix(writer): accept safe nested per-layer shard paths in EXL3 passthrough The EXL3 native checkpoint passthrough builder rejected every index shard entry whose name was not a bare basename. The public reshard() per-layer layout emits nested paths such as model.layers.0/layer.safetensors, so a valid resharded source could not be published. Accept safe relative paths while still rejecting absolute or drive-qualified paths, backslashes, NUL bytes, and empty, "." or ".." components. Hugging Face snapshot symlinks that resolve outside the source root remain permitted. Adds regression coverage for the reshard() layout and for rejected unsafe paths. * chore(lint): sort quantizer imports in gptq.py Restore the import order required by ruff after #3845 so the repository lint gate passes again.
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.
TL;DR
Fixes three backend-contract failures in the stable
hf_packing helpers. Net diff: 3 files, +310/−17. The helpers now (1) restore the GPTQ v2 runtime zero-point layout in the standalonehf_post_init, (2) preserve source checkpoint buffer dtypes acrosshf_repack_layer, and (3) dispatch AWQ kernels by declared method instead of aQUANT_TYPEname prefix.Closes #3822.
1. The problem
1.1 Split pack/init decoded GPTQ zero points one scale high
hf_pack_layer(..., post_init=False)(the default) leaves agptqcheckpoint request in the v1 export layout. The inlinepost_init=Truepath converts v1→v2 beforepost_init(), but the standalonehf_post_initonly calledpost_init().hf_post_initcalledpost_init()directly (gptqmodel/utils/packing.py:721and:726at base)_restore_gptq_runtime_qzerosruns first (:248)post_init()A zero-weight 128×64
TorchLinear(bits=4, group_size=32, sym=True)returned128per output channel afterhf_post_initinstead of0.1.2 Repack narrowed checkpoint buffers to FP16
hf_repack_layer'sdtypeargument selects the target kernel's activation/output dtype. The copy path used plainload_state_dictinto buffers the target allocated at its own width (the AWQ target allocates FP16), so a BF16 bias65536becameinfand a2**-30FP32 scale became0.load_state_dictcast into target allocations (:785-786at base)_preserve_checkpoint_buffer_dtypesretargets shared floating buffers to the source dtype first (:819,:828)1.3 AllSpark AWQ was rejected by the dispatcher
AllSparkAwqLineardeclaresMETHOD.AWQandQUANT_TYPE="allspark"and providespack(). The dispatcher recognized AWQ only by theawq_/llm-awqname prefix, then requiredpack_originaland raised.QUANT_TYPEprefix only (:577at base)METHOD.AWQ in SUPPORTS_METHODS(:609)ValueError: does not implement a supported packing pathpack()2. The new flow
flowchart TD A["hf_pack_layer(module, ...)"] --> B{"QUANT_TYPE == 'qqq'?"} B -->|yes| C["module.pack(linear, scales, s_extra)"] B -->|no| D{"AWQ backend?<br/>QUANT_TYPE prefix OR METHOD.AWQ declared"} D -->|yes| E["module.pack(linear, scales, zeros, g_idx)"] D -->|no| F{"hasattr(module, 'pack_original')?"} F -->|no| G["raise ValueError"] F -->|yes| H["pack_gpu / pack_block / pack_original"]flowchart LR A["hf_pack_layer(post_init=False)"] --> B["v1 checkpoint words<br/>qzero_format() == 1"] B --> C["hf_post_init(module or container)"] C --> D{"GPTQ and REQUIRES_FORMAT_V2<br/>and qzero_format() == 1?"} D -->|yes| E["convert_gptq_v1_to_v2_format_module"] D -->|no| F["skip"] E --> G["module.post_init()"] F --> Gflowchart TD A["hf_repack_layer(source, backend, dtype=...)"] --> B["_instantiate_kernel(target_cls)"] B --> C["target buffers at kernel default width"] C --> D["_copy_packed_state(source, target)"] D --> E{"shared floating buffer<br/>source dtype != target dtype?"} E -->|yes| F["retarget buffer to source dtype"] E -->|no| G["keep target width"] F --> H["load_state_dict copies checkpoint values"] G --> H H --> I["post_init() applies kernel ABI conversion"]3. Failure and ambiguity contract
hf_post_initon a v1-layoutREQUIRES_FORMAT_V2GPTQ layerpost_init()hf_post_initon a kernel withoutREQUIRES_FORMAT_V2(Marlin, ...)hf_repack_layerwith BF16/FP32 source bufferspost_init()still applies its ABI conversionhf_pack_layeron a kernel declaringMETHOD.AWQwithout anawq_prefixValueErrorpack()hf_pack_layeron a GPTQ kernel withoutpack_originalValueError4. Change inventory
gptqmodel/utils/packing.pytests/test_hf_packing_api.pydocs/hf_packing_api.md5. Tests
test_hf_post_init_restores_gptq_v2_runtime_layout[layer/container]qzero_format() == 2test_hf_repack_layer_preserves_awq_bfloat16_checkpoint_buffers65536survives; output finite and equal to sourcetest_hf_repack_layer_preserves_awq_fp32_checkpoint_scales2**-30FP32 scale does not underflow to zerotest_hf_pack_layer_dispatches_allspark_awqhf_pack_layeroutput matches directpack()6. Validation
pytest tests/test_hf_packing_api.py -q: 54 tests, all pass or skip as expected.pytest tests/test_packing_numeric_boundaries.py tests/test_hf_packing_api.py -q: 163 passed, 2 skipped.7. Reviewer notes
post_init()(for example ExLlamaV2's FP16 scales).QUANT_TYPEprefix match as a fallback so existingawq_*kernels are unaffected.