Repository navigation
Description
Found on main @ c2b0bf6, x86-64 AVX512-BF16 host (CPU only, OMP_NUM_THREADS=8, torch 2.15).
#4873 was closed by #4918 (b218dce93). #4918 fixed item 3 of that issue: the Fused/Paro operands no longer pin the safetensors mmap, and I confirmed this. Items 1 and 2 were not addressed and still reproduce on main. In both cases the CPU int4 kernel keeps a full checkpoint-layout copy of qweight (_fused_train_state_qweight) for the life of the model, even though a bitwise inverse exists. I verified both inverses below.
1. TorchCpuAvx512AwqLinear (CPU AUTO for bf16 AWQ) keeps the full qweight snapshot
gptqmodel/nn_modules/qlinear/torch_cpu_avx512_awq.py:40: _FUSED_TRAIN_STATE_REBUILD = None ("no verified inverse").
2. GPTQ desc_act checkpoints on TorchAtenLinear / TorchFusedLinear keep the full qweight snapshot
gptqmodel/nn_modules/qlinear/__init__.py:1334-1341 (_can_rebuild_checkpoint_qweight): the kind == "gptq" branch returns False whenever ret_idx is not the identity. The comment says the ATen transform reorders rows "without keeping the gather". However, the module does keep ret_idx: it is an attribute of every transformed module (attr:ret_idx below). Scattering the unpacked codes back through it is an exact inverse, the same thing rebuild_avx512_qweight already does for the AVX512 kind.
This path is not opt-in. AUTO with dtype=torch.float16 on CPU selects TorchAtenLinear.
Measured
GPTQModel.load(ckpt, backend=..., dtype=..., device="cpu"), then one forward of 1/7/64 tokens. Tensor bytes are unique storages of params, buffers and tensor attributes.
ckpt backend / kernel dtype ckpt MiB tensors after fwd MiB snapshot MiB RSS after fwd
Meta-Llama-3.1-8B-Instruct-GPTQ-INT4 GPTQ_TORCH_ATEN (TorchAtenLinear) bf16 5470 9216 3354 10.29 GB
(desc_act=True) GPTQ_TORCH_FUSED (TorchFusedLinear) bf16 5470 9216 3354 10.29 GB
AUTO (TorchAtenLinear) fp16 5470 9008 3354 12.54 GB
AUTO (TorchCpuAvx512Linear) bf16 5470 5732 130 6.80 GB <- fixed path, for comparison
Qwen2.5-0.5B-Instruct AWQ 4-bit g128 AUTO (TorchCpuAvx512AwqLinear) bf16 437 621 177 -
AWQ-Llama-3.2-1B-g128-gemm AUTO (TorchCpuAvx512AwqLinear) bf16 - - 464 (qweight) -
Qwen2.5-0.5B-Instruct GPTQ desc_act GPTQ_TORCH_ATEN / GPTQ_TORCH_FUSED bf16 438 631 172 -
The 8B desc_act checkpoint on ATen/Fused holds +3.28 GiB of host RAM (1.68x the checkpoint) that the AVX512 path no longer holds.
Verified inverses (bitwise against the snapshot buffer the module holds)
# item 2: GPTQ desc_act, ATen/Fused (runtime int4pack -> checkpoint qweight)
from gptqmodel.nn_modules.qlinear._cpu_int4pack_layout import int4pack_to_codes
codes = int4pack_to_codes(mod.qweight) # [out, in], runtime (ret_idx) order
ret_idx = mod._build_ret_idx().to(torch.long)
restored = torch.empty_like(codes); restored.index_copy_(1, ret_idx, codes)
grouped = restored.t().reshape(-1, mod.pack_factor, mod.out_features).to(torch.int32)
packed = torch.zeros((grouped.shape[0], mod.out_features), dtype=torch.int32)
for i in range(mod.pack_factor):
packed.bitwise_or_(grouped[:, i, :] << (i * mod.bits))
assert torch.equal(packed, mod._fused_train_state_qweight)
# item 1: AWQ AVX512
from gptqmodel.nn_modules.qlinear.torch_cpu_avx512 import unpack_hf_int4
from gptqmodel.quantization.awq.utils.packing_utils import pack_awq_columns, AWQ_ORDER
codes = unpack_hf_int4(mod.qweight, out_features=mod.out_features, in_features=mod.in_features)
assert torch.equal(pack_awq_columns(codes.t().to(torch.int32), mod.bits, order=AWQ_ORDER),
mod._fused_train_state_qweight)Results:
Meta-Llama-3.1-8B-Instruct-GPTQ-INT4 GPTQ_TORCH_ATEN 224/224 modules bitwise equal (all non-identity ret_idx)
Meta-Llama-3.1-8B-Instruct-GPTQ-INT4 GPTQ_TORCH_FUSED 224/224
Qwen2.5-0.5B-Instruct GPTQ desc_act GPTQ_TORCH_ATEN 168/168, GPTQ_TORCH_FUSED 168/168
Qwen2.5-0.5B-Instruct AWQ AUTO (AVX512 AWQ) 168/168
AWQ-Llama-3.2-1B-g128-gemm AUTO (AVX512 AWQ) 112/112
Suggested fix
- Item 2: in
rebuild_gptq_qweight, scatter the codes back throughret_idxwhen_ret_idx_is_identity()is False, as in the snippet above. Then drop thekind == "gptq" and not identity()early return in_can_rebuild_checkpoint_qweight._rebuild_layout_keyalready tags this case"reordered", so the once-per-layout verify from perf(cpu): verify the int4pack inverse once per layout instead of rebuilding every qweight (#4884) #4965 keys it separately. - Item 1: give
TorchCpuAvx512AwqLineara rebuild kind backed byunpack_hf_int4+pack_awq_columns(..., order=AWQ_ORDER).ParoLinear._rebuild_checkpoint_qweight(avx512 layout) already uses this pair. Callfinalize_fused_train_stateat the end of itstransform_cpu. finalize_fused_train_statekeeps the bitwise guard, so a wrong inverse still falls back to the clone.
Test that should have caught it
tests/test_cpu_int4_snapshot_dedup_4395.py does not cover desc_act on ATen/Fused or the AWQ AVX512 class. Parametrize it over all CPU int4pack classes with desc_act in {False, True}, and assert that no _fused_train_state_qweight buffer stays resident after the first forward.
Severity
Medium. +3.28 GiB host RAM (+68%) on an 8B desc_act GPTQ model with the CPU ATen/Fused kernels, including the default AUTO + fp16 CPU load. Bf16 AWQ on CPU AUTO holds 2.0x its quantized-linear bytes (177 MiB of snapshot next to 178 MiB of packed weights on Qwen2.5-0.5B, 464 MiB on Llama-3.2-1B). This is the residue of #4783/#4873.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-5013is working on this issue now.perf(cpu): drop the int4 qweight snapshot where the inverse is exact (#…
Qubitium commentedon Nov 17, 2026
Agent release:
agent-root-5013finished this issue. Fix: #5033, squash-merged as2620daf28.Both remaining CPU int4 layouts now drop the resident
qweightclone, because both inverses are exact:desc_act(TorchAtenLinear/TorchFusedLinear) —_can_rebuild_checkpoint_qweightno longer bails out for a non-identityret_idx. The transform packsweight.index_select(0, ret_idx)and the module keepsret_idx(argsort(g_idx), a permutation of[0, in_features)), soindex_copy_with that index is the exact inverse.AUTOwithdtype=torch.float16on CPU selects this kernel, so this was the non-opt-in case.TorchCpuAvx512AwqLinear— newrebuild_avx512_awq_qweight, the pure-Torch inverse of the extension'spack_awq_int4(reverse nibble read pluspack_awq_columns(..., order=AWQ_ORDER)).transform_cpunow ends withfinalize_fused_train_state, and_FUSED_TRAIN_STATE_REBUILD = "avx512_awq".Both are still fail-closed: the clone is only released after
finalize_fused_train_staterebuilds the checkpoint words and compares them bitwise with the pre-transform clone; a mismatch keeps the clone.Verification:
tests/test_cpu_int4_snapshot_5013.py(17 nodes): 17 failed on unmodifiedmain@8fd8644a1(neither inverse existed) → 16 passed, 1 skipped on the branch, where the skip is the cross-check against the real extensionpack_awq_int4(needs AVX512-BF16). It covers theret_idxscatter against an independent checkpoint-word oracle (group sizes 32/128), the drop + bitwise-identicalstate_dict()for both GPTQ kernels, the AVX512 AWQ nibble inverse over all 32 bits of every word (5 shapes), the realtransform_cpupath, and both fail-closed cases. The file now runs in the AWQ CPUunitCI lane.2620daf28: 70 passed, 1 skipped across the new file plustest_cpu_int4_snapshot_dedup_4395.py,test_cpu_int4_verify_cost_4884.pyandtest_docs_contract_refs.py. CI: 9/9 green (AWQ CPU unit 1054 passed / 110 skipped).Measured (Qwen2.5-0.5B-Instruct, 4-bit g128
desc_act, CPU fp16TorchAtenLinear, unique tensor storages before/after one forward):_fused_train_state_qweightbuffersorigin/mainThe residual 1.3 MiB is the
qzerossnapshot, which this change does not touch.Caveat stated in the PR: this host has no AVX512-BF16, so the AWQ AVX512 extension kernel cannot load. The AWQ inverse is verified against a line-by-line Python mirror of
int4_qzero_group_scaled_pack.cpp(cross-checked against the real kernel automatically on a host that has it) and the module-level test drives the realtransform_cpuwith that mirror installed as the pack kernel. No AVX512 end-to-end claim. The issue's 8B numbers could not be reproduced here (no 8Bdesc_actcheckpoint cached); the 0.5B delta is the same mechanism at 1/16 the width.