Repository navigation
[SM100] Mega MoE: all L1 tasks first when few L1 waves are left, shared L2 at the tail for large tiles - #157
Conversation
| const bool is_l1_first = num_total_m_blocks <= kNumRingBlocks and | ||
| (BLOCK_M <= 64 or num_total_l1_waves <= min_l1_warmup_waves + 1); |
There was a problem hiding this comment.
The interleaved L2/L1 order on dev also spreads the L2 epilogue's combine writes (NVLink to peer ranks) across the kernel, under L1 weight streaming. Issuing every L1 first moves all of that traffic to the tail, which is presumably why this is decode-only.
The BLOCK_M <= 64 branch doesn't bound the load, though, and nothing upstream does either. The tile heuristic picks 64 from the global per-expert average, so with many local experts (e.g. 104 per rank at EP4), uneven DP batches, or skewed routing, a 64-row config can still run many L1 waves with a lot of combine traffic behind them. The ungated numbers already trend toward break-even as load grows (0.972 / 0.975 / 0.993 at 240 / 264 / 336 tokens). This probably needs a load check too, e.g. a cap on L1 waves beyond the warm-up.
There was a problem hiding this comment.
[by Claude Code] Agreed, L1-first now has a load bound. It needs a ring slot for every pool block, and at most 4 extra L1 waves after the warmup with decode tiles (BLOCK_M <= 64), or 1 with larger tiles. I first set the cap at 8. After rebasing onto dev a96d065 (#160, #162) and re-measuring, the gain ends sooner, so the cap is now 4. On Vera Rubin (EP4, fp8xfp4, BLOCK_M 64), L1 first alone vs dev:
| extra L1 waves | load (active experts per rank, tokens per rank) | with shared expert | without |
|---|---|---|---|
| 1 | 13, 96 | 0.952 | 0.954 |
| 3 | 13, 240 | 0.982 | 0.991 |
| 4 | 16, 256 | 0.986 | 0.993 |
| 5 | 13, 336 | 1.000 | 1.006 |
| 7 | 13, 480 | 0.997 | 1.012 |
5 and 7 extra waves now keep dev's order. Your many-experts case does too: with all 104 local experts active (~16 extra waves), it measures 1.000-1.002 vs dev. All runs stay bitwise identical to dev.
|
B300 (148 SMs) / GB300 (152 SMs) A/B of
With 74–76 CTA pairs instead of 106, most of the Vera Rubin gain doesn't apply. The 13-block loads need 4 L1 waves, so L1-first stays off. On the 16-rank loads, |
…2 at the tail above BLOCK_M 64 - Routed tasks: issue every L1 task before the first L2 task when the L1 work is decode-sized (`BLOCK_M <= 64`, or at most one L1 wave left after the warmup waves) and every pool block has its own ring slot. The last M blocks start their L1 earlier, and their L1 -> L2 chain sets the tail. Larger loads keep the interleaved order. - Fused shared expert: the shared L2 tasks keep the early slot (before the routed tasks) only with decode tiles (`BLOCK_M <= 64`); with larger tiles they go after the routed tasks. Only the task order changes, so outputs are bitwise identical. Measured on Vera Rubin (CC 10.7), fp8xfp4 with a fused FP8 shared expert, DeepSeek-V4.1- Flash shapes, EP4: -2.3% to -7.2% per call at 32-rank decode loads and -2.1% to -6.9% at 16-rank loads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rly for 128-row tiles below 100 CTA pairs Review follow-up: - L1-first now needs at most 8 extra L1 waves after the warmup with decode tiles (BLOCK_M <= 64), and at most 1 with larger tiles. Unbounded, it was slightly slower with many local experts and few tokens each (104 experts per rank at EP4: up to +0.9%), while 13 experts per rank still gain through 7 extra waves. - With 128-row tiles the shared L2 keeps its early slot below 100 CTA pairs (B300 / GB300), where the tail was ~1% slower. BLOCK_M >= 192, and 128 on Vera Rubin's 106 pairs, keep the tail. Outputs stay bitwise identical to dev. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ebased dev Re-measured after rebasing onto dev a96d065 (sgl-project#160, sgl-project#162), same Vera Rubin setup: - L1-first with decode tiles (BLOCK_M <= 64) now allows at most 4 extra L1 waves after the warmup (was 8). 4 extra waves still gain 0.7-1.4%; 5 were 0-0.6% slower than dev and 7 up to 1.2% slower, worst without a shared expert (sgl-project#162's swizzled order). - Shared L2 keeps its early slot for every BLOCK_M < 192, on every part (was: decode tiles, or 128-row tiles below 100 CTA pairs). With 128-row tiles the tail no longer gains on Vera Rubin either: alone it was 0-0.8% slower, and with L1-first the early slot is 1.3% faster. This drops the CTA-pair term from the gate. Outputs stay bitwise identical to dev. Co-Authored-By: Claude Opus 5.5 <[email protected]>
be8427d to
f4dfd5c
Compare
|
[by Claude Code] Thanks for the A/B. The shared L2 tail is now gated to
So the CTA-pair term from the previous revision is gone. One change touches your L1-first rows. L1 first is now capped at 4 extra L1 waves with decode tiles (see the inline thread). With 74-76 CTA pairs, E416 T240 needs about 5 extra waves, so it returns to |
…e dispatch, partial-row loads, batched pull, RMSNorm/FP32 out) (#179) * [SM100] Mega MoE: barrier-free dispatch (port of upstream deepseek-ai#525) Drop the dispatch grid sync and the NVLink barrier before the pull. The last SM to arrive publishes the expert counts (per-rank counts, a system fence, then the sums), source slots hold token_topk_idx + 1 and are polled per slot and cleared in the cleanup, and combine / broadcast readiness become counters that each launch decrements and the peer increments, so graph replays need no reset. The scheduler acquires the expert-count sums. Unlike upstream, SMs still skip the send-count atomic for experts they send no tokens to; one arrival counter replaces upstream's per-expert arrival bits. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [SM100] Mega MoE: balanced expert blocks and partial-row activation loads (port of upstream deepseek-ai#525) Spread an expert's tokens evenly over its M blocks in 16-row steps (BLOCK_M >= 32), so its last block is no longer a short tail, and count each block's padding at its own last token. Routed L1/L2 activation loads use tensor maps sized to the block's UMMA-aligned valid rows, so short blocks skip the padding rows. Shared blocks keep full-row loads. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [SM100] Mega MoE: advance a short L1 tail past the L1-first cap (port of upstream deepseek-ai#525) Upstream advances up to kNumScheduleStages + 1 L1 waves when the remaining L1 work is within kNumScheduleStages waves of the warmup. Dev's L1-first rule (#157) already covers most of that range; keep upstream's rule only where L1-first does not apply. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [SM100] Mega MoE: batch whole-token TMA pulls (port of upstream deepseek-ai#525) When a token fits one pull chunk, the TMA pull keeps one token per lane and pulls a batch of them with one transaction: every token's load, then the weight, x_scale and SF loads, then one wait and every token's store. Batch sizes follow upstream's table (2 tokens at 2 KiB, 4 at 1 KiB, ...), not for the SIMT pull, the one-shot full-pool pull or BF16. DG_MEGA_MOE_PULL_TOKENS overrides the batch size. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [SM100] Mega MoE: fused post-combine RMSNorm and FP32 output (port of upstream deepseek-ai#525) `fp8_fp4_mega_moe` takes `rms_weights` (in `y`'s dtype) and `rms_eps` to apply an RMSNorm to the combined output, and `y` may be FP32. The norm is computed in FP32, over the BF16-rounded output when `y` is BF16; a two-chunk token keeps both chunks in adjacent warps of one CTA and exchanges the partial sums through shared memory. FP32 `y` is stored directly from registers; BF16 keeps the TMA store and the broadcast path (FP32 does not support `broadcast_y`). Co-Authored-By: Claude Opus 5.5 <[email protected]> * [SM100] Mega MoE: keep fences off the barrier-free dispatch count path Each per-rank count now carries an arrival word, which the pull and the cleanup wait for, so the last SM pushes counts and sums without a system fence, the arrival is one acq_rel atomic instead of a fence plus an atomic, and the scheduler polls the sums relaxed again. Only the fused post-expert norm keeps an acq_rel system fence on both sides, for its zeroed sums. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [SM100] Mega MoE: load send counts before the last SM's remote count pushes Each expert's send-count load sat behind the previous expert's remote store in the publish loop. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [SM100] Mega MoE: drop balanced expert blocks, keep partial-row activation loads Measured on SM107 EP4: balanced blocks cost 1.6% at 4096 NVFP4 tokens per rank and 0.3-0.7% elsewhere; the partial-row loads alone are a 1.2-1.6% win. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [SM100] Mega MoE: make the batched TMA pull opt-in On B300 NVFP4 hidden 4096 the batched pull was 2-3% slower at EP4 decode (T 1-512, every ABBA block), flat at EP4 prefill, and 1.8% faster only at EP8 T=4096. DG_MEGA_MOE_PULL_TOKENS still enables it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [SM100] Mega MoE: fix batched pull ring-wrap deadlock, rms_weights checks, and add RMSNorm/FP32 test * [SM100] Mega MoE: coalesce recv counts, parallelize slot cleanup, and port scheduler tail-drain fixes * [SM100] Mega MoE: port faster SwiGLU PTX primitives from upstream deepseek-ai#525 * [SM100] Mega MoE: streaming direct global stores for combine and SMEM-cached RMSNorm weights * [SM100] Mega MoE: fetch expert recv counts before epilogue barrier to prevent 0-token cleanup race * [SM100] Mega MoE: cap pull tokens by SMEM, check shared SymmBuffer slot extent, and acquire on per-expert count poll * [SM100] Mega MoE: honor mainloop min_stages in pull-token cap and drop stale BF16 comment * [SM100] Mega MoE: drop dead wait_result_store and use kNumChunkSlots in kPostNormInCombine check --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
[by Claude Code]
Problem
At decode sizes the Mega MoE kernel ends on the last M blocks' L1 -> L2 chain, and two scheduler choices make that chain start later than it has to:
Change
All L1 tasks first when few L1 waves are left. Every L1 task is issued before the first L2 task when both of these hold:
BLOCK_M <= 64), and at most 1 with larger tiles.L2 tasks still wait for their block's L1 tasks (or, with [SM100] Mega MoE: dynamic LPT expert ordering, N-outer L2 weight reuse, and skewed prefill BLOCK_M heuristic #162's swizzle, their M group's), as before. Past the cap, the extra waves hold back every L2 task and its combine writes, and the gain is gone (load bounds below).
Shared L2 at the tail for
BLOCK_M >= 192. Smaller tiles keep the early slot. With 192- and 240-row tiles the shared L2 tasks run after the routed tasks, where they fill the CTA pairs that idle during the last routed blocks' L1 -> L2 chain. With 128-row tiles the tail does not gain, on Vera Rubin or on B300 / GB300 (see the A/B in the comments).Both conditions are evaluated in the scheduler (
BLOCK_Mis a template parameter); the host is unchanged. Large loads keep the old order. Once the shared L2 tasks need more than one wave, they already went to the tail.Outputs are bitwise identical to
dev.Benchmark
Setup:
deva96d065, built from source, vs the same build with this PR's scheduler header (the only file it changes).fp8_fp4_mega_moeon Vera Rubin (CC 10.7, 212 SMs), one node, EP4, with the K=64 MMA and SIMT pull as SGLang runs it. DeepSeek-V4.1-Flash shapes: hidden 5120, intermediate 2304, top-6, 1 fused FP8 shared expert. Weights are localized over the 2 locality domains.DG_MEGA_MOE_TILESpins the tile the heuristic picks for 32 ranks (BLOCK_M128 at 240 tokens, 192 at 264 and 336). The twoBLOCK_M64 rows use the heuristic's own pick for the 4-rank call.fp8_fp4_mega_moe). Each result is the median of 5 replays, then the median over the 4 ranks, then the mean of 2 rounds run in ABBA order. Round-to-round spread is within ±0.3% on most rows.dev's, and 20 back-to-back calls reproduce it bit for bit.BLOCK_Mdevdev's order)Load bounds for L1 first,
BLOCK_M64 (heuristic), L1 first alone vsdev. The warmup is 2 waves in all of these. Extra L1 waves assume even routing over the active experts. "Without" runs with no shared expert, which takes #162's swizzled order:dev's orderdev's orderWith all 104 local experts active (~16 extra waves at 96-512 tokens per rank), the PR keeps
dev's order: 1.000-1.002. With 128-row tiles and 2 extra waves (20 active experts, 400 tokens per rank), issuing every L1 task first was 0.4% slower than the one-wave rule before the rebase, so larger tiles keep it.Shared L2 at
BLOCK_M128 (why the tail starts at 192): with shared L2 at the tail and the routed order unchanged, the 16-rank 468-token load ran at 1.000 and 400 tokens over 20 experts at 1.008 vsdev. At 240 tokens with L1 first, keeping shared L2 early ran at 0.959, vs 0.972 with it at the tail.Not measured here: real Blackwell parts (CC 10.0 / 10.3; see the B300 / GB300 A/B of the first revision in the comments), the BF16 and NVFP4 kernels (they share this scheduler), and other model shapes.
🤖 Generated with Claude Code