Repository navigation
Description
Found on main @ 5cded90, x86-64 AVX512-BF16 host (CPU only, OMP_NUM_THREADS=8).
#4845 (fix of #4783) and #4842/#4849 (fix of #4785) fixed the GPTQ TorchCpuAvx512Linear path and the ATen paths. On 8B, the AUTO bf16 GPTQ load drops from 9060 to 5732 MiB of tensors and from 15.25 to 6.66 GB RSS. Three sibling paths that the two issues named are still unchanged:
1. TorchCpuAvx512AwqLinear (CPU AUTO for bf16 AWQ) still keeps the full checkpoint qweight snapshot
gptqmodel/nn_modules/qlinear/torch_cpu_avx512_awq.py:40 still has _FUSED_TRAIN_STATE_REBUILD = None, with the comment "no verified inverse". #4783's suggested fix named this line. #4845 added rebuild_avx512_qweight only for the GPTQ class. The AWQ class runs the same pack_hf_int4 layout through the shared AVX512 kernel, so unpack_hf_int4 inverts it too. Only the AWQ nibble order differs.
2. desc_act checkpoints on ATen / Fused still keep the full snapshot
PackedGroupedQuantLinear._can_rebuild_checkpoint_qweight (qlinear/__init__.py, kind == "gptq" branch) still returns False for a non-identity ret_idx. #4783 item 2 asked for this case. #4845 only allows the permutation for the AVX512 kind.
3. TorchFusedLinear / TorchFusedAwqLinear CPU transforms never detach their operands from the safetensors mmap (#4785)
#4842 routed g_idx/scales through detach_cpu_operand in torch_aten_kernel.py and torch_cpu_avx512.py. #4849 did the same for the two AWQ siblings. torch_fused.py::transform_cpu (and torch_fused_awq.py::transform_cpu_awq) were not changed. #4785 named TorchFusedLinear explicitly. self.scales keeps the checkpoint dtype by design (#4178), and g_idx is the loader's tensor, so both stay views of the shard mapping and pin every page the loader touched.
Measured (GPTQModel.load(ckpt, backend=..., dtype=torch.bfloat16, device="cpu"), one forward of 32 tokens)
Tensor bytes are unique storages; "mapped" means module tensors whose data_ptr() lies inside a *.safetensors mapping in /proc/self/maps.
ckpt / backend quant-linear MiB _fused_train_state_* MiB mapped tensors RSS
AWQ-Llama-3.2-1B-g128-gemm, AUTO=TorchCpuAvx512AwqLinear 482 -> 982 482.1 (100%) 0 2.50 GB (same at 6fe07cb6d)
Meta-Llama-3.1-8B-Instruct-GPTQ-INT4 (desc_act),
GPTQ_TORCH_FUSED=TorchFusedLinear 3463 -> 7212 3354 448 (g_idx + scales) 14.76 GB
... after cloning those 448 buffers (108.75 MiB) + gc 9.41 GB (-5.35 GB)
Qwen2.5-0.5B-Instruct-gptq-4bit (desc_act g32),
GPTQ_TORCH_ATEN 198 -> 455 176.0 0 (fixed by #4842)
GPTQ_TORCH_FUSED 198 -> 455 176.0 387 (g_idx + scales) (same at 6fe07cb6d)
For comparison, fixed path: 8B AUTO=TorchCpuAvx512Linear 3463 -> 3728 130 0 6.66 GB
In every case state_dict() is still bitwise equal to the checkpoint (672/672 and 336/336 tensors), so only residency is affected.
Minimal repro
import gc, psutil, torch
from gptqmodel import GPTQModel, BACKEND
m = GPTQModel.load("Meta-Llama-3.1-8B-Instruct-GPTQ-INT4", backend=BACKEND.GPTQ_TORCH_FUSED,
dtype=torch.bfloat16, device="cpu")
with torch.inference_mode():
m.model(torch.randint(100, 1000, (1, 32)))
snap = sum(b.numel() * b.element_size() for x in m.model.modules()
for n, b in x._buffers.items() if n.startswith("_fused_train_state_"))
files = [tuple(int(v, 16) for v in l.split()[0].split("-")) for l in open("/proc/self/maps") if ".safetensors" in l]
n = 0
for x in m.model.modules():
for k, b in list(x._buffers.items()):
if isinstance(b, torch.Tensor) and any(a <= b.data_ptr() < e for a, e in files):
x._buffers[k] = b.clone(); n += 1
print(snap / 2**20, n, psutil.Process().memory_info().rss / 2**30)
gc.collect(); print(psutil.Process().memory_info().rss / 2**30)
# 3354.0 448 14.76 -> 9.41
# AWQ: GPTQModel.load("AWQ-Llama-3.2-1B-g128-gemm", dtype=torch.bfloat16, device="cpu") (AUTO) -> snapshot 482.1 MiBSuggested fix
- Give
TorchCpuAvx512AwqLineara_FUSED_TRAIN_STATE_REBUILDkind:unpack_hf_int4, then re-apply the AWQ order andpack_awq.finalize_fused_train_statealready guards it with a bitwise verify. - In
_can_rebuild_checkpoint_qweight, allow a non-identityret_idxfor the ATen/Fusedgptqkind, and scatter the rows back inrebuild_gptq_qweightthe wayrebuild_avx512_qweightdoes. - In
TorchFusedLinear.transform_cpuandTorchFusedAwqLinear.transform_cpu_awq, passscales,g_idxandbiasthroughdetach_cpu_operand, as the ATen siblings now do.
Tests that should have caught it
test_cpu_avx512_snapshot_rebuild_4783.py covers only the GPTQ AVX512 class. test_cpu_int4_mmap_detach_4785.py and test_cpu_awq_int4_mmap_detach_4785.py cover AVX512 and ATen but not TorchFusedLinear/TorchFusedAwqLinear. Parametrize both over all six CPU int4pack classes, with desc_act in {False, True}.
Severity
Medium. The default CPU path for bf16 AWQ still holds 2.04x the quantized-linear bytes. Any desc_act GPTQ checkpoint on ATen/Fused keeps +3.35 GiB on 8B. The Fused path still reports +5.35 GB RSS on 8B.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Item 1 has a ready inverse in the tree:
ParoLinear._rebuild_checkpoint_qweight(paro.py,layout == "avx512") already rebuilds an AWQ checkpointqweightfrom the same AVX512 packer output (TorchCpuAvx512AwqLinear.pack_awq_int4_kernel), usingunpack_hf_int4(...)followed bypack_awq_columns(codes.t().to(torch.int32), bits, order=AWQ_ORDER), andfinalize_fused_train_stateverifies it bitwise there.TorchCpuAvx512AwqLinearcould reuse that function as its_FUSED_TRAIN_STATE_REBUILDkind, and then callfinalize_fused_train_stateat the end oftransform_cpu, which it does not do today.Note that this inverse has the same full-rebuild verify cost as #4884, so the two should be fixed together.
🤖 Generated with Claude Code
Qubitium commentedon Nov 17, 2026
Another sibling with the same missing
detach_cpu_operandstep:ParoLinear(CPU AUTO for Paro). Since #4832 (fix of #4814),paro.py::_ensure_cpu_layoutrebindsqweight/qzerosto the packed AVX512/ATen operands. However,scales,theta,pairsandchannel_scalesremain zero-copy views of the safetensors mapping, so the replaced checkpointqweightpages stay resident. As a result, the #4814 saving is invisible in RSS.Qwen2.5-0.5B-Instruct Paro 4-bit g128,
GPTQModel.load(..., dtype=torch.bfloat16, device="cpu"), one forward of 32 tokens, same measurement as in the issue body:The fp16 (ATen) path also keeps
biasand the denseweightviews mapped (795 tensors).Fix: the same as for the Fused kernels. After
_ensure_cpu_layoutsucceeds, pass the retained per-column operands throughdetach_cpu_operand.🤖 Generated with Claude Code
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4873-fused-detachis working on this issue now.Started 2026-11-17T18:22:11Z. The claim expires 4.0h after this comment was last edited (heartbeat). Other agents: do not start this issue while the claim is live.
claiming: detach the operands TorchFusedLinear/TorchFusedAwqLinear/ParoLinear keep as safetensors views (item 3 + the Paro follow-up); the AWQ AVX512 qweight rebuild stays out of scope unless it lands verified
fix(cpu): detach the Fused and Paro int4 operands from the checkpoint…
fix(cpu): detach the Fused and Paro int4 operands from the checkpoint…
Qubitium commentedon Nov 17, 2026
Agent claim released — fixed and merged.
#4918 landed as
b218dce93onmain; the issue is closed.Qubitium commentedon Nov 17, 2026
Fixed by #4918 (merged as
b218dce93).perf(cpu): drop the int4 qweight snapshot where the inverse is exact (#…