Skip to content

perf(weight_loader): stop msyncing in-session file-backed offload writes - #6610

Merged
Qubitium merged 1 commit into
mainfrom
perf/filebacked-no-msync
Dec 1, 2026
Merged

Qubitium merged 1 commit into
mainfrom
perf/filebacked-no-msync

Conversation

@Qubitium

@Qubitium Qubitium commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

write_safetensors (gptqmodel/weight_loader/filebacked.py) flushed its mmap with msync(MS_SYNC) on every call, durable or not. Disk offload (offload_to_disk, the quantization default) backs every module with an in-session file through file_back_module. So each offloaded module blocked the quantization thread on the disk. This is a performance regression from #6473; there is no correctness change.

The page cache already serves every later reader of the file (Linux's cache is unified), and the kernel writes dirty pages back on its own. A process kill loses nothing, and the old msync without a directory fsync never protected against an OS crash. Now only durable=True writes flush; those still fsync too.

Found while profiling #6605 (the RTN slowdown that #6607 traced partly to this flush).

Measurements

RTN 4-bit g128 on Qwen2.5-0.5B-Instruct, default offload, RTX 5090, OMP_NUM_THREADS=16, cProfile around quantize():

quantize time in mmap.flush flush calls saved checkpoint SHA-256
main 12.40 s / 12.55 s 7.61 s / 8.03 s 168 7ebba80bd2a74997…
this PR 4.71 s / 6.94 s 0 0 7ebba80bd2a74997… (identical)
before #6473 (measured in #6605) 3.6 s – – –

Test plan

  • New test_in_session_backing_write_does_not_block_on_msync[False|True] and test_file_back_module_skips_msync_and_keeps_values (spy on mmap.flush, and check a fresh load_file reader sees the unsynced bytes):
    • Red on main: 2 failed; the durable=True control passes.
    • Green: 3 passed.
  • tests/test_weight_loader_filebacked.py: 17 passed, 1 skipped.
  • 48 offload / file-backed / resume / run-exit / weight-loader / weight-only test files: 589 passed, 23 skipped.
  • Checkpoint bit-identical to main (table above).
  • [email protected] clean.

🤖 Generated with Claude Code

write_safetensors flushed its mmap (msync MS_SYNC) on every call, durable
or not. Disk offload backs every module with an in-session file, so each
offloaded module blocked the quantization thread on the disk: RTN on
Qwen2.5-0.5B spent 7.6 of 12.4 s in 168 mmap.flush calls (pre-#6473: 3.6 s).
The page cache already serves every reader of the file and the kernel
writes it back on its own, so only a durable write needs the flush.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Qubitium
Qubitium marked this pull request as ready for review December 1, 2026 06:33
@Qubitium
Qubitium merged commit cb2e4ee into main Dec 1, 2026
6 checks passed
@Qubitium
Qubitium deleted the perf/filebacked-no-msync branch December 1, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant