mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #2016] [Bug]: HipTransport::setupP2PAccess leaves wrong active HIP device, causing OOM cascade in TP workers #560
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#560
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Lzy17 on GitHub (Apr 30, 2026).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/2016
Originally assigned to: @amd-arozanov on GitHub.
Bug Report
Summary
When
mooncake::HipTransportis constructed inside a multi-process tensor-parallel worker (one process per GPU),setupP2PAccess(int num_devices)walks every visible GPU withhipSetDevice(i)to enable peer access, but never restores the device that was active on entry. After the constructor returns, every TP rank's worker thread has its active HIP device pinned tonum_devices - 1(the highest-numbered GPU). All subsequenttorchallocations from those ranks then land on that single GPU, exhausting its VRAM and crashing the process at model load.Affected version
kvcache-ai/Mooncakemainb0bda8caa4e729208d3d8c073091851ab5f55ac1-DUSE_HIP=ONmooncake-transfer-engine/src/transport/hip_transport/hip_transport.cppstatic void setupP2PAccess(int num_devices)Environment
gfx950) per nodelibamdhip64.so.70.5.10.post1(imagerocm/sgl-dev:v0.5.10.post1-rocm720-mi35x-20260428)Reproduce
Build upstream Mooncake with HIP enabled:
Launch any tensor-parallel server that constructs
HipTransportper rank. Minimal repro using SGLang PD-disaggregation:Server fails to start. Each TP rank's log shows the diagnostic warning followed by the OOM:
GPU 7 hits 100% VRAM use while GPUs 0–6 stay near zero, confirming all ranks are allocating onto the same device.
Root cause
setupP2PAccess(current upstream):hipSetDeviceis per-thread state. The HipTransport constructor is called from the worker process / thread that PyTorch later uses for its own allocator. Because the active device is never restored, every worker leaves this function pinned to GPU 7, and everytorch.empty(...)/ weight load from that worker targets GPU 7 instead of the rank's own GPU.Suggested fix
Save the entry device with
hipGetDeviceand restore it before returning. This makes the function transparent to the caller's HIP context. (Bonus: clear stickyhipErrorPeerAccessAlreadyEnabledfrom the runtime's last-error slot so it doesn't surface on the next unrelated HIP call from PyTorch.)Verification
After applying the fix, rebuilding (
make && make install), and relaunching the same TP=8 server:HTTP server is started.current device is not X, but 7warning no longer appears.Notes
HipTransportis constructed in a process that has its own meaningful active device (e.g. one TP worker per GPU). A single-process launcher that always re-pins its device after Mooncake init would not see it, which may be why CI did not catch this.CudaTransport::setupP2PAccess, if present) should be checked for the same pattern.Before submitting...
@alogfans commented on GitHub (Jul 23, 2026):
Closed as the associated PR has been merged.