Skip to content

[FusedMoE] Ergo: fused expert-parallel ReLU² MoE with per-expert output RMSNorm, 8 ranks - #31

Open
andyluo7 wants to merge 2 commits into
Inferact:mainfrom
andyluo7:pr-ergo-fused-ep
Open

andyluo7 wants to merge 2 commits into
Inferact:mainfrom
andyluo7:pr-ergo-fused-ep

Conversation

@andyluo7

@andyluo7 andyluo7 commented Dec 2, 2026

Copy link
Copy Markdown

Summary

A new FlyDSL kernel package, moe/fused_ep_mxfp4_relu2_norm_h8192_i4096_e32_top8_ranks8. It is the one-launch expert-parallel MoE layer of moe/fused_ep_mxfp4_h5120_i2304_e48_top6_ranks8, adapted for Amazon Ergo:

  • gate-only ReLU² experts;
  • a per-expert output RMSNorm before the top-k sum;
  • H 8192, I 4096, top 8, 32 experts per rank over 8 ranks.

Depends on #30. The staged baseline in the benchmark uses that entry. This branch is stacked on it, so the diff shows both until it merges.

What changed against the DeepSeek-V4 package.

  • Protocol unchanged. Dispatch, route records, arrival and finish counters, and peer writes all stay as they were.
  • GEMM1. Gate-only, with relu(g)^2 and MXFP8 requant in the epilogue.
  • GEMM2. Returns unweighted bf16 route rows. The norm needs a route's whole 8192-wide row, and an expert rank only has that once every GEMM2 column tile is done. So each tile also writes the row's square-sum partial for its columns, one fp32 per (token, slot, column tile), beside the inbox.
  • Combine. Runs on the token's rank. It sums a slot's partials in tile order to get rstd, normalizes the slot with its expert's scale from a [epr * world, 8192] table of every rank's experts, and sums the route-weighted slots in slot order. There is still one rounding and no output atomics.
  • Tile table. Swept for these shapes at the per-rank token counts of DP8 decode with DSpark k=8 (sweep_dispatch.py). Against the DeepSeek-V4 tiers it started from: the same up to T 32, and 8–22% faster from T 64 to 1,024.
  • Benchmark. Adds a solo-rank scenario (one rank's prefill chunk, the others idle) and --hint-from for rows_hint.

Performance

Setup: 8 x MI350X, graph replay of 20 distinct inputs, µs per call (max over ranks); zipf = Zipf 1.2 expert popularity.

Staged = what DP + EP serving runs without this entry: RCCL all-gather of the bf16 rows, ids and weights, then moe/mxfp4_relu2_norm_h8192_i4096_e32_top8 on every gathered token, then RCCL reduce-scatter.

T per rank 1 8 16 32 64 128 256 512 1024
fused uniform 90 198 223 224 224 287 401 651 1127
staged uniform 130 241 268 293 335 460 838 1592 3114
fused zipf 70 166 185 237 319 445 673 1162 2168
staged zipf 115 192 267 387 377 545 1025 1988 3972

The fused layer is 1.16–2.76x faster. From T 256, the return of unreduced route rows over xGMI binds (134 MB per rank at T 1024).

End to end. In vLLM, Ergo on 8x MI350X with DP8 + EP8 and DSpark, the layer runs on decode steps, where every rank has at most 1,024 tokens. Prefill steps keep the all-gather path.

Concurrent requests 1 64 256 512
output tok/s, fused 186 5,627 12,432 17,459
output tok/s, staged 141 4,064 7,266 9,456

GSM8K is 97.6% with the fused layer and 97.3% without.

Prefill. #29 extends the DeepSeek-V4 fused EP to prefill sizes. The same change would let Ergo's prefill use this layer too.

Tests

python3 -m pytest tests/moe/fused_ep_mxfp4_relu2_norm_h8192_i4096_e32_top8_ranks8 -q
torchrun --nproc-per-node 8 benchmarks/moe/fused_ep_mxfp4_relu2_norm_h8192_i4096_e32_top8_ranks8/benchmark_experts.py [--baseline]
PYTHONPATH=. torchrun --nproc-per-node 8 benchmarks/moe/fused_ep_mxfp4_relu2_norm_h8192_i4096_e32_top8_ranks8/sweep_dispatch.py

The tests run on 8 x MI350X, for 32 and 33 experts per rank, with:

  • uniform, skewed and all-on-rank-0 routing;
  • MXFP8 and bf16 rows;
  • unequal and empty ranks;
  • unrouted ids.

They check:

  • the output against reference.py: cosine >= 0.99999, each row >= 0.9999;
  • unrouted tokens give exact zeros;
  • two runs and a CUDA graph replay with new inputs are bitwise identical;
  • nothing compiles after the warm-up.

The workload spreads the experts' output magnitudes up to 16x. A kernel that skipped or misplaced the per-expert norm therefore drops the cosine to about 0.7.

🤖 Generated with Claude Code

andyluo7 and others added 2 commits December 5, 2026 09:32
…192 I4096 E32 top8

`moe/mxfp4_relu2_norm_h8192_i4096_e32_top8`: one expert-parallel rank's routed
experts of Amazon Ergo (256 experts, top 8, 32 local): MXFP8 x MXFP4 gate-only
GEMM1 with ReLU² and MXFP8 requant in the epilogue, an unweighted GEMM2, and a
combine that RMS-normalizes each slot with its expert's scale before the
route-weighted sum in slot order. One launch after the sort; no output
atomics. Adapted from moe/mxfp4_h5120_i2304_e48_top6.

Co-Authored-By: Claude <noreply@anthropic.com>
…8 ranks

`moe/fused_ep_mxfp4_relu2_norm_h8192_i4096_e32_top8_ranks8`: the one-launch EP
layer of moe/fused_ep_mxfp4_h5120_i2304_e48_top6_ranks8 for Amazon Ergo's
gate-only ReLU² experts (H 8192, I 4096, top 8, 32 experts per rank). GEMM2
returns unweighted bf16 route rows with a square-sum partial per column tile;
the combine on the token's rank sums the partials in tile order, normalizes
each slot with its expert's scale and sums the route-weighted slots in slot
order. Tile table tuned per DP8 decode token count (sweep_dispatch.py).

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant