Repository navigation
Conversation
A safetensors load hands the CPU int4 modules zero-copy views of the shard mapping. The first-forward repack replaces qweight/qzeros with anonymous runtime tensors but kept g_idx, and on the ATen/fused kernels the checkpoint-dtype scales and bias, as views of the file. Each surviving view pins the whole shard, so every page the loader faulted in stays resident and the quantized weights are counted twice in RSS. Detach every module tensor still backed by a checkpoint file mapping at the end of the CPU int4 transform. The sweep copies only the small operands that survive the repack byte-identically; the packed weight is still rebuilt in place and never copied a second time. It runs outside inference_mode so a later load_state_dict can write the copied buffer. Non-Linux and anonymous tensors are left untouched. Measured on a synthetic 2048x8192 GPTQ layer loaded through safe_open (TorchAtenLinear, 8.3 MiB shard): - before: 2137 resident shard pages (8.3 MiB), scales + g_idx mapped - after: 0 resident shard pages, no module tensor in the mapping The same layer on unmodified main keeps all 2137 pages and both views. The regression test loads a synthetic checkpoint through safe_open, runs one forward, asserts the shard disappears from /proc/self/maps and no module tensor storage lies in a file mapping, and compares the output to the pre-repack dense result and to a repack of anonymous copies (bitwise). It fails on main for TorchAtenLinear and TorchFusedLinear and passes with this change. TorchCpuAvx512Linear is skipped on hosts without AVX512-BF16. Tests: new test 4 passed / 2 skipped; 229 passed / 111 skipped across the CPU kernel and checkpoint-state suites; the 4 AVX512-BF16 checkpoint-state failures reproduce identically on main (host lacks AVX512-BF16).
|
Closing as superseded — #4785 was fixed by #4842 ( The GPTQ CPU paths from #4785 are in The part of this PR's idea that the merged fix did not cover — a generic sweep over every tensor still backed by a checkpoint mapping — turned out to matter for the AWQ siblings, which still pinned If you want to pursue the generic sweep (detect file-backed storage instead of naming operands), it is worth its own PR against #4849's test file — that would also cover |
|
One residual gap for a separate follow-up, verified on main @
|
perf(cpu): release the checkpoint mmap after the int4 repack (#4785)
A safetensors load hands the CPU int4 modules zero-copy views of the
shard mapping. The first-forward repack replaces qweight/qzeros with
anonymous runtime tensors but kept g_idx, and on the ATen/fused kernels
the checkpoint-dtype scales and bias, as views of the file. Each
surviving view pins the whole shard, so every page the loader faulted in
stays resident and the quantized weights are counted twice in RSS.
Detach every module tensor still backed by a checkpoint file mapping at
the end of the CPU int4 transform. The sweep copies only the small
operands that survive the repack byte-identically; the packed weight is
still rebuilt in place and never copied a second time. It runs outside
inference_mode so a later load_state_dict can write the copied buffer.
Non-Linux and anonymous tensors are left untouched.
Measured on a synthetic 2048x8192 GPTQ layer loaded through safe_open
(TorchAtenLinear, 8.3 MiB shard):
The same layer on unmodified main keeps all 2137 pages and both views.
The regression test loads a synthetic checkpoint through safe_open, runs
one forward, asserts the shard disappears from /proc/self/maps and no
module tensor storage lies in a file mapping, and compares the output to
the pre-repack dense result and to a repack of anonymous copies
(bitwise). It fails on main for TorchAtenLinear and TorchFusedLinear and
passes with this change. TorchCpuAvx512Linear is skipped on hosts
without AVX512-BF16.
Tests: new test 4 passed / 2 skipped; 229 passed / 111 skipped across
the CPU kernel and checkpoint-state suites; the 4 AVX512-BF16
checkpoint-state failures reproduce identically on main (host lacks
AVX512-BF16).