Repository navigation
Conversation
…plit-4 combine threshold numerics='trtllm': the top-k weight is applied at the combine, SiTU runs on the FP32 accumulators, and the SiTU gate is literal. split4_combine_max_tokens=N: for calls of at most N tokens a token's top-k rows are summed in four interleaved accumulators. Both are opt-in per call and reject blockwise-128 and broadcast_y. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…pert The dispatch pull finds a token's expert with one prefix sum and a ballot instead of walking the experts. Any rank count. Co-Authored-By: Claude Fable 5.2 <[email protected]>
For kNumRanks == 1 the NVLink barrier is the grid sync; there is no pull barrier, no clean barrier, no per-rank count load and no combine-ready word. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…xpert tokens locally The scheduler issues all expert count loads before the first check and computes pool block offsets once per call (any rank count). One-rank groups count expert tokens from topk_idx locally instead of through the global count protocol. The count loader keeps one pending bit per 32 experts, so it carries a static assert for at most 1024 experts per rank. Counts are taken in physical expert order before the LPT slot sort; the pull looks a slot's source tokens up by its physical expert id. The one-rank flags sit behind both members of the count / send-buffer union, where the pull cannot overwrite them. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…t when all L1 tasks go first When every L1 task of a call is issued before its first L2 task (the L1-first order of sgl-project#157, which implies no ring reuse), the scheduler warp waits for a task's inputs before publishing it: an L1 task for its block's tokens, an L2 task for every L1 N block of its pool block. The load warps then start their TMA copies without polling. A checked task carries kDepsCheckedBit in m_block_idx. Opt-in per kernel (check_deps); only the FP8xFP4 kernel opts in, the BF16 kernel is unchanged. The task order is the scheduler's own (own-domain L1 tasks first, same steal rule). A kernel can also opt in to the L1-first order whenever the M blocks fit in the ring, past the cap on extra L1 waves (l1_first_whenever_fits); the FP8xFP4 kernel does so for one-rank groups only, where the checked order measures faster at 80 rows and above. Multi-rank groups keep the cap. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A block of at most 16 valid rows loads an 8-row activation box per CTA instead of the full box. Two new tensor-map arguments. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…FP8xFP4 groups topk_format='packed': int32 words (expert id << 16) | bf16(weight) at the start of topk_idx, ids counted from topk_first_expert, so a router can write its output straight into the buffer. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… symmetric buffer SymmBuffer(exact_num_max_tokens=True) keeps num_max_tokens_per_rank as given (a multiple of 128) instead of aligning it up to 1920 rows, and max_block_m=N sizes the token and SF rings for M tiles of at most N rows instead of every candidate tile. A call on such a buffer that would pick a larger tile is rejected on the host. Both default to the current behaviour; a decode-only group can allocate, for example, 256 rows with max_block_m=64. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… SiTU experts on SM107
weight_layout='row_shuffled' ('trtllm') is accepted for FP8xFP4 with packed
FP4 weights and the SM107 K=64 MMA: the kernel reads the caller's weight and
scale tensors directly, one 128x128 weight tile and one scale slab per
stage. L2's 32-row shuffle is undone by the descriptors; L1's 16-channel
order is undone on the FP8 output of the L1 epilogue. Routed experts only,
hidden and intermediate sizes in multiples of 128; any expert and rank count.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
…te tests test_mega_moe_compact_buffer.py: SymmBuffer(exact_num_max_tokens=True, max_block_m=64) keeps its row count, is smaller than the default buffer, gives bitwise equal outputs and rejects a call that picks a larger tile. test_mega_moe_fp8_fp4_row_shuffled_gates.py: weight_layout='row_shuffled' for FP8xFP4 is rejected without SiTU and with shared experts. Co-Authored-By: Claude Fable 5.2 <[email protected]>
3 of 5 tasks
aryatsc
marked this pull request as ready for review
November 25, 2026 07:13
… file The seven files shared one driver and differed only in group shapes and call sizes. test_mega_moe_invariants.py keeps every shape and size as a named suite (--suite to run one); suites that ran with two ranks still do. Co-Authored-By: Claude Fable 5.2 <[email protected]>
zcnrex
added a commit
that referenced
this pull request
Nov 27, 2026
- Add SM10xArch, MegaMoEMainloop, is_mega_moe_mainloop_valid (including num_stages >= 3 for SM103UltraK96), and uses_packed_fp4_weights in types.cuh; keep get_compiled_sm10x_arch() device-only. - Select the host SM10x arch from the JIT target (get_sm10x_arch()) and remove unused SM103ArchSpec. - Consolidate per-arch MegaMoE mainloop, store-tile override, SIMT/TMA dispatch pull, and SMEM budget into get_mega_moe_arch_policy(), and fall back to Default if the resulting pipeline has too few stages. - Add 5- or 6-int DG_MEGA_MOE_TILES support and include fp4_weights, gran_k, and mainloop in the DG_PRINT_CONFIGS dedup key. - Add constexpr make_mega_moe_mainloop_plan() and remove unreachable SM103 BM=240 compact K=96 ring. - Add SM107 FP4 (NVFP4/MXFP4) K=128 mainloop (2 MMAs per BLOCK_K=256 stage, no Default tail), SM100_MMA_MXF4NVF4_BLOCK32_2x1SM_SS, and 576-col Allocator2SmExclusive for BM=240. - Drop redundant RowShuffled/K64 asserts already implied by RowShuffled requiring NVFP4 (avoiding unnecessary conflict with #166).
zcnrex
added a commit
that referenced
this pull request
Nov 27, 2026
- Add SM10xArch, MegaMoEMainloop, is_mega_moe_mainloop_valid (including num_stages >= 3 for SM103UltraK96), and uses_packed_fp4_weights in types.cuh; keep get_compiled_sm10x_arch() device-only. - Select the host SM10x arch from the JIT target (get_sm10x_arch()) and remove unused SM103ArchSpec. - Consolidate per-arch MegaMoE mainloop, store-tile override, SIMT/TMA dispatch pull, and SMEM budget into get_mega_moe_arch_policy(), and fall back to Default if the resulting pipeline has too few stages. - Add 5- or 6-int DG_MEGA_MOE_TILES support and include fp4_weights, gran_k, and mainloop in the DG_PRINT_CONFIGS dedup key. - Add constexpr make_mega_moe_mainloop_plan() and remove unreachable SM103 BM=240 compact K=96 ring. - Add SM107 FP4 (NVFP4/MXFP4) K=128 mainloop (2 MMAs per BLOCK_K=256 stage, no Default tail), SM100_MMA_MXF4NVF4_BLOCK32_2x1SM_SS, and 576-col Allocator2SmExclusive for BM=240. - Drop redundant RowShuffled/K64 asserts already implied by RowShuffled requiring NVFP4 (avoiding unnecessary conflict with #166).
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.
Brings in sgl-project#177 (deepseek-ai public release 26/11/26, deepseek-ai#525) and deepseek-ai#478. No textual conflicts: this branch's changes follow the renames (csrc/apis/mega_moe.hpp -> mega_moe_inference.hpp, impls/sm100_fp8_fp4_mega_moe.{hpp,cuh} -> ..._inference.{hpp,cuh}, scheduler/mega_moe.cuh -> scheduler/mega_moe/inference.cuh).
…d split-4 paths The 26/11/26 release fences (`fence.proxy.async.global`) after the load warp's and the combine warp's waits for data written by other CTAs or ranks. Three paths of this branch skip those waits and so skipped the fence after the merge: - a task whose inputs the scheduler already checked (`kDepsCheckedBit`): the load warp fences before its TMA loads; - the combine of a one-rank group, which has no peer wait: one fence before the first row read; - the split-4 combine: a fence after its own peer wait.
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.
Motivation
With EP8, each rank of Kimi K3.1 owns 112 whole routed experts, so
fp8_fp4_mega_moecan run on a one-rank group: no peer, no NVLink barrier, no global count (sgl-project/sglang#52972 does this for speculative-verify calls). This PR adds whatdevlacks for that use: opt-in numerics that are bitwise equal to FlashInfer's trtllm-gen MoE, a low fixed cost for a group without peers, and a serving-shaped interface (packed top-k words, a small buffer, trtllm-gen's weight layout).On one Vera Rubin VR200 GPU (CC 10.7) at the K3.1 EP8 shape, with
deep_gemm.localized weights, this branch is 1.7 % (5 rows) to 23.6 % (235 rows) faster per call than trtllm-gen with a tuned tactic table and uses 12.5 to 19.9 % less net energy, with 0 differing output elements (3 processes). Everything new is off by default.Changes
Nine code commits; the later commits only fold and trim tests and comments:
numerics='trtllm': rounding placed as in trtllm-gen;split4_combine_max_tokens=Nfor its four-accumulator combine. Opt-in, FP8xFP4 SiTU, routed experts.topk_idxinstead of the global count protocol.topk_format='packed': int32 words(expert id << 16) | bf16(weight), which removes the caller's staging launch. One-rank groups.SymmBuffer(exact_num_max_tokens=True, max_block_m=N): a buffer sized for the calls it will see (256 rows instead of 1,920).weight_layout='row_shuffled'(alias'trtllm') for routed FP8xFP4 SiTU experts on SM107, so one weight copy serves this kernel and trtllm-gen.Relation to upstream: the branch is rebased over #160, #161 and #162 (commit 4 counts before #162's slot sort and keeps #161's union; commit 9 leaves #161's SM103 path alone), multi-rank groups keep #157's L1-first order and cap, which commit 5 builds on, and the open #156 overlaps commits 3 and 4, so if it lands first commit 3 shrinks and the one-rank half of commit 4 has to be re-derived.
Merged with
devon 2026-11-28 (two merge commits, up to 6840aa7: #170, #165, #169, #178, #171 and the 26/11/26 release sync #177). The files this PR touches are nowcsrc/apis/mega_moe_inference.hpp,csrc/jit_kernels/impls/sm100_fp8_fp4_mega_moe_inference.hpp,deep_gemm/include/deep_gemm/impls/sm100_fp8_fp4_mega_moe_inference.cuhanddeep_gemm/include/deep_gemm/scheduler/mega_moe/inference.cuh; the Python names are unchanged. #165: commit 9's layout now asserts the packed K=64 mainloop (SM107PackedK64), which is chosen from the JIT arch; the K=128 FP4 mainloop does not apply to FP8xFP4. #170: its LPT ordering runs after commit 4's count loads. One commit follows the merges: the one-rank paths (scheduler-side input check, one-rank combine) and the split-4 combine skip waits after which the release addedfence.proxy.async.global, so they now issue the same fence before their reads. Measured cost of that fence: within noise at 5 and 235 rows, 0.1 to 0.3 point of call time at 80 rows. After the merges: the three new test files pass at 1 and 2 processes, outputs stay bitwise equal to trtllm-gen (42 of 42 cells on each of two GPUs), and time against trtllm-gen is within 0.5 point of the pre-merge head at 5, 80 and 235 rows. The table below was measured before the merges, againstdev5121415;dev12be8d3 measured the same within 0.3 point, and 6840aa7 was not re-measured as a baseline.Existing callers: outputs are unchanged at the defaults, but commits 2, 4 (batched loads), 5 and 6 run on existing FP8xFP4 calls, and the BF16 kernel shares the headers touched by commits 3 and 4.
Performance
One VR200 GPU,
dev5121415 against this branch, FlashInfer 0.7.4. One rank of 112 experts, hidden 3,584, intermediate 3,072, top-16, real weights of one layer and captured routing. One CUDA graph of 8 MoE layers including routing, with a dense GEMM after each layer (subtracted). The reference is trtllm-gen with a tactic table from a live engine's autotune cache. Medians of 3 processes; ranges are within 0.2 points of the median in time and 0.6 in energy. Percent against tuned trtllm-gen, negative is better.dev+localizedev+localizelocalizereplaced by the identity. Localized weights are worth 8.1 to 21.5 points of the trtllm-gen call in time and 19.3 to 22.5 in net energy. Withoutlocalizethis branch beats tuned trtllm-gen only at 235 rows.dev+localize, measured directly: both builds in one process, alternating per round (3 processes, 12 rounds per row count). This branch is 29.1 / 24.2 / 22.0 / 17.9 / 15.2 / 11.3 / 12.7 % faster at 5 / 10 / 20 / 40 / 80 / 160 / 235 rows. Net energy is +0.8 / +1.3 / -3.1 / -3.7 / -4.4 / -5.8 / -6.2 %, so most of the energy saving against trtllm-gen is already indev.devitself depends onlocalizeas much: on ordinary pages it is 8.1 to 22.5 points slower and uses 18.3 to 21.1 points more net energy, and is slower than tuned trtllm-gen at every row count (+46.1 % at 5 rows to +6.5 % at 235).devarm runs SGLang's stock routing, a staging launch and MegaMoE; this branch runs one routing launch that writes packed words, then MegaMoE (commit 7). About 6 us per call of the lead overdevis that one fewer launch, not kernel time.localizeis worth 7.6 to 19.7 points in time and 13.4 to 16.7 in net energy.Correctness
numerics='trtllm'andsplit4_combine_max_tokens=84: 0 differing output elements in every timed cell (42: 7 row counts, 2 harnesses, 3 processes), for localized weights, ordinary pages, and the row-shuffled layout with the 256-row buffer.dev: with every option at its default, output sha256 matchesdevat nine sizes (1, 2, 8, 32, 84, 85, 128, 256, 512 tokens).split4_combine_max_tokensmakes a row's bits depend on whether the call is above or below N. The 84-token threshold is where FlashInfer 0.7.4's finalize was observed to change its summation order, not a documented contract.Tests
The kernel code of the posted head was re-run on 2026-11-26 (commit 1c34bbc; the commits after it only remove two test files, one duplicate test suite and three comments): the timing table above reproduces within 0.1 point in time, and the lists below pass.
Tests are in
sgl_deep_gemm/tests, registered inrun_tests.sh.test_mega_moe_trtllm_numerics.py(commit 1),test_mega_moe_invariants.py(commits 2 to 6, one suite each) andtest_mega_moe_packed_topk.py(commit 7). All pass on one VR200 GPU, and the first two at two processes. Commits 8 and 9 have no test file of their own; they are exercised by the bitwise timed cells above. Six existing MegaMoE test files (_situ,_nvfp4_trtllm,_bf16_trtllmand others) pass as ondev. Six existing MegaMoE test files (_situ,_nvfp4_trtllm,_bf16_trtllmand others) pass as ondev._trtllm_numericsand_invariantspass;_global_tokens,_nvfp4_alphasand the BF16 one-rank_bf16_trtllmpass on this branch and ondev.test_mega_moe.pyandtest_mega_moe_sgl.py(they need DeepEP reference operators the image lacks; the latter fails the same way ondev); the non-MoE tests; the sanitizer.Limits
SM107PackedK64).run_tests.shrun on 2 or more GPUs.🤖 Generated with Claude Code