Repository navigation
fix(moe): mask cudagraph pad rows under pure TP again - #2893
Merged
Merged
Conversation
#2776 gated pad-row masking on EP (`mask_pad_rows=layer.use_ep`) after a suspected "-1 route faults the TP a16w4 MoE". The fault does not reproduce: the TP regression from #2725 was the sort's pad sentinel (real token count) sitting inside the a16w4 gemm2's `token_id < M` bound (padded M), which piled every pad slot into one row. Routing pad rows to -1 is skipped by the sort, so restore it for TP and drop the switch. Kimi-K3 TP8, aiter bd4ff1c70: bs100 decode device time 44.56 -> 42.86 ms/step (-3.8%), c128 TPOT unchanged (102.46 -> 102.41 ms, full batches have no pad rows), GSM8K 0.9666, DSpark GSM8K 0.9651 / acceptance 51.57%, no fault. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
🏷️ CI GuideRuns automatically on every eligible PR before approval:
Heavy model tests:
|
gbyu-amd
marked this pull request as ready for review
November 2, 2026 14:32
valar-cop
reviewed
Nov 2, 2026
valar-cop
left a comment
There was a problem hiding this comment.
some changes needed..
smoke run on one non-Kimi-K3 TP MoE model? deepseek or qwen3-moe
ci green.
JiaoliangYu
approved these changes
Nov 3, 2026
charlieguo1106
added a commit
that referenced
this pull request
Nov 11, 2026
…imi-K3 main (#2893) dropped FusedMoE.select_experts' mask_pad_rows, so the HERD branch raised TypeError on its first decode step. Without it the Top-(K+1) candidates route pad rows to -1 like _select_logical, and apply() passes the same pass row count to fused_moe as num_local_tokens (#2905), which aiter's herd_route_psum takes as num_valid_rows: the pad rows of a partly filled graph bucket no longer vote in HERD's popularity. The experts must run their pass's own rows. A DP-attention or PCP gather, and simulated DP's repeat, interleave every rank's -1 pad rows, pass no count and can exceed the 1024 rows fused_moe(herd_topk) takes, so use_flydsl_herd stays off there. HERD now serves DeepSeek-V4's sqrtsoftplus top-k and Kimi-K3's sigmoid grouped top-k over one group only; both fold the routed scale in, which the drop applies. aiter's HERD constants import under a guard, and use_flydsl_herd needs aiter v0.1.29 (ROCm/aiter#7494, probed by herd_route_psum): older aiter aborts on Kimi-K3's Top-17 candidates with an FP32 bias. test_flydsl_herd_routing binds the HERD candidate call to the real FusedMoE.select_experts signature, and covers the routing set, the gather guard, the aiter probe and the num_local_tokens hand-off. test_flydsl_herd_graph_padding_gpu replays a bs=32 graph at 17, 1, 31 and 32 real rows against eager HERD over the real rows alone (gfx1250 only).
charlieguo1106
added a commit
that referenced
this pull request
Nov 16, 2026
…2713) * feat(moe): route FlyDSL MXFP4 decode through aiter HERD on gfx1250 With AITER_FLYDSL_USE_HERD=1, Mxfp4MoEMethod.apply() on gfx1250 picks the Top-(K+1) sqrtsoftplus candidates with topk_gating and passes them to fused_moe(herd_topk=K), which drops each token's least batch-popular candidate, renormalizes and applies the routed scale (fused into the route/prefix-sum kernel by default, AITER_HERD_FUSED_DROP=1). Only decode steps whose batch is inside aiter's HERD window (16..128 tokens) take this path, and only for TP (no EP or EPLB), GU-interleaved weights, sqrtsoftplus routing with renormalization, no grouped top-k, no custom or hash routing, no fused shared experts and no expert mask. Everything else keeps select_experts. * style(moe): sort the HERD import and use functools.cache Fixes ruff I001 (aiter.ops.topk sorts after aiter.ops.shuffle) and UP033 (@cache instead of @lru_cache(maxsize=None)) on the FlyDSL HERD change. * [MoE] Adapt FlyDSL HERD to aiter valid-row routing * [MoE] Route FlyDSL HERD candidates through the layer's own top-k The HERD branch of Mxfp4MoEMethod.select_experts forced a non-grouped top-k, and _flydsl_herd_step admitted sqrtsoftplus only, so DeepSeek-V4 was the only model HERD could serve. Candidates now take the layer's own routing at top_k + 1: topk_gating for sqrtsoftplus, fused_topk for softmax (GPT-OSS) and biased_grouped_topk for a one-group grouped top-k (Kimi-K3). Grouped top-k with more than one group keeps plain routes. The drop applies the routed scale the layer's own routing folds in. FusedMoE.routing_scale holds that rule and select_experts shares it: grouped top-k and sqrtsoftplus fold the scale in, sigmoid only with a fused shared column, softmax never. Also sets use_flydsl_herd on the Mxfp4MoEMethod objects that test_shared_expert_dispatch and test_mxfp4_triton_moe_decode build by hand; the HERD hooks broke three of those tests. * [MoE] Trim the FlyDSL HERD routing hooks Cuts the HERD additions to atom/model_ops/moe.py from 134 to 71 lines without changing behaviour: - Drop the one-shot HERD batch log and FusedMoE.routing_scale; apply() takes the routed scale select_experts folds in (grouped top-k and sqrtsoftplus) inline, and select_experts is back to main. - The HERD branch of select_experts leaves default arguments out. - _flydsl_herd_step folds its checks into one condition and drops the expert_mask test, which use_flydsl_herd's not-EP check already covers. - Shorter comments. * [MoE] Route FlyDSL HERD pad rows like the plain routing Since #2776, pure TP routes pad rows like real rows (mask_pad_rows= layer.use_ep) and passes fused_moe no scheduled_tokens_gpu. The HERD branch of select_experts kept the default mask, so its Top-(K+1) candidates still carried -1 pad rows while fused_moe got no num_local_tokens. aiter's HERD drop leaves -1 rows out only with that count, so pure-TP HERD decode broke. The HERD branch now takes the same mask_pad_rows as _select_logical: pure TP routes its pad rows as real candidates, and a later change to that policy applies to HERD as well. * [MoE] Keep graph pad rows out of FlyDSL HERD; serve DeepSeek-V4 and Kimi-K3 main (#2893) dropped FusedMoE.select_experts' mask_pad_rows, so the HERD branch raised TypeError on its first decode step. Without it the Top-(K+1) candidates route pad rows to -1 like _select_logical, and apply() passes the same pass row count to fused_moe as num_local_tokens (#2905), which aiter's herd_route_psum takes as num_valid_rows: the pad rows of a partly filled graph bucket no longer vote in HERD's popularity. The experts must run their pass's own rows. A DP-attention or PCP gather, and simulated DP's repeat, interleave every rank's -1 pad rows, pass no count and can exceed the 1024 rows fused_moe(herd_topk) takes, so use_flydsl_herd stays off there. HERD now serves DeepSeek-V4's sqrtsoftplus top-k and Kimi-K3's sigmoid grouped top-k over one group only; both fold the routed scale in, which the drop applies. aiter's HERD constants import under a guard, and use_flydsl_herd needs aiter v0.1.29 (ROCm/aiter#7494, probed by herd_route_psum): older aiter aborts on Kimi-K3's Top-17 candidates with an FP32 bias. test_flydsl_herd_routing binds the HERD candidate call to the real FusedMoE.select_experts signature, and covers the routing set, the gather guard, the aiter probe and the num_local_tokens hand-off. test_flydsl_herd_graph_padding_gpu replays a bs=32 graph at 17, 1, 31 and 32 real rows against eager HERD over the real rows alone (gfx1250 only). * [MoE] Decide FlyDSL HERD in apply() as select_experts did, not by width apply() told HERD's raw Top-(K+1) candidates from final routes by the ids' width, which also had to rule out a fused shared column. It now asks the same _flydsl_herd_step select_experts asked, over the same rows: HERD never runs on gathered rows, so their count is the one routing saw. Nothing per step is kept on the method. No try around aiter: the HERD constants import directly, and the v0.1.29 check looks herd_route_psum up on aiter.ops.flydsl.herd_topk, which aiter has had since those constants (v0.1.26). test_dp_gather_routed_rows stubs aiter.ops.topk with the other aiter modules moe.py imports.
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
#2776 limited pad-row masking to EP (
mask_pad_rows=layer.use_ep) because "-1 route faults the TP a16w4 MoE". That fault was real: the MXFP4 BM16 inline-sort (K3 decode M <= 64) indexed its LDS histogram with the -1 id. ROCm/aiter#7020 (merged 2026-10-28) fixed it, so the sort now skips ids outside [0, E). This PR requires aiter at or past #7020; with older aiter, -1 pad rows on the TP path can fault intermittently. All results below use aiter bd4ff1c70, which contains #7020.The TP regression from #2725 (K3 nightly 10/26 → 10/27, c128 TPOT ~96.6 → 99.8 ms) had a different cause: passing
num_local_tokenstogether with a padded cudagraph M.moe_2stage_a16wmix/gemm2.py,mxfp4_gemm2.py) bounds rows withtoken_id < M, where M is the padded count.gemm2_a16w4went 5.45 → 24.9 ms/step at bs100.Routing pad rows to -1 is safe because the sort skips them. This PR restores masking under TP and removes the
mask_pad_rowsswitch.Results (Kimi-K3, TP8, MI355X, image nightly_202610310756 / aiter bd4ff1c70)
Follow-up for aiter (ROCm/aiter#7294): EP still passes
num_local_tokenswith a padded M; that PR makes the a16wmix and mxfp4 atomic gemm2 honour the valid token count (use_valid_token_count).🤖 Generated with Claude Code