Repository navigation
fix(int8): crop padded input rows in the cold GPTQ source decode - #4503
Merged
Merged
Conversation
The packed INT8 layout pads the input-channel axis to the pack factor, so in_features=17 stores 20 decoded rows. transform_cpu() cropped them when it built the runtime view, but _dequantize_gptq_source_weight() reshaped all 20 and then subtracted per-channel zeros with 17 rows: RuntimeError: The size of tensor a (20) must match the size of tensor b (17) Any .to(...)/_apply drops the runtime view, so dequantize_weight() (and therefore explicit export) failed depending on call order. Crop to in_features and fail loudly if the buffers decode fewer rows than that.
This was referenced Nov 17, 2026
Closed
Collaborator
Author
|
Follow-up: the two pre-existing Tracked in #4511 and fixed by #4512: group codes are now zero-padded to the kernel alignment. |
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.
Summary
Fixes #4483. The packed INT8 layout pads the input-channel axis up to the pack factor, so
in_features=17stores 20 decoded rows.transform_cpu()cropped them toin_featureswhen it built the runtime view, but_dequantize_gptq_source_weight()reshaped all 20 and then subtracted per-channel zeros with 17 rows:BaseQuantLinear._applydrops the runtime view on any dtype/device apply, so explicit dequantization and export failed depending on call order.K=16was unaffected, which is why the aligned widths in the suite never hit it.What Changed
gptqmodel/nn_modules/qlinear/torch_int8.py: crop the decoded rows toself.in_featuresbefore indexing the per-channel groups, matching whattransform_cpu()already does for the runtime view. If the buffers decode fewer rows thanin_features, raise a clearRuntimeErrorinstead of the opaque size-mismatch error.tests/test_torch_int8_tail_padding_4483.py(new):K=17/18/19cold-vs-warm decode equality plus an independent value oracle, forward oracle after cache invalidation, and an alignedK=16control.No API change.
Tests
CPU-only (
GPTQ_BYPASS_SAFETY_CHECKS=1,CUDA_VISIBLE_DEVICES="",PYTHONPATH= worktree):The three cold-decode cases fail on unmodified
mainwith the reportedRuntimeError: The size of tensor a (20) must match the size of tensor b (19)and pass with the fix.tests/kernels/test_torch_int8.py::test_native_int8_negative_g_idx_matches_checkpoint_decodeand::test_native_int8_scale_cast_does_not_destroy_canonical_precisionalso fail on unmodifiedmainin this environment (same assertions,test_torch_int8.py:570); they are pre-existing and unrelated to this diff.Notes
dequantize_weight()is the only caller of_dequantize_gptq_source_weight(), and the forward path rebuilds the runtime view before decoding, so nothing else depended on the padded row count._cached_int8_dequantize) is unchanged; this only aligns the cold source path with it.