Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
… pair - Adds quantize_fp32 to the two-stage torch reference, which quantizes the stage-1 result before rounding it to the output dtype. - Retries a shape that fails the elementwise check against that reference and keeps the closer of the two. Fused-quantization kernel pairs quantize the stage-1 result in fp32, while the reference rounds it to bf16 first. On fp4 that moves every code sitting on a rounding tie by a whole step, so a correct fused pair was reported as mismatching most of its output. Shapes that pass against the existing reference are unchanged.
…tization - Compares fused fp4 stage-1 outputs code for code and scale for scale with the reference quantizer applied to the fp32 stage-1 result, for the FlyDSL and v2 tasks; the runners now return the block scales the kernels write. - Lays out the reference in the sorted layout the kernels write and marks rows and scale positions no route maps to, so padding is skipped rather than counted. - Builds the v2 stage-2 reference from the quantized intermediate the kernel reads for every weight dtype, and checks it elementwise instead of by cosine. - Checks non-fused FlyDSL stage 1 with fp4 activation elementwise, since its bf16 output and the reference share the quantized inputs. - Covers the comparison, padding rows and the scale layout in test_fast_tuning. The fused stage-1 checks decoded fp4 codes without their scales and dropped the scale tensor, and the v2 checks compared against references that skipped a quantization step, so a kernel writing misplaced scales or biased values could pass. Split-K stage 1, which quantizes a bf16 sum of partials, and paths whose reference does not use the kernel's fp8 activation keep their previous checks.
- Adds a compares_whole_output decorator; the worker calls a marked compare_fn once with the whole (ref, res) tuples instead of once per output tensor, also when it is wrapped in functools.partial. - Includes ref_kwargs in the cached reference key, so grouped tasks that differ only in reference keyword arguments no longer share one reference. - Covers both in the worker tests. Quantized codes and their block scales can only be judged together, which the per-tensor loop could not do.
- Compares fused fp8 stage-1 outputs (FlyDSL and opus) code for code and scale for scale, quantizing the reference with each kernel's own e8m0 rule; the runners now return the scales the kernels write. - Gives the fp8-activation references (FlyDSL, cktile, opus, v2) the fp8 activation and intermediate the kernels read, and checks bf16 stage-1 outputs elementwise. - Checks split-K fused stage 1 on dequantized values: each within one step of the fp32 reference on the kernel's grid, with a fitted slope near 1. - Checks the bf16 stage-2 outputs of these paths by relative L2 error and fitted slope, since atomic kernels round every partial sum to bf16. - Keeps the cosine check for opus stage-2 kernels with an MXFP8 route output, which quantize each route's result before the reduce. - Removes the cosine comparisons this replaces and covers the new checks in test_fast_tuning. These paths were judged by cosine against references that skipped the kernel's fp8 quantization, which cannot see a scale error.
- Passes the gate mode serving uses (interleaved for a8w4 and mxfp8) and takes the activation dtype from fused_moe's resolve_activation_dtype instead of a local copy of its rules. - Passes SiTUv2 rows the opt-in activation dtype they were tuned for. - Builds the reference from the kernel's mxfp8 activation and quantizes the stage-2 input with the rule of whatever produces it; asm 1-stage rows keep an fp4 reference activation, which those kernels quantize to themselves. - Warns when fused_moe runs a different activation dtype than the row, so the row's kernels are not the ones checked. - Logs the elementwise check against the threshold that decides the shape, and warns when a shape passes on logits_diff alone. run_config laid out a8w4 weights for the interleaved path but called fused_moe in the separated mode, so every a8w4 row ran other kernels against a mismatched layout and compared uncorrelated outputs.
abbef9d to
8b30234
Compare
- Runs FmoeTuner.run_config on synthetic rows with fused_moe and the torch reference replaced by recorders. - Checks the gate mode and activation dtype passed for a8w4, mxfp8, SiTUv2 and asm 1-stage rows, and the warning when fused_moe runs a different activation dtype than the row. - Checks the fp8 scale rule the reference uses for the stage-2 input, and that a failing shape is retried at the fp32 quantization point. The only other test of this path is the nightly run_config sweep over every shipped CSV, which does not finish within its timeout for fmoe.
…accuracy # Conflicts: # csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py
… the kernel INTERLEAVE launches quantize the hidden states and the stage-1 result to MXFP8, but run_torch_fhmoe kept both in bf16. Against that reference ~80% of a correct kernel's elements fall outside atol=rtol=0.01, so the cosine check could not tell a quantization error from a broken kernel. The reference now quantizes at both points. A fused-quant stage 1 quantizes its fp32 result; the unfused path rounds it to bf16 first. Tuning stacks both references and judges each candidate against the closest, since compare_fn only sees the reference and the result. run_config checks the bf16 reference and falls back to the fp32 one when it does not pass, as fmoe does in ROCm#7091. Gate modes with fp4 activations keep the bf16 reference.
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
The reference cache remains stale when fast_mode=False, incorrectly rejecting valid candidates, and the GPU test guard enables gfx950-specific fixtures on gfx942, causing routing assertion failures.
2 open issues
What changed in this PR
This PR improves fused-MoE tuning validation by comparing candidates against references with matching quantization and aligning run_config calls with serving behavior.
Changes:
- Adds scale-aware quantized comparisons and stricter checks for split-K and stage-2 outputs.
- Aligns reference inputs, activation dtypes, and gate layouts with the kernels being checked.
- Adds whole-output comparison support, reference-cache key changes, and regression tests.
| File | Description |
|---|---|
op_tests/tuning_tests/test_mp_tuner_logic.py |
Tests whole-output comparisons and reference keyword arguments in caching. |
op_tests/tuning_tests/test_fast_tuning.py |
Adds quantization, error-metric, and run_config routing tests. |
csrc/ck_gemm_moe_2stages_codegen/mxfp4_v2_tune_utils.py |
Builds quantization-matched v2 references and removes the old cosine comparator. |
csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py |
Updates candidate comparisons, quantized references, and run_config routing. |
aiter/utility/mp_tuner.py |
Adds opt-in whole-output comparisons and includes reference kwargs in cache keys. |
Review effort: Balanced
…stage-1 reference once - Recomputes the cached reference whenever a reference function is set and its key changes, so a change in ref_kwargs or data also takes effect when fast_mode is off. - Runs the cached-reference test with fast_mode on and off. - Skips the run_config routing tests unless the live GPU is gfx950, whose rows and fp8 dtype they hardcode. - Builds the v2 stage-1 reference once from the activation the kernels read: a plain fp8 cast of the input for a8w4, a1_qt otherwise. The stage-2 input and references follow from it, so they no longer start from a different activation than the fused stage 1 is checked against.
amd-bartgips
left a comment
There was a problem hiding this comment.
Thanks for this. Checking against references that quantize like the kernel is a big step up from the cosine checks.
The two comments below are about one remaining gap. The new checks score the whole output with a single fraction or average. A fault that damages only a small part of it, such as a few routes, one expert or one row, gets diluted and can pass, and the larger the shape, the more easily it passes. Both cases were reproduced on CPU with deliberately corrupted outputs.
- Fused stage 1 (
quantized_output_compare): a small fix that reusesdequantized_output_compare. - Stage 2 (
relative_l2_compare): a worst-row bound, if you have the numbers to set its cap.
I have asked @a-canadasruiz to do a full review as well; these comments only cover this gap.
…gure hides - Requires every dequantized fused stage-1 value to be within one step of the fp32 reference, or within a small fraction of its block's largest magnitude, instead of allowing a share of values beyond one step. - Checks the FlyDSL fused fp4 and fp8 stage 1 that way, as split-K already was, instead of counting differing code bytes, which cannot tell a rounding tie from a value that moved by its whole block. - Bounds the relative L2 error of each stage-2 output row next to the whole output's, so one wrong row no longer passes once the token count is large enough. - Covers a value near zero inside the block floor, a single corrupted route, and a single wrong row among many. A share or an average over the whole output dilutes a fault confined to a few routes or rows, and dilutes it further as the shape grows. The block floor covers values near zero, where the code grid is finer than the difference between the kernel's and torch's fp32 accumulation.
There was a problem hiding this comment.
🟡 Changes recommended
The tolerance fallback incorrectly includes non-split-K fused FlyDSL candidates, bypassing mismatch limits and allowing outputs with 50% relative L2 error and every packed byte differing to pass.
1 open issue
2 resolved since last review
Review effort: Balanced
…accuracy # Conflicts: # op_tests/tuning_tests/test_fast_tuning.py
- Accepts a dequantized value only when it equals the reference rounded on the kernel's grid after a shift of at most the block floor, so only a value on a rounding boundary may take either neighbour. - Keeps the one-step tolerance for split-K, which quantizes a bf16 sum of partials that no rounding of the reference reproduces. - Judges the FlyDSL v2 fused stage 1 by its dequantized values, mapping its sorted-row codes back to routes, instead of by the fraction of differing bytes. - Removes the v2 quantized reference, which nothing else uses. - Covers the rounding range, the split-K tolerance and the sorted-row layout in the fast tuning tests. The tuner runs only the v2 kernels when TUNE_ONLY is unset, so the byte count was the only check on the default path, and it let through candidates with isolated values off by more than one rounding.
- Requires the shifted reference to fit the scale's largest code, so a kernel that clips to a scale too small for its block fails instead of matching the clipped reference rounding. - Resets the v2 stage-1 output buffer before each candidate, so rows a kernel skips cannot keep another candidate's codes. - Fills integer output buffers with their largest value when the worker resets them, since they have no NaN. - Runs the corrupted-route, bias, misplaced-scale and wrong-exponent tests in both check modes, and covers the kernels' scale rule and the clipped case. - Rewords the block floor comment for its use as a shift before rounding.
…nto relbers/fmoe-tuner-accuracy
- Adds a built-in exclusion for the afp8_wfp4 t32x128x256 fused fp8 stage-1 kernels with w2 to w4, whose output holds a few wrong blocks on some runs and none on others. - Applies the tuning exclusion to the FlyDSL v1 and v2 stage-1 candidates, which bypassed it, so AITER_FMOE_TUNE_EXCLUDE_KERNELS now reaches them too. The accuracy check sees one run per candidate, so a lucky run could still put one of these kernels in a tuned CSV.
…accuracy # Conflicts: # csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py
|
No activity for 15 days, so this is now labelled |


The
test_run_configchange that stops it passing on a device with no tuned rows has moved to #7106.The fmoe tuner judged quantized MoE candidates against references that skipped a quantization step the kernel performs, mostly with a scale-blind cosine metric. It could accept a wrong kernel and reject a correct one. This PR checks each candidate against a reference that shares its quantization, and makes
run_configcallfused_moethe way serving does.What was wrong
calc_diffat 0.1 tolerates about 45% relative error.TUNE_ONLYis unset, so the v2 cosine check decided most tuning runs.run_configcalledfused_moeunlike serving. a8w4 weights were interleaved butgate_modewas not passed, so every a8w4 row ran kernels that read the layout wrongly (logits_diffabout 0.99). A local copy of the activation-dtype rules also sent SiTUv2 rows to fp4.What changes
dequantized_output_compare.DEQUANT_BLOCK_FLOOR).k_batch > 1) is looser: within one step of the reference on the kernel's grid, or within the floor. It quantizes a bf16 sum of partials, which no rounding of the reference reproduces._route_sorted_rows).quantized_output_compare) against a reference quantized with opus' RoundUp scale rule.output_keys.mp_tunernow fills integer buffers with their max value, since uint8 has no NaN and the old fill raised.run_configpassesgate_mode="interleave"for a8w4 and mxfp8, takes the activation dtype fromresolve_activation_dtype, passes SiTUv2'squant_dtype_a, and retries against the fp32 quantization point when the elementwise check fails.Why split-K alone keeps one step
bartgips asked whether one step is too loose for the rest (half step?). On the v1 path (
TUNE_ONLY=flydsl), four shapes, gfx950 256 CU: for every non-split-K candidate, one step, half step and the range check accept the same set. Only split-K differs; the range check would reject 66 split-K candidates on the a4w4 256-token shape. So the range check is the default and one step applies to split-K only.Results
gfx950, 256 CUs, one GPU, default (v2) tuner at 6ea9bbe. Every selected kernel passes.
t32x32x256_*_gui_fp8: 34% of values off, slope 1.04t32x128x256_w{2,3,4}_*_gui_fp8at 0.0005-0.01% of values offThe previous v2 check accepted the
t32x128x256_w*candidates. Those do not reproduce run to run: one passed in a rerun.python -m pytest op_tests/tuning_tests/test_fast_tuning.py op_tests/tuning_tests/test_mp_tuner_logic.py: 110 passed; the compare tests were stable over 20 repeated runs.run_configover all 2032 shipped gfx950/cu256 fmoe shapes: failing both checks went from 429 to 1 (elementwise passes 1284 to 1651). Measured at an earlier revision of this branch, not repeated.Not covered here
flydsl_moe_stage1returns is a freshtorch.emptyper call, so a kernel that skipped writing scales could read stale memory. Only the code buffer is reset.AITER_BF16_FP8_MOE_BOUND, so those tuned rows are never used, and for 137 shapes it has no backend at all.run_confignow warns. Whether to check them with their tuned dtype is a separate decision.logits_diff: asm 1-stage fp8, FlyDSL a16wi4,swiglu_kernels, a8w4 including opus MXFP8 route-out. Their references do not model a step the kernel performs.Note for
aiter/utility/mp_tuner.pyOpt-in. A compare function marked
@compares_whole_outputgets the whole(ref, res)tuples once; unmarked ones get the same per-tensor calls as before. The cached reference is now recomputed when its key changes, in both modes, and the key includesref_kwargs. Shape-grouped tuners pass the same reference arguments per shape and the fmoe tuner does not group, so no existing caller changes behaviour.PR Self-Review
Reviewed revision
f1f5cf6
Behavior and intent
The tuner now accepts or rejects fmoe candidates against references that share the kernel's quantization, and
run_configcalls fused_moe like serving. See "What changes" above. Fused stage 1 is checked on dequantized values with the kernel's own scales; split-K and opus keep their own rules.Validation and unverified scope
python -m pytest op_tests/tuning_tests/test_fast_tuning.py op_tests/tuning_tests/test_mp_tuner_logic.pypassed with 110 tests at f1f5cf6, and the default v2 tuner ran on four gfx950 shapes with every selected kernel passing (see Results). Unverified: other architectures and CU counts, stale scale memory for a kernel that never writes scales, and the Tuning Tests workflow at this revision.PR-specific question
No kernel, dispatch or shipped CSV changes; only tuner acceptance and
run_configchange. Fused fp4/fp8 FlyDSL stage-1 tasks (v1 and v2, gfx950 per_1x32 path) get the dequantized check, split-K (k_batch > 1, v1) gets the one-step variant, opus fused fp8 gets the byte compare, and other tasks keep their earlier checks. Route maps raiseValueErroron unmapped routes, and unwritten buffers hold a sentinel (0xFF or NaN) that fails.Changed op tests
op_tests/tuning_tests/test_fast_tuning.pycovers the compare functions andrun_configrouting: exact, within-floor, neighbouring-code and clipped-scale cases, sorted-row mapping, bias and permuted scales, atomic bf16 stage 2. Not redundant: nothing else exercises them.op_tests/tuning_tests/test_mp_tuner_logic.pycovers the shared worker: whole-output compare calls (also viafunctools.partial), cached reference followingref_kwargs, andoutput_keysfilling uint8 with its max. Not redundant: these are the only tests of thosemp_tunerpaths.