Repository navigation
Conversation
fused_moe(stage2_fp8=True) makes a FlyDSL layout reduce stage 2 of one call write each route's output as FP8 (e4m3, an e8m0 scale per 32 columns) and sum the routes in fp32, which AITER_FLYDSL_STAGE2_FP8=1 does for every call. With a flydsl_mxmoe_g1 stage 1, a scatter stage 2 with MXFP4 activations and bf16 output runs as the reduce stage 2 of the same tile. Other stage 2s (FlyDSL v1 included) and stage 2s with a bias are unchanged. Default False; with True the output is not bitwise equal to the default. The flag is part of the get_2stage_cfgs cache key, so a caller can set it for some layers of a model (for example its target layers) and not for others with the same shapes. The change is logged once per config. op_tests/test_moe_2stage.py: a per-call test at two tuned rows (an MXMOE scatter row and a flydsl_moe1 reduce row), a kernel-name test, and --stage2-fp8 for the tuned-row cases. Co-authored-by: Claude <[email protected]> Signed-off-by: Rony Leppänen <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…ithin the admission Patches 22, 23, 26 and 27; c12, c24, c48 and c80 set their two variables: - 22-23 FP8 stage-2 route output for the target's MXFP4 MoE (ROCm/aiter#8174 in the image's AITER checkout, sgl-project/sglang#51198 wiring), SGLANG_AITER_MOE_STAGE2_FP8 - 26 brings patch 15 to the head of sgl-project/sglang#50863; SGLANG_USE_HIP_HC_PREFILL_TRITON replaces SGLANG_AMD_HC_PREFILL, which 26 no longer reads - 27 decode FP8 quant fused into the GDN gated norm and the attention output gate (sgl-project/sglang#51023), no variable cuda-graph-bs-decode at c12-c80: every size to the admission at c12 and c24, every size to 64 and every 8 to 128 at c48 and c80. c48 also sets strip-thinking-cache and mamba-max-states-per-path 2, as c80 does. Patch 12's header names ROCm/aiter#7556's head 1c8725c7f3 and how the patch differs from it. c1 and c2 are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Rony Leppänen <[email protected]>
Summary
Adds
fused_moe(..., stage2_fp8=False). WithTrue, one call gets the FP8 route output thatAITER_FLYDSL_STAGE2_FP8=1gives every call in the process: a FlyDSL layoutreducestage 2 stores each route's output as FP8 (e4m3, an e8m0 scale per 32 columns) and sums the routes in fp32. After an MXMOE (flydsl_mxmoe_g1) stage 1, an MXFP4scatterstage 2 runs as thereducestage 2 of the same tile and gets the FP8 route output too. On MI355X, the Qwen3.8-Flash-Next MoE call at 16,384 tokens takes 918.4 µs instead of 1,137.6 µs (−19.3 %).Limits:
reducerows at ≤ 64 tokens change by −5.0 % to +4.5 % (median −0.1 %; 12 more than 1 % slower), the same kernels the env var runs there._ldspascatter rows (−1.3 % to +2.1 %), which the flag maps toreducelike the other MXFP4 scatter rows.atomicstage 2s, stage 2s with a bias, FP8-activationscatter, andscatterafter aflydsl_moe1stage 1 (2kimik3_a4w4rows; there the stage 1 sorts for the scatter).aiter/aot/flydsl/mxfp4_moe.py) contains the FP8reducekernels only when built withAITER_FLYDSL_STAGE2_FP8=1, and never thereducekernel ascatterrow maps to. With the flag, those compile at their first call, or raise underFLYDSL_RUNTIME_RUN_ONLY=1.Motivation
_flydsl_v2_stage2_wrapperandfused_moe_2stages, so the second to land needs a rebase.scatterstage 2 (bf16 route rows, thenmxfp4_moe_scatter_reduce), which the env var leaves as it is.fused_moe_prepare_stage2/fused_moe_run_stage2(per-route outputs, replaced stage-2 operands); FP8 route output is not one of their options. The flag can change the stage-2 kernel, which also decides whether the sort zero-fills the output, so it is chosen with the config, infused_moe;fused_moe_prepare_stage2does not take it.Changes
fused_moe,fused_moe_fake,fused_moe_,_fused_moe_impl:stage2_fp8(defaultFalse), passed toget_2stage_cfgs, whose cache key includes it, so both variants coexist in one process.get_2stage_cfgs: after an MXMOE stage 1 (tuned row, inline-sort probe, MXMOE heuristic fallback),_make_mxfp4_metadataruns the stage 2_stage2_fp8_kernel_namereturns, with FP8 route output; after aflydsl_moe1/opus_moe1stage 1, a layoutreducestage 2 gets FP8 route output. Each changed config logs one info line:[fused_moe] stage2_fp8: <kernel> writes FP8 route rows._stage2_fp8_kernel_name:reducekeeps its name; an MXFP4-activation bf16scatterbecomes the plainreduceof the same tile and sort block (no_persist,_nt,_ldspa); anything else returnsNone(unchanged)._flydsl_v2_stage2_wrapper: FP8 route output when the flag or the env var is set (its error text names both);fused_moe_2stagespassestopk_weightsfor it.deterministic=True(NotImplementedError).op_tests/test_moe_2stage.py: two gfx950 tests and--stage2-fp8.Scope (gfx950, tables under
aiter/configs): the flag changes 324 layoutreducerows (the ones the env var changes; 26 model tables) and 47 MXFP4scatterrows after an MXMOE stage 1 (DeepSeek-V3 14, Kimi-K2 12, MiniMax-M3 11, GLM-5.3-Flash 6, GLM-5 3, Qwen3.8-Flash-Next 1). These rows span 1 to 131,072 tokens, so decode-size calls change too. Measured: the Qwen3.8-Flash-Next 16,384-token call, and 252 of these rows in the in-tree benchmark below.Performance (if applicable)
Method, in-tree benchmark and stage-2 split
fused_moeas SGLang calls it (E 513, top-k 11, hidden 2560, inter 640,per_1x32, separated gate/up, shuffled weights,output=, sorting policy 2); 25 timed calls per round, each after a 512 MB write and a GPU sleep, CUDA events; the median of 3 rounds that alternate the arms in one process.mainwithout this PR (separate process): 1,121.7 / 1,110.5 µs. A second job: 1,114.2 → 902.4 µs (−19.0 %) / 1,109.1 → 901.1 µs (−18.8 %). Layer 20: the routed and shared experts and the router of layer 20 ofamd/Qwen3.8-Flash-Next-Quark-MXFP4-AttnFP8-PLEFP8, on N(0, 1) activations.moe_scatter_reduce) → 109.4 µs (moe_reduction, FP8 rows).python3 op_tests/test_moe_2stage.py --no-legacy --csv-filter _scatter_sbm128 _reduce [--stage2-fp8], run off, on, off, on; minimum of the two runs per arm.calc_diffoff → onreduce, > 64 tokensreducerows)reduce, ≤ 64 tokensscatter→reducescatter_ldspa→reducescatter, FlyDSL v1reduceQwen3.8-Flash-Next's row in this harness: 1,030.1 → 882.3 µs (−14.3 %).
The harness runs the untagged rows for the GPU's CU count, so 252 of the 371 rows the flag changes ran; the other 119 did not (82 with a
_tagvalue, 61 of them DeepSeek-V4.1; 28 for 128-CU GPUs; 9 the harness skips for its runtime mode).Setup: image
lmsysorg/sglang-rocm:v0.5.23-rocm10-mi35x-20261117with this branch copied over its AITER (JIT modules rebuilt) and FlyDSL 0.5.0; one MI355X.Accuracy
main's in the per-call benchmark.calc_diff(it warns above 1e-3 and fails above 0.01):reducerows ≤ 1.13e-3 → ≤ 1.48e-3 (above 1e-3: 13 → 22 of 205 rows), MXFP4scatterrows ≤ 6.1e-4 → ≤ 9.7e-4; every row passed the harness's assertion.581579ab5) with this change applied to itsfused_moe.py(the same added lines, without thedeterministichunk and [FlyDSL] MoE stage2: MXFP4 route-output reduction next to the FP8 one #7706's condition, which581579ab5predates).Testing
MI355X (gfx950) only: the changed paths are gfx950 FlyDSL, and the new tests run on gfx950 only.
Documentation
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
286cda3
Behavior and intent
Without the argument, behavior is unchanged (
main's output bit for bit in the benchmark above). With it, a call whose stage 2 is a FlyDSL layoutreduce, or an MXFP4-activation bf16scatterafter an MXMOE stage 1, writes FP8 route rows and sums them in fp32, as the env var does for every call; the cache key keeps both variants in one process, so a caller can choose per layer.Validation and unverified scope
main'sfused_moe.pythe file stops at the import of_stage2_fp8_kernel_name, andfused_moehas nostage2_fp8. Each of 9 mutations fails one of them on an assertion (flag ignored by the stage-2 wrapper,topk_weightsnot passed, noscattermapping, flag dropped at the tuned-row,_resolve_metadataorflydsl_moe1site, partial without the flag, FP8-activationscattermapped,reducenot kept).op_tests/test_moe_stage_api.py([MoE] Public two-stage fused_moe API: fused_moe_prepare_stage2 / fused_moe_run_stage2 (per-slot output, replaceable stage-2 operands) #7135's staged API) 16 passed,op_tests/flydsl_tests/test_flydsl_moe.py59 passed.PR-specific question
Both new tests fail before this PR:
fused_moehas nostage2_fp8argument and_stage2_fp8_kernel_namedoes not exist.test_stage2_fp8_per_callis the regression test: no existing test callsfused_moewith FP8 route output for one call only, andtest_flydsl_stage2_fp8_ep_reductioncovers the env var's reduction, not the per-call choice or thescattermapping.test_stage2_fp8_kernel_nameguards which kernels the flag maps.Changed op tests
op_tests/test_moe_2stage.py:test_stage2_fp8_per_call: at two tuned rows (Qwen3.8-Flash-Next 16,384 tokens, MXMOE stage 1 andscatter; DeepSeek-V3 MXFP4 2 tokens,flydsl_moe1stage 1 andreduce), the flag's output is bitwise the env var's output with the row'sreducekernel, differs from the default by under 5 %, and a call without the flag keeps the default output.test_stage2_fp8_kernel_name: MXFP4scatter(with_nt/_ldspa) →reduce,reduce_persistkept, FP8-activationscatterandatomic→None.--stage2-fp8: runs the tuned-row cases with the flag (the benchmark above).This change was developed with AI assistance (Claude); I reviewed every line and ran the tests listed.