fix: enable TBO compute/comm overlap in Deepseek V4 and fix mooncake gather hang for PD prefill#1121
Open
ZhangLirong-amd wants to merge 2 commits into
Open
fix: enable TBO compute/comm overlap in Deepseek V4 and fix mooncake gather hang for PD prefill#1121ZhangLirong-amd wants to merge 2 commits into
ZhangLirong-amd wants to merge 2 commits into
Conversation
Without this sync, the RDMA write can race the still-in-flight gather kernel that fills the staging buffer, causing GPU page faults under high-concurrency TBO prefill (DeepSeek-V4-Pro, mesh router, c=256).
42be4f3 to
62031bb
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets DeepSeek-V4-Pro PD-disaggregation prefill stability and performance under TBO by (1) moving specific DP/TP collectives off the main compute stream to improve true compute/comm overlap, and (2) preventing a Mooncake RDMA race by synchronizing after staging-buffer gathers.
Changes:
- Added a per-device auxiliary CUDA stream helper and routed DP
input_idsall-gather + MoEcombine_outputsTP all-reduce through it to avoid NCCL interleaving on the compute lane during TBO ping-pong. - Added an explicit CUDA stream synchronization after the staging-buffer gather in Mooncake block+slot transfers to prevent GPUDirect RDMA reads racing in-flight gathers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| atom/models/deepseek_v4.py | Adds _run_on_tbo_comm_stream and uses it for DP id all-gather + TP all-reduce to improve TBO overlap behavior. |
| atom/kv_transfer/disaggregation/mooncake/mooncake_connector.py | Synchronizes after _gather_slot(...) to avoid RDMA reading an incompletely-populated staging buffer. |
Comments suppressed due to low confidence (1)
atom/models/deepseek_v4.py:54
_run_on_tbo_comm_streamintroducestorch.cuda.stream(...)/wait_stream(...)control flow into the eager Python graph.DeepseekV4Modelis@support_torch_compile, and when MoE dual-stream is disabled (common when shared experts are fused),combine_outputs()executes in the compiled forward path. Dynamo/Inductor generally cannot trace stream-context switching reliably, which can break compilation or produce unexpected graph breaks.
Consider explicitly marking this helper as non-compilable so the rest of the model can still compile, while the stream manipulation runs eagerly at runtime.
tensor_model_parallel_all_reduce,
)
from aiter.dist.parallel_state import (
get_tensor_model_parallel_world_size,
)
from aiter.jit.utils.torch_guard import torch_compile_guard
from aiter.ops.topk import top_k_per_row_decode, top_k_per_row_prefill
from aiter.ops.triton.fp8_mqa_logits import fp8_mqa_logits
from aiter.ops.triton.fusions.fused_clamp_act_mul import (
fused_clamp_act_mul,
)
from aiter.ops.triton.pa_mqa_logits import deepgemm_fp8_paged_mqa_logits
from atom.config import (
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The DP input_ids all-gather (hoisted into DeepseekV4ForCausalLM.forward by #1109) and the MoE combine_outputs TP all-reduce both run on the same stream as the main TBO compute kernels. With NCCL interleaved on that lane the kernel queue serializes compute and NCCL, blocking the hardware-level overlap with TBO comm_stream during ping-pong. Move both collectives onto a per-device auxiliary stream with wait_stream sync at both ends so the main compute lane stays free of NCCL interleaving and can overlap with TBO comm_stream NCCL. Trace results on DeepSeek-V4-Pro (TP=8 --enable-dp-attention --enable-tbo, c=256 ISL=8192): before: 3.8 % of TBO NCCL overlaps with compute after: 91.7 % of TBO NCCL overlaps with compute
62031bb to
be7bda7
Compare
Comment on lines
+127
to
+132
| main = torch.cuda.current_stream() | ||
| side.wait_stream(main) | ||
| with torch.cuda.stream(side): | ||
| result = fn(*args, **kwargs) | ||
| main.wait_stream(side) | ||
| return result |
Comment on lines
1060
to
+1064
| self._gather_slot(src_slot, producer_pool_idx) | ||
| # Synchronize on the gather kernel before NIC starts reading the | ||
| # staging buffer. Without this, the RDMA can race the still-in-flight | ||
| # gather kernel on TBO prefill (page fault under high concurrency). | ||
| torch.cuda.current_stream().synchronize() |
valarLip
approved these changes
Jun 7, 2026
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
Two fixes for DeepSeek-V4-Pro PD-disaggregation prefill with
--enable-tbo:Enable real compute/comm overlap.
Fix mooncake gather hang under high-concurrency TBO prefill.
Trace results
DeepSeek-V4-Pro, TP=8,
--enable-dp-attention --enable-tbo, c=256, ISL=8192:Test plan