Repository navigation
[FlyDSL] [MegaMoE] fix(dispatch): source-indexed payload for every rank at the indexed MTPR class - #6556
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
f273f1e to
7123fa2
Compare
…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]>
7123fa2 to
d81c12a
Compare
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 + 1rows).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 receiverneeds 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 + tokenis bounded byworld_size*mtprby construction, sothe write always lands inside the buffer under any routing/skew. The indexed A-scale
gather is generalized to
sort_block_m < 128(the>= 128gate was conservative) andthe FP4 async A-copy stays on for the indexed path, so
sort_block_mkeeps its tunedvalue — it now only drives tiling, not the receive layout.
Scope (by construction)
Every change is gated on
mtpr >= 32768, somtpr < 32768is byte-identical tomainand 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)
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,
mainbaseline vs this PR, 8×MI355Xmtpr = 32768 (where the fix acts)
v4_pro a4w4 — async A-copy recovery, faster at nearly every bs (iters=5):
v4_pro a8w4 — the one trade-off is decode-scale bs 8–16; large bs clean (small bs
iters=100, large bs iters=5):
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:
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 < 32768or 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.