[AMD] [MORI-EP] Skip LocalExpertCount kernel in decode graph when not recording - #30302
Merged
HaiShaw merged 1 commit intoJul 7, 2026
Conversation
…ding Gate the capture-time count kernel on a configured (non-Noop) expert-distribution recorder instead of on stream-capturing alone, so normal no-recorder serving no longer bakes dead work into the decode graph. Recording paths are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
rbrugaro-amd
requested review from
BBuf,
Edwardf0t1,
Fridge003,
HaiShaw,
Ying1123,
ch-wan,
ispobock and
merrymercy
as code owners
July 6, 2026 21:38
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
HaiShaw
approved these changes
Jul 7, 2026
mattteochen
pushed a commit
to mattteochen/sglang
that referenced
this pull request
Jul 8, 2026
yangspirit
pushed a commit
to yangspirit/sglang
that referenced
this pull request
Jul 8, 2026
3 tasks
Chronostasys
pushed a commit
to MindLab-Research/sglang
that referenced
this pull request
Aug 24, 2026
…t kernel in decode graph when not recording (sgl-project#30302) (sgl-project#30726) Co-authored-by: Rita Brugarolas <Rita.BrugarolasBrufau@amd.com>
Chronostasys
pushed a commit
to MindLab-Research/sglang
that referenced
this pull request
Aug 24, 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.
Motivation
_should_record_expert_distribution()in the mori EP token dispatcher returnedTruewhenever the CUDA stream was capturing. This baked mori's
LocalExpertCountKernel(andits buffer memsets) into the decode CUDA graph for every run — including normal
serving with no expert-distribution recorder configured. The kernel then replayed on
every decode step, producing a
local_expert_countthat nothing consumes when recordingis off (the recorder hook is inactive), i.e. dead work in the decode hot path.
This affects any MoE model served via the mori EP all-to-all backend with CUDA graphs
enabled.
Modifications
Gate the capture-time path on whether an expert-distribution recorder is actually
configured (non-Noop) instead of on
is_current_stream_capturing()alone:start_record()→ still bake themachinery in at capture time, so
start_record()works when called after graph capture(the recorder's own
_on_hookcontinues to gate the actual gather onrecording/capturing).
Single-file change:
python/sglang/srt/layers/moe/token_dispatcher/moriep.py(+19/−2).Because the two recording paths (configured-but-not-yet-recording, and actively-recording)
are left untouched, there is no expert-distribution recording regression: an EPLB
stat_approxrecord run (expert_distribution_recorder_mode=stat_approx+/start_expert_distribution_record→ traffic →/dump_expert_distribution_record) stillproduces non-empty per-layer expert counts, and its gsm8k accuracy is unchanged (0.975).
Accuracy Tests
8×MI355X, DeepSeek-R1 MXFP4, mori EP (tp8/ep8/dp8, DP attention, aiter, full decode CUDA
graph). Post-patch, no recorder:
Speed Tests and Profiling
Decode-dominant
bench_servingA/B (baseline vs patched), same server config, samesettings, back-to-back,
randominput 256 / output 1024, seed 42, 8 warmup,num-prompts = 8 × concurrency:Median ITL moves the same way (−1.1%…−1.2%). ~1–2% TPOT / output-throughput improvement,
increasing with decode concurrency — consistent in direction at every point, as expected
from removing one small per-MoE-layer-per-decode-step kernel from the decode graph. Decode
batch was capped at 32 (
--cuda-graph-max-bs-decode 32); the uplift ceiling is likely abit higher at larger decode batches, where the kernel would have replayed more per step.
CI States
Latest PR Test (Base): ❌ Run #28825048244
Latest PR Test (Extra): ❌ Run #28825048081