Repository navigation
[SM100] Mega MoE: port upstream #525 features (barrier-free dispatch, partial-row loads, batched pull, RMSNorm/FP32 out) - #179
Merged
Conversation
…#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]>
…oads (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]>
… 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]>
…eek-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]>
… 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]>
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]>
…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]>
…ation 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]>
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]>
…ecks, and add RMSNorm/FP32 test
… port scheduler tail-drain fixes
…-cached RMSNorm weights
… prevent 0-token cleanup race
…ot extent, and acquire on per-expert count poll
…p stale BF16 comment
…in kPostNormInCombine check
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.
Based on
dev(merged withdevatc618b326, including#177,#182/#184PowLU, and#168in-combine post-expert norm). Ports the Mega MoE features and fixes from upstreamdeepseek-ai/DeepGEMM#525that#177did not take ontodev's kernels (NVFP4, SIMT pull, full-pool path, post-expert norm, PowLU, SiTU, broadcasty, LPT scheduler). Each feature was measured on its own before the next one was added; features that regressed perf were fixed or dropped.Commits
token_topk_idx + 1. The pull polls them, and cleanup zeroes them.-1/+1counters, so graph replays need no reset. They replace the grid-index fields at the same workspace offset.dev's L1-first does not.DG_MEGA_MOE_PULL_TOKENS=<n>).fp8_fp4_mega_moe(rms_weights,rms_eps, FP32y, also forwarded innvfp4_mega_moe).yis BF16.ywith broadcastyis rejected.(1ull << 32), the arrival counter usesatom.acq_rel.gpu, and the scheduler polls sums relaxed.devalready sizes UMMA N by valid rows, so balancing saved no MMA work and cost 1.6% at NVFP4 T=4096 and 0.3–0.7% elsewhere. Partial-row loads alone are a 1.2–1.6% win and stay.DG_MEGA_MOE_PULL_TOKENS=<n>). Measured on B300 below: it cost 2–3% at EP4 decode. Default compiles the single-token pull path.ring_covers_full_poolwhennum_pull_tokens > 1(prevents a batch from deadlocking on its own unpublished ring slot), addsrms_weightsdevice & alignment checks, tightens therms_sum_sqsmem assert tokNumChunks == 2, and ports--rms-norm/--output-dtype fp32checks totests/test_mega_moe_inference.py.expert_recv_count, parallelized source-slot cleanup, and scheduler fixes (from upstream#525).expert_recv_counttoexpert_idx * num_ranks + rank_idxso per-expert count loads are coalesced across ranks.(kNumSMs - 1) * kNumDispatchWarpswarps.cute::elect_one_leader_sync()inget_next_local_task_idxand upstream's sentinel tail-drain ordering.#525, FP8/FP4 and BF16 kernels). Usesptx::clamp_bf16x2_no_nan,ptx::cvt_bf16x2_to_fp32x2, andmath::fast_exp_ftz. Bitwise identical; −4.6% on 1-rank NVFP4 T=4096 and −1.1% on EP4 NVFP4.#525). Drops the combine TMA store buffer (kNumChunkSlots3 → 2), writes BF16ydirectly viaptx::st_evict_first(and direct register broadcast forkBroadcastY), caches FP32rms_weightsin the freed smem, and uses 4-accumulator RMSNorm ILP.#525). Hoists dispatch warps'scheduler.fetch_expert_recv_count()beforekDispatchWithEpilogueBarrierIdxin both FP8/FP4 and BF16 kernels so fast SMs cannot clearexpert_recv_count_sumbefore slower SMs' dispatch warps read it.DG_MEGA_MOE_PULL_TOKENSto preserve at leastmin_stagespipeline stages (3 forSM103UltraK96, 2 otherwise).SymmBuffer(base=...)extent check (num_experts * num_max_tokens_per_rank) on SM100+ (verified compatible with allsglangbase=callers).ptx::fence_acq_rel_sys()on the last SM before count publish paired withptx::ld_acq_sys+__syncwarp()on the coalesced once-per-expert count poll.dev(#168,#172,#182/#184). Integrates#168's in-combine post-expert norm cleanly withkNumChunkSlots = 2streaming combine (laying outsmem_norm_w→smem_rms_weights→rms_sum_sqwith no overlap and removing the deadwait_result_storeTMA wait).Not ported:
dev's NVFP4 path already stores its SFs coalesced.16dp256b2xloads and removal ofdev's BM240 epilogue prefetch.source_token_topk_idxreservation insideMegaMoESignals(guarded instead by theSymmBuffer(base=...)extent check).deep_gemm/mega_moePython package and heuristics (devkeeps its own).Validation (SM107 / VR, 4 GPUs)
Method. Every comparison runs both arms on the same node in ABBA order: 6 reps of 5-run medians for EP4, 3 reps for 1-rank. A row is flagged when
arm/base > 1.02and more than twice the A/A spread. Geo is thearm/basegeomean; lower is faster.Correctness.
fp8,nvfp4,post-expert norm,broadcast_y,masked,graph replay,graph replay + broadcast_y) are bitwise identical todev: 56/56.rms_fp8,rms_nvfp4): FP32yrounded to BF16 matches BF16ybitwise on every iteration (0mismatches); relative error vs FP32 reference is3.88e-3for BF16yand3.3e-7–3.8e-7for FP32y.test_mega_moe.py --post-expert-normat9af6741a, job7912): passed for no-gain,weight_first=True, andweight_first=FalseatH=4096(T=64andT=512,kPostNormInCombine),H=6144, andH=7168(kFusedPostNormPartials).Perf vs
dev(#177at7f533845, jobs7820/7827):branch/base, job7820/7827)7827)fp8xfp4h7168 i2048, T 1–4096/rank0.966/0.9710.9870.970/0.9760.994fp8xfp4SiTU top16 masked decode T40 / T1600.966/0.975(7827:0.978/0.972)0.978/0.9721.003/0.996(7827:1.002/0.996)1.008/1.0000.967/0.9710.976Per-step isolation (SM107 / VR):
7817)0.998–1.002)7818)7819)1.000–1.001)fence_acq_rel_sys+ld_acq_sys, job7863vsst_rel_sysjob7864)+1.1%FP8 /+1.3%NVFP4 (vsst_rel_sys:+16.0%/+15.1%,+19–20 µsat T=1)Batched pull (commit 4) on B300
Setup.
DG_MEGA_MOE_PULL_TOKENS=1(the pre-batching path) vs upstream's batch size, in one build.Reading.
DG_MEGA_MOE_PULL_TOKENS=2(test_mega_moe.pyat 8 ranks, hidden 2048, where it engages).