Skip to content

[FlyDSL] [AOT] Cover the gfx942 whole-graph MoE rows - #8495

Merged
zufayu merged 1 commit into
mainfrom
zhiding512/flydsl-aot-moe-impl-rows
Nov 23, 2026
Merged

zufayu merged 1 commit into
mainfrom
zhiding512/flydsl-aot-moe-impl-rows

Conversation

@zhiding512

Copy link
Copy Markdown
Contributor

Summary

The MoE AOT replay skipped every impl__flydsl_gfx942__* row, so none of the gfx942 whole-graph FlyDSL kernels had an AOT entry. test_moe_2stage.py checks the cache for those rows, so it fails under FLYDSL_RUNTIME_RUN_ONLY=1 with no usable AOT cache for launch_batch1 (MI300X shard 5 of #8353, worked around in #8485). This PR replays those rows and fixes the two failures that replaying them exposes.

Motivation

  • _reaches_flydsl only accepts kernel names starting with flydsl_/cktile_. Whole-graph rows (impl__flydsl_gfx942__...) launch FlyDSL kernels from fused_moe_gfx942, so all 157 of them in the merged table (4 at 304 CUs, 153 at 80 CUs) were never replayed.
  • Replaying them failed in two ways:
    1. per_tensor_quant_hip refuses num_rows with an assert. A per-tensor row called with num_local_tokens drops its whole-graph config, and the CK path then calls this function with num_rows. The replay reports a runtime refusal (NotImplementedError) as a refused caller-side variant, but any other error as a build failure.
    2. moe_2stage_down_prefill_1x4 shares one FlyObjCache across traces. Its functools.cache keeps the MLIR objects of the first trace. The replay traces a launcher again in the same process, and the second trace builds on the stale IR: a segfault, an MLIR Property type mismatch assertion, or MmaMakeFragmentOp: expected a TiledMmaType and a memref. The other two Down kernels (gemm2_1x4.py, gemm2_8x1.py) already use FlyObjCache(cache_ir=False).

Changes

  • aiter/aot/flydsl/moe.py: _reaches_flydsl also accepts impl__flydsl_ rows.
  • aiter/ops/quant.py: per_tensor_quant_hip raises NotImplementedError for num_rows instead of asserting. Callers that pass it still fail, now with the error the runtime uses for unsupported calls.
  • aiter/ops/flydsl/kernels/moe_gemm_2stage/gfx9_fp8/gemm2.py: clear the Down prefill kernel's FlyObjCache at the start of each trace. Every trace now starts from the empty cache the first trace had, so the generated code is unchanged.

Performance (if applicable)

Not applicable: the exported objects of the changed kernel are byte-identical before and after (see Testing).

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

All runs on MI308X (gfx942, 80 CUs), ROCm 7.2, torch 2.9.1, FlyDSL 0.5.3 (the official wheel and a source build). The 304-CU rows were exercised with CU_NUM=304.

  • MoE replay of all 157 impl__ rows of the merged table (GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.moe --csv <impl__ rows>, fresh cache): before 481 ok / 75 failed; after 524 ok / 0 failed / 32 refused (per-tensor + num_local_tokens), with both FlyDSL builds. --check on the built cache: 0 failed.
  • The three rows that crashed (BF16 2560x320 t8192, ptpc 2048x512 t1024/t2048), replayed alone with the official wheel: 12/12 jobs crashed before, 12/12 ok after.
  • CI case (Qwen3.8-Flash BF16, token 1/2/4/8, 2560/192, E=513, topk=11, 304 CUs): fused_moe under FLYDSL_RUNTIME_RUN_ONLY=1 fails with the CI error on an empty cache and passes with the built cache (max relative error 1.0%, cosine 0.99998 against torch_moe).
  • op_tests/test_flydsl_moe_gfx942.py, full run: 228 checkAllclose passed, 0 failed; all 153 whole-MoE rows report err 0, 47 of them on the changed prefill Down kernel.
  • GPU AOT export of the changed kernel (BF16 2560x320 t8192, ptpc 2048x512 t1024): the .o files are byte-identical before and after.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

The AOT README already states that the MoE replay covers every tuned row reaching FlyDSL; this makes the code match it.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. per_tensor_quant_hip(num_rows=...) raises NotImplementedError instead of AssertionError; nothing catches the latter.

PR Self-Review

Reviewed revision

c526587

Behavior and intent

The gfx942 MoE AOT build now prebuilds the whole-graph FlyDSL kernels of the tuned impl__ rows, so the runtime and test_moe_2stage.py hit the cache instead of needing a JIT. Kernel numerics and codegen are unchanged; the only runtime-visible change is the exception type above.

Validation and unverified scope

See Testing. Not verified: MI300X hardware, a full setup.py wheel build, and a replay of the whole MoE table (only the 157 impl__ rows were replayed). The 32 refused variants remain a runtime limitation: a per-tensor caller passing num_local_tokens on gfx942 is still refused by the CK path.

PR-specific question

Changed op tests

None.

The MoE replay skipped every impl__flydsl_gfx942__ row, so the gfx942
whole-graph kernels had no AOT entry and test_moe_2stage fails under
FLYDSL_RUNTIME_RUN_ONLY=1 (no usable AOT cache for launch_batch1).

- moe.py: replay impl__flydsl_ rows too.
- per_tensor_quant_hip: refuse num_rows with NotImplementedError, which
  the replay reports as a refused caller-side variant, not an assert.
- moe_2stage_down_prefill_1x4: clear its FlyObjCache at each trace. The
  cache kept MLIR objects of the first trace, and a second trace in the
  same process (as the replay does) built on them and crashed.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 09:49
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 8495 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@zhiding512
zhiding512 requested a review from a team November 23, 2026 09:49
@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision c526587afcaf · 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. What is the most important boundary or failure mode introduced by this change, and what evidence covers 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 — PR-specific question has no substantive answer

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

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.

🔵 Needs a closer look

The repeated-trace lifetime fix and whole-graph AOT launches require gfx942 compile/replay and cache-reuse validation that this review environment cannot independently perform.

No open issues 🎉

What changed in this PR

This PR extends MoE ahead-of-time (AOT) replay to gfx942 whole-graph FlyDSL rows, addressing the cache-coverage gap behind the on-demand compilation workaround in #8485.

Changes:

  • Include impl__flydsl_ rows in MoE AOT replay.
  • Raise NotImplementedError for unsupported per-tensor quantization calls with num_rows, allowing replay to classify them as refused variants.
  • Clear the Down prefill kernel’s IR cache at each trace to prevent stale objects from being reused.
File Description
aiter/​ops/​quant.py Use an explicit unsupported-call exception for num_rows.
aiter/​ops/​flydsl/​kernels/​moe_gemm_2stage/​gfx9_fp8/​gemm2.py Reset cached IR before tracing the Down prefill kernel.
aiter/​aot/​flydsl/​moe.py Recognize whole-graph FlyDSL rows for AOT replay.

Review effort: Balanced

@zufayu
zufayu merged commit 0ae9c0e into main Nov 23, 2026
56 checks passed
@zufayu
zufayu deleted the zhiding512/flydsl-aot-moe-impl-rows branch November 23, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants