Skip to content

[FlyDSL] [gfx1250] MegaMoE: stage-1 fused kernel for DSV4.1 Flash EP2/EP4 - #5899

Merged
JiaoliangYu merged 19 commits into
mainfrom
zxe/mega_stage1_compact_overlap
Nov 13, 2026
Merged

JiaoliangYu merged 19 commits into
mainfrom
zxe/mega_stage1_compact_overlap

Conversation

@XingerZhu

@XingerZhu XingerZhu commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Two goals at the start: overlap the compact plan with as much of the layer as the dataflow allows, and dedup a token's routes to the same peer so the payload moves once. Where this head ended up: Flash EP2 / EP4 run the S1F kernel at every width, the compact plan runs in stream order, and the dedup is measured and left out (see below).

The compact path that predates #6564 already does both. The plan launch follows this step's route count, and a local scatter expands one payload per (token, peer) into expert order before a contiguous GEMM1. #6564 fuses dispatch and GEMM1 into one stage-1 (S1F) kernel, and a scatter between them would split the overlap that kernel exists for. This head therefore runs Flash EP2 and EP4 on the S1F kernel at every width, and drops the scatter there.

Stage-1 fused kernel on Flash EP2 / EP4

tile_m 16. Decode (tpr 8 / 64) tunes GEMM1 to 16 rows, which S1F did not support, so those steps used dispatch + scatter + GEMM1. s1f_flag_m makes a tile below FLAG_M (64) its own flag tile. The compact plan and the producer pieces then use 16-row tiles. The 16-row variant uses 4 pipeline buffers and 2 CTAs/CU; three CTAs do not fit LDS (112 KB each, even with 3 buffers). The small-tile GEMM body (post-compute issue) now calls the S1F drain_start hook and uses the raw-drain fence. defer_c_wait stays off below 33 rows, because it needs the mid-loop fence.

tile_m 32. EP2 tpr 256 / 512 tune GEMM1 to 32 rows, which had no S1F variant, so those steps also fell back to dispatch + scatter + GEMM1. The 32-row variant is its own flag tile and reuses the 16-row layout (4 buffers, 2 CTAs/CU). At tpr 512 the S1F kernel takes 160.6 µs, against 169.8 µs for dispatch + scatter + GEMM1.

Recv cap. _S1F_MAX_RECV = 4096 made tpr 4096 / 8192 fall back to dispatch + scatter + GEMM1. s1f_max_recv(world, topk) adds a per-shape default and an AITER_S1F_MAX_RECV override (0 = no cap). Flash on EP2 and EP4 defaults to no cap, both at top-6 and at top-7 (the shared expert fused into MegaMoE, --fused_shared_experts 1). Other shapes keep 4096. Past 4096 tokens this precompiles a few more plan widths, 7 instead of 4 per tile at 8192 tokens/rank. On EP2 at tpr 8192 the S1F kernel takes 411 µs, while dispatch (46) + scatter (27) + GEMM1 (404) took 477 µs.

Plan in stream order. The compact plan used to launch on its own stream. That side stream no longer exists: the plan runs on the caller's stream, right before the step's dispatch (or S1F), and next_topk_ids / prefetch_compact_plan only enqueue it earlier on that stream.

  • On an S1F step the next layer's plan could not overlap anything anyway. A peer's GEMM2 of layer L+1 scatters into this rank's combine buffer, and with no dispatch tail barrier, only the next layer's X1 exchange in the plan orders that after this rank's reduce. So forward already dropped next_topk_ids there, and the side stream waited on the caller's stream and was waited on by it: a fork / join with no overlap.
  • Off S1F (other shapes, with next_topk_ids), the plan used to overlap the previous expert GEMM, and decode started it right after routing. It now sits on the critical path there. Flash EP2 / EP4 never take that path.

On Flash EP2 the change is within noise: 108.6 / 343.2 / 888.4 µs/layer at tpr 8 / 1024 / 8192, against 108.5 / 343.8 / 893.1 before.

Dedup inside the S1F producer: measured, not done. The S1F producer still ships one wire row per expert row (about 3 per token per peer on Flash EP2). An upper-bound test kept the per-rank load unchanged and cut remote rows from 3 to 1 per token. It routed each token to 5 local experts and 1 remote expert, against 3 + 3. The S1F kernel time did not move:

tokens/rank 3 remote rows 1 remote row
8 40.7 40.1
4096 268.4 267.0
8192 414.7 414.6

The S1F kernel is GEMM-bound and already hides the wire traffic. A staging + in-kernel expand would save at most about 1.5 µs/layer, and it would add a local copy to a persistent kernel that hangs if its CTAs are not all resident. The receiver-side expand is left out.

Grouped GEMM rows for the fused shared expert on EP4

With --fused_shared_experts 1, each EP4 rank holds 96 routed experts plus one shared-expert replica, so the grouped GEMM lookup asks for expert=97. dsv41_tuned_grouped_fmoe.csv only had expert=96 rows, so every bucket missed (grouped CSV config miss ... experts=97), and S1F and GEMM2 ran on the caller default (tile_m 64). The shared expert's 97th slot receives every local token, and each routed expert gets about 70 to 80 rows at tpr 1152. A 64-row tile splits most experts into two M tiles, so each expert's weights are read twice.

2f81baa reuses the expert=96 fp4 rows for expert=97, except for the 4096 bucket: there, the 96-expert row (tile 96) ran slower than the default tile 64 at tpr 1024 (319.6 against 291.8 µs/layer), so that bucket keeps the default. This is a config change only; no kernel or lookup code changes.

The kernel breakdown and the sweep in this section ran on a local branch carrying this PR's S1F changes, with AITER_S1F_MAX_RECV=6144 AITER_S1F_BLOCK_RUNS=4,2,8,8 AITER_S1F_ANY_TILE=1 AITER_TDM_COMPACT_ROUTE_UPTO=1024 AITER_TDM_COMPACT_ROUTE_SPEC=384,16. The table under Performance is this head with the PR command. At tpr 1152 (the token bucket is 8192, the row is tile 128x256x256 / 128x256x256, 3 / 3 buffers), the profile table goes from S1F 143.1 + GEMM2 91.0 µs to S1F 121.8 + GEMM2 77.1 µs. Plan and combine stay the same. A sweep around that row found nothing better. It covered tile_m 64 / 96 / 192 / 256, tile_n 512, tile_k 128, 2 / 4 buffers, cluster_m / cluster_n 2, next_stage_prefetch, a_preshuffle, tdm_b_th and waves_per_tensor_tdm. tile_m 96 and 192 (with tile_m2 128) exited with an error. persistent_workers2=1 ran 18844 µs/layer.

What this head does

  • Tag compact-plan histogram rows with the plan generation, and ship a dense row as one TDM store instead of a separate done counter and system fence.
  • Split a prefill plan across workgroups once the route count exceeds the LDS route cap. Decode stays on one workgroup. Launch width follows this step's route count; the histogram stride stays on the arena capacity, so every rank agrees.
  • Count each block's routes in a per-warp LDS histogram, then exclusive-scan the warps back into the same per-segment row offsets.
  • Skip a GEMM2 tile that starts inside an expert padding region instead of widening tile_m2 up to the plan alignment. When that skip is active, cluster_m is forced to 1.
  • Size the communicator VMM reservation with MegaMoEGfx1250.required_vmm_bytes, counting every compact row at the widest tuned tile.
  • On the non-S1F compact path with a quantizing wire, dispatch ships one payload per token per peer, and a local scatter expands it into expert order before a contiguous GEMM1. On Flash EP2 and EP4 every step now runs S1F, so this scatter does not run there.
  • EP2 top-6 (DSV4.1 Flash) has its own compact dispatch schedule. Past 4096 tokens/rank it is token-major 256x16.
  • The S1F kernel at tile_m 16 and 32, and no recv cap for Flash top-6 and top-7 on EP2 and EP4, as above.
  • Run the compact plan on the caller's stream: no side stream, no decode early start (_DECODE_PLAN_OVERLAP_TOKENS removed).
  • Grouped GEMM rows for EP4 with the shared expert fused (97 experts/rank) in dsv41_tuned_grouped_fmoe.csv, as above.
  • Resolve GEMM1's tile with the compact step instead of probing it, and launch the S1F kernel through its cached CompiledFunction, so every eligible step runs S1F (eager or captured, first time or not) without the per-launch JIT host cost.

Performance

Hardware: 2x gfx1250. Setup: bench_mega_moe.py with AITER_MEGA_PLAN_PREFETCH=0, stage1_fused true, stage2_fused true, dispatch wire fp4, quant a4w4_mxfp4, hidden 5120, intermediate 2304, 384 experts, topk 6, 192 experts/rank, fused_shared_experts 0, 8 layers, warmup 3, iters 8. Values are median per-layer µs. main is 6d8c8e9 with the same command. The previous head is 891de7f. tpr 256 / 512 used iters 50 and alternate main / this head runs, averaged over two rounds, since the gap is close to run-to-run noise; the previous head was not run there.

tokens/rank main previous head this head vs main
8 116.9 120.4 108.5 -7.2%
64 267.3 272.9 261.3 -2.2%
256 299.7 — 297.9 -0.6%
512 312.2 — 309.9 -0.7%
1024 346.1 346.6 343.8 -0.7%
4096 634.1 635.3 583.0 -8.1%
8192 1020.6 959.0 893.1 -12.5%

Flash EP4 (4x gfx1250, 96 experts/rank, same command with --nproc_per_node=4). The previous head kept the 4096 recv cap here, so 4096 / 8192 ran dispatch + scatter + GEMM1, and the scatter (14 / 24 µs) cost more than the dedup saved, with about 2.5 peers per token:

tokens/rank main previous head this head vs main
8 111.7 — 105.8 -5.3%
64 184.8 — 179.8 -2.7%
1024 266.0 — 267.5 +0.6%
4096 605.3 614.9 538.1 -11.1%
8192 1045.1 1063.2 898.2 -14.1%

Flash with the shared expert fused (--fused_shared_experts 1, so MegaMoE runs topk 7 over 385 experts). Before this head's last commit, (2, 7) / (4, 7) were not in the cap table, so tpr 4096 / 8192 fell back to dispatch + GEMM1. "4096 cap" below is that fallback, reproduced with AITER_S1F_MAX_RECV=4096 (the log prints S1F falls back to dispatch + GEMM1); "this head" is the default:

EP tokens/rank 4096 cap this head change
2 4096 851.4 693.5 -18.5%
2 8192 1404.5 1200.0 -14.6%
4 4096 776.1 656.5 -15.4%
4 8192 1372.3 1177.8 -14.2%

EP2 "this head" at 8192 ran with AITER_S1F_MAX_RECV=0, which is the same path the default now takes; at 4096 the default gives 693.5 and the env override 695.5. At tpr 8 top-7 already ran S1F (EP4 110.6 µs/layer).

EP4 kernels at 8192 tokens/rank: S1F 370.7 µs, against dispatch 130.7 + scatter 23.8 + GEMM1 363.4 on the previous head. S1F producers stay at 64. 32 and 96 run 918.4 and 1008.7 µs/layer at 8192.

Grouped GEMM rows for 97 experts/rank (2f81baa), EP4 (4x gfx1250), --fused_shared_experts 1, same command with --iters 20. "before" is 94cb8f5. Each tpr alternates before / after for two rounds; the value is the mean of the two. The first before round at tpr 256 / 512 ran 245.0 / 246.5 and is left out as a cold start. At tpr 8192 both sides ran four rounds and the value is the median: one after round ran 1168.0 against 994.4 / 996.3 / 1003.2 for the others.

tokens/rank before 97-expert rows change
256 210.3 202.7 -3.6%
512 225.6 225.2 -0.2%
1024 293.6 293.9 +0.1%
1152 333.3 297.9 -10.6%
1536 370.3 327.5 -11.6%
2048 422.1 379.1 -10.2%
4096 676.2 574.5 -15.0%
8192 1180.2 999.8 -15.3%

tpr 1024 lands on the 4096 bucket, which keeps the default tile, so it does not move. tpr 1152 to 2048 land on the 8192 bucket.

Prefill with a recv cap. The serving recipe below sets AITER_S1F_MAX_RECV=6144. ATOM bounds a step's receive count by the token sum over all DP ranks, and a c1024 prefill step carries about 14.5K tokens, so every prefill step ran dispatch + GEMM1 instead of S1F. This head has no cap for this shape. EP4 (4x gfx1250), --fused_shared_experts 1 --routing zipf --zipf_s 0.2 --iters 20, on the local integration branch with this head's S1F defaults set by env (AITER_S1F_BLOCK_RUNS=4,2,2,8 AITER_S1F_SHARED_FIRST=1 AITER_PLAN_SHAGG=1) and the recipe's other S1F settings. "6144 cap" sets AITER_S1F_MAX_RECV=6144; the bench bounds receives by tpr x 4, so every row logs S1F falls back to dispatch + GEMM1. "no cap" sets 0, which is what this head does by default. Each tpr alternates the two for two rounds; the value is the mean, and the two rounds agree within 3.2%:

tokens/rank 6144 cap no cap change
2048 441.7 371.8 -15.8%
3072 578.3 484.9 -16.2%
4096 694.7 570.4 -17.9%
6144 964.4 781.0 -19.0%

The end-to-end runs below kept the 6144 cap, so their prefill steps did not run S1F. Without the cap, the first layer of an eager prefill step still ran dispatch + GEMM1. The GEMM1 probe was keyed by the exact recv bound, and a prefill step's token sum is new almost every time. ATOM, like the bench, shares one MegaMoE op across layers, so the other layers reused that layer's probe. d84ec33 keys the probe by the CSV token bucket, _get_padded_m(recv_bound), which is what GEMM1 looks its row up by.

6eacb1c drops the probe. Even keyed by bucket, the first step of each bucket ran dispatch + GEMM1, and a bucket first seen inside a graph capture recorded that fallback into the graph for good. _compact_gemm_tiles now resolves (tile_m, tile_m2, m_warp2) the way grouped_gemm_gfx1250_a8w4 does (CSV row for _get_padded_m(recv_bound), then the AITER_TDM_* overrides). _CompactStep carries GEMM1's clamped tile_m and GEMM2's quant WMMA repeat, so eligible() and step_will_run() decide from the step alone. The GEMM1 hook still rejects a launch whose tile disagrees. The first eager S1F launch precompiles the launcher of every step bound that can fuse, so a capture does not JIT-compile it. Steps over the recv cap and configs S1F does not support still run dispatch + GEMM1.

With graph capture as the first forward (no eager warmup), tpr 2048:

6eacb1c d9da0c7 S1F off
EP4 µs/layer 372.6 442.2 441.6
EP4 captured S1F steps 61/61 0/61 -
EP2 µs/layer 470.0 551.8 551.2
EP2 captured S1F steps 61/61 0/61 -

The S1F kernel also cost host time. Its @flyc.jit launcher was called directly, so every launch rebuilt the FlyDSL cache key and checked the captured globals. Under cProfile that was about 370 of the 416 µs the S1F GEMM1 hook took per layer step. The non-S1F GEMM launches go through tensor_shim._run_compiled, which calls the cached CompiledFunction. c782790 launches the S1F kernel the same way. Its tensor arguments are layout-dynamic, so the cache is keyed by their dtype and rank.

Eager passes over 8 layers, each pass with a different recv bound inside one bucket (tpr x 4 minus 0 to 255), EP4 top-7, zipf 0.2, 24 passes, median µs/layer. S1F off is the mean of two or three runs. The output with each bound matches the unbounded run bit for bit with S1F on:

tokens/rank S1F off exact-bound key bucket key bucket key + cached launch vs S1F off
2048 469.9 497.9 483.0 405.7 -13.7%
6144 974.5 — 820.3 803.6 -17.5%
host enqueue per layer 332–337 — 444–455 306–307

With the exact-bound key, 169 of the 192 layer steps at tpr 2048 ran S1F; with the bucket key all 192 did. Before the cached launch, the S1F path enqueued more host work per layer than its GPU work at tpr 2048 (376 µs in the graph), so that eager pass was host-bound and ran 2.8% slower than S1F off. The graph timing does not move with the cached launch (tpr 2048: 374.3 against 376.4 µs/layer). A serving forward also enqueues attention between MoE layers; how much of the host time shows there was not measured.

End to end, DSV4.1 Flash on 4x gfx1250, ATOM EP4 + DP attention, FP4 index cache, FP8 KV cache, dspark speculative decoding (5 draft tokens), MLPerf agentic dataset, endpoints client at concurrency 1024 with a 600 s issue window. Both runs used the same recipe and environment (AITER_MEGA_S1F=1 AITER_MEGA_PLAN_PREFETCH=0 AITER_S1F_MAX_RECV=6144 AITER_S1F_BLOCK_RUNS=4,2,8,8 AITER_S1F_ANY_TILE=1 AITER_TDM_COMPACT_ROUTE_UPTO=1024 AITER_TDM_COMPACT_ROUTE_SPEC=384,16), on the same machine, one after the other. They ran on a local integration branch carrying this PR's commits (43abbc846), against the same branch plus the 13 rows from 2f81baa (9427f02fa). Both commits add the same rows. One run each:

c1024 before (43abbc846) 97-expert rows (9427f02fa) change
tokens/s/GPU 14287.96 14483.53 +1.37%
interactivity 67.32 68.38 +1.6%
TTFT median / p90 (ms) 967.3 / 2265.8 964.0 / 2265.8 -0.3% / 0.0%
TPOT median (ms) 10.89 10.85 -0.4%

The before run reproduced a run from the previous day, on the same commit and environment, within 0.02% (14285.20).

The serving step timer, averaged over each run's issue window, shows where the change lands:

per step before 97-expert rows change
decode forward (ms) 32.52 31.73 -2.4%
decode step period (ms) 37.90 37.45 -1.2%
prefill forward per token (µs) 8.22 8.04 -2.2%

The MoE kernels are about a third of a decode forward (40 layers x about 270 µs at tpr 1152, against 32.5 ms). Each decode step also spends about 5.4 ms outside the forward. The 13% MoE kernel gain in the bench therefore shows up as -2.4% on the decode forward, -1.2% on the step period and +1.37% on throughput. The decode forward gained less than the bench's MoE share would predict (about -4.4%), and that gap is not resolved here. The bench uses uniform routing, and serving decode steps at or below 1024 tokens/rank land on the 4096 bucket, which this commit leaves on the default tile.

EP2 kernel table (--profile_table 1, avg µs per call):

tokens/rank S1F (dispatch + GEMM1) GEMM2 plan combine sync + reduce
8 42.6 (t16) 23.1 7.9 7.6 + 2.7
64 135.3 (t16) 72.1 11.3 8.2 + 3.0
256 157.1 (t32) 86.4 13.0 6.1 + 3.7
512 160.6 (t32) 87.8 8.5 6.3 + 4.8
1024 169.0 (t64) 93.6 11.0 7.0 + 6.9
4096 270.1 (t128) 153.7 18.1 11.9 + 22.7
8192 414.3 (t128) 235.1 24.4 12.2 + 38.8

No step runs a separate ep_dispatch_tdm or moe_scatter_copy_compact kernel.

Testing

  • Performance benchmarks run
  • Accuracy, 2 layers, tol 0.0636. EP2: tpr 8 (logits diff 0.0422), tpr 8192 (0.0423) and tpr 64 with tile 16 (0.0420), tpr 256 / 512 with tile 32 (0.0423 / 0.0422). EP4: tpr 8 (0.0426) and tpr 8192 (0.0423). Top-7 (--fused_shared_experts 1): EP2 tpr 8192 (0.0422), EP4 tpr 8 (0.0427) and tpr 8192 (0.0422). With the 97-expert rows (2f81baa), EP4 top-7: tpr 1152 (0.0423) and tpr 8192 (0.0422), the same diffs as 94cb8f5. EP4 top-7, zipf 0.2, AITER_S1F_MAX_RECV=0: tpr 2048 / 4096 / 6144 (0.0423 / 0.0422 / 0.0422). With the bucket-keyed probe (d84ec33), and again with the cached S1F launch (c782790), EP4 top-7, zipf 0.2: tpr 8 (0.0432) and tpr 2048 (0.0423).
  • Unit tests added or updated. No op test changed.
  • Tested on MI250X. gfx1250 only.
  • Tested on MI300X. gfx1250 only.

Documentation

  • No documentation change is needed. The behavior is internal to the gfx1250 compact MegaMoE path. AITER_S1F_MAX_RECV is a tuning override.

Dependencies

Breaking Changes

None.

PR Self-Review

Reviewed revision

6eacb1c (GEMM1 tile resolved statically, probe removed) on top of the main merge d9da0c7, run with flydsl 0.5.0 and the bench's default 61 layers, zipf 0.2, --fused_shared_experts 1. EP4 graph at tpr 8 / 2048 / 6144: 125.0 / 370.1 / 781.6 µs/layer. The eager varying-bound passes ran S1F on every step (1464/1464) at EP4 tpr 2048 and EP2 tpr 256 / 2048 / 6144. EP2 graph ran at tpr 8 / 1152 / 2048 / 6144, and graph capture as the first forward at EP2 tpr 8 / 2048 and EP4 tpr 2048. All passed MEGA-CHECK without a fallback. A check over experts 48 / 96 / 97 / 192 / 384, both wires and buckets 1 to 131072 found _compact_gemm_tiles matching GEMM1's CSV resolution. test_grouped_ep_fused_lookup.py, ruff check and black --check passed. Later EP4 reruns hit a memory access fault on d9da0c7, 6eacb1c and S1F off alike while another container held GPU2, so those were not counted.

c782790 (S1F kernel launched through its cached CompiledFunction) on top of d84ec33. c782790 ran the eager varying-bound passes at tpr 2048 / 6144 against S1F off, and 2-layer accuracy at tpr 8 / 2048 (0.0432 / 0.0423). ruff check and black --check passed on s1f_ctl.py.

d84ec33 (GEMM1 probe keyed by the CSV token bucket) on top of the main merge 7fc819a. d84ec33 ran the eager varying-bound passes above at tpr 2048 / 6144 against S1F off, at tpr 2048 against the exact-bound key, and 2-layer accuracy at tpr 8 / 2048 (0.0432 / 0.0423). After 7fc819a it reran the varying-bound pass and the 2-layer accuracy at tpr 2048, and the accuracy at tpr 8. The earlier main merge a955bda ran tpr 8 / 1152 / 2048 against dc5ef4e (107.2 / 294.8 / 371.3 against 107.3 / 291.7 / 373.6 µs/layer, two rounds each), plus 2-layer accuracy at tpr 8. tpr 6144 aborted on both sides of that comparison while another container held GPU memory, and was not rerun.

dc5ef4e (S1F shared expert first, wave-aggregated plan tally) on top of 2f81baa. The prefill recv-cap table ran EP4 --fused_shared_experts 1 with zipf 0.2 at tpr 2048 / 3072 / 4096 / 6144, AITER_S1F_MAX_RECV=6144 against 0, with dc5ef4e's S1F defaults set by env on the local integration branch, plus 2-layer accuracy at tpr 2048 / 4096 / 6144 with no cap.

2f81baa (grouped GEMM rows for 97 experts/rank) on top of 94cb8f5. 2f81baa ran EP4 --fused_shared_experts 1 at tpr 256 / 512 / 1024 / 1152 / 1536 / 2048 / 4096 / 8192 against 94cb8f5, plus 2-layer accuracy at tpr 1152 / 8192, as listed above. It only adds CSV rows for expert=97, so top-6 and EP2 (which look up 96 / 192 / 193 experts) were not rerun. It also ran a DSV4.1 Flash c1024 end-to-end A/B on a local integration branch, one run each, as listed under Performance.

5f87064 (no recv cap for Flash top-7 on EP2 / EP4) on top of 8cf0c8c. 5f87064 ran EP2 tpr 4096 / 8192 and EP4 tpr 8 / 4096 / 8192 with --fused_shared_experts 1, against AITER_S1F_MAX_RECV=4096, plus 2-layer accuracy as listed under Testing. Top-6 was not rerun for 5f87064: it does not change the top-6 path.

8cf0c8c (compact plan in stream order) on top of 1380871. 8cf0c8c reran on EP2 at tpr 8 / 1024 / 8192 for performance, with 2-layer accuracy at tpr 8 / 8192, plus 2-layer accuracy with AITER_MEGA_PLAN_PREFETCH=1 at tpr 8 (S1F) and at tpr 8 / 1024 with AITER_S1F_MAX_RECV=1 forcing the non-S1F compact dispatch. A trace of the latter shows every kernel on one stream. EP4 was not rerun for 8cf0c8c.

1380871, on top of the main merge 45676c8. 1380871 adds the tile_m 32 variant on top of 1fc42c3; its EP2 numbers above were measured on 1fc42c3 plus that change. The merge 45676c8 brings in #5815 and #7323, which touch no MegaMoE file (quant_utils.py only gains new helpers), and was not re-benchmarked. Before it, on the main merge e16149f, EP4 reran at tpr 8 / 4096 / 8192 (106.9 / 538.2 / 895.6 µs/layer), and 2-layer accuracy passed again at tpr 8 and 8192. EP4 was not rerun with the tile 32 variant; Flash EP4 at tpr 256 / 512 may now pick it.

Behavior and intent

A compact plan consumes the current layer topk_ids. On Flash EP2 and EP4 (top-6, or top-7 with the shared expert fused), every step now runs the S1F kernel: tile 16 for decode, and tiles 64 / 128 up to 8192 tokens/rank with no recv cap. Other shapes keep the 4096 cap, and their S1F tile set changes only by the added 16-row variant. The shared GEMM body change touches only the post-compute (tile_m <= 32 or <= 2 buffers) branch when S1F hooks are passed (raw_drain is S1F-only). Without hooks it is unchanged.

Validation and unverified scope

Command, from outside the repo:

AITER_MEGA_PLAN_PREFETCH=0 HIP_VISIBLE_DEVICES=0,1 torchrun --standalone --nproc_per_node=2 op_tests/multigpu_tests/bench_mega_moe.py -q a4w4_mxfp4 -e 384 -k 6 -hd 5120 -id 2304 --fused_shared_experts 0 --layers 8 --stage2_fused true --dispatch_wire fp4 --stage1_fused true --profile_table 0 --acc_verify 0 --warmup 3 --iters 8 -tpr 8192

EP4 used HIP_VISIBLE_DEVICES=0,1,2,3 --nproc_per_node=4. The same command was also run at -tpr 8, 64, 256, 512, 1024 and 4096, with --profile_table 1 for the kernel table, with --layers 2 --acc_verify 1 for accuracy, and with --fused_shared_experts 1 for the top-7 table. ruff check and black --check passed on the edited files.

Unverified:

Changed op tests

None. This revision does not change any file under op_tests/.

@XingerZhu
XingerZhu requested a review from a team September 28, 2026 04:26
@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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5899 --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.

@github-actions github-actions Bot changed the title [FlyDSL][gfx1250] Overlap decode compact plan with dispatch [FlyDSL] [gfx1250] Overlap decode compact plan with dispatch Sep 28, 2026
@zufayu
zufayu requested a review from yadaish September 29, 2026 00:32
@zufayu
zufayu requested a review from coderfeli October 15, 2026 06:34
@zufayu zufayu assigned coderfeli and unassigned yadaish Oct 15, 2026
@zufayu zufayu assigned yadaish and unassigned coderfeli Oct 15, 2026
@XingerZhu
XingerZhu force-pushed the zxe/mega_stage1_compact_overlap branch from 5534a53 to 2ed5925 Compare October 26, 2026 09:41
Copilot AI balanced review requested due to automatic review settings October 26, 2026 09:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

An undefined decorator blocks compact-plan imports, and padding skips can deadlock M-cluster synchronization.

2 open issues
What changed in this PR

This PR reduces gfx1250 MegaMoE decode latency by overlapping the next layer’s compact plan with dispatch and sizing plan launches to the current route count.

Changes:

  • Adds decode-specific stream coordination and adaptive compact-plan launch geometry.
  • Allows smaller GEMM2 tiles with padding guards.
  • Adds geometry-based VMM reservation sizing and CPU-only arena-bound tests.
File Description
op_tests/​multigpu_tests/​test_mega_moe_vmm_bytes.py Tests VMM bounds across dispatch formats and configurations.
aiter/​ops/​flydsl/​kernels/​mxfp4_preshuffle_gfx1250_tdm.py Adds alignment-aware padding guards to grouped GEMM.
aiter/​ops/​flydsl/​kernels/​mega_moe_gfx1250/​mega_moe.py Coordinates plan overlap, launch sizing, and VMM reservations.
aiter/​ops/​flydsl/​kernels/​mega_moe_gfx1250/​compact_plan.py Adds multi-block planning and generation-tagged histogram exchange.
aiter/​ops/​flydsl/​grouped_moe_gfx1250.py Enables narrower GEMM2 tiles and passes compact alignment.
aiter/​ops/​flydsl/​grouped_gemm_mxfp4.py Forwards alignment to the GEMM launcher.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 27, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

An existing tuned configuration reaches the new gather rejection, and the compact GPU path needs numerical regression coverage.

4 open issues
1 resolved since last review

Review effort: Balanced

Comment thread aiter/ops/flydsl/grouped_moe_gfx1250.py Resolved
Comment thread aiter/ops/flydsl/grouped_moe_gfx1250.py Resolved
@Boss2002n
Boss2002n force-pushed the zxe/mega_stage1_compact_overlap branch from 6e4a540 to cab1e22 Compare October 29, 2026 08:25
Copilot AI balanced review requested due to automatic review settings October 29, 2026 08:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Padding workgroups can cause cluster-barrier deadlocks and out-of-bounds index reads, while compact gather fails with existing incompatible tuned configurations.

6 open issues

Review effort: Balanced

Comment thread aiter/ops/flydsl/grouped_moe_gfx1250.py Resolved
Copilot AI balanced review requested due to automatic review settings November 9, 2026 10:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

The probe recorded its result per exact recv bound. An eager prefill step carries a new token sum almost every time, so its first layer probed and ran dispatch + GEMM1 on every step. GEMM1 picks its CSV row by _get_padded_m(recv_bound), so the probe holds for the whole bucket.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 15:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

…ompiledFunction

Calling the @flyc.jit launcher directly rebuilt its cache key and checked its globals on every launch, about 110 us/layer of host time that left eager prefill host-bound at tpr 2048. Launch it through _run_compiled like the other grouped GEMM launches; its tensor arguments are layout-dynamic, so the dtype and rank of each pick the artifact.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 16:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@JiaoliangYu

Copy link
Copy Markdown
Contributor

Thanks for d84ec33. Keying the probe by the CSV bucket is what lets eager prefill steps run S1F in serving; we confirmed that end to end on DSV4.1-Flash DEP4 c1024 (MI455X).

A follow-up suggestion: the probe result can be computed up front instead of observed.

  • _step_for already derives align_m from the row GEMM1 later uses. Both look up _find_grouped_config(token_num=_get_padded_m(recv_bound), ...) with the same key (lru-cached), and on the compact path GEMM1 then clamps tile_m = min(tile_m, compact_align_m) (grouped_moe_gfx1250.py:812). So GEMM1's tile is min(row tile_m or AITER_TDM_TILE_M, align_m), and the tile-only check (AITER_S1F_ANY_TILE=1) reduces to row tile_m >= align_m. In dsv41_tuned_grouped_fmoe.csv every 96-expert row has tile_m == tile_m2, so the probe always matches.
  • Computing it in _step_for (e.g. keep a g1_tile_m on _CompactStep and compare it in _gemm1_reasons) would:
    • drop the fallback step per (align_m, bucket), and the g1_seen / probe hook with it;
    • remove the eager-before-capture dependency: should_probe() is False while capturing, so a bucket first seen inside a capture records dispatch + GEMM1 into that graph for good (ATOM warms up eagerly before recording, so it does not bite there today);
    • make step_will_run() exact from the first step;
    • let _precompile_s1f_plans, which already walks every bound through _step_for, precompile the S1F launchers for the fusing tiles as well, so the first S1F launch at a new tile does not compile inside the serving loop, and the dispatch + scatter + GEMM1 kernels for those buckets are never built.
  • The probe could stay behind an env as a debug check that the two agree.

#7600 routes the stage-1 launch through _run_compiled. Keep _run's
specialization key so layout-dynamic tensor arguments still pick the
cached CompiledFunction by dtype and rank.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 07:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

The stage-1 verdict waited for one eager probe per (align_m, CSV bucket)
step, so a bucket first seen inside a graph capture recorded dispatch +
GEMM1 for good, and every first eager step of a bucket ran the fallback.

_compact_gemm_tiles resolves (tile_m, tile_m2, m_warp2) the way
grouped_gemm_gfx1250_a8w4 does (CSV row, then AITER_TDM_* overrides) and
_CompactStep carries GEMM1's clamped tile_m and GEMM2's quant WMMA repeat,
so eligible() / step_will_run() decide from the step alone. The GEMM1
hook keeps rejecting a launch whose tile disagrees. The first eager S1F
launch precompiles the launcher of every step bound that can fuse.
Copilot AI balanced review requested due to automatic review settings November 10, 2026 08:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

#7726 adds gemm_stage and replaces IGLP_PARAMS with HYPER_PARAMS. Keep
that, and keep this branch's m_align guard that forces cluster_m to 1 so
a padding skip cannot deadlock the M-cluster barrier.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 05:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

XingerZhu added a commit that referenced this pull request Nov 13, 2026
…age-1 (#7919)

* Optimize FlyDSL grouped MoE kernels

* improve test

* support a preshuffle

* add csv support

* update quant and shuffle

* update

* update mega-moe

* update

* update csv

* update

* simplify code

* fix accuracy drop

* update csv

* fix format

* fix(flydsl): align A-preshuffle guards and AOT coverage

* improve cs test

* fix ruff

* Tune conc16384 benchmark with WPT2 and cluster sync disabled

* Add standalone conc16384 GEMM1 performance reproducer

Rename the benchmark to reproduce.sh and pin the validated zero-input configuration. Include standalone activation/quantization dependencies and tests so the script does not rely on stashed implementation changes. Preserve unrelated work in stash. GPU timing was not rerun for this commit.

* Tune grouped MoE LDS scheduling and prologue initialization

Use normal WMMA order with operand B reuse and precomputed payload LDS bases. Initialize accumulators before the prologue TDM wait and select WPT1 for the conc16384 tuned configuration.

Include the local benchmark scripts and the reproducer iteration update.

* Pin FlyDSL WMMA scale registers to disjoint low VGPR slots

* update

* update

* update

* remove useless tests

* add script

* update script

* update script and wheel

* update

* update1

* update

* Fix LDS helper shadowing after GEMM task refactor

* Simplify gfx1250 prefill scheduling and add reproducible MoE benchmarks

* Keep local GPU benchmark scripts and microtests out of the branch

* Restore LDS layout controls and decouple interleaving from scheduling

* Fix strict VGPR pinning with FlyDSL 0.5.0

Resolve sched_vgpr through rocdl.experimental on FlyDSL 0.5.0 while retaining compatibility with the older public API. Keep strict placement enabled for prefill kernels.

Validated DSV4 Pro conc16384 with three const/random runs at 32 iterations. Both GEMMs have zero scratch instructions and accumulator placement at physical v512-v1023; median const GEMM1/GEMM2 is 465.77/322.86 us.

* update for ds flash v4.1

* Tune DSV4.1 Flash 8192 prefill configuration

* update for release

* add csv

* update csv

* update csv for dsr1 fused expert

* Move DSR1 grouped MoE configs into a dedicated CSV

* remove useless csv

* update csv

* [FlyDSL] Simplify prefill WMMA emission and barriers

* Tune DSR1 65-expert (64 routed + 1 shared, topk 9) grouped MoE rows for 1-1024 tokens

The single 16x256x256 four-wave as-prologue row left gemm1 at ~16 TB/s for decode-sized
batches (three workgroup rounds, extra round at 4 tokens, and a 64-row tile that doubled
weight reads at 1024 tokens). Re-swept tiles and knobs for this shape on gfx1250:
narrower gemm1 tiles (tile_n 64/128) with deeper buffering for 1-32 tokens, as-prologue
kept only at 64 and 256 tokens where it measures faster, and 128x256 tiles at 1024 tokens.

gemm1+gemm2 vs the previous rows (test_flydsl_grouped_gemm, constant + uniform init):
1 tok 1.81x, 2 1.11x, 4 1.25x, 8-256 1.12-1.16x, 512 1.08x, 1024 1.38x; >= 2048 unchanged.

* Simplify FlyDSL KSL0 fence configuration and kernel symbols

* Merge PR #5899 (zxe/mega_stage1_compact_overlap) for local benchmarking

Co-authored-by: Cursor <[email protected]>

* mega: adapt S1F/GEMM2 to the MoE prefill path, tune DSV4.1 Flash EP4 buckets

- Pin VGPRs only for the 2x2 256^3 tile; S1F's 1x4 256 variant overflowed the map.
- S1F GEMM1 warp grid per tile_m (2x2 at 256, AITER_MEGA_S1F_WARPS override)
  and pass the GEMM kernel_attrs to the S1F launch.
- DSV4.1 Flash E96 rows: GEMM2 next_stage_prefetch + lds_soa_load_interleave
  at 8192+, add the missing 131072 bucket (tpr 32768: 3783 -> 3258 us/layer).

Co-authored-by: Cursor <[email protected]>

* [FlyDSL] [gfx1250] Pack GEMM1 A inside mega stage-1 for large prefill buckets

The stage-1 producer writes the M16 packed A layout, and the 256-row GEMM1
turns on a_preshuffle, lds_soa and next_stage_prefetch together with the
grouped-MoE prefill schedule. This runs only when the recv bound is at least
65536, which for EP4 top-6 is tpr 16384 and 32768. Payload and scale use
separate buffer resources so the masked store sentinel stays out of range.

DSV4.1 Flash EP4, 8-layer graph: 1654 vs 1704 us/layer at tpr 16384 (-2.9%)
and 3111 vs 3258 at tpr 32768 (-4.5%). Smaller buckets stay on the 128-tile path.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: yadaish <[email protected]>
Co-authored-by: JiaoliangYu <[email protected]>
Co-authored-by: lalala-sh <[email protected]>
Co-authored-by: hyi <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: XingerZhu <[email protected]>
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.

8 participants