Repository navigation
[SM100] Mega MoE: dynamic LPT expert ordering, N-outer L2 weight reuse, and skewed prefill BLOCK_M heuristic - #162
Merged
zcnrex merged 1 commit intoNov 23, 2026
Conversation
…e, and skewed prefill BLOCK_M heuristic
Collaborator
|
The LPT ordering, N-outer One tiny doc nit: the PR description mentions a 4-bucket |
trevor-m
added a commit
to trevor-m/DeepGEMM
that referenced
this pull request
Nov 23, 2026
…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]>
zcnrex
pushed a commit
that referenced
this pull request
Nov 23, 2026
…ed L2 at the tail for large tiles (#157) * [SM100] Mega MoE: all L1 tasks first for decode-sized loads, shared L2 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]> * [SM100] Mega MoE: bound L1-first by extra L1 waves, keep shared L2 early 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]> * [SM100] Mega MoE: retune the L1-first cap and shared L2 gate on the rebased dev Re-measured after rebasing onto dev a96d065 (#160, #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 (#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]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Under realistic skewed prefill routing, hot local experts receive multiple
M-blocks (2..5+blocks per expert) while cold experts receive0..1. In the currentMegaMoESchedulerand tile heuristic:0 .. kNumExperts - 1), so a hot multi-block expert at the end of the array can create a tail wave across SMs, and within a multi-block expert the task order sweeps allN-clusters form_block = 0before moving tom_block = 1(M-outer), thrashing L2 weight tiles when total expert weight bytes exceed L2 capacity.EVICT_NORMAL(EVICT_FIRSTfor activations whenBLOCK_M > 64), even when an expert hasnum_m_blocks >= 2and reuses the exact same weight tiles across consecutivem_blocks.get_block_config_for_mega_moeadds a1.0 * sqrt(expected)dispersion margin at all token counts. On multi-block prefill (num_expected_tokens >= 240), heavy-tailed expert popularity regularly exceeds+1 sigma, spilling hot experts into an extraM-block and reloading all of their L1 + L2 weight tiles from HBM.This PR addresses all three bottlenecks while keeping Decode (
num_expected_tokens <= 24,max_m_blocks <= 1) completely untouched:scheduler/mega_moe.cuh): whenkEnableLPTSwizzleis enabled (sm100_fp8_fp4_mega_moe.cuhwithkNumSharedExperts == 0) and runtimemax_m_blocks >= 3, bucket experts in registers by descendingm_blocks(>=4, 3, 2, 1) inO(E)warp-parallel operations with zero extra SMEM. Uniform and light loads (max_m_blocks <= 2) bypass the sort at zero cost.EVICT_LASThints (scheduler/mega_moe.cuh,sm100_fp8_fp4_mega_moe.cuh):kSwizzleGroupM = 4M-blocks of the same expert perN-cluster within eachkNumLocalityDomainspartition so allM-blocks in the group reuse the resident L1/L2 weight tile in L2 while preserving 2-die HBM locality affinity and deadlock-free ring/warmup bounds (get_num_l1_warmup_waves,get_num_max_live_pool_blocks).uint16_t m_block_idx, num_m_blocksintoTaskInfo(keepingsizeof(TaskInfo) == 32), promoteW1/W2/SFBTMA cache policy toEVICT_LASTwhenevertask_info.num_m_blocks >= 2, and useEVICT_LASTfor activation ring TMA loads.heuristics/mega_moe.hpp): use3.0f * std::sqrt(num_expected_tokens)whennum_expected_tokens >= 240.0f(1.0fotherwise), reducing hot-expert M-block spills on skewed multi-block prefill without changing Decode or medium-batch tile choices.Outputs across all tested workloads are 100% bitwise identical (
max_abs_diff = 0.0,100.00%exact element match) todev.Tests
Passed the Blackwell MegaMoE test suite on 8x B300 (
test_mega_moe_pre_dispatch,test_mega_moe_nvfp4_trtllm,test_mega_moe_nvfp4_alphas,test_mega_moe_l1_fp4_accuracy,test_mega_moe_l1_sentinel,test_mega_moe_situ,test_mega_moe_global_tokensacross 8-rank NVFP4, 2-rank MXFP4 ring wrap, and 2-rankx_scales) and verified thesetup.pypybind build.Microbenchmark & NCU
8x B300 (
EP = 8) standalonenvfp4_mega_moemicrobenchmark (fast_math=True, use_x_scales=True, median of 60 iterations across slowest rank;M= tokens per rank):H, I, E, top_k)M/rank, routing)BLOCK_M(dev-> PR)dev(us)devH=7168, I=5120, E=384, K=4M=16, uniformH=7168, I=5120, E=384, K=4M=2048, uniformH=7168, I=5120, E=384, K=4M=2048, skewedH=7168, I=5120, E=384, K=4M=4096, skewedH=7168, I=5120, E=384, K=4M=8192, skewedH=7168, I=2048, E=256, K=8M=8, uniformH=7168, I=2048, E=256, K=8M=2048, uniformH=7168, I=2048, E=256, K=8M=4096, skewedNsight Compute (
2026.3.0) 1-GPU (EP = 1,H=7168, I=5120, E_local=48, top_k=4) hardware counters — both fixed-tile (M=2048 skewed,BM=192 -> 192isolating LPT + N-outer +EVICT_LAST) and multi-block skewed (M=4096 skewed,BM=192 -> 240):BLOCK_Mdram__bytes_read.sumlts__t_sector_hit_rate.pctsm__pipe_tensor_cycles_activeM=2048, skeweddevM=2048, skewedM=4096, skeweddevM=4096, skewedM=4096, uniformdevM=4096, uniform