Skip to content

[FlyDSL] [MegaMoE] fix(dispatch): source-indexed payload for every rank at the indexed MTPR class - #6556

Merged
coderfeli merged 1 commit into
mainfrom
xyw/mega_moe_bugfix
Oct 20, 2026
Merged

coderfeli merged 1 commit into
mainfrom
xyw/mega_moe_bugfix

Conversation

@Yaowu-Xiong

@Yaowu-Xiong Yaowu-Xiong commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

At the indexed-capable MTPR class (max_tok_per_rank == 32768) the dispatch payload /
scale buffers are sized for the source-indexed layout (world_size*mtpr + 1 rows).
Previously each rank chose indexed vs route-major receive from its local
sort_block_m (>= 128); under cross-rank token skew a small-SBM route-major receiver
needs one row per (token, expert) and can overflow that shared indexed-sized buffer →
out-of-bounds payload/scale writes (a dispatch-handshake hang under bounds-checking)
that the local-token capacity guard cannot see. The same mix also gave a writer/reader
layout mismatch (wrong numerics).

Fix: decide the receive layout from the MTPR class alone — every rank at the
indexed-capable class uses the source-indexed layout regardless of sort_block_m.
source_key = rank*mtpr + token is bounded by world_size*mtpr by construction, so
the write always lands inside the buffer under any routing/skew. The indexed A-scale
gather is generalized to sort_block_m < 128 (the >= 128 gate was conservative) and
the FP4 async A-copy stays on for the indexed path, so sort_block_m keeps its tuned
value — it now only drives tiling, not the receive layout.

Scope (by construction)

Every change is gated on mtpr >= 32768, so mtpr < 32768 is byte-identical to
main
and cannot be affected. The behavioral delta is confined to
{mtpr == 32768} ∩ {sort_block_m < 128}.

Correctness — relL2 vs torch reference, 8×MI355X (rtol = 0.25)

network quant bs SBM relL2
v4_pro a8w4 8 / 16 / 32 32 0.0592 / 0.0591 / 0.0592
r1_v3 a4w4 8 / 16 32 0.2068 / 0.2073
r1_v3 a4w4 64 64 0.2078
kimi_k3 a4w4 8 / 16 / 64 64 0.2191 / 0.2187 / 0.2187

All pass. The previously-unreachable SBM=32 indexed path (R1 bs 8/16, v4_pro a8w4) is
now exercised and correct. The concentrated-skew repro that used to hang now passes.

Performance — e2e ms, main baseline vs this PR, 8×MI355X

mtpr = 32768 (where the fix acts)

v4_pro a4w4 — async A-copy recovery, faster at nearly every bs (iters=5):

bs 1 8 128 512 2048 8192 32768
base 0.1845 0.4097 0.5813 0.6503 1.2769 3.6547 13.286
this PR 0.1766 0.3996 0.5690 0.6215 1.2671 3.6240 13.452
Δ −4.3% −2.5% −2.1% −4.4% −0.8% −0.8% +1.2%

v4_pro a8w4 — the one trade-off is decode-scale bs 8–16; large bs clean (small bs
iters=100, large bs iters=5):

bs 8 16 32 128 512 2048 8192 32768
base 0.3287 0.3896 0.4332 0.4718 0.7062 1.5302 4.4424 16.578
this PR 0.3353 0.4003 0.4373 0.4806 0.6898 1.5216 4.4355 16.572
Δ +2.0% +2.8% +1.0% +1.9% −2.3% −0.6% −0.2% −0.0%

R1 a4w4 (SBM=32 small bucket): −3.6% … +0.7% (noise).
R1 a8w4: bs1 +2.6% (bs=1 jitter), otherwise −1.7% … +1.8%.
K3 a4w4 / a8w4: −4.3% … +1.7% (noise / faster).

mtpr = 8192 (fix inert — byte-identical) — controlled same-session A/B, iters=200

v4_pro a8w4, e2e Δ across bs 1…8192:

bs 1 8 16 32 128 512 2048 8192
base 0.2091 0.3252 0.3945 0.4234 0.4681 0.6859 1.5236 4.4687
this PR 0.2079 0.3255 0.3950 0.4243 0.4689 0.6902 1.5281 4.4799
Δ −0.6% +0.1% +0.1% +0.2% +0.2% +0.6% +0.3% +0.3%

Within ±0.6% — pure noise, as expected for byte-identical code. No regression.

zipf-1.2 skew — v4_pro a4w4, mtpr = 32768

bs8 −2.9% / bs128 −6.4% (faster) / bs512 +2.6% / bs2048 +1.8% / bs32768 −1.3% — bidirectional
noise, no systematic regression.

The one trade-off: a8w4 decode-scale (bs 8–16) ≈ +2.5% (+0.005–0.008 ms)

Forcing the overflow-safe indexed receive makes the A-scale loader resolve each
row's source through an srcmap indirection, where route-major read contiguously. At
throughput bs this is fully hidden behind compute; at decode-scale bs (8–16, SBM=32) it
is exposed → ≈ +2.5% e2e (absolute +0.005–0.008 ms), a8w4 only (a4w4 is faster via the
async A-copy). This is the price of overflow-safety under cross-rank skew; it never
appears at mtpr < 32768 or at throughput bs.

Two recovery levers were measured and rejected: (1) promoting SBM 32→64 balloons the
GEMM2 (stage2) tiling at small bs, net worse; (2) an R-bounded gather that skips the
tile's padding rows is correct but perf-neutral in a controlled A/B — the padding
reads are coalesced (all hit the same invalid row), so the real cost is the intrinsic
per-row srcmap indirection, which is inseparable from the indexed layout. Accepted.

@Yaowu-Xiong
Yaowu-Xiong requested a review from a team October 15, 2026 01:59
@github-actions github-actions Bot changed the title [FlyDSL][MegaMoE] fix(dispatch): write payload by destination layout under mixed SBM [FlyDSL] [MegaMoE] fix(dispatch): write payload by destination layout under mixed SBM Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6556 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

…MTPR class

At MTPR32768 the dispatch payload buffer is sized for the source-indexed layout
(world_size*mtpr+1 rows). Previously each rank picked indexed vs route-major from
its LOCAL sort_block_m (>=128); cross-rank token skew could make a small-SBM
route-major receiver need one row per (token,expert) and overflow that shared
indexed-sized buffer -> OOB payload/scale writes (dispatch-handshake hang under
bounds-checking), which the local-token capacity guard cannot see. The same mix
also caused the writer/reader layout mismatch (wrong numerics).

Decide the payload layout from the MTPR class alone: every rank at the
indexed-capable class uses source-indexed, regardless of sort_block_m. Indexed
source_key = rank*mtpr + token is bounded by world_size*mtpr by construction, so
the write always lands in the buffer under any routing/skew. Generalize the
indexed A-scale gather to sort_block_m<128 (the >=128 gate was conservative) and
keep the FP4 async A-copy on indexed (its per-thread source-key addressing serves
it), so sort_block_m keeps its tuned value and there is no perf tax. sort_block_m
now only drives tiling/padding, not the receive layout.

Validated on 8xMI355X: v4_pro/R1/K3 a4w4 indexed relL2 correct down to SBM=32;
concentrated-skew overflow repro hang->pass; a8w4 zero perf delta and a4w4
recovered to baseline via async (v4_pro); mtpr<32768 byte-identical. Adds
--concentrate-experts / --zipf op-test knobs that reproduce the overflow/skew.

Co-authored-by: Cursor <[email protected]>
@Yaowu-Xiong Yaowu-Xiong changed the title [FlyDSL] [MegaMoE] fix(dispatch): write payload by destination layout under mixed SBM [FlyDSL] [MegaMoE] fix(dispatch): source-indexed payload for every rank at the indexed MTPR class Oct 15, 2026
@coderfeli
coderfeli merged commit 033e8bd into main Oct 20, 2026
@coderfeli
coderfeli deleted the xyw/mega_moe_bugfix branch October 20, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants