Repository navigation
Description
Audit of main @ ffa0502, RTX 4090 and CPU. Checks the fixes for #4091 (#4101, #4103, #4110) and #4095 (#4096, #4104). Before/after comparisons use git archive trees of 0ff46b6^ and 1a3943e^.
- Hold up: fix(packing): repair hf_repack_layer and hf_pack_layer GPTQ v1 qzero format alignment (#4095) #4096, fix(interop): HF quant refusers, optimize() pickling, CPU-only max_memory, MLX masks/export (#4091) #4101 and fix(awq): validate group size against the packing kernel (#4095) #4104 (GEMM).
- Regression: fix(checkpoint): make state_dict() a real checkpoint for every kernel (#4091) #4103 (item 1).
- Incomplete: fix(checkpoint): make state_dict() a real checkpoint for every kernel (#4091) #4103 in two more places (items 2, 3), and fix(awq): replay packed calibration rows with their own mask and positions (#4091) #4110's per-document mask is never built for real HF masks (item 4).
1. Regression from #4103: HF save_pretrained() on ExLlamaV2 / Marlin / AWQ-Marlin / AWQ-ExLlamaV2 no longer raises; it writes the runtime layout, and ExLlamaV2 files reload as garbage with no error (high)
The refusals in qlinear/exllamav2.py:193, marlin.py:484, marlin_awq.py:363 and exllamav2_awq.py:157 now fire only inside checkpoint_serialization(), which only models/writer.py:744 enters. model.save_pretrained() (transformers) and torch.save(model.state_dict()) therefore serialize shuffled/repacked tensors under an ordinary GPTQ/AWQ config. docs/checkpoint-interop.md:451 still promises "save_pretrained() on a Marlin/ExLlamaV2 model → RuntimeError". AUTO on CUDA selects these kernels by default: ExLlamaV2 for asym GPTQ, Marlin for sym GPTQ and AWQ.
Llama-3.2-1B-Instruct GPTQ 4-bit g128 asym, default load:
HEAD: kernel ['ExllamaV2Linear']; before ' Paris.\nThe capital of France is Paris'
model.model.save_pretrained(...): OK (no error)
reloaded: ' flags flags flags flags flags flags flags flags'
pre-4103: save_pretrained raised RuntimeError: ExLlamaV2 shuffles `qweight` ...
Marlin (GPTQ-4bits-gp128): save OK -> reload ValueError: Trying to set a tensor of shape [0] in "g_idx"
AWQ-Marlin: save OK -> reload qweight shape error (pre-4103: raised at save)
state_dict() of ExLlamaV2 model -> fresh TORCH model: max logit diff 24.6-33.7 (v1, v2, asym, desc_act, asym-v2)
Fix: keep refusing by default, with an explicit read-only scope for PEFT, or have GPTQModel.load run the HF model's save_pretrained inside checkpoint_serialization(). At minimum, record the runtime layout in the state-dict metadata so a reload fails loudly. tests/test_checkpoint_state_invariant.py:327-346 only asserts the raise inside an explicit scope; add a test that calls model.save_pretrained().
2. #4103 incomplete: AWQ CPU kernels (CPU AUTO default for AWQ) still serialize int4pack runtime tensors (medium)
Only GPTQQuantLinear._save_to_state_dict (qlinear/__init__.py:1346) emits the snapshot. AWQuantLinear (:2304) has no hook. torch_fused_awq.py:395, torch_aten_kernel_awq.py:282 and torch_cpu_avx512_awq.py:279 capture _fused_train_state, but nothing writes it out, although checkpoint-interop.md:96 says these kernels "emit the captured checkpoint snapshot".
CPU, Llama-3.2-1B-Instruct-AWQ, AUTO -> ['TorchCpuAvx512AwqLinear'], after an eval forward:
save_pretrained: OK (no error)
reload: ValueError Trying to set a tensor of shape torch.Size([2048, 4096]) in "qweight" (which has shape torch.Size([8192, 256]))
same for AWQ_TORCH_FUSED and AWQ_TORCH_ATEN (pre-4103 identical -> incomplete fix, not a regression)
The AWQ cases in test_checkpoint_state_invariant.py never reach the transform: the modules stay training=True and qweight stays (128, 8). Fix: move _write_fused_train_state_snapshot up to PackedGroupedQuantLinear (or add it to AWQuantLinear).
3. #4103 incomplete (#4091 item 3): the v1↔v2 copy is exact only while state_dict._metadata survives (low-medium)
The qzeros layout now lives only in non-tensor metadata (_write_state_dict_layout_metadata / _incoming_qzeros_format). A safetensors round trip (Trainer/accelerate checkpoints) or any {k: v.to(dev) for k, v in sd.items()} drops it:
A = Llama-1B GPTQ v1, B = HF-GPTQV2 checkpoint, TORCH kernel, max logit diff after A.load_state_dict(B's sd):
torch.save path 0.0 | safetensors round trip 25.646 | dict copy 25.646 | B<-A safetensors 26.656 (same as the pre-fix numbers in #4091)
Fix: store the layout in a tensor, either a persistent qzeros_format int buffer or a tensor-encoded _extra_state.
4. #4110 incomplete: the per-document mask is never built for real padded bs>1 SDPA bool masks (Qwen2, Llama) (low; no measured PPL loss)
HF bool masks keep pad keys masked, but pad query rows still see real keys. So allowed_grid.any(-1) (awq_processor.py:1372-1373, :1387) counts all B·S rows, the != row_count check fails, and the code always takes the fallback at :1458: one causal sequence across the whole batch.
right-padded mask (2,1,8,8) bool: real rows 11, B*S 16; a pad query row sees keys [0, 1, 2]; structure: None
bs=4 calibration: structure recovered in 0/56 calls on Qwen2.5-0.5B and Llama-3.2-1B (keep_sum 1124 vs rows 993); Gemma-3: 56/56
Fix: derive the keep mask from the diagonal, since a real token always attends to itself. With that fix PPL doesn't improve (Qwen bs4 24.21 → 24.62, Llama 21.80 → 21.89), so the cost is the dead code path and an inaccurate claim in the PR, not accuracy. tests/test_awq_weight_mean.py::test_awq_token_rows_replay_mask_stays_inside_each_document uses a hand-built mask with fully masked pad rows, unlike real HF masks.
Plausible, not verified
- fix(awq): replay packed calibration rows with their own mask and positions (#4091) #4110 positions are dead code for HF attention.
_sanitize_kwargs(awq_processor.py:3684) dropsposition_ids(Qwen2/Llama/Gemma3 attention doesn't take it), and_prepare_module_forward:3269-3272rebuilds RoPE fromarange(packed_len). Restoring the positions gives mixed PPL results (gemma bs1 45.39 → 43.03, bs4 45.59 → 47.03; qwen bs1 24.03 → 24.50). - MACaQ Triton vs Torch: max logit diff 5.84 on the same Qwen-0.5B checkpoint (top-1 identical).
- MLX
pad_token_idfallback: it strips leading and trailing pad ids, which can remove a BOS when bos == pad (static review).
Checked, clean
state_dictround trips (self, cross-kernel, safetensors andsave_pretrained) are exact for:- TORCH/TRITON: v1, asym, v2, desc_act g32 and dynamic;
- GPTQ TorchFused/Aten/AUTO on CPU ([BUG] Follow-up on #4071/#4082/#4083/#4085: AWQ batch_size>1 crash (regression), CPU AUTO kernels corrupt state_dict (inf/NaN), v1<->v2 state_dict copy, PEFT on Marlin, HF random weights for exl3/gguf, MLX batched generate #4091 item 2 fixed);
- AWQ GEMM/GEMM_TRITON, EXL3, GGUF, FP8, NF12, QQQ, MACaQ and ParoQuant.
- PEFT on Marlin and ExLlamaV2 loads and re-saves ([BUG] Follow-up on #4071/#4082/#4083/#4085: AWQ batch_size>1 crash (regression), CPU AUTO kernels corrupt state_dict (inf/NaN), v1<->v2 state_dict copy, PEFT on Marlin, HF random weights for exl3/gguf, MLX batched generate #4091 item 4 fixed).
- fix(packing): repair hf_repack_layer and hf_pack_layer GPTQ v1 qzero format alignment (#4095) #4096:
hf_repack_layerto TRITON/FUSED/ATEN/AVX512/TORCH matches (rel ≤ 3e-3) for v1, asym, v2 and desc_act.hf_pack_layerwrites correct qzero words for gptq and gptq_v2, with and withoutpost_init. - fix(awq): validate group size against the packing kernel (#4095) #4104: Phi-tiny-MoE AWQ GEMM retunes 1536 modules to g64 (PPL 11.66 AUTO / 11.61 GEMM_TRITON). OLMoE needs no retune (11.39).
- fix(awq): replay packed calibration rows with their own mask and positions (#4091) #4110 AWQ bs=1 vs bs=4 PPL (RTN): Qwen 24.03 / 24.21 (24.82), gemma-3 45.39 / 45.59 (48.01), Llama 21.88 / 21.80 (24.49).
- fix(interop): HF quant refusers, optimize() pickling, CPU-only max_memory, MLX masks/export (#4091) #4101: every
max_memorycombination behaves. Pickle/deepcopy afteroptimize()works for TORCH and FP8.
🤖 Generated with Claude Code
Activity
fix(awq): preserve the captured mask form and fallback precedence (#4121
fix(checkpoint): refuse runtime-layout HF saves, emit AWQ snapshots, …
Qubitium commentedon Nov 15, 2026
All four items are now on
main:save_pretrained()refusing again on ExLlamaV2/Marlin/AWQ-Marlin/AWQ-ExLlamaV2, AWQ CPU kernels emitting the checkpoint snapshot, and the v1↔v2 layout surviving a safetensors round trip — PR fix(checkpoint): refuse runtime-layout HF saves, emit AWQ snapshots, carry layout in a tensor (#4125) #4134.bs>1SDPA bool masks — PR fix(awq): preserve the captured mask form and fallback precedence (#4121, #4125) #4131.Item 1 was the serious one: #4103's refusals had been scoped to
checkpoint_serialization(), which onlymodels/writer.pyenters, so a plainmodel.save_pretrained()wrote shuffled tensors and the reload silently produced' flags flags flags flags flags flags flags flags'instead of raising. The reason it shipped: the regression test only asserted the raise inside an explicit scope and never calledmodel.save_pretrained(). That gap is now covered directly.Item 4's root cause is worth recording because it was a wrong-shape check rather than a wrong idea: HF bool masks keep pad keys masked but pad query rows still see real keys, so
allowed_grid.any(-1)counted allB·Srows, the row-count check never matched, and the code silently fell back to one causal sequence across the whole batch. The keep-set now comes from the grid diagonal. Measured side effect: AWQbatch_size=4PPL on Qwen2.5-0.5B moved 25.52 → 25.13 (bs=1unchanged at 22.09, RTN 22.77).Closing as resolved.
fix(checkpoint): stop HF save_pretrained from writing qzeros_format m…
test: realign ROCm suite expectations, thread-cap probe and qzeros ma…