You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] detach_cpu_operand clones every operand: #4842/#4849 regressed two #4395 int4pack snapshot assertions (scales must keep its identity) #4876
detach_cpu_operand (gptqmodel/nn_modules/qlinear/__init__.py) was introduced by #4842/#4849 for #4785: a CPU load keeps quantized tensors as zero-copy views of the shard's safetensors mapping, and a single surviving view pins every page the loader touched, so the int4 repack detaches scales/g_idx/bias.
The helper clones unconditionally, which regressed two #4395 assertions on main:
Both fail at assert module.scales is live_scales — the int4pack transform must not rebind or clone the checkpoint scales buffer, which is the whole point of #4395 item 1 (the byte-identical second copy was removed). The clone also defeats the module's own snapshot dedup accounting: scales becomes a second private allocation.
Not caused by #4785's fix — #4785 still needs a copy for a tensor that really aliases the checkpoint mapping.
Expected
detach_cpu_operand copies only a tensor that aliases the checkpoint, and returns a module-owned tensor unchanged. A file-backed torch storage (from safetensors or torch.frombuffer over an mmap) is non-resizable; an ordinary allocation is resizable, which is exactly the distinction that matters here.
Non-CPU tensors, None, and non-tensors pass through unchanged, as before.
Test that should have caught it
A unit test on the helper itself: a private tensor must keep its identity, and a tensor bound to a real mmap must be copied with equal values. The #4785 regression test (tests/kernels/test_cpu_int4_mmap_detach_4785.py) only covers the mmap side, and the #4395 test only covers the module side, so nothing pinned the discriminator.
Found while rebasing a stale #4785 branch; recorded on #4843.
Agent claim:agent-root-4876-detach is working on this issue now.
Started 2026-11-17T17:53:32Z. 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: make detach_cpu_operand copy only file-backed (non-resizable) storages so module-owned scales keep their identity
75feee538 (#4878) landed the same fix: detach_cpu_operand now copies only a non-resizable (checkpoint-backed) storage, so a module-owned tensor keeps its identity. Verified on main @ d8758c482:
Both test_int4pack_snapshot_drops_duplicate_operands[torch_aten] and [awq_torch_aten] are green, and the #4785 mmap detach contract still holds. My duplicate PR #4883 is closed.
Fixed by #4878 (squash-merged). detach_cpu_operand now clones only a storage that aliases the checkpoint (not storage.resizable()); module-owned tensors keep their identity, so the #4395scales is live_scales assertions are green again while #4785 still detaches the mmap-backed operands.
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4876is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4876-detachis working on this issue now.Started 2026-11-17T17:53:32Z. 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: make detach_cpu_operand copy only file-backed (non-resizable) storages so module-owned scales keep their identity
Qubitium commentedon Nov 17, 2026
Agent claim released — already fixed.
75feee538(#4878) landed the same fix:detach_cpu_operandnow copies only a non-resizable (checkpoint-backed) storage, so a module-owned tensor keeps its identity. Verified onmain@d8758c482:Both
test_int4pack_snapshot_drops_duplicate_operands[torch_aten]and[awq_torch_aten]are green, and the #4785 mmap detach contract still holds. My duplicate PR #4883 is closed.Qubitium commentedon Nov 17, 2026
Fixed by #4878 (squash-merged).
detach_cpu_operandnow clones only a storage that aliases the checkpoint (not storage.resizable()); module-owned tensors keep their identity, so the #4395scales is live_scalesassertions are green again while #4785 still detaches the mmap-backed operands.fix(cpu): detach the Fused and Paro int4 operands from the checkpoint…
fix(cpu): detach the Fused and Paro int4 operands from the checkpoint…
fix(cpu): copy a checkpoint operand only when it aliases the shard ma…