Skip to content

[FlyDSL] [CI] [Feature] Add explicit clamped SiLU to FlyDSL a16w-mix GEMM1 - #6995

Merged
LiuYinfeng01 merged 8 commits into
ROCm:mainfrom
LiuYinfeng01:pr/flydsl-clamped-silu-a16wmix
Nov 10, 2026
Merged

LiuYinfeng01 merged 8 commits into
ROCm:mainfrom
LiuYinfeng01:pr/flydsl-clamped-silu-a16wmix

Conversation

@LiuYinfeng01

@LiuYinfeng01 LiuYinfeng01 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Explicit clamped-SiLU A16W4 MoE on FlyDSL: BF16 activations, native MXFP4 weights, optional BF16 pre-activation rounding, paired tile selection and a same-math fallback. This is the operator used by vLLM#64640; it does not change vLLM's default backend.

Current head: 002152e6a9c764c055256f017e96d604b915cf98. The latest commit addresses the remaining K-tile review finding. The previous SiTUv2 dispatch fix is retained, and the temporary xfail remains removed.

All performance and numerical tables in this body have been regenerated from the November 9 validation. They replace the older prefetch screen, 50-shape/30-GEMM1 matrices, tuning holdouts and downstream serving tables. Those experiments were not rerun by this review fix and are not presented as measurements of this head. There is no fresh vLLM-comparator, TP8 serving or GSM8K result here.

Motivation

DeepSeek-style clamped SiLU requires silu(min(gate, limit)) * clamp(up, -limit, limit). BF16 pre-activation rounding must occur before this activation when matching a separate BF16 gate/up projection. The explicit wrapper keeps that contract without quantizing activations.

The new review finding is a separate correctness issue: positivity and divisibility allow unsupported packed-weight K tiles. TILE_K=16 makes the accumulation loop execute zero times, while TILE_K=64 supplies no 128-element raw-weight groups. An explicit caller or tuner can otherwise accept a very fast all-zero result.

Changes

  • act="silu_clamped" with optional activation_bf16; runtime positive clamp, with positive infinity disabling clamping.
  • flydsl_a16w4_moe: sorting, two GEMMs, routing-weighted BF16 atomic reduction and output clearing; exact-key CSV selection with a same-math fallback.
  • Opt-in gfx942 GEMM1 prefetch=2..4; default 1 retains the original loop. k_wave is intra-block slice-K, not grid split-K.
  • Opt-in GEMM2 LDS reuse, limited to gfx942, FP4 weights and the atomic epilogue.
  • Existing pytest CI wiring and the f16bca38 SiTUv2 layout/parameter dispatch correction, without xfail.
  • Latest fix: require positive multiples of 128 for FP4/INT4 K tiles at the complete-MoE API, both single-stage wrappers and both shared compile entry points. Invalid pairs fail before sorting, buffer allocation or tracing. BF16 tile support, valid kernel bodies, CSV rows, prefetch settings and LDS allocation are unchanged by this commit.

Reviewer Reproduction and Numerical Result

MI325X/gfx942, M=3, H=256, I=384, E=8, top-2, clamp10, BF16 pre-activation rounding. Both packages receive exactly the same inputs and packed weights. NRMSE below is a percentage; the all-zero results are failures, not performance candidates.

Stage1 K Stage2 K Original result Original ref NRMSE % Fixed result Fixed ref NRMSE %
128 128 valid 0.24478 valid 0.24478
16 128 all-zero failure 100.00000 ValueError rejected before execution
128 16 all-zero failure 100.00000 ValueError rejected before execution
64 128 IndexError not produced ValueError rejected before execution

The reviewer originally reproduced this on gfx950. The table above independently reproduces it on actual gfx942 hardware at public head f16bca38 and verifies the local fix. It is not a new gfx950 hardware result.

Existing SiTUv2 Fix

The shape-only tuning lookup can select raw-layout Kimi-K3 1-stage ASM rows for preshuffled tensors. f16bca38 discards only incompatible SiTUv2 MXFP4 ASM rows for separated preshuffled input, allowing the existing two-stage FlyDSL path. Compatible FlyDSL rows and raw-layout fixed-beta ASM calls remain unchanged. Mixed layouts and unsupported raw ASM beta overrides fail explicitly. The original GPU test dimensions and tolerances remain, with no xfail.

Performance

Measured on one MI325X/gfx942 GPU, 304 CU, gpu-1, Torch 2.13.0+rocm10.0.0, FlyDSL 0.4.2. Baseline is public head f16bca382a7023ce94c54ff0f4ca5c07ed11858e; candidate is the exact source now committed at 002152e6a9c764c055256f017e96d604b915cf98. Both packages were independently loaded in one process, with actual import locations checked.

The TP-local shape is H5120, physical I384/logical I288, E384, top-6, clamp10, BF16 input/intermediate/output and BF16 pre-activation rounding. The same quantized weights, activations, IDs and routing weights are passed to both arms. Weight seed is 607; routing/input seed is 601 + M. Routing modes are uniform, skewed and hot.

  • Graph: complete MoE captured with 5 calls per graph. Main matrix: 9 alternating rounds, 30 replays/round. Independent decode confirmation: 15 alternating rounds, 100 replays/round.
  • Eager event/wall: complete Python wrapper invocation, including checks, sorting, both GEMMs and output zeroing. Main matrix: 20 calls/round; confirmation: 100 calls/round. Wall timing ends after completion synchronization.
  • Compilation, data generation, reference construction and initial warmup are outside timing. Router scoring, shared experts and TP communication are not included.
  • Weights are reused, not rotated to claim cold-HBM bandwidth. M is TP-local token rows, not request concurrency.
  • Every cell below is the median of all rounds, not the fastest trial. Positive delta means the candidate is slower. All timings are microseconds.

Current CSV Configuration

These are configuration values, not newly tuned rows. The latest commit leaves them unchanged. Missing exact keys use BM32/G1 N128 K256/G2 N256 K128 without LDS reuse.

M BM G1 N/K k_wave prefetch G2 N/K LDS reuse
1 16 32/128 4 1 256/128 no
8 16 64/256 1 4 128/128 yes
32 16 32/128 2 3 128/128 yes

Latest Uniform Decode Summary

This compares the candidate's fallback and CSV in the same main run, as well as the public-head CSV against the review fix. It is not a comparison with vLLM Triton, and the fallback/CSV speedup is not an improvement introduced by the guard fix.

M Fixed fallback graph us Fixed CSV graph us Fallback / CSV Public-head CSV graph us Fix-only graph delta
1 85.967 36.884 2.331x 36.646 +0.648%
8 118.131 66.449 1.778x 66.602 -0.230%
32 223.793 160.409 1.395x 160.354 +0.035%

Measured Cost of the Fix

Run Mode Graph delta range Graph geometric mean delta Median eager wall delta us Eager wall delta range us
Main / 9 rounds dispatch -0.298% to +0.648% +0.039% +0.169 -1.029 to +0.802
Main / 9 rounds default -0.236% to +0.420% +0.051% +0.040 -1.957 to +0.542
Decode confirmation / 15 rounds dispatch -1.739% to +0.324% -0.433% +0.322 -0.001 to +0.535
Decode confirmation / 15 rounds default -0.147% to +0.655% +0.166% +0.070 -0.085 to +0.400

The graph results are close at the measured scale. The independent decode run still shows a small eager checking cost, so this is not described as zero overhead, universally faster or a new throughput optimization. These operator latencies must not be summed to infer model TPOT.

Main Matrix: All 36 Graph and Numerical Rows

18 route/M combinations, each with automatic dispatch and explicit default fallback. dispatch uses the three CSV rows above and the same-math fallback elsewhere. Reference NRMSE compares up to 8 token rows to a FP32 reference with the required BF16 projection/activation round points. Pair NRMSE compares candidate and baseline complete outputs; BF16 atomic accumulation can change bits between calls.

Routing M Mode Base graph us Fixed graph us Delta Base ref NRMSE % Fixed ref NRMSE % Pair NRMSE %
uniform 1 dispatch 36.646 36.884 +0.648% 0.40734 0.42012 0.26307
uniform 1 default 85.932 85.967 +0.040% 0.40061 0.40764 0.33734
uniform 8 dispatch 66.602 66.449 -0.230% 0.39922 0.39659 0.19151
uniform 8 default 118.081 118.131 +0.043% 0.40198 0.38848 0.28994
uniform 32 dispatch 160.354 160.409 +0.035% 0.40514 0.40390 0.21736
uniform 32 default 224.290 223.793 -0.221% 0.40496 0.40528 0.12331
uniform 64 dispatch 347.098 346.163 -0.269% 0.38585 0.38627 0.09443
uniform 64 default 358.399 358.042 -0.100% 0.38617 0.38603 0.10673
uniform 128 dispatch 476.852 475.575 -0.268% 0.38191 0.38032 0.08241
uniform 128 default 477.478 476.353 -0.236% 0.37989 0.37984 0.10496
uniform 4096 dispatch 1437.871 1438.500 +0.044% 0.39947 0.39947 0.05332
uniform 4096 default 1441.195 1441.527 +0.023% 0.39947 0.39947 0.04963
skewed 1 dispatch 38.143 38.314 +0.447% 0.41463 0.42826 0.43344
skewed 1 default 92.456 92.440 -0.018% 0.41198 0.37485 0.41523
skewed 8 dispatch 59.902 59.724 -0.298% 0.39150 0.39157 0.23064
skewed 8 default 111.973 111.997 +0.021% 0.40122 0.39761 0.26957
skewed 32 dispatch 67.035 67.124 +0.132% 0.39557 0.39708 0.20579
skewed 32 default 117.399 117.570 +0.145% 0.39065 0.39280 0.22993
skewed 64 dispatch 119.454 119.691 +0.199% 0.38218 0.38713 0.26635
skewed 64 default 119.518 119.618 +0.083% 0.38480 0.38184 0.28062
skewed 128 dispatch 124.427 124.558 +0.105% 0.38929 0.39006 0.22991
skewed 128 default 124.329 124.668 +0.273% 0.38943 0.38937 0.19175
skewed 4096 dispatch 1137.862 1138.518 +0.058% 0.40563 0.40480 0.08859
skewed 4096 default 1138.436 1138.570 +0.012% 0.40598 0.40493 0.13697
hot 1 dispatch 38.229 38.252 +0.059% 0.41601 0.40100 0.44017
hot 1 default 92.653 92.654 +0.001% 0.41772 0.37236 0.43579
hot 8 dispatch 51.839 51.708 -0.252% 0.39019 0.39474 0.43214
hot 8 default 91.534 91.666 +0.145% 0.39355 0.39480 0.36141
hot 32 dispatch 37.951 37.867 -0.221% 0.39758 0.39518 0.31071
hot 32 default 84.770 85.126 +0.420% 0.39973 0.38114 0.43599
hot 64 dispatch 96.590 97.070 +0.497% 0.39339 0.39012 0.41576
hot 64 default 96.957 97.077 +0.123% 0.38911 0.38911 0.41779
hot 128 dispatch 105.897 105.911 +0.013% 0.39838 0.39355 0.29437
hot 128 default 105.950 106.207 +0.242% 0.39625 0.39279 0.36074
hot 4096 dispatch 1052.526 1052.616 +0.009% 0.40907 0.40976 0.15594
hot 4096 default 1053.477 1052.745 -0.070% 0.40576 0.40763 0.24031

Main Matrix: All 36 Eager Event and Wall Rows

These are from the same 9-round matrix as the graph table, not a second selection of samples. Both event and wall measurements include host submission gaps.

Routing M Mode Base event us Fixed event us Base wall us Fixed wall us Wall delta us
uniform 1 dispatch 70.429 70.725 71.075 71.350 +0.275
uniform 1 default 88.565 88.611 89.194 89.225 +0.030
uniform 8 dispatch 71.025 71.817 71.636 72.438 +0.802
uniform 8 default 120.426 120.418 121.047 121.031 -0.016
uniform 32 dispatch 160.450 159.804 161.094 160.439 -0.656
uniform 32 default 225.425 225.245 226.054 225.891 -0.163
uniform 64 dispatch 349.355 349.849 350.004 350.508 +0.505
uniform 64 default 361.580 361.548 362.237 362.175 -0.061
uniform 128 dispatch 480.321 479.285 480.963 479.934 -1.029
uniform 128 default 480.909 480.469 481.541 481.102 -0.439
uniform 4096 dispatch 1453.448 1453.650 1454.139 1454.283 +0.143
uniform 4096 default 1457.124 1455.174 1457.788 1455.832 -1.957
skewed 1 dispatch 69.975 70.401 70.599 71.027 +0.428
skewed 1 default 94.935 94.993 95.553 95.623 +0.069
skewed 8 dispatch 70.495 71.253 71.111 71.885 +0.774
skewed 8 default 114.250 114.200 114.871 114.808 -0.062
skewed 32 dispatch 76.851 77.315 77.473 77.938 +0.465
skewed 32 default 119.898 119.978 120.513 120.600 +0.087
skewed 64 dispatch 121.930 122.028 122.548 122.678 +0.130
skewed 64 default 121.730 121.846 122.353 122.497 +0.144
skewed 128 dispatch 126.588 126.686 127.218 127.365 +0.147
skewed 128 default 126.444 126.628 127.073 127.319 +0.245
skewed 4096 dispatch 1155.494 1155.776 1156.137 1156.422 +0.286
skewed 4096 default 1156.146 1156.702 1156.841 1157.383 +0.542
hot 1 dispatch 69.819 70.307 70.498 70.910 +0.413
hot 1 default 95.145 95.099 95.771 95.765 -0.007
hot 8 dispatch 70.703 70.879 71.320 71.510 +0.190
hot 8 default 94.087 94.163 94.703 94.768 +0.065
hot 32 dispatch 76.391 76.435 77.020 77.068 +0.048
hot 32 default 87.927 88.461 88.544 89.079 +0.535
hot 64 dispatch 99.822 99.906 100.496 100.552 +0.056
hot 64 default 99.736 99.826 100.376 100.433 +0.057
hot 128 dispatch 108.754 108.638 109.422 109.267 -0.156
hot 128 default 108.354 108.412 108.976 109.026 +0.050
hot 4096 dispatch 1065.812 1065.442 1066.457 1066.080 -0.377
hot 4096 default 1066.028 1065.678 1066.683 1066.317 -0.366

Independent Decode: All 18 Graph and Numerical Rows

A separate run of M=1/8/32 across the same three routes, with 15 alternating rounds and 100 replays per round. It is retained separately from the main matrix; no best-of-two selection is used.

Routing M Mode Base graph us Fixed graph us Delta Base ref NRMSE % Fixed ref NRMSE % Pair NRMSE %
uniform 1 dispatch 36.790 36.541 -0.677% 0.41145 0.41060 0.45152
uniform 1 default 85.810 86.372 +0.655% 0.40128 0.40720 0.25816
uniform 8 dispatch 66.569 65.411 -1.739% 0.40209 0.39538 0.28851
uniform 8 default 118.051 118.150 +0.084% 0.40134 0.38795 0.26320
uniform 32 dispatch 160.972 161.110 +0.085% 0.40458 0.40299 0.11794
uniform 32 default 225.215 225.469 +0.113% 0.40408 0.40507 0.13697
skewed 1 dispatch 38.347 38.168 -0.467% 0.38618 0.42946 0.45102
skewed 1 default 91.760 91.890 +0.143% 0.36922 0.39654 0.41875
skewed 8 dispatch 59.735 58.981 -1.262% 0.39233 0.39412 0.26643
skewed 8 default 111.982 111.839 -0.128% 0.38674 0.39746 0.33872
skewed 32 dispatch 66.909 66.914 +0.007% 0.39361 0.39625 0.20386
skewed 32 default 117.705 117.533 -0.147% 0.39199 0.38950 0.20915
hot 1 dispatch 38.425 38.419 -0.017% 0.36789 0.39538 0.40695
hot 1 default 92.322 92.443 +0.131% 0.37490 0.36705 0.40354
hot 8 dispatch 51.661 51.591 -0.135% 0.38761 0.39398 0.36861
hot 8 default 90.021 90.075 +0.060% 0.39525 0.39498 0.43406
hot 32 dispatch 37.861 37.983 +0.324% 0.39977 0.39686 0.33306
hot 32 default 85.375 85.875 +0.586% 0.39239 0.39154 0.41310

Independent Decode: All 18 Eager Event and Wall Rows

100 eager calls per round, from the independent confirmation run above.

Routing M Mode Base event us Fixed event us Base wall us Fixed wall us Wall delta us
uniform 1 dispatch 72.158 72.300 72.311 72.454 +0.143
uniform 1 default 86.868 87.028 87.024 87.182 +0.158
uniform 8 dispatch 72.904 72.902 73.054 73.053 -0.001
uniform 8 default 118.567 118.505 118.707 118.652 -0.055
uniform 32 dispatch 161.690 161.821 161.842 161.978 +0.136
uniform 32 default 226.897 226.814 227.049 226.965 -0.085
skewed 1 dispatch 71.114 71.434 71.260 71.583 +0.322
skewed 1 default 92.594 92.779 92.743 92.930 +0.187
skewed 8 dispatch 72.329 72.731 72.478 72.882 +0.404
skewed 8 default 112.220 112.139 112.370 112.288 -0.082
skewed 32 dispatch 78.606 79.086 78.751 79.233 +0.482
skewed 32 default 117.757 117.764 117.909 117.915 +0.006
hot 1 dispatch 71.922 72.460 72.071 72.606 +0.535
hot 1 default 93.297 93.420 93.446 93.570 +0.124
hot 8 dispatch 73.050 73.468 73.203 73.616 +0.413
hot 8 default 90.723 90.794 90.873 90.943 +0.070
hot 32 dispatch 78.474 78.782 78.623 78.930 +0.307
hot 32 default 85.420 85.825 85.571 85.971 +0.400

Testing

The combined regression command ran on the exact candidate source on November 9:

python -B -m pytest -p no:cacheprovider \
  op_tests/test_flydsl_moe_a16wfp4.py \
  op_tests/test_moe_a16w16_default_dispatch.py \
  op_tests/flydsl_tests/test_gemm2_valid_token_count.py -q --tb=short
Check Observed result
New packed-K host regressions on original f16bca3 96 failed / 18 passed (expected failure)
Same new host regressions on fixed source 114 passed
Combined exact-source gfx942 regression command 330 passed / 36 existing skips; exit 0
Actual GPU reviewer shape 4 old/new configurations; 3 invalid pairs rejected only by fix
Main graph/eager A/B 18 route/M cases x 2 modes x 2 revisions x 9 rounds; all numerical gates pass
Independent decode graph/eager A/B 9 route/M cases x 2 modes x 2 revisions x 15 rounds; all numerical gates pass
Maximum sampled-reference NRMSE, both measured runs 0.42946%
Black / Ruff / diff / source-import verification passed

The new 114 host cases are included in the combined result, not additional passes. The 36 skips retain existing architecture/mode conditions; the two valid-token-count tests are gfx950-only and were skipped on gfx942. No skip, xfail or tolerance relaxation was introduced to mask the review finding.

An initial run failed 39 reporting calls because tabulate was missing from its path; the existing test dependency directory corrected the environment before rerunning. No kernel assertion was changed. A preliminary multi-process timing stopped after its first baseline case because resource counters lagged child exit; its partial output is excluded. The complete same-process data above is the accepted measurement source.

The existing canonical test file now covers the reviewer's valid M3/top2 shape with its original reference tolerance and output canaries, packed K rejection before sorting/compile/IR, legal 128/256 boundaries, both stages and FP4/INT4. Earlier activation, prefetch, CSV, SiTUv2 layout and runtime-beta tests remain.

  • Unit tests added or updated.
  • Operator performance benchmarks run on MI325X/gfx942.
  • MI250X execution: not performed.
  • MI300X execution: not performed; the measured device is MI325X, not MI300X.
  • Fresh gfx950 hardware qualification and new-head hosted CI.
  • Matched final-stack TP8 serving and complete GSM8K acceptance.

Documentation

No new CLI, default backend, activation quantization or external user option is added by the latest guard fix. The API now rejects tile pairs its packed loader cannot execute. This body documents the constraint, measured eager cost and validation scope.

  • Existing operator contract and regression coverage describe the change.
  • No separate user-guide change is needed for rejecting unsupported internal tile configurations.

Dependencies

  • No new third-party dependencies added by the commit.

The validation uses existing FlyDSL and test dependencies. Global dependency pins and workflow permissions are unchanged.

Breaking Changes

Previously accepted but unsupported FP4/INT4 K tiles now raise ValueError. Such tiles could silently produce zeros or fail during tracing and were not valid computations. Use positive multiples of 128 that also divide the physical dimensions. Supported BF16 calls and valid packed-weight configurations are unchanged.

Limits

  • This validates the latest guard fix on gfx942. It does not complete independent gfx950 acceptance of the earlier SiTUv2 dispatch correction.
  • There is no fresh vLLM comparator, broad 50-shape/30-GEMM1 rerun, prefetch retuning, independent unseen-seed tile selection or full-model result for this commit. Those older tables have been replaced rather than relabeled as current data.
  • Full TP8 serving, checkpoint-wide inputs and matched full GSM8K were not rerun. Earlier downstream evaluations did not establish the requested no-quality-loss acceptance; readable responses alone are not quality acceptance. No current model score is claimed.
  • No fresh CI success is inferred from local results. The previous wheel pull failed with Docker Hub 429 before compilation; the new commit still needs hosted checks.

AI assistance: GitHub Copilot assisted with code and validation. LiuYinfeng01 is the sole Git author of the latest commit; there are no coauthor trailers on that commit.

PR Self-Review

Reviewed revision

002152e

Behavior and intent

Reject unsupported FP4/INT4 K tiles before output allocation, sorting or shared compilation, preventing zero-trip accumulation and missing raw-fragment groups. Require positive multiples of 128 in the complete MoE API, stage wrappers and compile entry points. BF16 support and valid kernel bodies, CSV, prefetch, LDS settings and the previous SiTUv2 layout correction are preserved. This closes the remaining explicit-tile correctness finding without weakening tests.

Validation and unverified scope

MI325X/gfx942, Torch 2.13.0+rocm10.0.0, FlyDSL 0.4.2: 330 passed / 36 existing skips in the combined command above, real old/new GPU reproduction, complete 18-case graph/eager A/B and independent 9-case decode confirmation. All raw trial counts, numerical gates, source/import identities and table calculations were checked. Black, Ruff and diff checks passed. The snapshot's four source files are byte-identical to the tested candidate; committing does not modify them. Remaining unverified scope: gfx950 hardware, new-head hosted CI, broad historical operator sweeps, full TP8 serving and full GSM8K. No model-quality acceptance is claimed.

PR-specific question

The branch's CI change is the literal-file case in .github/scripts/aiter_test.sh that invokes timeout 60m python3 -m pytest -q "$file" for the canonical A16W4 test. This latest commit does not modify CI. No PR text is evaluated as shell, no pull_request_target path or privileged execution is added, and token permissions, secrets and checkout refs are unchanged. Existing fork-code execution remains subject to the existing runner isolation and approval policy.

Changed op tests

op_tests/test_flydsl_moe_a16wfp4.py: 114 host cases exercise FP4/INT4 K values -128/0/16/32/64/96/192 and legal 128/256 boundaries at both wrapper and shared compile entry points, with gfx942/gfx950 compile parameters. Explicit MoE cases use the reviewer's real input shapes and confirm rejection before sorting. The existing GPU complete-MoE test additionally covers M3/top2, preserving reference tolerances, repeated zeroing and canaries. These are not redundant: dimension divisibility alone failed to enforce raw-loader granularity, and direct compiler callers bypass the high-level API. Existing activation, prefetch, CSV and SiTUv2 coverage remains unchanged.

Add optional BF16 accumulator rounding before activation and regression coverage for runtime limits, padding, canaries, and full two-stage MoE.

Assisted-by: GitHub Copilot
Signed-off-by: yinfengLiu <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6995 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Add exactly two runtime-consumed rows for gfx942/304 CU, H5120,
physical I384/logical I288, E384, top-6, clamp10, BF16 pre-activation:
- M8: GEMM1 16x64x128; GEMM2 16x256x128, LDS reuse enabled.
- M32: GEMM1 16x128x128; GEMM2 16x256x128, LDS reuse enabled.

Use exact shape, architecture, CU and activation-semantic matching.
Unmatched inputs keep the same-math default tile pair; explicit tiles
remain supported. Keep this table separate from generic tuned_fmoe.csv.
Add paired wrapper, opt-in GEMM2 LDS allocation reduction and distinct
JIT cache keys; existing calls keep their default LDS allocation.
Forward BF16 pre-activation through the existing FlyDSL stage1 entry.

Acceptance uses two held-out seeds (89/97), uniform/skewed/hot routing,
and three timed passes for each of 12 cases. All pass numerical checks
against pinned vLLM and sampled torch math and a strict no-regression
gate on both summed kernel time and CUDA-event elapsed time. M8 gains
are 1.612-1.719x kernel and 1.364-1.388x elapsed; M32 gains are
1.104-1.247x kernel and 1.060-1.200x elapsed, versus same-math AITER
default tiles. These are not base-PR or full-model speedup claims.

Final MI325X verification: 53 tests passed; M8/M32 automatic CSV
lookup, full-MoE numerical comparisons, output canaries and repeated
zeroing passed. Bound reference quantization temporary memory per
expert; packed weights and scales match the original method exactly.
The earlier high-memory test OOMs were not numerical failures and
were resolved without shrinking test dimensions or relaxing tolerance.
Black 26.3.0, Ruff 0.15.7 and diff whitespace checks pass.

This extends the explicit clamped-SiLU experiment in PR ROCm#6995, not
initial gfx942 support (ROCm#5583) or vLLM serving integration. Clamp
arithmetic overlaps ROCm#6552; explicit opt-in semantics and BF16 rounding
remain subject to API consolidation. No new issues or attachments.
Full-model accuracy, graphs and gfx950 execution are not claimed.

Assisted-by: GitHub Copilot
Signed-off-by: yinfengLiu <[email protected]>
@LiuYinfeng01
LiuYinfeng01 marked this pull request as ready for review October 29, 2026 09:01
@LiuYinfeng01
LiuYinfeng01 requested a review from a team October 29, 2026 09:01
@github-actions github-actions Bot changed the title [Feature] Add explicit clamped SiLU to FlyDSL a16w-mix GEMM1 [FlyDSL] [Feature] Add explicit clamped SiLU to FlyDSL a16w-mix GEMM1 Oct 29, 2026
Route the existing operator test through pytest. Execute both real CSV shapes (M8/M32, H5120, I384/logical288, E384, top6), and add FP4/INT4/BF16 GEMM2 regressions with routing references and output guards.

Limit opt-in LDS reuse to gfx942 MXFP4 atomic kernels. Retain the original SharedStorage allocation and capacity behavior for default calls. Reject unqualified architectures, dtypes and reduce epilogues before tracing; retain distinct default/reuse cache keys.

Use +inf for the ordinary-versus-explicit no-clamp equivalence test so PR6552 can implement finite ordinary-SiLU clamping independently. A read-only merge preview against 6bf3c53 finds localized wrapper/GEMM1/stage1-dispatch conflicts; that PR was not merged into this branch.

Validation: gfx942 MI325X, FlyDSL 0.4.0, complete pytest 71 passed; actual AITER_TEST CI-script invocation 71 passed with exit 0. Focused stage2 19 passed and final stage1 12 passed. Black 26.3.0, Ruff 0.15.7, Bash syntax and staged whitespace checks passed. gfx950 execution is unavailable and is not claimed; new LDS reuse is disabled there. Correctness timings are not new isolated performance evidence.

Assisted-by: GitHub Copilot
Signed-off-by: yinfengLiu <[email protected]>
@github-actions github-actions Bot changed the title [FlyDSL] [Feature] Add explicit clamped SiLU to FlyDSL a16w-mix GEMM1 [FlyDSL] [CI] [Feature] Add explicit clamped SiLU to FlyDSL a16w-mix GEMM1 Oct 29, 2026
@github-actions github-actions Bot added the CI label Oct 29, 2026
@aiter-bot

aiter-bot commented Oct 29, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 002152e6a9c7 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

Reject unsupported FP4/INT4 K tiles before output allocation, sorting or shared compilation, preventing zero-trip accumulation and missing raw-fragment groups. Require positive multiples of 128 in the complete MoE API, stage wrappers and compile entry points. BF16 support and valid kernel bodies, CSV, prefetch, LDS settings and the previous SiTUv2 layout correction are preserved. This closes the remaining explicit-tile correctness finding without weakening tests.

Validation and unverified scope

MI325X/gfx942, Torch 2.13.0+rocm10.0.0, FlyDSL 0.4.2: 330 passed / 36 existing skips in the combined command above, real old/new GPU reproduction, complete 18-case graph/eager A/B and independent 9-case decode confirmation. All raw trial counts, numerical gates, source/import identities and table calculations were checked. Black, Ruff and diff checks passed. The snapshot's four source files are byte-identical to the tested candidate; committing does not modify them. Remaining unverified scope: gfx950 hardware, new-head hosted CI, broad historical operator sweeps, full TP8 serving and full GSM8K. No model-quality acceptance is claimed.

PR-specific question

The branch's CI change is the literal-file case in `.github/scripts/aiter_test.sh` that invokes `timeout 60m python3 -m pytest -q "$file"` for the canonical A16W4 test. This latest commit does not modify CI. No PR text is evaluated as shell, no `pull_request_target` path or privileged execution is added, and token permissions, secrets and checkout refs are unchanged. Existing fork-code execution remains subject to the existing runner isolation and approval policy.

Changed op tests

`op_tests/test_flydsl_moe_a16wfp4.py`: 114 host cases exercise FP4/INT4 K values -128/0/16/32/64/96/192 and legal 128/256 boundaries at both wrapper and shared compile entry points, with gfx942/gfx950 compile parameters. Explicit MoE cases use the reviewer's real input shapes and confirm rejection before sorting. The existing GPU complete-MoE test additionally covers M3/top2, preserving reference tolerances, repeated zeroing and canaries. These are not redundant: dimension divisibility alone failed to enforce raw-loader granularity, and direct compiler callers bypass the high-level API. Existing activation, prefetch, CSV and SiTUv2 coverage remains unchanged.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Resolve conflicts with ROCm#6552 (a16wmix SiLU honours swiglu_limit), ROCm#7294
(gemm2 use_valid_token_count) and the a8w8 literal-file CI case:

- gemm1 epilogue: plain silu keeps ROCm#6552's clamp_gate_up; the optional
  activation_bf16 rounding is applied before the activation. situ_params
  is now built for every activation, as on main.
- gemm2 and flydsl_a16w4_gemm2: keep both reuse_lds and
  use_valid_token_count; their kernel-name tags stay distinct.
- moe_kernels: keep the silu_clamped/activation_bf16 validation with
  main's bf16-weight comment.
- aiter_test.sh: keep the pytest case for test_flydsl_moe_a16wfp4.py next
  to main's test_gemm_a8w8.py case.

silu_clamped and ROCm#6552's clamped silu share the same clamp: gate is
upper-bounded and up is clamped to [-limit, limit] before silu(gate) * up.
silu_clamped additionally requires a positive limit and is the only mode
that accepts activation_bf16.

Assisted-by: GitHub Copilot
Signed-off-by: yinfengLiu <[email protected]>
On gfx942 the A16W4 GEMM1 K loop stages A through VGPRs: each tile's
global load is waited on before its LDS write, and each E8M0 scale dword
is decoded right after it is loaded. vmcnt retires in issue order, so
every K tile exposes two memory latencies; at decode-sized M there are
too few waves per CU to hide them.

Add an opt-in prefetch=P (1..4) pipeline for gfx942 MXFP4 weights. A, B
and scale loads are issued P tiles ahead, A is committed to the free LDS
slot after the current tile's MFMAs, and scales are decoded when they are
consumed. Loads, MFMA order and epilogue are unchanged, so the output is
bitwise identical to prefetch=1. prefetch=1 keeps the original loop and
kernel name; P>1 is rejected for other architectures and weight dtypes.

The tuned A16W4 CSV gains optional stage1_k_wave and stage1_prefetch
columns (default 1), validated by the policy and the wrapper:
- M1 (new): BM16, stage1 N32/K128/k_wave 4, stage2 N256, no prefetch.
- M8: stage1 N64/K256 with prefetch 4, stage2 N128 with LDS reuse
  (prefetch is what makes the K256 tile win; without it it is slower).
- M32: stage1 N32/K128/k_wave 2 with prefetch 3, stage2 N128 with reuse.
Rows were screened on MI325X with FlyDSL 0.4.2 and kept only if they beat
the previous selection with a strict timing margin on all ten holdouts
(uniform/skewed/hot routing, unseen seeds): full MoE 2.41-2.47x vs the
fallback at M1, 1.03-1.17x at M8 and 1.03-2.16x at M32 vs the previous
rows. Prefetch is not used where it did not win reproducibly (M1).

Also store moe_a16w4_policy.py with LF line endings.

Tests cover optional-column parsing and bounds, the prefetch scope
assertion, bitwise prefetch equality for M1/8/33 over three tile shapes,
and the automatic M1/M8/M32 dispatch on the real shape.

Assisted-by: GitHub Copilot
Signed-off-by: yinfengLiu <[email protected]>
Routing op_tests/test_flydsl_moe_a16wfp4.py through pytest made its
existing SiTUv2 end-to-end cases run in CI for the first time. On MI35X
four of them fail (H3584/I384/E896/top-16 at M1 and M16, cos diff 0.98).
For M <= 32, kimik3_a16w4_tuned_fmoe.csv routes this shape to 1-stage
ASM SiTUv2 kernels. The tuner's 1-stage path checks those kernels with
unshuffled weights and scales, while this test passes the
shuffle_weight_a16w4 layout of the a16w4 caller contract. M128 (FlyDSL
rows) and I512 (default heuristics) pass.

Mark only those gfx950 cases as non-strict xfail so the rest of the file
keeps gating CI. They will report XPASS once the tuned rows or the
dispatch honour the layout. gfx942 behaviour is unchanged.

Assisted-by: GitHub Copilot
Signed-off-by: yinfengLiu <[email protected]>
The SiTUv2 tuned CSV is indexed by shape, not by runtime weight layout.
Its small-M gfx950 ASM rows are tuned with raw weights/scales, whereas
shuffle_weight_a16w4 callers pass separated preshuffled tensors. Returning
those 1-stage rows reads the wrong layout and bypasses the existing
layout-compatible two-stage FlyDSL path.

Reject only those SiTUv2 MXFP4 ASM rows for preshuffled input, preserving
compatible FlyDSL tuned rows and the raw fixed-beta ASM path. Reject
mixed-shuffle or interleaved input explicitly. The ASM launcher has no
runtime beta ABI; raw calls with non-production betas now fail explicitly
instead of silently ignoring them.

Remove the gfx950 xfail added by 3a18403. The original numerical cases
and tolerances remain, with an additional dispatch assertion. Add 36
layout/flat/emsort/beta selector cases, 10 real-CSV preservation cases,
and 2 runtime-beta forwarding cases.

Verification: the same 48 regressions give 33 failures/15 passes on the
old selector, and 48 passes after this fix. The broader host slice has
73 passes; neighboring host dispatch tests have 12 passes/82 GPU skips.
Black 26.10.1, Ruff 0.16.0 and diff checks pass. GPU execution and gfx950
numerical/performance acceptance remain pending; no fresh speedup or
model-quality claim is made by this commit.

Assisted-by: GitHub Copilot
Signed-off-by: yinfengLiu <[email protected]>

@xytpai xytpai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up on the two findings originally reviewed at f52deefccdb6, rechecked against f16bca382a70 before posting.

The latest commit addresses the previous SiTUv2 ASM/preshuffled-layout selection finding and adds dispatch assertions, so I am not posting that as an outstanding issue. I have not rerun GPU numerical validation of that fix.

One issue remains in the new explicit-tile API: unsupported K tiles pass validation and can silently produce all-zero output. Please add the missing guards and regression tests described inline.

Validation provenance: the GPU reproductions below were run at f52deefccdb6 on gfx950 with Torch 2.10.0 / ROCm 7.2.4 and FlyDSL 0.3.4.1. For the current head, I independently executed the wrapper's host-side validation with mocked launches and confirmed that the invalid values are still forwarded; source inspection confirms the zero-trip accumulation condition remains. This is a targeted recheck of those findings, not a fresh full GPU review of the expanded branch.

Validate the raw-loader K granularity at the explicit A16W4 MoE API,
both stage wrappers, and both shared compile entry points. FP4 and INT4
K tiles must be positive multiples of 128. Previously K=16 could skip
every accumulation and silently return zeros, while K=64 supplied no
raw-weight groups and failed during tracing. Preserve BF16 support,
valid kernel bodies, CSV rows, prefetch and LDS settings.

Add 114 host rejection and legal-boundary cases, and extend the existing
GPU MoE test with the reviewer's valid M3/top2 shape without changing
numerical tolerances or canaries. The original implementation fails 96
of the new host cases; the fixed implementation passes all 114.

MI325X gfx942 validation: 330 passed, 36 existing skips across the A16W4
and neighboring suites. The reviewer's two K16 cases reproduce all-zero
output and the K64 case reproduces IndexError on f16bca3; all three are
rejected before execution after this fix. Legal K128 output passes.

Same-input paired graph/eager tests cover 18 route/M cases, plus a
separate 9-case decode confirmation. Main graph changes range from
-0.30% to +0.65%; the confirmation records a median 0.322 us eager
checking cost. No model-throughput, GSM8K or gfx950 acceptance is claimed.

Signed-off-by: LiuYinfeng01 <[email protected]>
@LiuYinfeng01
LiuYinfeng01 merged commit 9c119bb into ROCm:main Nov 10, 2026
@LiuYinfeng01
LiuYinfeng01 deleted the pr/flydsl-clamped-silu-a16wmix branch November 10, 2026 11:00
vedenev-amd added a commit that referenced this pull request Nov 10, 2026
main gained the FlyDSL a16w16 path (#6552), the explicit clamped SiLU with an
activation_bf16 stage-1 argument (#6995) and the mxfp4 a8w4 replacement (#6464),
which were added in the same places as this branch's gfx942 a8w4 path: the kernel
registry, the stage-1 signatures and the MoE tuner. Both sides are kept everywhere:
the registry registers the _g942 and a16w16 names, stage 1 takes in_dtype, x_layout
and activation_bf16, and the tuner picks candidates in the order a16w16, gfx942
a8w4, other, with the bf16-intermediate stage 2 for both a16w-mix and gfx942 a8w4.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
MHYangAMD added a commit to AFDEAPAC/aiter that referenced this pull request Nov 11, 2026
…942-fp8-mfma

Conflicts with ROCm#6995 (clamped SiLU, gemm1 prefetch, gemm2 LDS reuse) in the
a16wmix port and its test file, resolved by keeping both sides. The fp8
kernels are separate definitions, so:

- gemm1: the fp8 kernel passes activation_bf16 to the shared body, which now
  dequantizes before the bf16 rounding. fp8 requires prefetch=1; the deep
  prefetch pipeline is not validated with the fp8 A loader.
- gemm1: SLP is off for the fp8 silu_clamped kernels too, as for SiLU and
  SwiGLU. With SLP on they spilled 334-651 VGPRs on the BM16/32 x TILE_N 128
  tiles (E=896, 3584/384, MI308X); with it off they do not spill, and the
  outputs are bitwise identical.
- gemm2: fp8 rejects reuse_lds, which the fp8 kernel's LDS layout does not
  implement.
- op_tests: ROCm#6995's per-expert MXFP4 quantization and its two-stage dispatch
  check move into the _situv2_problem helper and the e2e test.
zufayu pushed a commit that referenced this pull request Nov 11, 2026
test_stage2_lds_variants_have_distinct_cache_keys imported
flydsl.compiler.jit_function._jit_function_cache_key, which FlyDSL 0.5.0
removed (#7600 moved the library off it; #6995 added the test after). It
failed on main and on every PR that runs Standard Tests.

FlyDSL 0.5.0 keys its cache on the traced IR, so take each variant's key
the way aiter's AOT replay does: launch it under dry_run and
identified_kernels, which stops the launch at its key without compiling
or running it, and check the two variants' keys are disjoint.
zufayu pushed a commit that referenced this pull request Dec 3, 2026
* [MoE] moev2 step 3.1: bf16/fp16 a16w16 path (not graduated)

Unquantized bf16/fp16 fused_moe calls (QuantType.No) can run through
aiter.moev2 when enabled with AITER_MOEV2=a16w16 (or on). The path is not
graduated: by default every call still runs the legacy code.

Behavior claim:
- Legacy dispatch is unchanged. The CPU dispatch snapshot of legacy
  fused_moe is identical on gfx942, gfx942_cu80, gfx950 and gfx1201,
  including the new QuantType.No feature variants, which are byte-identical
  to ones generated with the upstream base's aiter package.
- When a16w16 runs a call in v2, it makes the same choices as legacy:
  same kernels, parameters and inputs, same log lines and exceptions, and
  the same outputs within legacy's own run-to-run noise (see Tests).
- a8w8_pt keeps its choices. It no longer takes g1u0 weights, which now
  run on legacy (see Known differences).
- Both paths decline what they do not reproduce, and those calls run on
  legacy: herd_topk, deterministic=True, a registered presort, a
  clamping swiglu_limit (None, 0 and inf do not clamp), beta or
  linear_beta, bias, global scales, padding, scatter, caller-chosen
  activation dtypes, AITER_ONLINE_TUNE,
  g1u0 weights, and a call whose second lookup after the sort would raise
  or be declined.

What changed:
- migration/a16w16.py: path a16w16. It claims QuantType.No calls with
  g1u1 bf16/fp16 3D weights on gfx942/gfx950, Silu or Gelu, separated
  gate/up. Its segments are sort, quant, CK stage 1/2 and whole graph.
- migration/local.py: what the single-GPU paths share. That is the
  common claims checks, the per-key cached resolve, the log-only second
  lookup after the sort, run and dispatch_record. a8w8_pt now uses it.
  The check phase 2 added to a8w8_pt moves here, so every local path
  declines a call whose second lookup would raise or be declined, and
  says so under AITER_MOE_EXPLAIN=1.
- Path.takes(problem): the dispatch keys a path runs. One segment (CK)
  serves several formats, and takes keeps one path from taking another
  path's keys. Dispatch, the CPU differential and the ranking checks use
  it.
- CK stage 1/2 and the whole graph accept bf16 and fp16, one capability
  per dtype. CK stage 1 is g1u1 only, since it always reads w1 as gate and
  up (N = w1.size(1) / 2).
- Ranking:
  - an a16w16 entry: the get_2stage_cfgs CK default branch;
  - named boolean predicates in when(...). fmoe_1stage tests a copy of the
    keys of legacy fused_moe_1stage_dict, current with upstream (it has
    the gfx950 SwiGLU per_1x32 keys), and a test checks the copy;
  - regions that hand their problems back to legacy (legacy="...").
  The shipped table uses neither predicates nor legacy regions yet. When
  the resolver declines, it says why: no entry applies, a legacy region,
  or no listed structure is feasible.
- Dispatch snapshot: QuantType.No keys also get the feature variants
  (FEATURE_QUANT_TYPES), and the goldens are regenerated.
- README: rows for local.py and a16w16.py (to be removed), plus the
  updated descriptions of paths, ranking, resolver, CK and the tests.
- Tests:
  - claims, takes and their agreement on key fields;
  - g1u0 not claimed;
  - the second-lookup declines, now through the shared dispatch;
  - feature variants of QuantType.No keys are legacy calls;
  - predicates and legacy regions;
  - gpu_differential.py gains a16w16 cases and per-path synthetic rows.

Known differences and limits:
- g1u0 calls run on legacy. Legacy's CK 2-stage gives wrong output for
  g1u0 (the stage-1 kernel reads w1 as gate and up), so v2 has nothing to
  match. The QuantType.No keys of fused_moe_1stage_dict are all g1u0, so
  legacy's default 1-stage ASM fmoe branch stays on legacy too. For
  a8w8_pt this drops 544 / 751 / 544 keys on gfx942 / gfx942_cu80 /
  gfx950 that phase 2 claimed, all of them the g1u0 feature variants;
  it gains none.
- gfx942-only parts are checked only by the CPU differential: the
  impl__flydsl_gfx942 tuned rows and the gfx942-only suites. gfx1201
  bf16 rows stay on legacy.

Tests:
- CPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py, 100
  passed.
- CPU gates, on all 4 archs, 0 problems:
  - differential.py: a16w16 8000 / 11,724 / 8084 and a8w8_pt 5984 /
    8280 / 5984 keys on gfx942 / gfx942_cu80 / gfx950 (none on gfx1201);
  - key_checks.py: 181,478 keys, 27,963 tuned rows;
  - ranking_checks.py: 51,828 ranked keys, both entries reached.
- GPU differential, gfx950, 0 problems, each also with AITER_USE_NT=1
  and AITER_BYPASS_TUNE_CONFIG=1:
  - a16w16: 21 default and shipped-tuned cases, and 69 with a synthetic
    table of bf16 CK rows;
  - a8w8_pt: 15 cases, and 63 with its synthetic table.
- GPU suites, gfx950, AITER_MOEV2=off vs on (both paths):
  test_moe_2stage -q 0 and -q 1 (--no-flydsl-csv), test_moe.py,
  test_moe_per_tensor_a2_init, test_moe_sorting, test_moe_ep,
  test_moe_local_expert_ids and test_moe_dp_share_expert. Same exit codes
  and the same verdict for every check, except two swiglu_limit=7.0
  checks of test_moe_2stage -q 0 (per-token and per-tensor fp8, which run
  on legacy in both modes). Their verdicts also change between two runs
  with AITER_MOEV2=off (1 or 2 of 2048 elements past the tolerance).
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255):
- local.py carries PR 8255's a8w8_pt code: why_not reasons, the clamps
  helper, w1/w2 global scales unsupported, the live arch only, and the
  preview prologue that declines before copying anything. Both paths
  set why_not and supported_archs and have the ownership NOTE.
- gpu_differential.py keeps PR 8255's variant, raise and gfx942 cu80
  cases; the a8w8_pt g1u0 variant is dropped (no longer claimed).
- The golden delta equals the original step's exactly. The key counts
  and GPU results above are from the original base. On this base: CPU
  tests 133 passed; differential a16w16 8712 / 12,773 / 8803 and
  a8w8_pt 6528 / 9031 / 6528 keys on gfx942 / gfx942_cu80 / gfx950;
  key_checks, ranking_checks and snapshot --check, 0 problems. The GPU
  differential is rerun at the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.2: fp8 per-token and 1x128 blockscale paths (not graduated)

fp8 per-token (QuantType.per_Token) and fp8 1x128 blockscale
(QuantType.per_1x128, and per_128x128, which legacy remaps to it)
fused_moe calls can run through aiter.moev2 when enabled with
AITER_MOEV2=a8w8_ptok / a8w8_blockscale (or on). Neither path is
graduated: by default every call still runs the legacy code.

Behavior claim:
- Legacy dispatch is unchanged. The CPU dispatch snapshot of legacy
  fused_moe is identical on gfx942, gfx942_cu80, gfx950 and gfx1201,
  including the new per_Token and per_1x128 feature variants, which are
  byte-identical to ones generated with the upstream base's aiter package.
- When either path runs a call in v2, it makes the same choices as
  legacy: same kernels, parameters and inputs, same log lines and
  exceptions, and the same outputs within legacy's own run-to-run noise.
  The exceptions are two legacy ASM stage 1 kernel families that are not
  repeatable even legacy against legacy (see Known differences).
- Calls legacy runs on 1-stage ASM are handed back to legacy: the default
  1-stage regions of both formats, and 1-stage tuned rows. So is what the
  shared local checks decline (herd_topk, deterministic=True, a
  registered presort, a clamping swiglu_limit, beta, linear_beta, bias,
  global scales, padding, scatter, caller-chosen activation dtypes,
  AITER_ONLINE_TUNE, g1u0, and a call whose second lookup after the
  sort would raise or be declined).
- a8w8_pt and a16w16 keep their keys and choices.

What changed:
- migration/a8w8_ptok.py: path a8w8_ptok. It claims per-token calls with
  g1u1 fp8 3D weights (the arch's fp8) on gfx942/gfx950, Silu or Gelu,
  separated gate/up. These resolve to CK 2-stage, ASM stage 1 + CK
  stage 2, or the FlyDSL gfx942 whole graph. int8 and int4 weights stay
  on legacy.
- migration/a8w8_blockscale.py: path a8w8_blockscale, the same checks for
  per_1x128 / per_128x128. These resolve to CK 2-stage (with the 1x128
  block_m and split-K defaults) or asm.stage1_1x128 + CK stage 2.
- segments/asm.py: asm.stage1_1x128, the ASM stage 1 that writes the
  quantized intermediate and its fp32 scales into one buffer. It covers
  GEMM1 and the intermediate quant, and asks for the a1 scale transposed.
  The per-tensor ASM stage 1 also takes per-token fp8.
- execute/executor.py: a stage 1 that covers the intermediate quant gets
  its own buffer and splits its output into the GEMM2 inputs, as legacy
  does. segments/quant.py: the a1 quant can write the scale transposed.
- CK stage 1/2 accept per-token and 1x128 fp8; the whole graph accepts
  per-token fp8.
- segments/defaults.py: default_block_m / default_ksplit, the legacy
  default branch's 2-stage block_m and split-K per quant type.
- Ranking:
  - entries fp8_per_token and fp8_blockscale. Their legacy regions are
    the 1-stage branches of get_2stage_cfgs, with the thresholds as
    written; everything else ranks CK 2-stage;
  - predicates inter_dim_128 and blockscale_1stage_kernel (the kernel
    library's fmoe_fp8_blockscale_g1u1_has_kernel, which legacy calls);
  - when() tests its conditions in the order written, so the kernel
    library is asked only where legacy asks it;
  - FMOE_1STAGE_KEYS reads fp8 as the arch's dtypes.fp8 when looked up,
    as legacy does.
- The resolver finds stage segments by the op they cover rather than by
  name (MoePlan.starting). local.why_not takes a set of quant types.
  overrides.xbf16 reads AITER_XBFLOAT16 where legacy reads it.
- Dispatch snapshot: per_Token and per_1x128 keys also get the feature
  variants (FEATURE_QUANT_TYPES), and the goldens are regenerated.
- README: rows for a8w8_ptok.py and a8w8_blockscale.py (to be removed),
  plus the updated descriptions of plan, ranking, resolver, overrides,
  quant, CK, ASM, defaults, executor, the differential and the tests.
- Tests:
  - claims and takes of both paths;
  - the per-token 1-stage hand-back, the 1x128 block_m and split-K
    defaults, a tuned ASM 1x128 row running the packed stage 1, and the
    packed buffer splitting like legacy;
  - when() evaluation order;
  - feature variants of per_Token and per_1x128 keys are legacy calls;
  - the CPU differential counts 1-stage hand-backs separately;
  - gpu_differential.py gains cases for both paths (shapes with shipped
    gfx950 rows among them) and, for a8w8_blockscale, synthetic rows that
    swap the arch's ASM 1x128 stage 1 into its CK rows.

Known differences and limits:
- Two legacy ASM stage 1 families give different outputs for identical
  inputs on gfx950, legacy against legacy, on main and on the older base
  this work started from. The GPU differential reports them (they are
  not excused):
  - per-token fmoe_stage1_bf16_pertokenFp8_g1u1_64x128_2tg_pf3 and
    _32x128_3tg_pf2 at the shipped 5120/1536 E40 top8 and E41 top10
    rows: output garbage up to 1e34 in some runs;
  - the 1x128 fmoe_stage1_bf16_pertokenFp8_blockscale_g1u1_* family,
    which only the synthetic table runs on gfx950 (shipped ASM 1x128 rows
    are gfx942 only): stage 1 output differs on every run.
- Upstream's tuned lookup now falls back to rows tuned for another
  activation, except CK 2-stage and MXFP4 rows. The shipped gfx950
  4096/384 E128 top8 1x128 Silu rows are 1-stage at 4 to 128 tokens, so a
  Gelu call there runs 1-stage on legacy (and is handed back). The GPU
  differential's Gelu case for that shape therefore moves from 32 tokens
  to 2, which still runs the CK split-K default.
- gfx942-only parts are checked only by the CPU differential: the ASM
  1x128 rows and the impl__flydsl_gfx942 rows.

Tests:
- CPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py, 112
  tests, 111 passed. test_outputs_match_legacy[a8w8_ptok] fails on the
  per-token legacy race above.
- CPU gates, on all 4 archs, 0 problems:
  - differential.py: a8w8_ptok 3657 / 6724 / 3061 and a8w8_blockscale
    5523 / 7583 / 6154 keys on gfx942 / gfx942_cu80 / gfx950, with 2375 /
    3357 / 4111 and 1529 / 605 / 4256 keys handed back as 1-stage;
    a16w16 and a8w8_pt unchanged (none on gfx1201);
  - key_checks.py: 323,445 keys, 51,639 tuned rows;
  - ranking_checks.py: 104,820 ranked keys, every entry and region
    reached.
- GPU differential, gfx950, shipped tables, AITER_USE_NT=1 and
  --synth-table:
  - a8w8_ptok: 22 cases (70 with the synthetic table); the only
    problems are 2 of the per-token race cases in each mode;
  - a8w8_blockscale: 20 cases, 0 problems; with the synthetic table, 64
    of 136 pass and all 72 failures run the ASM 1x128 family;
  - with AITER_BYPASS_TUNE_CONFIG=1, legacy runs 6 per-token and 4
    blockscale cases on 1-stage ASM, and v2 hands them back; the rest
    pass;
  - a16w16 and a8w8_pt: 0 problems in every mode.
- GPU suites, gfx950, AITER_MOEV2=off vs on (all four paths):
  test_moe_2stage -q 2, -q 3 and -q 5 (--no-flydsl-csv), test_moe_tkw1,
  test_moe_blockscale, test_moe_sorting, test_moe_ep,
  test_moe_local_expert_ids and test_moe_dp_share_expert. Same exit codes
  and the same verdict for every check, except three that run on legacy
  in both modes and also change between two AITER_MOEV2=off runs: the
  per-tensor swiglu_limit=7.0 check of test_moe_2stage -q 3 and -q 5, and
  the first check of test_moe_tkw1 (its 1-stage tkw1 ASM kernel, which
  fails or warns on every run).
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
step 3.1):
- Both new paths set why_not and supported_archs and carry the
  ownership NOTE; like a8w8_pt they claim swiglu_limit None, 0 and inf
  (legacy reads them as no clamp for every format).
- differential.py keeps PR 8255's compare_launches (the 1-ulp and
  legacy-spread tolerance, whole-graph launches, a second legacy run)
  and adds this step's 2-stage guard, 1-stage hand-backs and output
  check. gpu_differential.py keeps PR 8255's rule that a case where
  legacy and v2 both raise fails unless listed in _RAISES; this step's
  "both raise" pass is not taken. New GPU cases: output=, a
  non-contiguous input and swiglu_limit 0 / inf for both new paths.
- The fused_moe.py note on get_2stage_cfgs points at the README's path
  list instead of naming per-tensor fp8.
- Goldens regenerated. gfx950 and gfx1201 get exactly this step's
  delta; on gfx942 and gfx942_cu80, 125 / 223 of the new swiglu_limit=7
  per-token variant lines differ from the original step's: upstream
  #8531 keeps clamped SiLU on CK where the old base chose the FlyDSL
  whole graph, and PR 8255 records whole-graph plans structurally.
- The counts and GPU results above are from the original base. On this
  base: CPU tests 143 passed (the GPU-only ones skip); differential
  a8w8_ptok 3979 / 7355 / 3329 and a8w8_blockscale 6012 / 8265 / 6682
  keys on gfx942 / gfx942_cu80 / gfx950, with 2601 / 3624 / 4486 and
  1673 / 664 / 4644 handed back as 1-stage; key_checks, ranking_checks
  and snapshot --check, 0 problems. The GPU differential is rerun at the
  end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.3: int8 and int4-weight formats (not graduated)

No new paths. The int8 and int4-weight formats join the paths that
already own their scale layout:
- a8w8_pt takes int8 per-tensor weights;
- a8w8_ptok takes int8 per-token weights, and int4 weights packed eight to
  a uint32 with fp8 activations.
No path is graduated: by default every call still runs the legacy code.

Behavior claim:
- Legacy dispatch is unchanged. The dispatch snapshot grid gains the fp8 x
  uint32 per-token combination (272 keys per arch, 2992 with their feature
  variants; additions only). The snapshot is identical on gfx942,
  gfx942_cu80, gfx950 and gfx1201 to one generated with the upstream
  base's aiter package.
- When either path runs an int8 or int4 call in v2, it makes the same
  choices as legacy: same kernels, parameters and inputs, same log lines
  and exceptions, and the same outputs within legacy's own run-to-run
  noise. One int8 case is the exception (see Known differences).
- int8 calls with doweight_stage1 stay on legacy. No ASM int8 stage 1
  kernel applies the routing weights, so legacy raises in the kernel
  lookup, and still does.
- A format added to a path later stays behind AITER_MOEV2 once the path
  graduates, until it passes its own gate (Path.graduated_claims).

What changed:
- CK segments accept the int8 and fp8 x int4 instances gen_instances.py
  builds. asm.stage1 accepts int8 without doweight_stage1 (the get_cfg
  kernel tables have no int8 kernel with it).
- Ranking: entries int8_per_token, int8_per_tensor and int4_per_token,
  following the legacy default branch:
  - int8 runs ASM stage 1 + CK stage 2 (int8 is not in the CK branch's
    weight list), with block_m rounded up to a CK stage 2 size;
  - int8 per-token keeps legacy's 1-stage branch above 32 tokens as a
    legacy region;
  - int4 runs CK 2-stage.
- migration/local.py: claims require w2 to have w1's dtype, and leave int8
  with doweight_stage1 to legacy (in claims and in the key-level check,
  so claims and takes agree).
- paths.py: Path.graduated_claims(call). When the path runs by default, it
  claims only the calls this also accepts; None accepts all.
- Dispatch snapshot: the fp8 x uint32 per-token grid combination, and the
  goldens are regenerated.
- README: the paths, CK, ASM and path rows describe the new formats.
- Tests:
  - int8 and int4 claims, including mixed w1/w2 dtypes and int8 with
    doweight_stage1;
  - a8w8_pt runs only when enabled;
  - int8 defaults run ASM stage 1 and int4 runs CK;
  - the ASM int8 stage 1 has no doweight_stage1 kernel;
  - gpu_differential.py builds int8 and int4 weights and adds their
    cases.

Known differences and limits:
- Left on legacy: per-token torch.int4 weights (the a16wi4 path, a later
  step) and per-tensor uint32.
- The int8 per-tensor Gelu GPU case (32 tokens, 4096/384, E128 top8) runs
  the default ASM stage 1 fmoe_stage1_bf16_pertokenInt8_g1u1_32x128_3tg_pf3,
  whose output differs between two legacy runs (in 2 of 3 pairs; final
  outputs within 0.016). On the older base this work started from,
  legacy raised in CK stage 2 for this call, so the case passed there.
  The GPU differential reports it in every mode.
- The other ASM stage 1 kernels that are not repeatable legacy against
  legacy (step 3.2) still show up: the per-token fp8 race cases, and,
  with the synthetic table, two int8 per-tensor cases that legacy has
  already been seen to get wrong in some runs.
- gfx942-only parts are checked only by the CPU differential.

Tests:
- CPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py, 119
  tests, 117 passed. test_outputs_match_legacy[a8w8_pt] and [a8w8_ptok]
  fail on the legacy ASM stage 1 cases above.
- CPU gates, on all 4 archs, 0 problems:
  - differential.py: a8w8_pt 7480 / 9787 / 7480 and a8w8_ptok 5817 /
    8884 / 6189 keys on gfx942 / gfx942_cu80 / gfx950, with 3343 / 4325 /
    4111 per-token keys handed back as 1-stage; a16w16 and
    a8w8_blockscale unchanged (none on gfx1201);
  - key_checks.py: 335,413 keys, 51,639 tuned rows;
  - ranking_checks.py: 118,703 ranked keys, 7 entries, every region
    reached.
- GPU differential, gfx950, shipped tables, AITER_USE_NT=1,
  AITER_BYPASS_TUNE_CONFIG=1 and --synth-table:
  - a8w8_pt: 23 cases (9 int8), 72 with the synthetic table. The only
    problem is the int8 Gelu case above in each mode; with the synthetic
    table, also the int8 (64, 7168, 256, E256, top8) case, whose two legacy
    runs differed by 4e36;
  - a8w8_ptok: 40 cases (18 int8 or int4), 88 with the synthetic table.
    The only problems are 2 per-token fp8 race cases in each mode, and in
    bypass mode the 6 fp8 cases legacy runs on 1-stage ASM, which v2 hands
    back;
  - a16w16 and a8w8_blockscale: as in step 3.2.
- GPU suites, gfx950, AITER_MOEV2=off vs on (all paths):
  test_moe_2stage -q 1, -q 2 and -q 3 (--no-flydsl-csv),
  test_moe_per_tensor_a2_init, test_moe_tkw1, test_moe_sorting,
  test_moe_ep, test_moe_local_expert_ids and test_moe_dp_share_expert.
  Same exit codes and the same verdict for every check, except checks
  that run on legacy in both modes and also change between two
  AITER_MOEV2=off runs: the per-token and per-tensor swiglu_limit=7.0
  checks of test_moe_2stage -q 2 and -q 3, and the first check of
  test_moe_tkw1 (its 1-stage tkw1 ASM kernel).
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.2):
- local.why_not gives reasons for the new declines (int8 weights with
  doweight_stage1, w2 dtype differing from w1); both paths keep why_not
  and supported_archs.
- route_to_v2 applies graduated_claims and still logs refusals under
  AITER_MOE_EXPLAIN, now also "a format not graduated yet" when only
  the graduation gate turns a call away (tested in
  test_moev2_switch.py).
- gpu_differential.py case tuples: field 10 is the weight format, field
  11 a dict of options; PR 8255's input variants move to
  {"variant": name} (case_variant), and a test rejects the old form.
- The golden delta equals the original step's exactly. The counts and
  GPU results above are from the original base, where a case that
  raised the same error on legacy and v2 passed; PR 8255 fails such a
  case unless listed in _RAISES. On this base: CPU tests 150 passed (the
  GPU-only ones skip); differential a8w8_pt 8160 / 10,675 / 8160 and
  a8w8_ptok 6323 / 9699 / 6729 keys on gfx942 / gfx942_cu80 / gfx950;
  key_checks, ranking_checks and snapshot --check, 0 problems. The GPU
  differential is rerun at the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.4a: feasible_plans checks segment boundaries (not graduated)

A plan is now feasible only if every buffer a segment reads matches the
one produced before it, not only if the segments cover adjacent ops. This
prepares formats whose segments share an op but not a buffer layout. No
behavior change for the registered paths.

Behavior claim:
- Legacy dispatch is unchanged: the dispatch snapshot is identical on all
  4 archs, and to one generated with the upstream base's aiter package.
- v2 dispatch is unchanged: the CPU differential claims the same keys per
  path on every arch as before, and the ranking checks rank the same keys.

What changed:
- Segment.reads(p) lists the buffers a segment reads. Each is matched
  against the last buffer of its kind produced upstream, the call's
  hidden_states first. A segment without the declaration raises, so it
  cannot join a plan by accident.
- feasible_plans reports a segment that fits the op chain but no plan
  because of its boundaries, with the first mismatch.
- Buf.mismatch gives the reason. quant.inter reads any unquantized
  intermediate, because asm.stage1 writes bf16 for fp16 outputs too.
- README: the buf, base, resolver and test rows.
- Tests: the boundary check and the rejection reasons.

Tests:
- CPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py, 120
  tests, 118 passed. test_outputs_match_legacy[a8w8_pt] and [a8w8_ptok]
  fail on the legacy ASM stage 1 cases that are not repeatable, as in
  step 3.3.
- CPU gates, on all 4 archs, 0 problems, with the same counts as step
  3.3: differential.py 26,820 / 37,978 / 27,907 keys claimed on gfx942 /
  gfx942_cu80 / gfx950; key_checks.py 335,413 keys; ranking_checks.py
  118,703 ranked keys.
- No GPU run: the change is in plan resolution only, and the CPU
  differential shows the same plans for every claimed key.
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.3): the code hunks apply unchanged (Sort.reads lands in
segments/sort.py, where PR 8255 moved the sort); buf.py keeps PR 8255's
ownership NOTE. The test counts above are from the original base. On
this base: CPU tests 152 passed (the GPU-only ones skip); the CPU
differential claims the same keys per path as step 3.3 on every arch;
key_checks, ranking_checks and snapshot --check, 0 problems.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.4: mxfp4 a4w4 path (not graduated)

MXFP4 a4w4 fused_moe calls on gfx950 (per_1x32 fp4x2 activations and
weights, Silu or Gelu, separated gate/up, g1u1) can run through
aiter.moev2 with AITER_MOEV2=a4w4. The path is not graduated, so the
default is unchanged.

Behavior claim:
- Legacy dispatch is unchanged. The snapshot grid adds the per_1x32
  feature variants and a4w4 Silu with doweight_stage1 on preshuffled
  weights (the combination that reaches the CK-Tile split-K default).
  Every existing record is kept as is; the goldens grow to 114,542 /
  135,489 / 159,565 / 110,824 keys on gfx942 / gfx942_cu80 / gfx950 /
  gfx1201.
- CPU differential, all 4 archs: 0 problems. gfx950 claims 9,363 a4w4
  keys, hands 552 back as legacy 1-stage and 284 to a legacy 2-stage
  branch (CK-Tile split-K). The other paths claim the same keys as in
  step 3.4a.
- On a gfx950 GPU, gpu_differential.py --path a4w4 runs 27 cases with
  the shipped table, the synthetic table, AITER_USE_NT=1 and
  AITER_BYPASS_TUNE_CONFIG=1. Both sides launch the same kernels on the
  same inputs with the same outputs, except (16, 6144, 512, 257, 9) and
  (16, 4096, 512, 512, 10). On those two cases, two legacy runs also
  differ in the sorted ids (legacy issue). The other paths give the same
  results as in step 3.3.

What changed:
- The FlyDSL, MXMOE and route-reduce helpers move from fused_moe.py into
  segments/flydsl.py, segments/mxmoe.py and segments/sort.py (adaptive
  aux sort, fused decode sort+quant). Their text is identical to this
  base's fused_moe.py. Legacy imports them back, so both sides run the
  same objects. _stage2_scratch now lives in segments/flydsl.py;
  aot/flydsl/moe.py and op_tests/test_moe_scatter_reduce.py patch it
  there.
- segments/mxfp4.py: FlyDSL stage 1 (plain, fused fp4 quant, layout-v2
  output), FlyDSL stage 2, layout-v2 stage 2 (plain and scatter over the
  aux sort), MXMOE stage 1 and 2, sort.aux; CK with the fp4 instances
  (and doweight_stage1, which legacy runs on CK). Boundaries aux_sorted,
  v2_sorted and mxmoe_sorted; Buf.layout=None reads any layout.
- Resolver hooks:
  - Segment.check_row: legacy's tuned-row discard chain, with the same
    warnings.
  - Segment.declines_row: a tuned CK row on preshuffled weights, which
    legacy overrides with the FlyDSL heuristic.
  - Segment.default_kernels: default kernel names, with legacy's tile
    tiers and warning.
  - Segment.stage2_kernel: the fp8 GEMM2 rename, from q_dtype_a2 or
    AITER_SITUV2_A4W4_FP8_INTER.
  - Segment.metadata_fields.
- This base's legacy MXFP4 changes, mirrored:
  - The MXMOE discard chain rejects a row excluded for the call, inline
    GEMM1 with non-BF16 input, and a sort block_m or GEMM2 tile that
    differs from GEMM1's BM. It no longer rejects stage-1 bias. MXMOE
    stage 1 gets native_scale_layout.
  - LocalDispatch makes legacy's runtime fallbacks before the first
    dispatch logs anything: the MXMOE fallback when block_size_M differs
    from the configured BM (resolve again with _exclude_mxmoe; raise as
    legacy does if the fallback still needs another block_m), and the
    inline-sort fallback (resolve again with _disable_inline_sort). It
    checks the fallback keys without logging and declines the call if
    one of them declines. The inline-sort check probes a JIT module, so
    it runs only after the first lookup has logged, as in legacy; a call
    whose _disable_inline_sort key declines is therefore declined even
    where the inline-sort row could run. The post-sort relookup drops
    both flags, as legacy does.
  - executor.run_mxfp4 follows the per_1x32 branches of _fused_moe_impl
    and fused_moe_2stages, including:
    - a contiguous hidden_states copy outside inline sort;
    - num_local_tokens passed to the fused decode sort+quant;
    - pre-quantization only for fp4 GEMM1 activations;
    - the configured SiTU betas for MXMOE;
    - topk_ids for skip_dropped_routes;
    - the valid-token count for MXMOE stage 2;
    - topk_weights for FlyDSL v2 stage 2 with the fp4 intermediate.
  - The resolver discards a post-reduction row for a weight layout other
    than separated gate/up on fully shuffled weights, with legacy's
    warning, and runs the default heuristics. With a dedicated table it
    declines instead.
- hooks.legacy_globals bridges legacy's _fused_decode_sort_quant_disabled
  (set by test_moe_sorting_mxfp4.py) to v2, next to kernel_bench_callable.
  When legacy's flag is unset it leaves the v2 hook as the caller set it.
- Ranking entry a4w4: the FlyDSL heuristic where legacy picks it, the
  CK-Tile split-K default as a legacy= region, CK 2-stage otherwise.
  local.key_args_supported requires Silu or Gelu.
- Differential: keys handed back to a legacy 2-stage branch are counted
  separately and checked against the legacy record. The GPU differential
  compares m_indices as ids, and compares sorted MX scales only at the
  bytes the quant kernels write.
- README: rows for the new segment and path modules and the updated
  dispatch, execute and test modules.
- Tests: the MXMOE discard chain, the block_size_M and inline-sort
  fallbacks (declines decided before logging, and the order of lookups
  and warnings in run), the post-reduction discard, and legacy_globals
  with legacy's flag unset.

Known differences and limits:
- Left on legacy:
  - 1-stage tuned rows (and FLAT, 1-stage only) until 3.6;
  - CK-Tile split-K (3.5, with the a8w4 CK-Tile port);
  - num_local_tokens, a1_scale and activation scales (no segment
    declares them, so these calls find no plan);
  - Swiglu/Situv2/Relu2, interleaved gate/up, bias, padding and scatter
    (3.5).
- Legacy issue, unchanged: the MXFP4 sorts used for few tokens
  (mxfp4_moe_sort and mxfp4_moe_sort_quant_fwd) do not give the same
  token order on every run. The two GPU cases above fail on it with
  legacy alone.

Tests:
- CPU and GPU: tests/test_moev2_*.py and test_moe_dispatch_snapshot.py,
  133 tests, 131 passed. test_outputs_match_legacy[a8w8_pt] and
  [a8w8_ptok] fail on the legacy cases that are not repeatable, as in
  step 3.3. [a4w4] fails in some runs on the two sort cases above.
- CPU gates, 0 problems on all 4 archs: key_checks.py 524,332 keys;
  ranking_checks.py 129,333 ranked keys.
- GPU suites, AITER_MOEV2=off vs on: test_moe_2stage.py (-q 0, -q 4,
  --no-legacy), the MXFP4 sort, aux, dispatch and codegen tests, the
  FlyDSL MoE tests, and test_moe.py, test_moe_sorting.py, test_moe_ep.py,
  test_moe_local_expert_ids.py and test_moe_dp_share_expert.py.
  - Results: the same exit codes and check verdicts in both modes, except
    the per-token swiglu_limit=7.0 check. That check also flips between
    two runs with v2 off.
  - --no-legacy exits 1 in both modes: the FlyDSL AOT cache is missing on
    this machine. Rerun with --csv-filter afp4_wfp4 mxmoe_g1_a4w4 to skip
    the cache check: 745 checks with the same verdicts apart from the
    swiglu_limit check, exit 0 in both modes. After the review fixes,
    --csv-filter mxmoe_g1_a4w4 again: 203 checks, all the same.
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.4a):
- fused_moe.py is this base's file minus the moved definitions. PR 8255
  had already moved moe_sorting and the adaptive aux sort helpers
  (with _empty_bf16, which stays there) into segments/sort.py, so this
  step adds there only the fused decode sort+quant, Sort's extras and
  accumulate, and SortAux. All 40 moved definitions equal this base's
  text, including three changed upstream since the original step:
  _flydsl_v2_stage2_wrapper and _mxfp4_a4w4_stage2_fw (the
  scatter_intermediate combine, #7771; expert_mask and topk_ids, #7542)
  and _mxfp4_inline_sort_unsupported (inline sort under EP, #7542).
- This base's legacy MXFP4 expert-parallel rules (#7542), mirrored:
  - a tuned inline-sort row is no longer discarded under EP;
  - under EP the MXMOE discard chain rejects BM16, activations other
    than SiTUv2, a GEMM2 that is not flydsl_moe2_layout_ and the scatter
    epilog, and checks the generated aux shapes only without EP;
  - run_mxfp4 raises under EP only for a GEMM2 that is not a layout-v2
    kernel, and forwards expert_mask and topk_ids to the MXMOE stage 2
    too.
- PR 8255's review changes applied to this step's code:
  - a4w4 has why_not and supported_archs; the new modules carry the NOTE
    banner (flydsl.py and mxmoe.py with the shared-with-legacy wording);
  - LocalDispatch decides the MXFP4 fallbacks on the preview prologue,
    so a call it declines reaches legacy before the prologue copies
    anything; the fallback warnings read the prepared call;
  - key_args_supported keeps clamps (None, 0 and inf do not clamp);
  - compare_launches keeps PR 8255's tolerance (1 ulp, or twice legacy's
    own spread) for floating-point tensors and its whole-graph handling;
    MX scales (at the bytes the quant kernels write) and fp4 values must
    be bitwise equal, and sorted fp4 buffers are masked on their raw
    bytes (fp4 tensors cannot be indexed).
- Tests: the live-arch claims test runs each path on its first arch
  (a4w4 is gfx950 only); under EP the BM16 inline-sort row is now
  discarded by the MXMOE chain, and a BM128 MXMOE row by the SiTUv2 rule,
  with legacy's warnings; the run test checks that the fallbacks are
  decided on the preview and the warnings get the prepared call; CPU
  tests for the sorted fp4 and MX-scale comparisons. gpu_differential
  adds the generic variants for a4w4 (and noncontiguous on an inline-sort
  MXMOE shape).
- The golden delta equals the original step's exactly. The counts and GPU
  results above are from the original base. On this base: CPU tests
  166 passed (the GPU-only ones skip); differential 0 problems on all
  4 archs, gfx950 claims 10,413 a4w4 keys, hands 623 back as legacy
  1-stage and 299 to CK-Tile split-K, and the other paths claim the same
  keys as in step 3.4a; key_checks 524,332 keys, ranking_checks 140,392
  ranked keys and snapshot --check, 0 problems. The GPU differential
  (with the new variant cases and this base's EP behavior) is rerun at
  the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.5: a16w4, a16wi4, a8w4, mxfp8 paths and a4w4 leftovers (not graduated)

Every per_1x32 2-stage format can run through aiter.moev2 with
AITER_MOEV2=<path>. New paths: a16w4 (bf16 x MXFP4, gfx942/gfx950),
a16wi4 (bf16 x int4 in 1x32 groups, gfx942/gfx950), a8w4 (MXFP8 x
MXFP4, gfx950) and mxfp8 (MXFP8 x MXFP8, gfx950). a4w4 gains Swiglu,
SiTUv2, bias, activation parameters, padding and the CK-Tile branches.
No path is graduated, so the default is unchanged.

Behavior claim:
- Legacy dispatch is unchanged. The snapshot grid gains bias,
  interleave, pad and standard-layout variants of the per_1x32
  combinations, an MXFP4-only shape and a bf16 x fp4 SiTUv2
  doweight_stage1 combination. Every existing record resolves as
  before; the goldens grow to 126,095 / 147,042 / 171,118 / 122,377
  keys on gfx942 / gfx942_cu80 / gfx950 / gfx1201, identical to the
  records this base's own code writes.
- CPU differential, all 4 archs: 0 problems. gfx950 claims a4w4=20,175,
  a16w4=7,064, a16wi4=5,052, a8w4=13,211, mxfp8=5,142 keys (other paths
  as in step 3.4); gfx942 a16w4=5,108, a16wi4=4,572; gfx942_cu80
  a16w4=4,801, a16wi4=3,996. 0 problems on gfx950 under
  AITER_FLYDSL_FORCE=0, AITER_MXMOE_FALLBACK=0,
  AITER_SITUV2_A4W4_FP8_INTER=1 and AITER_OPUS_STAGE2_FP8=0; under
  AITER_BYPASS_TUNE_CONFIG=1 only the known declines of 1-stage rows
  legacy runs 2-stage.
- On a gfx950 GPU, gpu_differential.py with the shipped table, the
  synthetic table, AITER_USE_NT=1 and AITER_BYPASS_TUNE_CONFIG=1: a4w4
  49 cases, a16w4 22, a16wi4 11, a8w4 37, mxfp8 20. Both sides launch
  the same kernels on the same inputs with the same outputs, and raise
  the same errors, except on legacy issues that two legacy runs also
  show (see Known differences) and two a4w4 SiTUv2 declines under
  AITER_BYPASS_TUNE_CONFIG=1. Runs sharing a JIT directory in parallel
  logged or raised differently around the mxfp8 CK build that fails;
  run alone, mxfp8 matches. gfx942 not run on a GPU.

What changed:
- The CK-Tile stage functions move verbatim from fused_moe.py to
  segments/ck_tile.py, the MXFP4 reroute and bias predicates to
  segments/flydsl.py and _opus_stage2_fp8_enabled to segments/opus.py.
  Legacy imports them back.
- executor.run_mxfp4 follows every per_1x32 branch of _fused_moe_impl
  and fused_moe_2stages: bf16/fp8/int4 activation quant, bias, local
  topk ids, Opus and CK-Tile arguments, route-bucket checks. Calls
  legacy rejects with the a16w4 NotImplementedError are declined before
  dispatch, so legacy raises.
- Segments: cktile.gemm1/gemm2 (legacy's four CK-Tile branches in
  order, the swiglu_mxfp4_bf16_cktile alias row), opus.gemm1,
  opus.gemm1_layout, opus.gemm2 (tuned only), asm.stage1_cktile; FlyDSL,
  MXMOE and CK caps for the new formats; the untuned a16wi4 fallback and
  MXMOE SiTUv2 heuristic as default kernels. The FlyDSL bias rule
  follows legacy's enable_bias, which differs between heuristic and
  tuned plans (Segment.row_params).
- local.claims takes per-path allowances (activations, gate modes,
  bias, activation parameters, padding, quant_dtype_a, g1u0) and splits
  calls by activation format; key_args_supported checks the same at
  key level.
- Ranking: RANKING moves to dispatch/ranking_table.py, which states the
  table rules (no overlapping entries or regions, a default for every
  problem, prefer xor legacy, feasible last structure, no dead
  regions). Regions can be untuned_only. New predicates for the legacy
  CK-Tile and FlyDSL branches and padding.
- This base's legacy changes the original step did not cover, mirrored:
  - The resolver discards, with legacy's warnings, a 1-stage SiTUv2 ASM
    row on preshuffled MXFP4 weights (#6995), a 1-stage row for an
    activation the ASM kernels lack, and a 1-stage SwiGLU OAI row the
    call cannot run (no kernel name, not flat=1, bias, a swiglu_limit
    other than 7.0, gate/up not separated GGUU). The last two apply to
    plain ASM rows only, as legacy checks rows naming other kernel
    families first; such 1-stage rows are declined (none ships). It
    declines where legacy raises (SiTUv2 on mixed shuffles, other
    gate/up layouts or runtime betas) and for a dedicated table (the
    FHMoE path).
  - MXMOE stage 1 sets has_bias from the call's bias1 alone.
  - The prologue normalizes a SiLU swiglu_limit as _fused_moe_impl does;
    run_mxfp4 hands an active SiLU limit to a CK or ASM stage 1 and
    raises for CK-Tile, as fused_moe_2stages does.
  - The MXMOE segments take a8w4 problems too, and the a8w4 path lists
    them, for the tuned flydsl_mxmoe_g1_a8w4_* rows (kimik3, dsv4,
    gptoss a8w4 tables).
  - a8w4 declines interleaved calls while AITER_USE_GROUPED_GEMM is on:
    legacy may hand them to grouped_gemm_gfx1250_a8w4 before dispatch.
- Differential: --env NAME=VALUE compares live legacy records under a
  dispatch override; every legacy= region maps to its stage 1. The GPU
  differential covers the new weight formats, SiLU swiglu_limit on
  a4w4, a 1-stage SwiGLU OAI row discarded for bias, and compares a
  failed JIT build by its module; --synth-table works for paths with no
  gfx942 CK rows to rewrite.
- README: rows for the new segment, path and table modules and the
  updated ones.
- Tests: the SiTUv2 and SwiGLU OAI 1-stage discards and declines, the
  SiTUv2 post-reduction case, the prologue's SiLU limit, MXMOE a8w4 rows
  (inline or prequantized fp8, discarded with expert_mask), and a8w4
  leaving interleaved calls to the grouped path.

Known differences and limits:
- Left on legacy: 1-stage tuned rows (3.6), FHMoE rows (3.7), padded
  keys on kernels that take no padding (CK, MXMOE, layout-v2 GEMM2),
  CK 2-stage a16w4, CK-Tile alias rows outside the CK-Tile branches,
  and, under AITER_BYPASS_TUNE_CONFIG=1, a4w4 SiTUv2 keys with a tuned
  row (the branch legacy takes then is not ported). Under that variable
  legacy also attaches an Opus row's route-bucket fields to the default
  (a possible warning); v2 does not, and no shipped table has them.
- op_tests/test_moe_2stage.py::test_presorted_moe_hook counts sorts by
  patching fused_moe.moe_sorting, which v2 does not call through. With
  AITER_MOEV2=on its own-sort call runs on v2 and fails that assertion,
  ending a --no-legacy run. Calls with a registered presort stay on
  legacy.
- Legacy issues seen while testing, unchanged, each also seen with two
  legacy runs: the MXFP4 sorts for few tokens do not give the same token
  order every run (a4w4 (16, 6144, 512, 257, 9), (16, 4096, 512, 512,
  10) and (16, 3584, 384, 896, 16, SiTUv2); a8w4 MXMOE (16, 7168, 384,
  385, 7)); the FlyDSL a8w4 stage 1 ..._w3_gui_fp8 races on (64, 7168,
  3072, E24, top6). Also: a8w4 on untagged separated weights raises in
  the untuned branches; a tuned cktile_* kernelName1 with an Opus stage
  2 runs ASM stage 1; the mxfp8 CK instances fail to compile; tuned
  mxfp8 Swiglu drops its bias.

Tests:
- tests/test_moev2_*.py and test_moe_dispatch_snapshot.py: 154 tests,
  150 passed. test_outputs_match_legacy[a8w8_pt] and [a8w8_ptok] fail
  on the legacy cases that are not repeatable, as in step 3.3; [a4w4]
  and [a8w4] on the legacy issues above (each failing case rerun and
  matched to them).
- CPU gates, 0 problems on all 4 archs: key_checks.py 571,700 keys;
  ranking_checks.py 202,831 ranked keys.
- GPU suites, AITER_MOEV2=off vs on: test_moe_2stage.py (-q 4, 6, 7, 8,
  9 --no-flydsl-csv, --no-legacy), the MXFP4 sort, aux, dispatch,
  codegen and glm5 EP dispatch tests, the FlyDSL MoE, a16wfp4, inter_dim
  and mxfp8 passthrough tests, test_moe_sorting.py, test_moe_ep.py,
  test_moe_local_expert_ids.py and test_moe_dp_share_expert.py.
  - The same exit codes and check verdicts in both modes, except the
    per-token swiglu_limit=7.0 check, which also flips between two runs
    with v2 off, and --no-legacy's test_presorted_moe_hook (above).
  - --no-legacy with the hook test skipped: 207 checks in both modes,
    the same verdicts apart from the swiglu_limit check; both modes
    exit 1 where the FlyDSL AOT cache is missing on this machine.
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.4):
- fused_moe.py is this base's file minus the seven moved definitions,
  which equal this base's text. PR 8255's legacy moe_sorting already
  returns local topk ids, so segments/sort.py takes from this step only
  Sort's and SortAux's return_local_topk_ids, bias features and pads.
- PR 8255's review changes applied to this step's code:
  - local.why_not takes the per-path allowances and names each refusal
    (the activation format of the call too); the new paths and a4w4
    have why_not and supported_archs; arch checks use get_gfx_runtime
    alone; ranking_table.py, ck_tile.py and opus.py carry the NOTE
    banner (ck_tile.py and opus.py with the shared-with-legacy wording);
  - a clamping swiglu_limit (None, 0 and inf do not clamp) and the
    global scales stay refused without act_params; key_args_supported
    keeps clamps;
  - the a16w4 NotImplementedError decline is decided on the preview
    prologue, before anything is copied;
  - compare_launches keeps PR 8255's tolerance and dataclass expansion,
    with this step's own-buffer and split-K stage 1 exemptions; the GPU
    cases keep the unified encoding (options dict with "variant") and
    add the generic variants for a16w4, a16wi4, a8w4 and mxfp8.
- This base's legacy MXFP4 expert-parallel rules (#7542, ported in step
  3.4) cover the MXMOE a8w4 rows too: under EP a BM16 row is discarded
  as BM16 and a BM64 Silu row by the SiTUv2 rule, with legacy's
  warnings. The output_aux EP raise legacy also applies to MXMOE + Opus
  metadata has no v2 counterpart to mirror: no MXMOE stage 1 feeds an
  Opus stage 2 in v2, so such rows are declined.
- README: status lists the nine registered paths.
- The golden delta equals the original step's exactly. The counts and GPU
  results above are from the original base. On this base: CPU tests
  184 passed (the GPU-only ones skip); differential 0 problems on all 4
  archs, claiming the same keys as the original step on every arch
  (and on gfx950 under AITER_FLYDSL_FORCE=0, AITER_MXMOE_FALLBACK=0,
  AITER_SITUV2_A4W4_FP8_INTER=1 and AITER_OPUS_STAGE2_FP8=0, 0
  problems); key_checks 571,700 keys, ranking_checks 212,754 ranked
  keys and snapshot --check, 0 problems. The GPU differential (with the
  variant cases, this base's EP behavior, and the cases where legacy and
  v2 both raise, which this base's harness accepts only when listed) is
  rerun at the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.6: 1-stage ASM fmoe (default, tuned, FLAT, g1u0) (not graduated)

The 1-stage ASM fmoe kernels run through aiter.moev2 with
AITER_MOEV2=<path>, wherever legacy runs them: the default 1-stage
regions, tuned 1-stage rows (xbf16 and FLAT too) and the g1u0 bf16 and
int8 keys. No path is graduated, so the default is unchanged. The local
grouped gfx1250 branch is not ported (step 4.6a); a8w4 leaves those
calls to legacy.

Behavior claim:
- Legacy dispatch is unchanged. fused_moe_1stage, _ASM_ACT_TAG and
  _retarget_asm_activation move verbatim to segments/asm.py and
  _moe_prepare_unsorted_input to segments/sort.py; legacy imports them
  back. The goldens (126,095 / 147,042 / 171,118 / 122,377 keys on
  gfx942 / gfx942_cu80 / gfx950 / gfx1201) are identical to the records
  this base's own code writes.
- CPU differential, all 4 archs: 0 problems. Keys claimed: gfx950
  87,674 (78,551 in step 3.5), gfx942 43,123 (36,500), gfx942_cu80
  53,578 (46,775). Keys legacy runs 1-stage that v2 still declines:
  gfx950 9,330 -> 338, gfx942 4,872 -> 89, gfx942_cu80 4,930 -> 15 (see
  Known differences). 0 problems on gfx950 and gfx942 under
  AITER_FLYDSL_FORCE=0, AITER_MXMOE_FALLBACK=0,
  AITER_SITUV2_A4W4_FP8_INTER=1, AITER_OPUS_STAGE2_FP8=0 and
  AITER_XBFLOAT16=1; under AITER_BYPASS_TUNE_CONFIG=1 only declines of
  calls whose tuned 1-stage row v2 cannot run while legacy, bypassing
  the table, runs them 2-stage (338 on gfx950, 89 on gfx942; 2,409 on
  gfx950 in step 3.5).
- On a gfx950 GPU, gpu_differential.py with the shipped table, the
  synthetic table, AITER_USE_NT=1 and AITER_BYPASS_TUNE_CONFIG=1:
  a16w16 21 cases (69 synthetic), a16w4 25, a8w8_blockscale 31 (147
  synthetic), a8w4 37, a4w4 52, a8w8_ptok 49 (97 synthetic). Both sides
  launch the same kernels on the same inputs with the same outputs and
  logs, except on legacy issues that two legacy runs also show (see
  Known differences), the two a4w4 SiTUv2 declines under
  AITER_BYPASS_TUNE_CONFIG=1 of step 3.5, and, in runs sharing a JIT
  directory in parallel, the log of a CK build that fails landing in a
  different case (as in step 3.5). gfx942 not run on a GPU.

What changed:
- Segments: asm.fmoe_1stage covers quant through reduce and builds
  legacy's fused_moe_1stage call (kernel name, activation, quant type,
  xbf16, FLAT mode, expert_mask). sort.flat is legacy's pass-through for
  the FLAT modes (flat 1 and 2: unsorted topk, over-allocated moe_buf,
  num_local_tokens in the num_valid_ids slot). ASM stage 1 is g1u1 only.
- Buf: a layout in `reads` may be a set. ASM stage 1 reads the default
  or unsorted sort; the Opus and FlyDSL layout segments read default or
  aux_sorted, so only the 1-stage fmoe follows sort.flat.
- Resolver: 1-stage plans from the default regions and tuned rows, with
  legacy's log line. match_row takes plain ASM 1-stage rows (named
  kernel, no stage 2), matching FLAT rows to sort.flat. It declines
  post-reduction rows (flat=3), other 1-stage rows, rows whose flat or
  xbf16 cell legacy cannot parse (legacy raises) and a 1-stage plan with
  a finite SiLU limit (legacy raises).
- executor.run_one_stage follows legacy's 1-stage branch: contiguous
  hidden_states, the host sort or the FLAT pass-through (given the
  row's mode), expert_mask and the FLAT output copy.
- local: 1-stage plans have no lookup after the sort, as in legacy.
- Ranking: an ASM 1-stage structure in the fp8 per-token, 1x128, int8
  and g1u0 regions; g1u0 tables for a16w16 and int8 per-token.
  check_problems ignores 1-stage plans an entry does not list (only
  tuned rows reach them).
- Paths: a16w16 and a8w8_ptok (int8) claim g1u0; a4w4, a16w4 and
  a8w8_blockscale gain the FLAT and 1-stage segments; a8w4 declines
  calls legacy sends to the grouped gfx1250 kernel (the narrower check
  of the original step replaces step 3.5's).
- This base's legacy changes the original step did not cover, mirrored:
  the post-reduction mode and expert_mask of fused_moe_1stage (the moved
  code is the new one), num_local_tokens in the FLAT prep, moe_sorting
  passing through only the modes without a host sort, the retarget of a
  1-stage row tuned for the twin activation (with legacy's INFO line),
  the SiLU-limit raise and the skipped second lookup.
- Differential: 1-stage and FLAT launch positions; the g1u0 legacy
  branches. The GPU differential gains default, tuned, xbf16 and FLAT
  1-stage cases.
- README: rows for the changed modules.
- Tests: 1-stage defaults and tuned rows (FLAT, xbf16, retarget), the
  declines, the SiLU-limit decline, the skipped second lookup, the FLAT
  sort pass-through, a strided input and the FLAT mode reaching the
  sort, the ranking of 1-stage plans only tuned rows reach, and a8w4
  leaving grouped gfx1250 calls to legacy.

Known differences and limits:
- Left on legacy: post-reduction rows (8 shipped a4w4 rows), 1-stage
  rows outside the plain form (empty kernelName1, a stage 2), g1u0
  calls outside the 1-stage regions (legacy's CK 2-stage is wrong for
  g1u0), the grouped gfx1250 branch (step 4.6a), FHMoE rows (3.7),
  calls with bias, padding or other features fmoe lacks whose key has a
  tuned 1-stage row (legacy runs the row and drops the bias or padding),
  and tuned 1-stage rows for keys outside legacy's default 1-stage table,
  where v2 has no 1-stage plan: the Gelu calls the act-type-disabled
  fallback gives a SiLU row (the gfx942 1x128 keys, which legacy
  retargets to the Gelu twin; a8w8_ptok tkw1 Gelu on gfx950).
- op_tests/test_moe_2stage.py::test_presorted_moe_hook still ends a
  --no-legacy run with AITER_MOEV2=on (step 3.5).
- Legacy issues seen while testing, unchanged, each also seen with two
  legacy runs: the ASM 1x128 blockscale stage 1 is not repeatable on
  gfx950 (the same 72 synthetic cases fail since step 3.2); the MXFP4
  sorts for few tokens (a4w4 (16, 4096, 512, 512, 10), (16, 6144, 512,
  257, 9), (16, 3584, 384, 896, 16, SiTUv2); a8w4 MXMOE (16, 7168, 384,
  385, 7)); the ASM per-token fp8 stage 1 (a8w8_ptok (8|64|256, 5120,
  1536, 40|41, 8|10)); the FlyDSL a8w4 stage 1 w3 kernels ((64, 7168,
  3072, E24, top6), (2048, 7168, 384, E384, top6)). The FLAT sort drops
  expert_mask; v2 does the same.

Tests:
- tests/test_moev2_*.py and test_moe_dispatch_snapshot.py: 169 tests,
  165 passed. test_outputs_match_legacy [a4w4], [a8w4], [a8w8_pt] and
  [a8w8_ptok] fail on the legacy issues above, as in step 3.5.
- CPU gates, 0 problems on all 4 archs: key_checks.py 571,700 keys;
  ranking_checks.py 210,064 ranked keys.
- GPU suites, AITER_MOEV2=off vs on: test_moe_2stage.py (-q 0, 2, 3, 4,
  5, 6, 7 --no-flydsl-csv, --no-legacy), test_moe.py, test_moe_tkw1.py,
  test_moe_blockscale.py, the MXFP4 sort, aux, dispatch, codegen and
  glm5 EP dispatch tests, the FlyDSL MoE, a16wfp4 and inter_dim tests,
  test_moe_sorting.py, test_moe_ep.py, test_moe_local_expert_ids.py and
  test_moe_dp_share_expert.py.
  - The same exit codes and check verdicts in both modes, except the
    swiglu_limit=7.0 checks of test_moe_2stage.py, which also flip
    between two runs with v2 off; the first test_moe_tkw1.py check, a
    2-stage case on the ASM per-token fp8 stage 1 that legacy does not
    repeat (failed off, warning on; the same flip in step 3.3); and
    --no-legacy's test_presorted_moe_hook (above).
  - --no-legacy with the hook test skipped: 207 checks in both modes,
    the same verdicts apart from a swiglu_limit check; both modes exit 1
    where the FlyDSL AOT cache is missing on this machine.
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.5):
- fused_moe.py is this base's file minus fused_moe_1stage, _ASM_ACT_TAG
  and _retarget_asm_activation, which equal this base's text and are
  re-exported from segments/asm.py. PR 8255 already moved legacy
  moe_sorting, its FLAT branch and _moe_prepare_unsorted_input to
  segments/sort.py, so this step adds only Sort.flat and SortFlat there.
- PR 8255's review changes applied to this step's code: a16w16 and
  a8w8_ptok pass the g1u0 allowance to local.why_not; asm.py carries the
  NOTE banner with the shared-with-legacy wording; compare_launches
  keeps PR 8255's tolerance and whole-graph guard and gains this step's
  1-stage and FLAT launch layouts; the GPU cases keep the unified
  encoding.
- a8w4 mirrors legacy's grouped gfx1250 checks exactly: a gfx1250-strict
  build counts as gfx1250 (the original step checked gfx1250 alone), and
  an expert_mask call with doweight_stage1, which legacy hands to the
  generic MoE, is claimed. It reads get_gfx itself, as legacy's check
  does, and why_not names the refusal.
- This base's legacy 1-stage branch and the 1-stage regions of
  get_2stage_cfgs equal the original base's.
- The goldens are unchanged, as in the original step. The counts and GPU
  results above are from the original base. On this base: CPU tests 199
  passed, 9 skipped (the GPU-only ones); differential 0 problems on all
  4 archs, with the same a16w4, a16wi4, a4w4, a8w4 and mxfp8 claims and
  the same 1-stage and 2-stage hand-backs as the original step on
  gfx950; a16w16, a8w8_pt, a8w8_ptok and a8w8_blockscale see about 9%
  more keys, from this base's tuned tables (a8w8_pt included, which this
  step does not change); key_checks 571,700 keys, ranking_checks 220,531
  ranked keys and snapshot --check, 0 problems. The GPU differential is
  rerun at the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.7: FHMoE path (fhmoe_, shared expert as the last row) (not graduated)

FHMoE calls (fused_moe with shared-expert tensors, which legacy sends
to fhmoe_) run through aiter.moev2 with AITER_MOEV2=fhmoe. No path is
graduated, so the default is unchanged.

Behavior claim:
- Legacy dispatch is unchanged. The FHMoE contract, metadata and table
  helpers and the two FlyDSL FHMoE stage wrappers move verbatim to
  aiter/moev2/segments/flydsl_fhmoe.py; aiter/fhmoe.py imports them
  back. _fhmoe_impl gets the same v2 hook as fused_moe_; the fhmoe_ op
  schema is unchanged. The goldens (126,095 / 147,042 / 171,120 /
  122,377 keys on gfx942 / gfx942_cu80 / gfx950 / gfx1201) are
  identical to the records this base's own code writes; gfx950 gains
  two keys, the dedicated-table misses (both raise).
- CPU differential, all 4 archs: 0 problems. gfx950: fhmoe claims
  1,804 keys; it declines 15,180 where legacy raises (non-FlyDSL plans,
  dedicated-table misses) and 1,520 where legacy runs (see Known
  differences). The other paths' counts are unchanged from step 3.6.
  0 problems on gfx950 and gfx942 under AITER_FLYDSL_FORCE=0,
  AITER_MXMOE_FALLBACK=0, AITER_SITUV2_A4W4_FP8_INTER=1,
  AITER_OPUS_STAGE2_FP8=0 and AITER_XBFLOAT16=1; under
  AITER_BYPASS_TUNE_CONFIG=1 only step 3.6's 1-stage declines (the same
  338 gfx950 and 89 gfx942 keys).
- On a gfx950 GPU, gpu_differential.py --path fhmoe: 14 cases (MXFP4
  interleaved and separated, DSV4 I384 tuned and beyond its table, HY4
  MXFP8 with the shared expert clamped and unclamped, another MXFP8
  geometry, the block size and clamp_shared errors) launch the same
  kernels on the same inputs with the same outputs and logs, or raise
  the same errors, with the shipped table, AITER_USE_NT=1 and
  AITER_BYPASS_TUNE_CONFIG=1. All other paths rerun as in step 3.6 (the
  shared code changed): a16w16 21 (69 synthetic), a16w4 25, a16wi4 11,
  a4w4 52, a8w4 37, a8w8_blockscale 31 (147 synthetic), a8w8_pt 23 (72
  synthetic), a8w8_ptok 49 (97 synthetic), mxfp8 20; the same results
  as before, apart from the legacy issues under Known differences.
- op_tests/test_fhmoe.py: 119 passed with AITER_MOEV2=off and =on;
  under AITER_MOEV2=fhmoe v2 runs 46 calls, raises the 2 errors the
  tests expect and declines none.

What changed:
- Segments flydsl_fhmoe.gemm1, gemm1_q and gemm2: the FlyDSL MXFP4 and
  MXFP8 stages run through the FHMoE wrappers (Silu, the shared expert,
  dedicated tables). Segment.call_args(c) gives a stage the call
  arguments its launch adds (the shared weights, shared_expert_id,
  swiglu_limit, clamp_shared); run_mxfp4 starts the stage arguments from
  them, as legacy starts from _stage1_extra_args/_stage2_extra_args.
  Sort and the quant segments accept the shared expert and a dedicated
  table.
- Path fhmoe (entry "fhmoe", gfx950): run follows _fhmoe_impl (the
  contract, the activation format from the gate layout, the
  clamp_shared check, the DSV4 I384 or MXFP8 dedicated table), then the
  local dispatch with the table in the key and the selected block size
  enforced. The problem has SharedExpertSpec("fused_row"). The
  capability checks supports_dsv4_i384_fhmoe and
  supports_mxfp8_fhmoe_config resolve through the path. claims declines
  under AITER_ONLINE_TUNE, while a presort is registered (legacy
  consumes it) and for the interleaved MXFP4 calls legacy's grouped
  gfx1250 branch takes (the check moves from a8w4 to local).
- local: the FHMoE key; a lookup with no call (the capability probes)
  skips the second-lookup decline, as legacy's probe calls only
  get_2stage_cfgs.
- Ranking: an fhmoe entry (FlyDSL 2-stage where use_mxfp4_flydsl
  holds; elsewhere legacy raises). Entries without `shared` match only
  problems without a shared expert. The resolver declines a dedicated
  table without an exact row, where legacy raises.
- api.fused_moe sends shared-expert calls to the fhmoe path after
  legacy's argument checks (api.fhmoe_call), including this base's
  herd_topk and deterministic errors, in legacy's order.
- This base's changes the original step did not cover, mirrored: the
  hook sits in _fhmoe_impl (upstream wraps it in drop_presort_on_error
  under the fhmoe_ op), the presort decline, the herd/deterministic
  errors, and the second-lookup decline's token argument.
- Harness: the differential compares FHMoE keys separately and reports
  outcomes (claimed, declined where legacy raises or runs); FHMoE keys
  in the ranking checks; FHMoE GPU cases built as op_tests/test_fhmoe.py
  builds them; the snapshot keys add a dedicated-table miss per
  geometry.
- README: rows for the new and changed modules.
- Tests: the FHMoE helpers moved verbatim, the stages, the capability
  checks against legacy, the API errors (herd_topk and deterministic
  too), the grouped gfx1250 and presort declines.

Known differences and limits:
- Declined where legacy runs (gfx950 CPU differential, all on the
  snapshot's feature variants; no base key): MXMOE rows path fhmoe has
  no segment for (exclude_mxmoe 325, fp8_input_no_scales 190) and calls
  no FHMoE plan serves (fp8_input 353; num_local_tokens, activation
  scales and input activation scales 163 each, the a4w4 gap; scatter
  163, which fhmoe_ rejects before its dispatch). Legacy runs them
  unchanged.
- Legacy's grouped gfx1250 branch is not ported (step 4.6a):
  interleaved MXFP4 FHMoE calls it would take stay on legacy.
- The six private FHMoE hooks on _fused_moe_impl stay for legacy.
- gpu_differential.py --synth-table has no fhmoe rows.
- op_tests/test_moe_2stage.py::test_presorted_moe_hook still ends a
  --no-legacy run with AITER_MOEV2=on (step 3.5).
- Legacy issues seen while testing, unchanged, each also seen with two
  legacy runs: the ASM 1x128 blockscale stage 1 (the same 72 synthetic
  cases since step 3.2); the MXFP4 sorts for few tokens (a4w4 (16, 4096,
  512, 512, 10), (16, 6144, 512, 257, 9), (16, 3584, 384, 896, 16,
  SiTUv2); a8w4 (16, 7168, 384, 385, 7)); the ASM per-token fp8 stage 1
  (a8w8_ptok (8|64|256, 5120, 1536, 40|41, 8|10)); the CK int8
  per-tensor Gelu stage 1 (a8w8_pt (32, 4096, 384, 128, 8), as since
  step 3.3); the FlyDSL a8w4 stage 1 w3 kernel ((64, 7168, 3072, E24,
  top6)). In runs sharing a JIT directory in parallel, a CK module
  another process is building fails to load (mxfp8 and a8w4 std_shuffle
  cases; mxfp8 rerun alone: 20 of 20 ok).

Tests:
- tests/test_moev2_*.py and test_moe_dispatch_snapshot.py: 177 tests,
  173 passed. test_outputs_match_legacy [a4w4], [a8w4], [a8w8_pt] and
  [a8w8_ptok] fail on the legacy issues above, as in step 3.6.
- CPU gates, 0 problems on all 4 archs: key_checks.py 571,702 keys;
  ranking_checks.py 220,216 ranked keys (10,152 FHMoE).
- GPU suites, AITER_MOEV2=off vs on: test_moe_2stage.py (-q 0 to 9
  --no-flydsl-csv, --no-legacy), test_moe.py, test_moe_tkw1.py,
  test_moe_blockscale.py, test_moe_per_tensor_a2_init.py, the MXFP4
  sort, aux, dispatch, codegen and glm5 EP dispatch tests, the FlyDSL
  MoE, a16wfp4, inter_dim and mxfp8 passthrough tests, test_fhmoe.py,
  test_moe_sorting.py, test_moe_ep.py, test_moe_local_expert_ids.py and
  test_moe_dp_share_expert.py.
  - The same exit codes and check verdicts in both modes, except the
    swiglu_limit=7.0 checks of test_moe_2stage.py, which also flip
    between two runs with v2 off; the first test_moe_tkw1.py check (the
    ASM per-token fp8 stage 1, as in step 3.3); and --no-legacy's
    test_presorted_moe_hook (above).
  - --no-legacy with the hook test skipped: 207 checks in both modes,
    the same verdicts apart from a swiglu_limit check; both modes exit 1
    where the FlyDSL AOT cache is missing on this machine.
- black and ruff (0.16.0) clean.

Ported onto main (which holds the squashed phases 0-2, PR 8255, and
steps 3.1-3.6):
- aiter/fhmoe.py's moved definitions equal this base's text (the file has
  no upstream drift); it carries PR 8255's NOTE above the moev2 imports
  and at the _fhmoe_impl hook, and flydsl_fhmoe.py the shared-with-legacy
  NOTE.
- PR 8255's review changes applied to this step's code: path fhmoe has
  why_not (claims = why_not is None) and supported_archs, and checks the
  runtime arch; legacy_grouped_gfx1250 moves from a8w4 to local with
  step 3.6's port fixes (gfx1250-strict, and the EP + doweight_stage1
  early return); LocalDispatch.run passes the forced q_dtype_a and
  config_file to both dispatch_key calls.
- Fixed while porting (the original step had them too):
  - Every claimed FHMoE call raised KeyError 'w1_global_scale': the
    fhmoe_ op has no NVFP4 global scales, so run's defaults now add them
    as None, and api.fhmoe_call rejects shared-expert calls that set
    them.
  - herd_topk with NVFP4 global scales now raises legacy's error before
    the call is built.
  - why_not declines up front the arguments no FHMoE stage takes
    (a1_scale, a2_scale, num_local_tokens, doweight_stage1), so a
    declined call no longer logs the table checks twice.
- The goldens gain the same two gfx950 keys as in the original step. The
  counts and GPU results above are from the original base. On this base:
  CPU tests 207 passed, 10 skipped (the GPU-only ones); differential 0
  problems on all 4 archs, with fhmoe claiming 1,804 gfx950 keys and
  declining 15,180 where legacy raises and 1,520 where it runs, as in
  the original step; the other paths' counts equal step 3.6 on this
  base. key_checks 571,702 keys, ranking_checks 230,683 ranked keys
  (10,152 FHMoE) and snapshot --check, 0 problems. The GPU differential
  is rerun at the end of the port.

Co-authored-by: Cursor <[email protected]>

* [MoE] moev2 step 3.8: coverage report in CI (not graduated)

Step 3.8 of the moev2 revamp: a coverage report over the snapshot key
grid that fails CI on capability gaps and unranked segments and lists
the tuned rows that do not run. No path is graduated, so the default is
unchanged.

Behavior claim:
- No dispatch changes: the paths decline the same calls as before and
  legacy runs them. The CPU differential on every arch has 0 problems.
  The bf16 g1u0 keys without a 1-stage fmoe kernel now go to the named
  legacy branch, and the differential checks that legacy runs CK stage 1
  for them.
- Coverage, ranking and key checks: 0 problems on every arch.

What changed:
- aiter/moev2/dispatch/coverage.py:
  - classify: how the resolver serves a problem a path takes. The kinds
    are a plan, a gap (no plan from the path's segments), a ranking
    region naming a legacy branch, a decline caused by the tuned row, or
    a resolver raise (unshuffled gfx950 fp8 CK weights, as in legacy).
  - row_status: whether the exact tuned row runs, and if not, why.
  - segment_errors: fails a segmen…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants