Repository navigation
perf(weight_loader): stop msyncing in-session file-backed offload writes - #6610
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
write_safetensors(gptqmodel/weight_loader/filebacked.py) flushed its mmap withmsync(MS_SYNC)on every call, durable or not. Disk offload (offload_to_disk, the quantization default) backs every module with an in-session file throughfile_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=Truewrites 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 aroundquantize():mmap.flush7ebba80bd2a74997…7ebba80bd2a74997…(identical)Test plan
test_in_session_backing_write_does_not_block_on_msync[False|True]andtest_file_back_module_skips_msync_and_keeps_values(spy onmmap.flush, and check a freshload_filereader sees the unsynced bytes):durable=Truecontrol passes.tests/test_weight_loader_filebacked.py: 17 passed, 1 skipped.[email protected]clean.🤖 Generated with Claude Code