Skip to content

[FLYDSL] Fea/mxfp4 flydsl a8w4 opt & replace - #6464

Merged
coderfeli merged 50 commits into
mainfrom
fea/mxfp4-flydsl-a8w4-support
Nov 5, 2026
Merged

coderfeli merged 50 commits into
mainfrom
fea/mxfp4-flydsl-a8w4-support

Conversation

@Bernard-Liu

@Bernard-Liu Bernard-Liu commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Extend the gfx950 MXMOE runtime and AOT pipeline to support A8W4 and allow explicit CSV configurations to pair FlyDSL MXMOE GEMM1 with the existing OPUS Stage2 backend.

The change establishes a consistent intermediate data contract across runtime and AOT and fixes GEMM1 correctness issues involving BM128 LDS reuse and payload addressing beyond 2 GiB.

Technical Details

  • Coupled tuning (gemm_moe_tune.py --mxfp4-flydsl) stays A4W4-only, as on main. Mxfp4FlydslTuner.tune() now rejects the batch when a row's q_dtype_a or q_dtype_w is not fp4x2, naming the row and shape; main would build A4W4 candidates for such a row and write them under its A8W4 key. The _g1_kname, _prepare_case and _port_e2e helpers also accept an FP8 activation (a8w4/_fp8out names, MXFP8 activation, interleaved W1, MXFP8 prequant), so the GPU coupled tests build A8W4 pairs through the production quantization and sorting path.
  • Add generated auxiliary coverage for additional model shapes. Before launching an explicit MXMOE → OPUS pair, the runtime raises an error naming any required generated sorting instance that is not compiled.
  • Support explicit flydsl_mxmoe_g1_a8w4_* → opus_moe2_layout_* configurations through the public runtime. Compatibility checks cover precision, prepared weights, BM/SBM, activation, bias, and sorting requirements. Incompatible per-call overrides trigger a separate cached resolution without modifying previously resolved metadata.
  • Select GEMM1 scale layout according to the Stage2 consumer. OPUS receives regular E8M0 scales with the required physical padded width, stride, and capacity. Runtime and AOT use the same layout and bias selection rules, preserving separate compiled variants.
  • Synchronize non-inline BM128 waves before reusing the same LDS slot for both A4W4 and A8W4. Keep FP8/FP4 payload store offsets in i64 to avoid signed address wrapping beyond 2 GiB.
  • Add a public CSV validation harness (op_tests/test_mxfp4_flydsl_public_csv.py) that executes configured A8W4 MXMOE pairs through public fused_moe and writes a JSON execution report.
  • Update the A8W4 model configs (dsv4_fp8fp4, kimik3_a8w4, gptoss_fp8fp4) with 159 faster tuned rows; see Performance. EP rows (DSV4 E24/E48) and DSV4 rows that carry comm_fused_configs are unchanged. These rows come from A8W4 coupled tuning done during development (DSV4 source table: docs/a8w4_work/dsv4_a8w4_tuned_fmoe.csv); the A4W4-only tuner in this PR does not regenerate them.

The OPUS pair uses explicit CSV selection and preserves existing automatic backend selection.

Performance

Full fused_moe latency reduction of the 159 replaced rows versus the previous model configs on gfx950 (median, with range):

Model Shape (D/I/E/K) Replaced token buckets Latency reduction
DSV4 4096/256/256/6 1–32768, 131072 (17) 15.2% (5.0–28.4%)
DSV4 4096/2048/256/6 1–16, 64, 512–32768 (13) 9.9% (1.8–23.3%)
DSV4 7168/384/384/6 32, 2048 (2) 5.4% (2.4–8.4%)
DSV4 7168/384/385/7 1–32768 (16) 14.4% (5.8–33.9%)
DSV4 7168/512/384/6 1–128, 512–16384 (14) 6.8% (2.3–18.4%)
DSV4 7168/512/385/7 1–512, 4096–32768 (14) 9.2% (2.5–18.9%)
DSV4 7168/768/384/6 1–512, 4096, 16384, 32768 (13) 4.1% (1.2–24.0%)
DSV4 7168/768/385/7 1–512, 8192–32768 (13) 6.9% (1.3–18.9%)
DSV4 7168/1536/384/6 1–32, 128 (7) 9.5% (1.4–20.6%)
DSV4 7168/1536/385/7 1–32, 512–32768 (13) 5.2% (1.8–16.7%)
Kimi-K3 3584/384/896/16 1–1024, 4096, 8192 (13) 6.9% (1.4–26.6%)
Kimi-K3 3584/512/896/16 1–512, 32768 (11) 6.2% (3.0–26.7%)
GPT-OSS 3072/3072/128/4 1–32, 256, 512, 2048–32768 (13) 9.4% (1.6–24.7%)

Token ranges list power-of-two buckets. Overall: DSV4 122 rows, median 9.9% (up to 33.9%); Kimi-K3 24 rows, median 6.6% (up to 26.7%); GPT-OSS 13 rows, median 9.4% (up to 24.7%); all 159 rows, median 9.8%.

Test Plan

CPU suites at edab5008fa, each module in its own process (89 tests, all passed; test_fast_tuning and test_config_shape_collision need one visible GPU for arch detection):

python -m unittest op_tests.tuning_tests.test_mxmoe_opus_runtime      # 14
python -m unittest op_tests.tuning_tests.test_mxmoe_opus_aot          # 5
python -m unittest op_tests.tuning_tests.test_mxfp4_flydsl_tuning     # 9
python -m unittest op_tests.tuning_tests.test_mxfp4_cpu_test_isolation  # 3
python -m unittest op_tests.tuning_tests.test_mxfp4_moe_aux_codegen   # 6
python -m unittest op_tests.tuning_tests.test_public_a8w4_csv_lookup  # 2
python -m unittest op_tests.tuning_tests.test_fast_tuning             # 24
python -m unittest op_tests.tuning_tests.test_config_shape_collision  # 26

GPU validation at edab5008fa (gfx950, FlyDSL 0.4.0):

  • op_tests/flydsl_tests/test_mxfp4_flydsl_coupled.py: 90 passed, covering A4W4/A8W4 coupled pairs at BM16/32/64/128 with Silu/Situv2/Swiglu, the runtime bias switch, BM16 producer/consumer, BM128 fixed-input repeats and GEMM1 stores on both sides of the 2 GiB payload boundary.
  • gemm_moe_tune.py --mxfp4-flydsl on one A4W4 DSV4.1 shape (token 1, 5120/640/384/6): all 192 candidates evaluated and the winner written.
  • The same command on an A8W4 row stops before any candidate is timed and writes no tuned file.

Pre-rebase GPU validation covered:

  • 37 actual public CSV target-pair executions, including BM16/32/64/128, raw BF16 and prequantized FP8 inputs, activation parameters, Stage1 bias, caller output buffers, and atomic/BF16/FP8 route-output modes. Fallbacks and skips were excluded from target-pair success.
  • Finite outputs, cosine_diff_compare <= 0.1, and element mismatch ratio <= 0.05 at rtol=0.1, atol=0.05.
  • Native/regular scale equivalence, pre-producer 0xFF poison, valid-byte coverage, load bounds, selectors, and compiled auxiliary availability on both sides of the sorting crossover.
  • A4W4/A8W4 BM128 replay regressions, controlled scheduling and ISA checks, plus existing BM16, padded-width, and MXFP8 passthrough regressions.
  • Actual AOT compilation and fresh-process run-only execution. Kernel and memory-copy traces confirmed no additional layout-conversion or intermediate-copy operation in the measured calls.

Fixed-configuration benchmarks showed higher latency for the sampled OPUS pairs than existing FlyDSL pairs. The public CSV executions above and the performance results retain their original pre-rebase source revisions.

@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 6464 --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.

@Bernard-Liu
Bernard-Liu force-pushed the fea/mxfp4-flydsl-a8w4-support branch from 6082c41 to 17eeb33 Compare October 20, 2026 09:18
@Bernard-Liu
Bernard-Liu force-pushed the fea/mxfp4-flydsl-a8w4-support branch 2 times, most recently from 84a6b11 to 32782a0 Compare October 30, 2026 08:38
@aiter-bot

aiter-bot commented Oct 30, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision c1839200f6be · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_fhmoe.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_moe_2stage.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/tuning_tests/README.md
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

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

@Bernard-Liu
Bernard-Liu marked this pull request as ready for review November 1, 2026 13:19
@Bernard-Liu
Bernard-Liu requested review from a team and a balanced review from Copilot November 1, 2026 13:19
@github-actions github-actions Bot changed the title Fea/mxfp4 flydsl a8w4 opt & replace [HIP] [CK] [OPUS] Fea/mxfp4 flydsl a8w4 opt & replace Nov 1, 2026

Copilot AI 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.

🟡 Changes recommended

The standard runner exits before executing the new test because required arguments are missing, while unresolved fallback and validation defects can raise errors or incorrectly report successful results.

4 open issues
What changed in this PR

This PR extends gfx950 A8W4 mixture-of-experts execution to pair FlyDSL MXMOE GEMM1 with OPUS Stage2 through explicit CSV configurations, while aligning runtime and ahead-of-time compilation contracts.

Changes:

  • Add consumer-specific scale layouts, runtime bias selection, compatibility checks, and per-call fallback handling.
  • Improve GEMM1 staging, synchronize BM128 shared-memory reuse, and preserve 64-bit payload store offsets.
  • Update model configurations and add runtime, compilation, auxiliary-kernel, and public CSV validation coverage.
File Description
op_tests/​tuning_tests/​test_public_a8w4_csv_lookup.py Tests padded-token CSV selection.
op_tests/​tuning_tests/​test_mxmoe_opus_runtime.py Tests pair selection, input contracts, and fallback behavior.
op_tests/​tuning_tests/​test_mxmoe_opus_aot.py Tests runtime/AOT layout and bias consistency.
op_tests/​tuning_tests/​test_mxfp4_moe_aux_codegen.py Checks auxiliary catalogs and generated instances.
op_tests/​tuning_tests/​test_mxfp4_flydsl_tuning.py Tests kernel names, candidate constraints, and bias handling.
op_tests/​tuning_tests/​test_mxfp4_cpu_test_isolation.py Checks restoration of CPU test environment state.
op_tests/​tuning_tests/​README.md Documents GPU-free test execution and requirements.
op_tests/​tuning_tests/​mxfp4_cpu_test_utils.py Provides a scoped CPU-only test environment.
op_tests/​test_mxfp4_moe_aux_support.py Validates and benchmarks generated sorting kernels.
op_tests/​test_mxfp4_flydsl_public_csv.py Adds public CSV execution and JSON reporting.
csrc/​opus_moe/​opus_moe_common.py Registers a BM64 Stage2 variant using SBM32 sorting.
csrc/​opus_moe/​include/​gfx950/​a8w4/​opus_moe_traits_stage2_a8w4_decode_gfx950.cuh Defines sort-aware route strides and constraints.
csrc/​opus_moe/​include/​gfx950/​a8w4/​opus_moe_stage2_a8w4_decode_dispatch_gfx950.cuh Sizes launches using the route stride.
csrc/​opus_moe/​include/​gfx950/​a8w4/​opus_moe_pipeline_stage2_a8w4_decode_main_gfx950.cuh Restricts route loading to the sorting block boundary.
csrc/​opus_moe/​gen_instances.py Emits sort-block specialization parameters.
csrc/​kernels/​mxfp4_moe/​moe_aux/​codegen/​gen_instances.py Extends auxiliary generation to additional model shapes.
csrc/​ck_gemm_moe_2stages_codegen/​mxfp4_staged_search.py Removes the obsolete kernel-name bias check.
csrc/​ck_gemm_moe_2stages_codegen/​gemm_moe_tune.py Adds A8W4 preparation and naming support to coupled helpers.
aiter/​ops/​moe_mxfp4_aux.py Expands support catalogs and adds compiled-instance preflight checks.
aiter/​ops/​flydsl/​mxfp4_kname.py Selects scales by consumer and removes bias name flags.
aiter/​ops/​flydsl/​mxfp4_gemm1_kernels.py Tightens supported variants and permits BM16 native FP8 scales.
aiter/​ops/​flydsl/​kernels/​mxfp4_gemm1.py Updates staging, synchronization, addressing, and shared validation.
aiter/​fused_moe.py Integrates explicit MXMOE–OPUS pairs and their runtime contracts.
aiter/​configs/​model_configs/​kimik3_a8w4_tuned_fmoe.csv Replaces selected Kimi configurations with MXMOE pairs.
aiter/​configs/​model_configs/​gptoss_fp8fp4_tuned_fmoe.csv Replaces selected GPT-OSS configurations with MXMOE pairs.
aiter/​aot/​flydsl/​mxfp4_moe.py Generates consumer-specific scale and runtime bias variants.

Review effort: Balanced


def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--csv", type=Path, required=True)
Comment thread aiter/fused_moe.py
Comment on lines +4166 to +4167
elif _exclude_mxmoe:
reject_reason = "excluded for this invocation"
Comment on lines +836 to +837
if is_opus:
assert math.isfinite(element_error) and element_error <= 0.05
Comment on lines +1023 to +1024
row["kernelName1"],
row["kernelName2"],
zhiding512 added a commit that referenced this pull request Nov 9, 2026
Main's gfx1250-strict wheel builds (#7379, #7434) and MegaMoEV2 (#6881)
edited the code this branch rewrites; both sides are kept:

- moe.py: an arch's replay keeps the jobs of that arch's family, retargets
  them to it and leaves out the MXFP4 ones on gfx1250-strict; deployment
  jobs now pass through that filter as rows do. run_aot and moe.py's main
  run inside fail_build_on_missing_target_feature(), and run_aot still ends
  with the strict errata check.
- mega_moe.py: the MTPR 8192 instances build the opt-in small- and
  large-input paths, and --check compiles nothing. FUSED_PATHS_MTPR and
  FUSED_PATHS_ENV stay module constants: they say how the replay builds an
  instance, not what a deployment is.
- README: main's gdn_fused_prefill entries next to the deployment ones.

#6464 moved DeepSeek-V4-Pro's TP8 rows at M 32 and 2048 to MXMOE stage 1,
which compiles the clamp in, so the clamp the TP8 deployment passes now
picks kernels the deployment builds.

The merge changes no job list: the 1195 deployment jobs are 88ab025's, the
14374 tuned-row jobs main's (apart from the empty expert_mask_size this
branch adds) and the 192 MegaMoE jobs main's.

Co-authored-by: Cursor <[email protected]>
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]>
zhiding512 pushed a commit that referenced this pull request Nov 12, 2026
#6464 moved the GEMM1 payload store offset to i64 so sorted payloads above 2 GiB cannot sign-wrap. Every lane then carries 64-bit store addresses, which raises the k_wave=2 (8-wave) A8W4 variant from 128 to 136 VGPRs and halves its resident workgroups per CU. Store through a buffer resource based at the block's first sorted row instead: the base is i64 and wave-uniform, and each lane keeps an i32 byte offset below BM * OUT_ROW_BYTES (asserted at compile time). The FP8 dword pair becomes one 2xi32 buffer store; FP4 stores one dword.

Validation: the kw2 GEMM1 drops to 112 VGPRs (nt_xcd2 130 -> 126), with no spills and unchanged LDS. On 2.25 GiB A8W4 and A4W4 payloads (87k and 175k rows past 2 GiB), every valid row matches the i64 store bit for bit, while the earlier i32 store faults. test_moe_mxmoe_ep.py: 31 passed. On Kimi K3 inputs the kw2 GEMM1 is 7-8% faster than with the i64 store and 3% faster than before #6464, and test_moe_ep EP32 M=3/4 fmoe is 3.9%/4.0% faster.
Signed-off-by: Wulley <[email protected]>
zhiding512 pushed a commit that referenced this pull request Nov 12, 2026
- moe_mxfp4_aux.py: drop the second is_mxfp4_moe_scatter_supported left by the rebase onto #6464, which defines the same check (ruff F811). The file now matches origin/main.
- gemm_moe_tune.py: sort the mxfp4_v2_tune_utils import (I001), and drop the expert-inter and token locals that _time_pair and _check_reference_pair no longer use since they build data through _case (F841).
- test_moe_mxmoe_ep.py: pass check=False to the CLI subprocess.run, whose return code the test asserts with the captured output (PLW1510), and apply black 26.
- aiter/aot/flydsl/gemm.py: restore the executable bit that #7439 dropped; the script keeps its shebang and __main__ like the other FlyDSL AOT scripts (EXE001).

Validation: ruff 0.16.0 `ruff check .` passes; black 26.10.1 passes on the changed files and on `black .`. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity).
Signed-off-by: Wulley <[email protected]>
Bernard-Liu added a commit that referenced this pull request Nov 16, 2026
#6464 moved the GEMM1 payload store offset to i64 so sorted payloads above 2 GiB cannot sign-wrap. Every lane then carries 64-bit store addresses, which raises the k_wave=2 (8-wave) A8W4 variant from 128 to 136 VGPRs and halves its resident workgroups per CU. Store through a buffer resource based at the block's first sorted row instead: the base is i64 and wave-uniform, and each lane keeps an i32 byte offset below BM * OUT_ROW_BYTES (asserted at compile time). The FP8 dword pair becomes one 2xi32 buffer store; FP4 stores one dword.

Validation: the kw2 GEMM1 drops to 112 VGPRs (nt_xcd2 130 -> 126), with no spills and unchanged LDS. On 2.25 GiB A8W4 and A4W4 payloads (87k and 175k rows past 2 GiB), every valid row matches the i64 store bit for bit, while the earlier i32 store faults. test_moe_mxmoe_ep.py: 31 passed. On Kimi K3 inputs the kw2 GEMM1 is 7-8% faster than with the i64 store and 3% faster than before #6464, and test_moe_ep EP32 M=3/4 fmoe is 3.9%/4.0% faster.
Signed-off-by: Wulley <[email protected]>
Bernard-Liu added a commit that referenced this pull request Nov 16, 2026
- moe_mxfp4_aux.py: drop the second is_mxfp4_moe_scatter_supported left by the rebase onto #6464, which defines the same check (ruff F811). The file now matches origin/main.
- gemm_moe_tune.py: sort the mxfp4_v2_tune_utils import (I001), and drop the expert-inter and token locals that _time_pair and _check_reference_pair no longer use since they build data through _case (F841).
- test_moe_mxmoe_ep.py: pass check=False to the CLI subprocess.run, whose return code the test asserts with the captured output (PLW1510), and apply black 26.
- aiter/aot/flydsl/gemm.py: restore the executable bit that #7439 dropped; the script keeps its shebang and __main__ like the other FlyDSL AOT scripts (EXE001).

Validation: ruff 0.16.0 `ruff check .` passes; black 26.10.1 passes on the changed files and on `black .`. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity).
Signed-off-by: Wulley <[email protected]>
Bernard-Liu added a commit that referenced this pull request Nov 17, 2026
#6464 moved the GEMM1 payload store offset to i64 so sorted payloads above 2 GiB cannot sign-wrap. Every lane then carries 64-bit store addresses, which raises the k_wave=2 (8-wave) A8W4 variant from 128 to 136 VGPRs and halves its resident workgroups per CU. Store through a buffer resource based at the block's first sorted row instead: the base is i64 and wave-uniform, and each lane keeps an i32 byte offset below BM * OUT_ROW_BYTES (asserted at compile time). The FP8 dword pair becomes one 2xi32 buffer store; FP4 stores one dword.

Validation: the kw2 GEMM1 drops to 112 VGPRs (nt_xcd2 130 -> 126), with no spills and unchanged LDS. On 2.25 GiB A8W4 and A4W4 payloads (87k and 175k rows past 2 GiB), every valid row matches the i64 store bit for bit, while the earlier i32 store faults. test_moe_mxmoe_ep.py: 31 passed. On Kimi K3 inputs the kw2 GEMM1 is 7-8% faster than with the i64 store and 3% faster than before #6464, and test_moe_ep EP32 M=3/4 fmoe is 3.9%/4.0% faster.
Signed-off-by: Wulley <[email protected]>
Bernard-Liu added a commit that referenced this pull request Nov 17, 2026
- moe_mxfp4_aux.py: drop the second is_mxfp4_moe_scatter_supported left by the rebase onto #6464, which defines the same check (ruff F811). The file now matches origin/main.
- gemm_moe_tune.py: sort the mxfp4_v2_tune_utils import (I001), and drop the expert-inter and token locals that _time_pair and _check_reference_pair no longer use since they build data through _case (F841).
- test_moe_mxmoe_ep.py: pass check=False to the CLI subprocess.run, whose return code the test asserts with the captured output (PLW1510), and apply black 26.
- aiter/aot/flydsl/gemm.py: restore the executable bit that #7439 dropped; the script keeps its shebang and __main__ like the other FlyDSL AOT scripts (EXE001).

Validation: ruff 0.16.0 `ruff check .` passes; black 26.10.1 passes on the changed files and on `black .`. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity).
Signed-off-by: Wulley <[email protected]>
coderfeli pushed a commit that referenced this pull request Nov 24, 2026
* [Test] test_moe_ep: add SiTUv2 A8W4 EP support and per-rank routing stats

- Add -a/--activation, --beta and --linear-beta to the mxfp4 EP tests and
  pass beta/linear_beta through to fused_moe (defaults 4.0/25.0).
- gfx950 a8w4: set AITER_SITUV2_A8W4=1 so SiTUv2 runs with fp8
  activations instead of the a16w4 path, which rejects expert_mask; the
  a4w4 path clears it again.
- Reference: reuse the quantized-activation path (previously gfx1250
  a4w4 only) for a8w4 SiTUv2, quantizing both activations to fp8 with
  e8m0 scales; torch_moe has no SiTUv2.
- SiTUv2 accuracy follows test_moe_2stage: fail only when checkAllclose
  mismatches and logits_diff exceeds 0.01.
- Print local_routes / active_experts once before timing. It draws no
  random numbers and stays outside the timed fused_moe call, so inputs
  and timing are unchanged.

* [FlyDSL] [MoE] Support EP for MXMOE GEMM1 with layout-v2 GEMM2

Port #7284 (00527e5) and cover the a8w4 SiTUv2 pairing used by
Kimi K3 EP32.

- get_2stage_cfgs: keep MXMOE rows under EP when GEMM2 is a
  flydsl_moe2_layout_ kernel. Skip the NE-keyed aux shape check there,
  since expert is the local count; only the scatter epilog still needs a
  generated scatter_reduce instance for (model_dim, topk).
- _mxfp4_inline_sort_unsupported: accept expert_mask and skip the
  adaptive-sort instance check, since EP sorts with Opus.
- _fused_moe_impl: raise NotImplementedError under EP only for native
  MXMOE GEMM2.
- _mxfp4_a4w4_stage2_fw: forward expert_mask/topk_ids to the layout-v2
  wrapper. Without them the reduce epilog sums unwritten remote-route
  slots.
- op_tests/test_moe_mxmoe_ep.py: the PR's a4w4 tests, plus a8w4 SiTUv2
  cases at Kimi K3 dims (BM32/64/128 x atomic/reduce, with and without a
  num_local_tokens dead tail) against an FP8-quantized torch reference,
  with NaN-filled stage2 buffers.

* [FlyDSL] [MoE] Support A8W4 and real EP routing in tuners

Add A8W4 candidate generation, activation quantization and gate/up layouts to the coupled MXFP4 tuner. Model real EP routing in the standard layout-v2 and coupled tuners, including route-stat matching, masked sorting, valid token bounds and local-expert references. Cover precision contracts and EP candidate selection with CPU unit tests.

Signed-off-by: Wulley <[email protected]>

* [Test] Fix A4W4 SiTUv2 reference and dtype selection in EP CLI

Use the existing FP4-quantized two-stage reference for gfx950 A4W4 SiTUv2 instead of torch_moe, which does not implement SiTUv2. Set the A4W4 activation opt-in and clear the opposite precision flag when switching A4W4/A8W4. Add native CLI regression cases for real/fake EP modes and default/custom beta values.

Validation: 7 dispatch checks and 4 CLI regression cases passed. A8W4 SiTUv2 and Kimi K3 EP32 with BM32 also passed the existing SiTUv2 criterion. The additional EP32 BM16/persist run stalled at GPU synchronization and was terminated; it is not counted as passing.
Signed-off-by: Wulley <[email protected]>

* [FlyDSL] [MoE] Use bench balanced routing for EP tuning data

Replace the independent random EP routing of the layout-v2 and coupled tuners with the balanced routing of amd_moe_bench_share/bench_moe.py: tokens take topk experts at a time from a stream of random global-expert permutations, so every token picks distinct experts and global expert loads differ by at most one. When the global expert count is a multiple of topk the ids equal the bench's for the same seed; other topk/EP combinations skip experts that a permutation-spanning token already holds. Simulate EP rank 0 with 1/topk route weights, keep the test_moe_ep real-mode dispatch layout, and route padding rows to the masked extra slot so they stay inert. Replace --ep-route-match and its seed search with --ep-seed.

Validation: ids and rank-0 route stats equal bench make_input() on 104 divisible cases; 49 non-divisible cases keep distinct experts per token and a global spread of at most one. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity). Kimi K3 A8W4 EP16/EP64 coupled tunes completed, and all 72 test_moe_ep real-mode cases with the tuned configs passed.
Signed-off-by: Wulley <[email protected]>

* [FlyDSL] [MoE] Keep MXMOE GEMM1 payload stores on 32-bit lane offsets

#6464 moved the GEMM1 payload store offset to i64 so sorted payloads above 2 GiB cannot sign-wrap. Every lane then carries 64-bit store addresses, which raises the k_wave=2 (8-wave) A8W4 variant from 128 to 136 VGPRs and halves its resident workgroups per CU. Store through a buffer resource based at the block's first sorted row instead: the base is i64 and wave-uniform, and each lane keeps an i32 byte offset below BM * OUT_ROW_BYTES (asserted at compile time). The FP8 dword pair becomes one 2xi32 buffer store; FP4 stores one dword.

Validation: the kw2 GEMM1 drops to 112 VGPRs (nt_xcd2 130 -> 126), with no spills and unchanged LDS. On 2.25 GiB A8W4 and A4W4 payloads (87k and 175k rows past 2 GiB), every valid row matches the i64 store bit for bit, while the earlier i32 store faults. test_moe_mxmoe_ep.py: 31 passed. On Kimi K3 inputs the kw2 GEMM1 is 7-8% faster than with the i64 store and 3% faster than before #6464, and test_moe_ep EP32 M=3/4 fmoe is 3.9%/4.0% faster.
Signed-off-by: Wulley <[email protected]>

* [MoE] Add Kimi K3 A8W4 EP16/EP32/EP64 MXMOE rows to the tuned fMoE config

Add the coupled MXMOE (GEMM1 + layout-v2 GEMM2) rows that real-mode EP16/32/64 runs look up for per-rank batch 1-16 x qlen 1/4/8: lookup tokens EP * {1, 2, 4, ..., 128} with expert = 896 / EP local experts, at topk 16 and 17 (identical except topk; 17 carries the masked column). 48 rows are appended; the existing rows are unchanged. The rows come from the EP tuned configs of the coupled tuner; EP16 lookup 256 and EP32 lookup 128 use the k_wave=2 GEMM1, which assumes the preceding payload-store fix.

Validation: the merged tuned_fmoe has no duplicate keys. test_moe_ep.py real mode without AITER_CONFIG_FMOE passes and hits the new rows for EP32 M=1/4/128, EP16 M=1/16/128 and EP64 M=1/128.
Signed-off-by: Wulley <[email protected]>

* [MoE] Fix black and ruff findings on the EP32 branch

- moe_mxfp4_aux.py: drop the second is_mxfp4_moe_scatter_supported left by the rebase onto #6464, which defines the same check (ruff F811). The file now matches origin/main.
- gemm_moe_tune.py: sort the mxfp4_v2_tune_utils import (I001), and drop the expert-inter and token locals that _time_pair and _check_reference_pair no longer use since they build data through _case (F841).
- test_moe_mxmoe_ep.py: pass check=False to the CLI subprocess.run, whose return code the test asserts with the captured output (PLW1510), and apply black 26.
- aiter/aot/flydsl/gemm.py: restore the executable bit that #7439 dropped; the script keeps its shebang and __main__ like the other FlyDSL AOT scripts (EXE001).

Validation: ruff 0.16.0 `ruff check .` passes; black 26.10.1 passes on the changed files and on `black .`. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity).
Signed-off-by: Wulley <[email protected]>

* [MoE] Add Kimi K3 A8W4 EP16/EP32 token-8192 MXMOE rows and group the EP rows

Add the token-8192 rows for EP16 (expert 56) and EP32 (expert 28), at topk 16 and 17: MXMOE GEMM1 64x256x256_fp8out_situv2 with layout GEMM2 t64x256x128_atomic_sbm64, block_m 64, from the coupled tuner (bench balanced routing, full search). These lookups previously fell back to the default heuristics. EP64 already had the same token-8192 row. Also group the EP rows by EP size (EP16, EP32, EP64; topk 16 then 17, by token); the other rows are unchanged.

Validation, against the config without these rows: test_moe_ep.py real mode, global -m 5120/6144/8192, passes, hits the new rows, and cuts fmoe time by 46-56% at EP32 and 39-49% at EP16. amd_moe_bench_share at the same batch sizes cuts FC1+FC2 time by 41-52% at EP32 and 31-44% at EP16. EP64, whose row is unchanged, stays within 0.7%.

Signed-off-by: Wulley <[email protected]>

* [MoE] Drop the Kimi K3 A8W4 EP16/EP32/EP64 token-8192 rows

Remove the token-8192 rows for EP16 (expert 56), EP32 (expert 28) and EP64 (expert 14), at topk 16 and 17, from kimik3_a8w4_tuned_fmoe.csv. Those lookups fall back to the default heuristics again. The EP rows now cover lookup tokens up to 2048 (EP16) and 4096 (EP32, EP64); the other rows are unchanged.

Signed-off-by: Wulley <[email protected]>

* [Test] test_moe_2stage: skip tuned CSV rows whose topk exceeds the expert count

Expert-parallel fMoE rows key on the local expert count, so the Kimi K3
A8W4 EP64 rows carry expert=14 with topk=16/17. The tuned-CSV sweep runs
every row as a non-EP MoE with E=expert, where fused_topk cannot pick topk
distinct experts and pads the extra slots with duplicate expert-0 routes,
so the strict accuracy check fails (logits_diff ~0.17). Skip such rows;
runtime config selection is unchanged.

* Revert "[Test] test_moe_2stage: skip tuned CSV rows whose topk exceeds the expert count"

This reverts commit 42e54f9.

Signed-off-by: Liu <[email protected]>

* [MoE] Drop EP16/EP64 and EP32 topk-17 Kimi K3 rows

Retain the eight newly added EP32 topk-16 configurations and all pre-existing Kimi K3 rows.

Signed-off-by: Liu <[email protected]>

* [MoE] Restore Kimi K3 EP16 and EP32 topk-17 rows

Signed-off-by: Liu <[email protected]>

* [Test] Remove MXMOE EP regression test

Signed-off-by: Liu <[email protected]>

* [MoE] Limit MXMOE under EP to validated SiTUv2 atomic/reduce configs

get_2stage_cfgs now accepts MXMOE rows under EP only with SiTUv2 and an
atomic or reduce layout GEMM2, and rejects BM16 rows. BM16 sorts through
the masked Opus aux sort with dispatch_policy=1, which hangs at >= 819
experts (#8014). Other activations and the scatter epilog are not
validated under EP, so they stay rejected as on main.

Validation: get_2stage_cfgs over every gfx950 tuned MXMOE row with
is_ep=True accepts only the Kimi K3 SiTUv2 atomic/reduce rows. A BM16 EP
row falls back to the default heuristics; a non-EP BM16 row is still
selected.

Signed-off-by: Wulley <[email protected]>

* [FlyDSL] [MoE] Skip BM16 GEMM1 candidates when tuning under EP

The coupled tuner (--mxfp4-flydsl) still enumerated BM16 GEMM1
candidates for A4W4 under --ep-size, and its M_est pruning kept only
BM16 for rows below M_est 4. Those candidates sort through the masked
Opus aux sort with dispatch_policy=1, which hangs at >= 819 experts
(#8014), and the runtime rejects BM16 under EP anyway. Skip BM16 under
EP for both precisions and, as for A8W4, keep every larger BM unpruned.
Also fix the scatter comment: the runtime rejects the scatter epilog
under EP.

Validation: test_fast_tuning.py: 59 passed. The new case checks that an
EP32 A4W4 row with M_est 1 gets BM32/64/128 instead of BM16 only, and
that a dense A4W4 row still gets BM16.

Signed-off-by: Wulley <[email protected]>

* [FlyDSL] [MoE] Reject non-SiTUv2 rows when tuning MXMOE under EP

get_2stage_cfgs rejects every non-SiTUv2 MXMOE row under EP, but the
coupled tuner (--mxfp4-flydsl --ep-size N) still accepted SiLU and
SwiGLU rows and ran a full search whose winner inference always
discards. Reject them in _unsupported_row_reason, and move the EP CPU
tests to SiTUv2 rows.

Validation: test_fast_tuning.py: 59 passed. The EP case now also checks
that a SiLU row is rejected under EP; it fails without this change.

Signed-off-by: Wulley <[email protected]>

---------

Signed-off-by: Wulley <[email protected]>
Signed-off-by: Liu <[email protected]>
kyle-256 added a commit to AMD-AGI/AKLR that referenced this pull request Nov 26, 2026
- e2e.yaml: kimik3-fp4 (moonshotai/Kimi-K3) on mi355x for vLLM and SGLang; the recipes are InferenceX's vLLM
  config at concurrency 48 as AgentX serves it and the SGLang cookbook's MI355X command (draft decoding, prefix
  caching and the KV offload kept). The hub holds the draft models beside the model.
- A recipe names the AITER its two modes serve on ("aiter": "image", the default, or "stack"). Kimi-K3's recipes
  take stack.json's, installed over the image's as aiter-test does: it has the aiter.plugin through which AKLR
  serves AITER's ops, so the modes differ in AKLR alone. The GLM recipes stay on their image's.
- The AKLR-on mode also puts AKLR among aiter's providers (AKLR_AITER_PLUGIN=1); an AITER without aiter.plugin
  has none to join.
- SGLang v0.5.23 on stack.json's AITER computes Kimi-K3's MoE wrong: it holds w13 gate/up-interleaved under
  AITER_SITUV2_A8W4 and tells AITER "separated", which the image's AITER ignored and ROCm/aiter#6464 obeys. The
  install gives its SiTU call the weights' layout, as sgl-project/sglang#51000 does, in both modes; the MoE
  provider takes that call.
kyle-256 added a commit to AMD-AGI/AKLR that referenced this pull request Nov 27, 2026
- e2e.yaml: kimik3-fp4 (moonshotai/Kimi-K3) on mi355x for vLLM and SGLang; the recipes are InferenceX's vLLM
  config at concurrency 48 as AgentX serves it and the SGLang cookbook's MI355X command (draft decoding, prefix
  caching and the KV offload kept). The hub holds the draft models beside the model.
- A recipe names the AITER its two modes serve on ("aiter": "image", the default, or "stack"). Kimi-K3's recipes
  take stack.json's, installed over the image's as aiter-test does: it has the aiter.plugin through which AKLR
  serves AITER's ops, so the modes differ in AKLR alone. The GLM recipes stay on their image's.
- The AKLR-on mode also puts AKLR among aiter's providers (AKLR_AITER_PLUGIN=1); an AITER without aiter.plugin
  has none to join.
- SGLang v0.5.23 on stack.json's AITER computes Kimi-K3's MoE wrong: it holds w13 gate/up-interleaved under
  AITER_SITUV2_A8W4 and tells AITER "separated", which the image's AITER ignored and ROCm/aiter#6464 obeys. The
  install gives its SiTU call the weights' layout, as sgl-project/sglang#51000 does, in both modes; the MoE
  provider takes that call.
kyle-256 added a commit to AMD-AGI/AKLR that referenced this pull request Nov 27, 2026
- e2e.yaml: kimik3-fp4 (moonshotai/Kimi-K3) on mi355x for vLLM and SGLang; the recipes are InferenceX's vLLM
  config at concurrency 48 as AgentX serves it and the SGLang cookbook's MI355X command (draft decoding, prefix
  caching and the KV offload kept). The hub holds the draft models beside the model.
- A recipe names the AITER its two modes serve on ("aiter": "image", the default, or "stack"). Kimi-K3's recipes
  take stack.json's, installed over the image's as aiter-test does: it has the aiter.plugin through which AKLR
  serves AITER's ops, so the modes differ in AKLR alone. The GLM recipes stay on their image's.
- The AKLR-on mode also puts AKLR among aiter's providers (AKLR_AITER_PLUGIN=1); an AITER without aiter.plugin
  has none to join.
- SGLang v0.5.23 on stack.json's AITER computes Kimi-K3's MoE wrong: it holds w13 gate/up-interleaved under
  AITER_SITUV2_A8W4 and tells AITER "separated", which the image's AITER ignored and ROCm/aiter#6464 obeys. The
  install gives its SiTU call the weights' layout, as sgl-project/sglang#51000 does, in both modes; the MoE
  provider takes that call.
kyle-256 added a commit to AMD-AGI/AKLR that referenced this pull request Nov 28, 2026
- e2e.yaml: kimik3-fp4 (moonshotai/Kimi-K3) on mi355x for vLLM and SGLang; the recipes are InferenceX's vLLM
  config at concurrency 48 as AgentX serves it and the SGLang cookbook's MI355X command (draft decoding, prefix
  caching and the KV offload kept). The hub holds the draft models beside the model.
- A recipe names the AITER its two modes serve on ("aiter": "image", the default, or "stack"). Kimi-K3's recipes
  take stack.json's, installed over the image's as aiter-test does: it has the aiter.plugin through which AKLR
  serves AITER's ops, so the modes differ in AKLR alone. The GLM recipes stay on their image's.
- The AKLR-on mode also puts AKLR among aiter's providers (AKLR_AITER_PLUGIN=1); an AITER without aiter.plugin
  has none to join.
- SGLang v0.5.23 on stack.json's AITER computes Kimi-K3's MoE wrong: it holds w13 gate/up-interleaved under
  AITER_SITUV2_A8W4 and tells AITER "separated", which the image's AITER ignored and ROCm/aiter#6464 obeys. The
  install gives its SiTU call the weights' layout, as sgl-project/sglang#51000 does, in both modes; the MoE
  provider takes that call.
kyle-256 added a commit to AMD-AGI/AKLR that referenced this pull request Nov 28, 2026
- e2e.yaml: kimik3-fp4 (moonshotai/Kimi-K3) on mi355x for vLLM and SGLang; the recipes are InferenceX's vLLM
  config at concurrency 48 as AgentX serves it and the SGLang cookbook's MI355X command (draft decoding, prefix
  caching and the KV offload kept). The hub holds the draft models beside the model.
- A recipe names the AITER its two modes serve on ("aiter": "image", the default, or "stack"). Kimi-K3's recipes
  take stack.json's, installed over the image's as aiter-test does: it has the aiter.plugin through which AKLR
  serves AITER's ops, so the modes differ in AKLR alone. The GLM recipes stay on their image's.
- The AKLR-on mode also puts AKLR among aiter's providers (AKLR_AITER_PLUGIN=1); an AITER without aiter.plugin
  has none to join.
- SGLang v0.5.23 on stack.json's AITER computes Kimi-K3's MoE wrong: it holds w13 gate/up-interleaved under
  AITER_SITUV2_A8W4 and tells AITER "separated", which the image's AITER ignored and ROCm/aiter#6464 obeys. The
  install gives its SiTU call the weights' layout, as sgl-project/sglang#51000 does, in both modes; the MoE
  provider takes that call.
RuibinCheung pushed a commit to AMD-AGI/AKLR that referenced this pull request Nov 29, 2026
)

- e2e.yaml: kimik3-fp4 (moonshotai/Kimi-K3) on mi355x for vLLM and SGLang; the recipes are InferenceX's vLLM
  config at concurrency 48 as AgentX serves it and the SGLang cookbook's MI355X command (draft decoding, prefix
  caching and the KV offload kept). The hub holds the draft models beside the model.
- A recipe names the AITER its two modes serve on ("aiter": "image", the default, or "stack"). Kimi-K3's recipes
  take stack.json's, installed over the image's as aiter-test does: it has the aiter.plugin through which AKLR
  serves AITER's ops, so the modes differ in AKLR alone. The GLM recipes stay on their image's.
- The AKLR-on mode also puts AKLR among aiter's providers (AKLR_AITER_PLUGIN=1); an AITER without aiter.plugin
  has none to join.
- SGLang v0.5.23 on stack.json's AITER computes Kimi-K3's MoE wrong: it holds w13 gate/up-interleaved under
  AITER_SITUV2_A8W4 and tells AITER "separated", which the image's AITER ignored and ROCm/aiter#6464 obeys. The
  install gives its SiTU call the weights' layout, as sgl-project/sglang#51000 does, in both modes; the MoE
  provider takes that call.
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