Repository navigation
fix(awq): decode 8-bit packed readers in natural order (#3974) - #3993
Merged
Merged
Conversation
This was referenced Nov 14, 2026
Merged
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 #3974
TL;DR
AWQ only interleaves the 4-bit packed layout. The 8-bit Marlin repack (Python and CUDA), the Machete un-interleave, and
convert_awq_fileall assumed the INT4 interleave existed for 8-bit too, andconvert_awq_fileadditionally ignored the checkpoint width. The readers now undo the interleave only for 4-bit, decode 8-bit in natural column order, and takebitsfrom the quantization config. 4-bit behaviour is unchanged.Root cause
1. 8-bit Marlin/Machete un-interleaved data that was never interleaved
pack_awq(gptqmodel/quantization/awq/utils/packing_utils.py) uses the classic[0, 2, 4, 6, 1, 3, 5, 7]interleave only forbits == 4; every other width goes through_pack_contiguous, a plain little-endian stream.reverse_awq_orderis likewise a no-op forbits != 4, and the AllSpark reader documents that "AWQ_ORDER only applies to the 4-bit layout".The 8-bit readers disagreed:
gptqmodel/utils/marlin.py:1124-1133undo_interleave = argsort([0, 2, 1, 3])for 8-bitgptqmodel_ext/marlin/awq_marlin_repack.cu:99-105undo_pack[4] = {0, 2, 1, 3}for every non-4-bit widthgptqmodel/nn_modules/qlinear/machete_awq.py:35-45_undo_awq_interleave(..., 8)permuted with[0, 2, 1, 3]That swaps columns 1 and 2 inside every 32-bit word for both weights and zero points, so an 8-bit layer produces silently wrong output.
2.
convert_awq_fileskipped the INT4 nibble order and hardcoded 4-bitgptqmodel/utils/model_dequant.py:1569-1572unpackedqweight/qzeroswith the genericunpack_cols(lanei→ columni) and never appliedAWQ_REVERSE_ORDER, so even a 4-bit checkpoint came out with output channels permuted inside every group of 8.bits = 4was also hardcoded, so an 8-bit shard was decoded as 4-bit and crashed on the shape mismatch.Fix
awq_to_marlin_zero_points: undo the interleave only fornum_bits == 4; 8-bit goes tomarlin_zero_pointsin natural order. Unsupported widths still raise.awq_marlin_repack.cu:cur_n_pos_unpacked = cur_n_posby default; only thenum_bits == 4branch appliesundo_pack.AwqMacheteLinear._undo_awq_interleave: returns 8-bit input unchanged.convert_awq_file: new keyword-onlyconfigparameter;bits = int(config.get("bits", 4)); decodes withunpack_awq+reverse_awq_order(a no-op for 8-bit).dequantize_modelpasses itsquantization_config.docs/awq-packed-layout.md, linked fromREADME.md.Logic flow
flowchart TD A["AWQ checkpoint<br/>qweight, qzeros, scales"] --> B{"bits from config"} B -->|"4"| C["unpack contiguous words<br/>lane i to column i"] B -->|"8"| C B -->|"other"| X["raise: unsupported AWQ width"]:::fail C --> D{"bits == 4 ?"} D -->|"yes"| E["reverse AWQ interleave<br/>AWQ_REVERSE_ORDER"] D -->|"no, 8-bit"| F["identity<br/>natural order"] E --> G["dense weight<br/>out_features x in_features"] F --> G classDef fail fill:#ffdddd,stroke:#cc0000,color:#660000flowchart LR A["packed AWQ word<br/>K x N/pack"] --> B{"num_bits == 4 ?"} B -->|"yes"| C["undo AWQ interleave<br/>0,4,1,5,2,6,3,7"] B -->|"no, 8-bit"| D["identity lane index"] C --> E["Marlin / Machete layout<br/>permutation"] D --> E E --> F["quantized MMA"] classDef fail fill:#ffdddd,stroke:#cc0000,color:#660000The failure path is the
bitsguard:awq_to_marlin_zero_pointsand_undo_awq_interleaveraise for widths other than 4/8 instead of guessing a layout.Fail-before / pass-after
The new tests use an independent Torch packer and a dense
(codes - zeros) * scalesoracle; no reference value comes from the code under test. Fail-before was captured in a clean worktree atorigin/main(1a30538bc) with only the new test files applied.Before (base):
After (this branch):
The two skips are Machete (SM90-only) and Swordfish (Blackwell-only); neither can run on the RTX 4090. Machete's 8-bit decision is covered by
test_machete_undo_awq_interleave_8bit_is_identityon CPU.Full dequant test file on CUDA:
33 passed, 1 skipped, 1 failed. The single failure istest_ignored_layers_are_honored_by_non_fp8_converters, which fails identically on the base worktree becausebitsandbytesis not installed in this environment (RuntimeError: ... requires the 'bitsandbytes' package). It is unrelated to this change.CUDA and ROCm
GPU-1ece7ec2-...):test_awq_marlin_cuda_8bit_matches_dense_referencepasses forgroup_size=128andgroup_size=-1; the same layer's max error against the dense oracle moved from3.306to4.88e-4. All 4-bit Marlin tests still pass.HIP_VISIBLE_DEVICES=1): the five CPU regression tests pass,tests/kernels/test_awq_torch.pypasses (14 tests), and an 8-bit/4-bitAwqTorchLinearlayer on the GPU matches the dense oracle withmax_err=0.000000for both widths. Marlin and Machete are CUDA-only (SUPPORTS_DEVICES = [DEVICE.CUDA]), so their kernels were not executed on ROCm.Lint
(The branch is rebased onto main after #3987 fixed the known
audio.pyF401.)Reviewer notes
convert_awq_filestill assumes the GEMM packed axis (qweightis[in_features, out_features/pack]). GEMV/GEMV_FAST checkpoints pack the other axis; the issue marked that path unverified and it is not changed here.