[None][perf] Bound Triton MoE JIT specializations via token-dim bucketing and warmup - #15311
Draft
arysef wants to merge 1 commit into
Draft
[None][perf] Bound Triton MoE JIT specializations via token-dim bucketing and warmup#15311arysef wants to merge 1 commit into
arysef wants to merge 1 commit into
Conversation
…ting and warmup The TRITON MoE backend (matmul_ogs) JIT-compiles a new grouped-GEMM specialization per novel total token count: block_m is derived from m (triton_kernels/matmul_ogs_details/opt_flags.py) and Triton specializes m-derived integer kernel arguments on divisibility by 16. Under serving traffic with varied prompt lengths each first-seen specialization stalls the GPU ~0.2-2s, measured at 12.6-34% of wall time for gpt-oss-120b W4A16 MXFP4 on H200 across ISL/OSL 1k1k and 8k1k at concurrency 4-64. Add moe_config.triton_pad_token_dim (default off): pad the MoE token dim to geometric buckets (8 per power-of-two octave, <=12.5% padding) before the grouped GEMMs and slice back before the allreduce, making the JIT specialization space finite; engine warmup then pre-compiles exactly those buckets before serving (same pattern as the trtllm-gen FMHA JIT warmup). Restricted to W4A16 MXFP4 where padded rows are provably unable to change real-token outputs (bit-identity covered by unit test). Measured (gpt-oss-120b, H200, randomized-length serving): +14.9% tok/s/GPU at 1k1k TP1 conc64, +27.9% at 8k1k TP1 conc64, +50.7% at 8k1k TP2 conc16, with simultaneous median-TPOT improvements and GSM8K unchanged. Signed-off-by: Aryan Sefidi <aryansefidi@gmail.com>
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.
Description
The TRITON MoE backend (OpenAI
matmul_ogsgrouped GEMMs, the recommended backendfor gpt-oss MXFP4 on Hopper) JIT-compiles a new kernel specialization the first
time it sees a novel total token count
m: kernel meta-parameters such asblock_mare derived fromm(triton_kernels/matmul_ogs_details/opt_flags.py),and Triton additionally specializes the
m-derived integer kernel arguments ondivisibility by 16. Under serving traffic with varied prompt lengths, novel
mvalues keep arriving for the whole lifetime of the server, and each first-seen
specialization stalls the GPU for the duration of a JIT compile (~0.2–2 s).
Measured on gpt-oss-120b (W4A16 MXFP4) on H200 under a randomized-length serving
workload (uniform input lengths in [0.8·ISL, ISL], streaming, concurrency 4–64),
these stalls account for 12.6% of wall time at ISL/OSL 1k/1k conc 64,
22% at 8k/1k conc 64, and ~34% at TP2 8k/1k conc 16 (the per-layer
allreduce propagates either rank's stall to both ranks).
This PR adds
moe_config.triton_pad_token_dim(default off): the MoE tokendimension is padded to geometric buckets (8 per power-of-two octave, ≤12.5%
padding, ~6% average) before the grouped GEMMs and sliced back before the
allreduce, which makes the set of observable
mvalues — and therefore the JITspecialization space — provably finite (97 buckets for max_num_tokens=20000).
Engine warmup then pre-compiles exactly those buckets before the server starts
taking traffic (
_run_triton_moe_prewarm), following the same pattern as thetrtllm-gen FMHA JIT warmup (#14851).
The flag is restricted to W4A16 MXFP4, where padded rows provably cannot change
the outputs of real tokens (row-independent grouped GEMMs, BF16/FP16 activations,
no dynamic activation scales); on other quantization modes it logs a warning and
stays off (dynamic per-tensor activation scales would let padded rows shift the
second GEMM's amax).
Measured impact (InferenceX harness recipe, gpt-oss-120b, H200, 1.3.0rc14+patch,
GSM8K unchanged at 0.956 vs 0.957 baseline):
Full 20-cell sweep: +8% to +65% throughput (avg ≈ +25% attributable to this
change alone), with simultaneous interactivity (median TPOT) improvements.
A cold→warm
TRITON_CACHE_DIRA/B on the unmodified code reproduces the samegains, confirming the mechanism; warmup-grid-only (without padding) recovers
almost nothing because Triton's
%16integer specializations are not coverableby a finite grid of raw (unpadded) token counts.
Note on scope:
TritonFusedMoEis on the legacy MoE path, but the TRITONbackend exists only there, and this is a perf fix scoped to that backend —
pattern-identical to
disable_finalize_fusion(CUTLASS-specific knob consumedinside the legacy backend file).
Test Coverage
tests/unittest/_torch/modules/fused_moe/test_triton_moe_padding.pytest_bucket_round_up_properties/test_bucket_iter_is_sorted_and_compact(CPU): exhaustive bucket-math properties over [1, 65536] — rounds up by
≤12.5%, fixed-point, monotonic, enumeration matches closure.
test_triton_moe_padding_bit_identical(@skip_no_hopper):torch.equalbetween padded and unpadded forwards on the W4A16 MXFP4 path,parametrized over token counts and bias.
test_triton_moe_padding_requires_w4a16_mxfp4(@skip_no_hopper):the flag is ignored on non-W4A16 quant modes.
l0_h100.yml(SM90 lane).PR Checklist
field with description; nested MoeConfig field — no api_stability
reference changes required, matching precedent [None][chore] Cherry-pick from (#7598) Make low_precision_combine as a llm arg #7898).