Skip to content

Fix routed-experts device buffer overflow under DP attention - #26123

Merged
ch-wan merged 1 commit into
sgl-project:mainfrom
brucechanglongxu:upstream/routed-experts-dp-buffer-shape-fix
May 31, 2026
Merged

ch-wan merged 1 commit into
sgl-project:mainfrom
brucechanglongxu:upstream/routed-experts-dp-buffer-shape-fix

Conversation

@brucechanglongxu

@brucechanglongxu brucechanglongxu commented May 22, 2026

Copy link
Copy Markdown
Contributor

The routed experts device buffer in RoutedExpertsCapturer can overflow when DP attention is enabled and max_running_requests is larger than chunked_prefill_size * dp_size. The buffer's first dim is currently max(chunked_prefill_size * dp_size, max_running_requests). On non-DeepEP DP-attention paths _get_local_slice goes through get_dp_local_slice_cpu, which returns local_start_pos = dp_rank * cuda_graph_batch under a cuda graph. On ranks with dp_rank > 0 the slice can walk past the end of the buffer when the second branch of the max wins.

The fix multiplies the second branch by dp_size so the buffer can hold the full concatenated batch across DP ranks. No-op when dp_size == 1 or when chunked_prefill_size * dp_size already dominates.

Originally part of #23999. Splitting it out as a standalone fix since the larger PR needs to be reworked on top of the recent state_capturer refactor (#24403, #24450).

Verified on an MoE model with DP attention where max_running_requests > chunked_prefill_size, which previously hit the overflow.


CI States

Latest PR Test (Base): ✅ Run #26649038783
Latest PR Test (Extra): ❌ Run #26649038428

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@brucechanglongxu

Copy link
Copy Markdown
Contributor Author

Friendly bump for a first reviewer here. This is a small, focused correctness fix for the routed-experts host buffer when DP attention is on: the device-side allocation was sized for a single TP shard but the gather lands the full DP-aggregated rows, so we either OOB or silently truncate routing trajectories. The change just sizes the buffer for the gathered shape and adds a sanity check. cc @Kangyan-Zhou @ch-wan @merrymercy since this touches both the routed-experts capturer and DP attention paths. Happy to split further or add a regression test if helpful.

@alexnails alexnails left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the FIXME given your change

@brucechanglongxu
brucechanglongxu force-pushed the upstream/routed-experts-dp-buffer-shape-fix branch from b0c7e6f to 38f05f7 Compare May 29, 2026 16:25
@brucechanglongxu

Copy link
Copy Markdown
Contributor Author

updated the FIXME, thanks for the review.

@ch-wan

ch-wan commented May 30, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label May 30, 2026
@ch-wan
ch-wan merged commit 376635c into sgl-project:main May 31, 2026
204 of 234 checks passed
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants