Skip to content

[FlyDSL] [gfx1250] grouped MoE: read the live GPU, not GPU_ARCHS - #8724

Merged
zufayu merged 1 commit into
mainfrom
fix/grouped-moe-gfx1250-runtime-arch
Nov 27, 2026
Merged

zufayu merged 1 commit into
mainfrom
fix/grouped-moe-gfx1250-runtime-arch

Conversation

@zufayu

@zufayu zufayu commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Summary This PR adds aiter/moev2, a rebuild of fused_moe dispatch and execution from small parts: - a problem description (MoeProblem); - segments, one per kernel family (sort, quant, CK, ASM, whole graph); - a plan that chains them. It lives next to the legacy code and takes over one group of calls (a path) at a time. Nothing changes by default. Paths run only when explicitly enabled with AITER_MOEV2. No path is graduated, so with the variable unset or off, every call runs exactly the legacy code. This PR has two commits: 1. Phase 0/1: scaffolding, a harness that locks in legacy behavior, and helpers moved verbatim out of fused_moe.py. No behavior change. 2. Phase 2: the problem/plan/segment framework, plus the first path, a8w8_pt (per-tensor fp8, 2-stage). It runs only with AITER_MOEV2=a8w8_pt (or on). aiter/moev2/README.md lists every new file with its purpose. It also says whether the file is permanent or removed once the migration finishes and the legacy code is retired. ## How to enable bash AITER_MOEV2=a8w8_pt python ... # per-tensor fp8 calls go through moev2 AITER_MOEV2=on python ... # every registered path (only a8w8_pt today) AITER_MOE_EXPLAIN=1 # log why moev2 picked or declined each call ## Commit 1: phase 0/1, scaffolding and harness (no behavior change) - aiter/moev2 scaffolding: - AITER_MOEV2 switch (envs.py); - path registry (paths.py, empty in this commit); - v2 entry point with the legacy fused_moe signature (api.py); - test hooks (hooks.py); - cache helper (dispatch/tuned.py). - Helpers moved from fused_moe.py: resolve_activation_dtype, quant_remap, get_inter_dim, fused_topk, and the torch reference MoE. Each definition is AST-identical to the one it replaces, and each is imported back into fused_moe.py, so every existing from aiter.fused_moe import ... still works (36 names checked). - Import rule: aiter/moev2 never imports the legacy MoE modules. The legacy modules may import from it, and tests/test_moev2_imports.py enforces this. - fused_moe() hook: it does nothing while no path is enabled. - tests/moe_dispatch, to lock in legacy behavior: - a public-name inventory; - CPU arch simulation (gfx942, gfx942_cu80, gfx950, gfx1201); - a golden dispatch snapshot: what legacy get_2stage_cfgs picks for every tuned row plus a grid of untuned keys, read from frozen tuned tables; - a GPU suite list per planned path; - a perf baseline (perf_gfx950.json). ## Commit 2: phase 2, framework and the a8w8_pt path (not graduated) - Framework: - MoeProblem round-trips the legacy get_2stage_cfgs key, so v2 and legacy can be compared key by key. - Segments declare what they can run. A problem with anything no segment declares is rejected. - dispatch/ holds the kernel-name parser, the tuned lookup (with legacy's fallbacks), the resolver (legacy order, legacy log lines, legacy raises), and a default ranking table with static checks. - execute/ mirrors _fused_moe_impl and fused_moe_2stages statement for statement. - Path a8w8_pt covers: - per-tensor fp8 weights on gfx942 and gfx950, Silu or Gelu, separated gate/up; - the CK default heuristic; - tuned CK and ASM+CK rows; - FlyDSL gfx942 whole-graph rows. - It declines (legacy runs the call): - herd routing, deterministic=True, or a registered presort; - swiglu_limit, beta or linear_beta; - bias, padding or scatter; - caller-chosen activation dtypes, or AITER_ONLINE_TUNE; - tuned rows for kernel families it doesn't own (1-stage, post-reduction); - a call whose post-sort second lookup would raise, or that v2 can't reproduce. - More helpers moved verbatim: output-buffer validation, MOEMetadata/AsmMoeMode, get_padded_M, ck_moe_stage1, asm_stage1, the default kernel parameters, and the tuned-table reader. Each is AST-identical and imported back. - Upstream changes mirrored. These upstream changes touch code that v2 copies rather than calls, so git showed no conflict; each is mirrored in v2 and has tests: - #6736: gfx950 fp8 CK needs shuffled weights. v2 raises the same RuntimeError, at the same two points, after the same log lines. - #7500: row-strided activations. v2 makes the same two hidden_states copies. - #6926: zero a2 before dynamic per-tensor quant. op_tests/test_moe_per_tensor_a2_init.py is added to the path's GPU suites. - #5988: post-reduction (flat=3) tuned rows are declined. - Harness additions: - CPU differential (v2 plan and log lines equal legacy's for every key the path claims); - key round-trip checks; - ranking checks; - GPU differential (same kernels, inputs and outputs as legacy). - Feature-variant keys in the snapshot. For per-tensor keys, the same call is added with one extra get_2stage_cfgs feature (num_local_tokens, activation scales, fp8 input, unshuffled weights, bias, padding, doweight_stage1, Gelu, ...). A changed decision then names the exact feature responsible. ## Behavior claim - Legacy dispatch is unchanged. Every existing snapshot record is identical on all 4 archs. The new feature-variant records are byte-identical to ones generated with the upstream base's aiter package. - When a8w8_pt runs a call, it launches the same kernels with the same parameters and inputs as legacy. It prints the same log lines, raises the same exceptions, and gives the same outputs, within legacy's own run-to-run noise. ## Testing | Check | Result | |---|---| | CPU unit tests (tests/test_moev2_*.py, test_moe_dispatch_snapshot.py) | 89 passed | | CPU differential, 4 archs | 22,087 claimed keys, 0 problems | | Key checks / ranking checks | 107,572 keys / 29,424 keys, 0 problems | | GPU differential, gfx950 (default, synthetic tuned table, AITER_USE_NT=1, AITER_BYPASS_TUNE_CONFIG=1) | 15 / 63 / 15 / 15 cases, 0 problems | | GPU suites, AITER_MOEV2=off vs a8w8_pt (test_moe_2stage -q 1, test_moe_per_tensor_a2_init, test_moe_sorting, test_moe_ep, test_moe_local_expert_ids, test_moe_dp_share_expert) | same exit codes and same per-check outcomes in both modes | | Legacy outputs, base vs this branch (test_moe_2stage small cases, all 10 quant types, 8,410 calls) | the 170 deterministic calls are bit-identical; the rest are within legacy's run-to-run noise | | Perf, dsv3_tp8_pt, a8w8_pt vs legacy | within 2.2% at every token count, mixed signs | | black, ruff | clean | Mutation checks confirm the new tests catch real breakage: - Without the a2 zero-fill, all 4 a2_init cases fail under v2. - Without the gfx950 raise, the differential reports 1,088 problems, all in the new feature-variant keys. - Without the second-lookup decline, its unit tests fail. ## Known limits - swiglu_limit=0.0, which vLLM sends for "no limit", is declined like any other limit value, so those calls stay on legacy. - The ASM and whole-graph branches are verified only by the CPU differential: their tuned rows are gfx942-only, and only gfx950 was available for GPU runs. - Pre-existing failures, unchanged by this PR: test_moe_2stage -q 1 has 28 failing swiglu-limit checks, test_moe_ep has 2 and test_moe_dp_share_expert has 13. They fail the same way with AITER_MOEV2 off and on, and on the upstream base. - Legacy nondeterminism found while building the GPU gate: CK stage 2 accumulates with atomics, and some ASM stage 1 kernels aren't repeatable. The gate compares within a tolerance measured legacy-vs-legacy, and doesn't excuse a case that hits the non-repeatable kernels. ## Review guide - Start with aiter/moev2/README.md. - Moved helpers are AST-identical to the originals. The diff in fused_moe.py is mostly deletions plus import-backs. - The behavior-relevant v2 code is in dispatch/resolver.py, execute/executor.py and migration/a8w8_pt.py. - The golden .jsonl.gz files are generated. Regenerate with python tests/moe_dispatch/snapshot.py --update, and check with --check.

PR Self-Review

Reviewed revision

f76850c

Behavior and intent

Default behavior does not change: with AITER_MOEV2 unset or off, every call still uses the legacy fused_moe path. The PR introduces an explicitly enabled a8w8_pt path for per-tensor FP8 two-stage MoE and decomposes the monolithic dispatch/execution flow into a problem, feasible kernel segments, and a plan. The existing implementation is insufficient for a controlled multi-phase migration because dispatch choices, execution details, and fallback boundaries are intertwined; the new framework can claim one narrowly defined workload family at a time and decline every call it cannot reproduce back to legacy.

Validation and unverified scope

Exact-head validation on f76850c9e9a8254ee063ad2991e8e9539dda17e7: Python compileall, Black, and Ruff pass; focused regressions cover multi-target runtime architecture claims, declined-call no-copy dispatch, path-specific GPU architecture filtering, architecture-binding restoration, architecture-specific GPU case selection, fail-closed performance token coverage, and resolved whole-graph implementation/config equality. Repository Aiter Test and MI300X CI are running on this head. The full CPU parity and gfx950 GPU results recorded on pre-rebase c32cff446f351bc8ce3e60d0c0a14c70931b8186 remain useful evidence but are advisory until repeated on the exact head. gfx942-cu80 ASM and FlyDSL whole-graph hardware validation remains unverified and is a prerequisite for graduating the opt-in path, not for merging this disabled-by-default implementation.

PR-specific question

The new configuration is consumed only by workload keys that the a8w8_pt path claims: per-tensor FP8 weights on gfx942 or gfx950, two-stage execution, Silu or Gelu, and separated gate/up, using the CK default heuristic, matching tuned CK or ASM+CK rows, or matching gfx942 FlyDSL whole-graph rows. Keys with herd routing, deterministic mode, a registered presort, swiglu_limit, beta/linear-beta, bias, padding, scatter, caller-selected activation dtypes, online tuning, unsupported tuned kernel families, or an unreproducible second lookup are declined to legacy. Unrelated shapes keep their prior selection because the feature is opt-in, the legacy snapshot is byte-identical on all four architecture grids, feature-variant keys exercise each exclusion independently, and the differential requires every claimed key to match the legacy plan while every declined key continues through the unchanged legacy path.

Changed op tests

None. This PR does not change any file under op_tests/; it only adds the existing op_tests/test_moe_per_tensor_a2_init.py to the moev2 GPU suite manifest so the already-canonical zero-fill coverage runs in both legacy and opt-in modes.

grouped_moe_gfx1250 called get_gfx() in five places, all of them at call
time: enabling grouped GEMM, keying the tuned-config lookup twice, and the
two gfx1250 dispatch branches, including the a4w4-as-a8w4 fallback added in
 #8670 for the MI450 A0 errata.

get_gfx() follows GPU_ARCHS and returns its last entry on a multi-target
build, so it does not name the running GPU. Measured on an MI308X with
GPU_ARCHS='gfx950;gfx1250-strict':

    live GPU           gfx942
    get_gfx()          gfx1250-strict   -> grouped GEMM on, strict fallback on
    get_gfx_runtime()  gfx942           -> both off

That fires the strict a4w4-as-a8w4 fallback on a GPU that has wmma-f4-insts,
and the mirror case (an MI450 A0 whose build lists another arch last) skips
the fallback the A0 errata needs, which is the NaN output #8670 fixes.

Alias the import to get_gfx_runtime, as aiter/ops/gemm_op_a8w8.py and
aiter/ops/gemm_op_a4w4.py already do, so all five call sites follow the live
GPU. aiter/ops/rmsnorm.py already spells the same gfx1250 test with
get_gfx_runtime(). No call site runs at import time or without a GPU, and
get_gfx_runtime() keeps its AITER_AOT_REPLAY path for AOT processes.

Tests: TestGroupedMoeArchSource in op_tests/test_gfx1250_strict_alias.py.
Reverting the import alias fails test_dispatch_reads_the_runtime_arch.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zufayu
zufayu requested a review from a team November 26, 2026 01:59
@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 8724 --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.

@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision cd2dc6c12850 · 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 behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  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 — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_gfx1250_strict_alias.py

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

@zufayu
zufayu requested a review from a team November 27, 2026 08:46
@zufayu
zufayu merged commit 00a00f6 into main Nov 27, 2026
89 of 93 checks passed
@zufayu
zufayu deleted the fix/grouped-moe-gfx1250-runtime-arch branch November 27, 2026 08:46
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