Repository navigation
Conversation
Main work done by eppaneamd <[email protected]> The FP8 route rows written by the FlyDSL v2 stage-2 GEMM are read exactly once by the topk reduction. Pass streaming_loads=True to that reduction when the route buffer exceeds 192 MiB (configurable with AITER_FLYDSL_STAGE2_FP8_REDUCE_STREAMING_MIN_MIB); below that size the nontemporal loads are slower. The output is bit-identical. FlyDSL AOT now builds both reduction variants for FP8 route-out jobs, so FLYDSL_RUNTIME_RUN_ONLY finds whichever one the runtime selects. This is eppaneamd's work: he found and measured that nontemporal loads speed up the FP8 stage-2 reduction for large Kimi-K3 prefill batches on MI350X. jakki-amd ported it to main and added the size gate, the AOT coverage and the tests. Co-authored-by: eppaneamd <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
|
With Could you run a correctness test (gate on vs. off, bit-identical output) and a performance regression test (the stage-2 GEMM plus reduction, before vs. after) for all affected configs before this merges? |
|
How was the 192 MiB threshold chosen? The description places it from Kimi-K3 reduction-only measurements on MI355X and says it was tuned on one shape. Has it been validated on the other affected models' shapes? If not, please confirm that the crossover point holds for them too, or explain why the threshold should not depend on the shape (e.g. hidden size and topk). |
@Bernard-Liu Thanks, both are done on MI355X. Results are in the description under "All affected tuned rows"; summary below. Method
Correctness and regression on all affected configs The same 109 rows in 20 CSVs that you counted:
|
I added 198 sweep cases around the gate (33 to 696 MiB, token counts that hit each shape's tuned rows) and pooled them with the 111 tuned-row cases: 309 cases over all 21 (hidden, top-k) shapes in the shipped CSVs, 33 MiB to 8.2 GiB.
Not covered: MI350X for shapes other than Kimi-K3, and end-to-end serving. I also merged main into the branch (conflicts with the new FP4 route reduction; both kept, and FP4 never streams). |
|
After looking at the results, I'm going to close this PR, for two reasons. The gain is small. All numbers time only the stage-2 pair (GEMM plus reduction). Across the 109 affected tuned rows the geomean is x1.032. Just above the gate (192–256 MiB) the gain is about 1%, close to the ±0.7% A/A noise, and above 1.5 GiB it is flat. End-to-end serving was not measured. Stage-2 is only part of a MoE layer, so the end-to-end gain would be well below these numbers. The change is not general. It only takes effect when the following all hold:
The 192 MiB gate is an empirical constant tied to the gfx950 cache size. In return for this narrow gain, the codebase gets a new environment variable, an extra AOT reduction variant per shape, and a threshold that would need re-validation whenever kernels, tuned configs or hardware change. If end-to-end serving data later shows a meaningful gain in a configuration we ship by default, I'm happy to reopen and revisit. |
Main work done by @eppaneamd: he found and measured that nontemporal loads speed up the FP8 stage-2 reduction for large Kimi-K3 prefill batches on MI350X. @jakki-amd ported it to main, added the size gate, AOT coverage and tests, and re-measured on MI355X; opening on his behalf.
Summary
The FlyDSL v2 stage-2 wrapper (
_flydsl_v2_stage2_wrapper,AITER_FLYDSL_STAGE2_FP8=1) writes FP8 route rows that the topk reduction reads exactly once. This PR passesstreaming_loads=Trueto that reduction when the route buffer exceeds 192 MiB. Output is bit-identical.Motivation
compile_moe_reductionsupportsstreaming_loadsand the Q256 ASM path uses it; the v2 stage-2 FP8 reduction did not. On large buffers the default cache policy costs 6-7 % of stage-2 time (GEMM plus reduction) at Kimi-K3 prefill sizes. On small buffers streaming is slower, hence the size gate.Changes
aiter/fused_moe.py:_use_streaming_reduce_loads(route_out_nbytes, is_fp8_route)enables streaming for FP8 route rows aboveAITER_FLYDSL_STAGE2_FP8_REDUCE_STREAMING_MIN_MIB(default 192). BF16 and FP4 route reductions are unchanged (not measured).aiter/aot/flydsl/mxfp4_moe.py: FP8 route-out reduce jobs compile both variants (_ntand default), soFLYDSL_RUNTIME_RUN_ONLY=1finds the one the runtime selects.op_tests/flydsl_tests/test_flydsl_moe.py: threshold test (CPU) and bit-equality test of the two variants (gfx950).Performance
All numbers time the stage-2 pair as
fused_moecalls it (GEMM plus reduction) on one GPU, withAITER_FLYDSL_STAGE2_FP8=1, tuned kernels from the shipped CSVs and random weights. Cold regime: 1 GiB is written before every call.Kimi-K3
Shape: hidden 3584, inter 384, 896 experts, top-16, MXFP4 a4w4. 12 interleaved rounds of 6 calls, geomean of per-round median ratios; A/A within ±0.7 %.
MI355X:
* Gate forced on (threshold 0), the same choice the default makes here; "After" computed from the measured ratio.
MI350X (@eppaneamd, same shape, 16-round cold ruler): x0.956 to x0.976 up to 2048 tokens, x1.007-1.010 at 4096, x1.019-1.056 from 5120 to 16384.
All affected tuned rows
MI355X. Each case runs
fused_moewith inputs that match a tuned CSV row and checks that the row's kernel ran. Arms: gate off, gate off again (A/A noise), streaming forced on. 10 rounds in shuffled arm order, median of 5 calls per round. "Faster" or "slower" means outside the A/A spread.Testing
The FlyDSL v2 stage-2 path is gfx950-only, so MI250X and MI300X do not apply.
pytest op_tests/flydsl_tests/test_flydsl_moe.py -k "streaming or fp8_ep_reduction": 3 passed on MI355X at this PR's head 7dd9c0d (merged with main b9e08da), FlyDSL 0.5.0. Black and ruff 0.16.0 clean.python -m aiter.aot.flydsl.mxfp4_moeon the 16384-token row ofkimik3_a4w4_tuned_fmoe.csvwithAITER_FLYDSL_STAGE2_FP8=1(10/10 compiled); both variants then run withFLYDSL_RUNTIME_RUN_ONLY=1.Documentation
The new environment variable is a tuning override with a measured default, documented at its definition.
Dependencies
Breaking Changes
None. Bit-identical output; default behavior changes only for FP8 route buffers above 192 MiB.
PR Self-Review
Reviewed revision
7dd9c0d
Behavior and intent
With
AITER_FLYDSL_STAGE2_FP8=1, the FP8 stage-2 reduction now reads route buffers larger than 192 MiB with nontemporal loads. The buffer is read exactly once, so it gains nothing from being cached. Smaller buffers keep the default cache policy, because streaming is slightly slower there. The gate is set by measured GEMM plus reduction time, and the result is bit-identical in every measured case.Validation and unverified scope
Validated: see Testing and Performance (every timed output bit-checked); MI350X data from @eppaneamd.
Not verified:
--checkreplay of the default CSV corpus (one Kimi-K3 row built);PR-specific question
Which configs change behavior? With
AITER_FLYDSL_STAGE2_FP8=1, everyflydsl_moe2_layout_*_reduce*config whose FP8 route buffer exceeds 192 MiB, regardless of model: 109 rows in 20 shipped CSVs (DeepSeek, GLM, Kimi, Qwen, MiniMax, Mistral and gpt-oss configs). All 109 were run on MI355X with bit-identical output; see "All affected tuned rows". With the defaultAITER_FLYDSL_STAGE2_FP8=0nothing changes.Changed op tests
test_stage2_fp8_reduce_streaming_threshold(CPU, new): gate boundary, BF16 never streams, and the Kimi-K3 sizes the default was measured at.test_flydsl_stage2_fp8_reduction_streaming_loads_bit_equal(new):_ntis bit-identical to the default variant for FP8 route rows with deferred route weights at the Kimi-K3 row width. The existingtest_flydsl_stage2_fp8_ep_reductioncovers only the default.