Repository navigation
fix(packing): repair hf_repack_layer and hf_pack_layer GPTQ v1 qzero format alignment (#4095) - #4096
Merged
Qubitium merged 1 commit intoNov 15, 2026
Conversation
…format alignment (ModelCloud#4095) In _copy_packed_state(), copy live named buffers and parameters directly instead of calling source.state_dict(). state_dict() produces checkpoint-converted v1 zero points, which previously caused repacked modules that decode v2 zero points to decode every zero point one step low. Propagate _checkpoint_format_on_disk from source to target during _copy_packed_state() so targets preserve their serialization layout. In _restore_gptq_runtime_qzeros(), set _checkpoint_format_on_disk = FORMAT.GPTQ when converting v1 checkpoint words to v2, ensuring save_pretrained() and state_dict() emit proper v1 words instead of v2 words under a v1 label. In hf_pack_layer(), record _checkpoint_format_on_disk for GPTQ formats. Add regression test test_hf_repack_layer_preserves_gptq_v1_zero_points and assertions to test_hf_pack_layer_post_init_restores_v2_runtime_layout and test_hf_post_init_restores_gptq_v2_runtime_layout. Signed-off-by: Prajwal7-2002 <[email protected]>
Qubitium
added a commit
that referenced
this pull request
Nov 15, 2026
main now carries #4101 (d7a41a1) and #4096 (c73793c) in squashed form. The only conflict is tests/test_checkpoint_interop_4053.py, which both #4101 and this branch extend. Resolution: * kept both new test sets: main's test_hf_from_pretrained_refuses_every_refused_method (#4091 item 5) and this branch's test_runtime_layout_state_dict_is_readable_but_checkpoint_writes_refuse (item 4) + test_state_dict_copy_between_v1_and_v2_models (item 3). * dropped only test_runtime_layout_kernels_refuse_state_dict, which #4101 inherited byte-identical from main and never edited. It asserts an unconditional raise from Marlin/ExLlamaV2 `_save_to_state_dict`, which is the exact contract item 4 changes. Both of its assertions (marlin and exllamav2 raise "cannot be reconstructed") are preserved and strengthened by the parametrized replacement, which asserts the same raise under `checkpoint_serialization()` *and* that a read-only collection succeeds. * removed one duplicate copy of test_hf_from_pretrained_refuses_every_refused_method: this branch already carried it from the earlier pr4101 merge, so taking main's copy as well defined it twice (ruff F811). One copy remains, identical to main. Merged test inventory: 15 test functions / 26 collected cases, none of this branch's and none of main's new tests lost.
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 #4095 (items 1-2)
Summary
This PR covers items 1 and 2 of #4095:
hf_repack_layerzero-point alignment: copy live named buffers and parameters directly instead of callingsource.state_dict().source.state_dict()produces checkpoint-converted v1 zero points, which caused repacked modules that decode v2 zero points to decode every zero point one step low._checkpoint_format_on_diskfrom source to target during_copy_packed_state()so targets preserve their serialization layout._restore_gptq_runtime_qzeros(), set_checkpoint_format_on_disk = FORMAT.GPTQwhen converting v1 checkpoint words to v2, ensuringsave_pretrained()andstate_dict()emit proper v1 words instead of v2 words under a v1 label.hf_pack_layer(), record_checkpoint_format_on_diskfor GPTQ formats.What Changed
gptqmodel/utils/packing.py:_copy_packed_state()to copy raw named parameters and buffers rather than callingsource.state_dict()._checkpoint_format_on_diskfrom source to target in_copy_packed_state()._restore_gptq_runtime_qzeros(), markedmodule._checkpoint_format_on_disk = FORMAT.GPTQ.hf_pack_layer(), recordedmodule._checkpoint_format_on_disk = requested_format.tests/test_hf_packing_api.py:test_hf_repack_layer_preserves_gptq_v1_zero_pointsverifying both live runtime and serializedstate_dict()zero points match identically without off-by-one shifts.test_hf_pack_layer_post_init_restores_v2_runtime_layoutandtest_hf_post_init_restores_gptq_v2_runtime_layoutverifying_checkpoint_format_on_diskand v1 serialized layout parity.Tests
pytest tests/test_hf_packing_api.py -k "test_hf_repack_layer_preserves_gptq_v1_zero_points or test_hf_pack_layer_post_init_restores_v2_runtime_layout or test_hf_post_init_restores_gptq_v2_runtime_layout" -vOutput:
Model Support / Module Plan
Not applicable (quantization packing utility bugfix).
Logic Flow Documentation
Not applicable (bugfix aligning buffer copying and format marker persistence with existing runtime/serialization specifications).
Review Requirements
Kernel Accuracy Requirements
state_dict()outputs.