Skip to content

[SM10x] Mega MoE: recover the NVFP4 prefill perf regression - #170

Merged
zcnrex merged 2 commits into
sgl-project:devfrom
wookjeHan:wookjeh/megamoe-recover-perf
Nov 25, 2026
Merged

zcnrex merged 2 commits into
sgl-project:devfrom
wookjeHan:wookjeh/megamoe-recover-perf

Conversation

@wookjeHan

Copy link
Copy Markdown

Problem

NVFP4 MegaMoE prefill on the Muse shape (256 experts, top 8, hidden 4096, intermediate 4096, post-expert norm) became slower after #162 and #160. At 16K tokens it is about 1.34x slower on CC 10.7 and about 1.4x slower on GB300 than 169d4d5. Leave-one-out arms on dev attribute the gap to two causes:

  1. Tile ([SM100] Mega MoE: dynamic LPT expert ordering, N-outer L2 weight reuse, and skewed prefill BLOCK_M heuristic #162). The 3-sigma margin moves 16K tokens from BLOCK_M 192 to 240. A 240-row tile measured slower than a 192-row tile at every shape, chunk and routing skew we tried, also when 192 rows need more M blocks.
  2. Instruction Cache miss & epilogue ([SM100] Mega MoE: dynamic LPT expert ordering, N-outer L2 weight reuse, and skewed prefill BLOCK_M heuristic #162, [SM100] Mega MoE: fix FP4 full-pool TMA pull, cache ready peers in combine, and vectorize L1 FP4 epilogue #160).
    • The fully unrolled LPT sort is inlined in every dispatch warp and in the scheduler warp. It grows the kernel from about 7K to 21K SASS instructions, and the cost shows even where the sort never runs.
    • The shuffle-packed STS.32 L1 FP4 store and the Newton-Raphson SF reciprocal cost more in this epilogue than the byte stores and the shared-memory LUT they replaced.

Change

Two commits:

  1. Cap the NVFP4 tile at BLOCK_M 192.
  2. Bucketed LPT order, byte L1 FP4 stores, SF reciprocal LUT for BLOCK_M > 64.

Outputs are bitwise identical to dev without the post-expert norm, at every point below. With the post-expert norm, they stay within the run-to-run variation of its atomics.

Benchmark

Setup

  • CC 10.7 and GB300, nvfp4_mega_moe, dev (5121415) built from source vs this PR.
  • Arms ran interleaved in one allocation, 4 rounds, median.
  • GB300 EP8 runs span two nodes. They take 5 rounds and drop the first, since first-launch outliers are up to 2x slower in every arm.
  • Values are speedups (base time / new time), with the range over uniform routing and lognormal expert-popularity skew σ 0.5 / 1.0. Per-expert load CV is about 0.5 / 1.1 for those σ.
  • replay = 16 captured Muse serving routings.
  • CC 10.7 uses the default SIMT dispatch pull. There, BLOCK_M 192 and 240 both get 5 stages in the normal shared memory budget. With the TMA pull, 192 also gets the larger budget, so TMA-pull numbers include that effect.

#160 / #162 benchmark shapes, dev vs this PR (tokens per rank)

model (E/top-k/hidden/inter) part 8 16 2048 4096 8192
#160/#162 shape (384/4/7168/5120) CC 10.7, EP4 1.00x 1.00x 1.00x 1.00x 1.08-1.20x
#160/#162 shape (384/4/7168/5120) GB300, EP8 1.00x 1.00x 1.01-1.04x 1.15-1.22x 1.00-1.02x
DeepSeek-V3 (256/8/7168/2048) CC 10.7, EP4 1.00x 1.00x 1.01-1.02x 1.11-1.15x
DeepSeek-V3 (256/8/7168/2048) GB300, EP8 1.00x 1.00x 1.05-1.10x 1.03-1.04x

Muse Spark (256/8/4096/4096), GB300 EP8 (32 local experts), dev vs this PR

tokens / rank 1024 2048 4096 6144 8192
speedup 1.02-1.04x 1.15-1.22x 1.14-1.17x 1.13-1.16x 1.15-1.16x

Other model shapes, CC 10.7 EP4, no post-expert norm, dev vs this PR

model (E/top-k/hidden/inter), tokens / rank 1024 2048 / 3072 4096 6144 / 8192 12288
DeepSeek-V4-Flash (256/6/4096/2048) 1.02-1.07x 1.23-1.26x 1.18x 1.14-1.19x
GLM-5 (256/8/6144/2048) 1.02-1.04x 1.12-1.15x 1.11-1.16x 1.09-1.11x
Inkling-2 (384/8/4608/2304) 1.00-1.01x 1.13-1.23x 1.08-1.16x 1.06-1.10x

Commit 1 alone (EP4), dev vs commit 1

Muse Spark tokens (all ranks) 6144 12288 16384 24576 32768 replay
CC 10.7 uniform 1.18x 1.19x 1.21x 1.22x 1.18x 1.10x
CC 10.7 skew 1.0 1.17x 1.15x 1.18x 1.17x 1.17x
GB300 uniform 1.11x 1.13x 1.21x 1.17x 1.15x 1.07x
GB300 skew 1.0 1.13x 1.13x 1.12x 1.14x 1.12x

Commit 2 on top of commit 1 (CC 10.7 EP4), commit 1 vs both commits

model skew σ 1024 16384 65536
Muse Spark 0 - 3 1.00-1.09x 1.03-1.08x 1.02-1.03x
DeepSeek-V3 (256/8/7168/2048) 0 - 3 1.00-1.02x 1.00x
  • σ 3 puts up to 32x the mean load on the hottest expert. Visiting only occupied buckets keeps the LPT order at 1.00x or better there; a loop over every block count measured 0.99x.
  • Decode sizes (8 and 16 tokens per rank): 1.00x.

Not covered

  • SM100 (B200).
  • MXFP4 and FP8 x FP4 performance: commit 1 does not apply to them. The byte stores of commit 2 also run for MXFP4.

@wookjeHan wookjeHan changed the title [SM100] Mega MoE: recover the NVFP4 prefill perf regression [SM10x] Mega MoE: recover the NVFP4 prefill perf regression Nov 25, 2026
@zcnrex
zcnrex merged commit bb94f52 into sgl-project:dev Nov 25, 2026
zcnrex added a commit that referenced this pull request Nov 25, 2026
Resolve the get_block_config_for_mega_moe conflict: keep the SM103/SM107
NVFP4 decode block_m floor and #170's NVFP4 192-row cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zcnrex added a commit that referenced this pull request Nov 25, 2026
…ompiled arch

- Host picks the SM10x arch from the JIT target (`103a` / `107a` / `100f`), so an
  older NVCC that compiles CC 10.3 / 10.7 as `100f` gets the `Default` policy
  instead of a K=96 / K=128 request the kernel cannot run.
- Rename the mainloops by arch: Default, SM107PackedK64, SM103UltraK96, SM107K128.
- The device plan no longer downgrades the request: it static_asserts the
  mainloop's constraints and that the compiled arch supports it.
  MegaMoEEffectiveMainloop and the plan's arch parameter are gone.
- SM103 K=96 is selected only for BLOCK_M <= 192. The compact 32-col K=96
  ring for BLOCK_M = 240 is removed: NVFP4 is capped at 192 since #170, so it
  was only reachable through DG_MEGA_MOE_TILES, which now runs `Default`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
aryatsc added a commit to aryatsc/DeepGEMM that referenced this pull request Nov 28, 2026
Brings in sgl-project#170, sgl-project#165, sgl-project#169, sgl-project#178 and sgl-project#171.

Conflicts:
- csrc/jit_kernels/impls/sm100_fp8_fp4_mega_moe.hpp: the K=64 switch is now
  `uses_packed_fp4_weights(config.mainloop)` (sgl-project#165); the row-shuffled FP8 x FP4
  layout asserts that mainloop instead of `config.use_sm107_k64`. The kernel
  template takes the mainloop in place of the two K=64 / K=96 flags, followed by
  this branch's four parameters.
- deep_gemm/include/deep_gemm/impls/sm100_fp8_fp4_mega_moe.cuh: sgl-project#165's mainloop
  plan and validity check replace the K=64 static assert; the base MMA loop is
  taken from dev (now under `run_base_loop`) with this branch's SFB word order
  for row-shuffled packed FP4 weights re-applied in it.
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.

2 participants