Repository navigation
[https://nvbugs/6272421][fix] avoid host OOM in HfWeightLoader checkpoint prefetch - #15711
Conversation
📝 WalkthroughWalkthrough
ChangesChunked file prefetch in HfWeightLoader
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
1b718ea to
1178edc
Compare
Prefetch warmed the OS page cache by reading each safetensors file with a bare f.read(), which copies the entire file into a process-owned anonymous bytes buffer. On a multi-GPU node every local rank prefetches concurrently, so the peak transient anonymous memory scales with the number of local ranks times the shard size. For large checkpoints (e.g. DeepSeek-R1-0528-FP8 641GB, Nemotron-Ultra-253B 472GB) this reaches hundreds of GB of non-reclaimable memory and trips the Linux OOM killer (SIGKILL) during prefetch, before any weights reach the GPU. Warm the page cache with posix_fadvise(WILLNEED) instead: the kernel reads the file into the reclaimable, file-backed page cache directly, with no copy into our address space. This adds zero anonymous memory (so it cannot trigger the OOM killer; under pressure the kernel just reclaims or caps the cache) and removes the need for the per-file read buffer, the chunk-size tuning knob, and the now-pointless ThreadPoolExecutor (the hint is non-blocking). Signed-off-by: Ruodi Lu <[email protected]>
1178edc to
6f83071
Compare
brnguyen2
left a comment
There was a problem hiding this comment.
The description and the diff describe two different fixes. The description says the file is read "in bounded 16 MiB chunks and discard[ed]", "preserving the synchronous warm-up before the local MPI barrier" — the code issues posix_fadvise(WILLNEED) and reads nothing. Those have different properties (chunked reads still block until the data is resident; the hint does not), so please update the description to match what's actually implemented, or restore the chunked-read version if that was the intent.
On the implemented approach: it does remove the anonymous allocation that was getting the process SIGKILLed, so the OOM should be fixed. What's unclear is whether prefetch still does its job. WILLNEED returns once readahead is queued, and those pages are reclaimable, so after this change nothing guarantees a shard is resident when _load_weights_in_parallel reaches it — which is what the local_mpi_barrier() and the 90%-of-available-memory gate were built around. Can you post before/after weight-load wall time for one of the large checkpoints in the bug (e.g. the 240 GB FP8 config)? If load time is unchanged the change is clearly good; if it regresses, chunked reads are the better trade.
No test was added. _prefetch_one_file is cheap to cover in tests/unittest/ (nonexistent path, unreadable path, normal path) without a GPU or model weights.
| # on a node, could exhaust host RAM and SIGKILL the process during | ||
| # prefetch (before any weights reach the GPU). The hint is asynchronous; | ||
| # the kernel reads ahead in the background, overlapping with the | ||
| # subsequent weight load, and caps itself to available memory. |
There was a problem hiding this comment.
The comment claims the kernel "caps itself to available memory" and overlaps readahead with the subsequent load. Both are plausible but neither is guaranteed by the posix_fadvise contract — WILLNEED is a hint, the pages are reclaimable, and on some network filesystems it is effectively a no-op. Please trim this to what the syscall actually promises (queue readahead into the page cache, no anonymous allocation) rather than asserting kernel behavior the code doesn't verify.
| # whole file. | ||
| os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_WILLNEED) | ||
| except (AttributeError, OSError) as e: | ||
| logger.debug(f"posix_fadvise unavailable, skipping prefetch: {e}") |
There was a problem hiding this comment.
This is the one path where prefetch silently does nothing, and it logs at debug — meanwhile _prefetch_and_load has already printed Prefetching 472.00GB checkpoint files. at info. On a platform or filesystem where posix_fadvise is missing or inert, the logs will read as though a multi-hundred-GB prefetch succeeded while the load pass goes straight to disk. Log the skip at warning (once per process is enough) so this is diagnosable from a normal run.
| len(local_file_names)) | ||
| with ThreadPoolExecutor(max_workers=max_workers) as executor: | ||
| list(executor.map(self._prefetch_one_file, local_file_names)) | ||
| for file_name in local_file_names: |
There was a problem hiding this comment.
Dropping the thread pool is fine for a non-blocking hint, but it also means this loop is now the only place the design assumption is recorded. If the chunked-read version from the PR description is what ends up merged, this has to go back to concurrent workers — a serial 16 MiB-at-a-time read of a 472 GB checkpoint slice would be far slower than the load it is meant to accelerate. Worth a one-line comment noting the serial loop is only valid because the hint doesn't block.
| weight loading reads from memory instead of disk/network. | ||
| When multiple ranks run on the same node, each rank warms a disjoint | ||
| slice of the files to avoid redundant work; the page cache is shared | ||
| node-wide. |
There was a problem hiding this comment.
Now that the warm-up is a hint rather than a read, splitting files across local ranks doesn't save any work — the syscall is nearly free, and every rank could hint every file. The split only mattered when each rank was doing a real full-file read. Not a bug, but the docstring's stated rationale ("to avoid redundant work") no longer describes why the code is written this way.
Disposition (2026-10-30): Superseded by #17430, merged as 0946d54. Resolving this branch against current main produces no effective changes (identical Git tree).
Prefetch warmed the OS page cache by reading each safetensors file with a bare f.read(), which allocates an anonymous bytes buffer the size of the entire file. On a multi-GPU node every local rank prefetches concurrently, each with a ThreadPoolExecutor of up to min(cpu*2, 16) workers, so the peak transient anonymous memory is roughly n_local_ranks * workers * shard_size. For large checkpoints (e.g. DeepSeek-R1-0528-FP8 641GB, Nemotron-Ultra-253B 472GB) this reaches several hundred GB of non-reclaimable memory and trips the Linux OOM killer (SIGKILL) during prefetch, before any weights reach the GPU.
Read the file in bounded 16 MiB chunks and discard them instead. This warms the same page cache with O(chunk) resident anonymous memory per thread while preserving the synchronous warm-up before the local MPI barrier.
Summary by CodeRabbit
Description
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.