Repository navigation
[ROCm] Stage large pageable H2D copies instead of pinning them in place - #37720
Merged
HaiShaw merged 1 commit intoSep 6, 2026
Merged
Conversation
JohnQin-llm
force-pushed
the
fix/rocm-pageable-h2d-staging
branch
from
September 3, 2026 06:05
5e10bea to
59c5910
Compare
Weight loading on ROCm spends most of its wall clock with the GPU queues
suspended, with no error and no warning. On MI355X loading GLM-5.2 (408 GB,
117410 tensors) the slowest rank takes 505.7 s at tp=4 and 300.4 s at tp=2.
With this change they take 40.4 s and 43.4 s.
Above GPU_PINNED_MIN_XFER_SIZE the HIP runtime stops staging a large pageable
host-to-device copy through its own buffer and registers the source pages with
the GPU instead, DMA-ing directly out of them. Registered host memory carries an
MMU notifier, so any kernel-side touch of that mapping -- page cache reclaim,
readahead, the munmap when the loader moves to the next shard -- makes KFD
suspend the process's queues on every device it holds until the range is
restored, at roughly 10 ms an event. The safetensors mmap path gives every
tensor a file-backed source, so this fires once per tensor.
Raising the default threshold past the largest tensor makes the runtime stage
these copies, and it then registers nothing.
tp=4, per rank slowest
before 139.8 / 140.4 / 445.4 / 505.7 505.7 s
after 38.7 / 39.3 / 39.8 / 40.4 40.4 s
12.5x on the slowest rank, and the spread across ranks collapses from 366 s to
1.7 s. Server startup to "Uvicorn running" at tp=4 was 12m43s before it.
Evidence, read from the KFD SMI event channel at tp=4: 315780 eviction events,
trigger 100% USERPTR, all of them inside [Load weight begin, Load weight end]
with steady-state serving recording zero. 39352 on each of the two slow ranks
against 122 on each of the two fast ones -- one per logical weight
(117410 tensors / 3). Inter-arrival p10/p50/p90 of 8.8 / 10.9 / 14.1 ms, far too
narrow for a random event stream; it is a saturated invalidate/evict/restore
loop.
Two controls, since a 12x speedup on a load path invites suspicion. The load is
complete: 197.71 GB resident per rank afterwards, identical to the unpatched
run, and the server generates correct output. The speedup is not page cache
warmth: a control run with a warm cache and the change reverted reproduced
229.2 / 312.1 s.
setdefault rather than an assignment, so an operator who has tuned the threshold
keeps their value; the test pins that.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
JohnQin-llm
force-pushed
the
fix/rocm-pageable-h2d-staging
branch
from
September 3, 2026 06:17
59c5910 to
0fe2c34
Compare
This was referenced Sep 5, 2026
Collaborator
|
/tag-and-rerun-ci |
Collaborator
|
@JohnQinAMD Can you post the results - the local run of test added? |
HaiShaw
approved these changes
Sep 6, 2026
Contributor
Author
@HaiShaw Local run of the added test, on MI355X / ROCm 7.2.0: Thanks Environment: torch 2.9.1+rocm7.2.0.git7e1940d4, hip 7.2.26015-fc0010cf6a, ROCm 7.2.0. |
hdt98
pushed a commit
to hdt98/sglang
that referenced
this pull request
Sep 10, 2026
JohnQin-llm
added a commit
to JohnQin-llm/vllm-amd
that referenced
this pull request
Sep 17, 2026
The weight loader mmaps the safetensors, so every tensor's H2D source is a file-backed page. Above GPU_PINNED_MIN_XFER_SIZE the HIP runtime registers those pages with the GPU rather than staging the copy, and each registration's MMU notifier makes KFD suspend the process's GPU queues. There is no error and no warning, just a slow loader. Raise the threshold so the staging path is taken for weight-sized transfers. Measured on 4x MI355X (gfx950), ROCm 7.2.3, TP4, DeepSeek-V4.1-Flash, a 475 GiB checkpoint that is fully page-cached (/proc/diskstats shows 0 MB/s read for the whole load, so this is not I/O): Loading weights took 231.75 s without this change Loading weights took 108.31 s with this change, nothing else set setdefault, so an operator's own value survives. It is a HIP runtime flag, not a vLLM one, so this is engine-agnostic; the SGLang counterpart is sgl-project/sglang#37720, which reports a larger factor because that checkpoint has many more, much smaller tensors. Declared in additional_env_vars because check_and_update_config runs on the driver, and the Ray executor copies env vars to workers by allowlist: GPU_PINNED_MIN_XFER_SIZE matches none of DEFAULT_ENV_VAR_PREFIXES or DEFAULT_EXTRA_ENV_VARS, so without it a Ray deployment would keep the slow path on every worker. Signed-off-by: JohnQinAMD <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[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.
Motivation
Loading GLM-5.2 onto 4× MI355X takes 8 minutes 26 seconds. Almost none of that is spent copying — the GPUs are stalled, waiting. With this change the same load takes 40 seconds.
Here is the chain, and each step is ordinary behaviour on its own:
GPU_PINNED_MIN_XFER_SIZEthe HIP runtime skips its own staging buffer and instead registers those pages with the GPU, DMA-ing straight out of them. That threshold defaults to 1 MB (ROCclr flags.hpp), and GLM-5.2's tensors run to 1903 MB, so essentially every one of them takes this path.munmapwhen the loader finishes a shard.Step 1 makes step 4 fire once per tensor. GLM-5.2 has 117410 of them, so the loader spends most of its wall clock suspended rather than copying — with no error and no warning, which is why this looks like "loading is just slow on ROCm".
Raising the default from 1 MB to 4 GiB — above the largest tensor — puts step 2 back on the staging path. Nothing gets registered, so steps 3 and 4 never happen.
Impact
Seconds to
Load weight end, per rank:Note the before-row at tp=4: two ranks finish in 140 s and two take 3× longer. That spread — 366 s of it — collapses to 1.7 s, which is what you would expect if the cause is an eviction storm some ranks fall into rather than anything about the ranks themselves.
Evidence
Read from the KFD SMI event channel during a tp=4 load: 315780 eviction events, trigger 100%
USERPTR. All of them fall inside[Load weight begin, Load weight end]; steady-state serving records zero. The two slow ranks see 39352 each, the two fast ones 122 each — 39352 is one per logical weight (117410 / 3). Inter-arrival times cluster at p50 10.9 ms with p10–p90 of 8.8–14.1 ms, far too narrow for a random stream: it is a saturated invalidate → evict → restore loop.Two controls, since a 12× speedup on a load path invites doubt:
Modifications
One
setdefaultinhandle_amd_specifics, which already guards onget_platform().is_hip, so nothing changes off ROCm.setdefaultrather than an assignment, so an operator who has tuned the threshold keeps their value — the test pins that, along with the HIP and non-HIP cases.Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #33722540716
Latest PR Test (Extra): ❌ Run #33722540504
Latest PR Test (AMD ROCm 7.2): ❌ Run #33722540717