Skip to content

[FlyDSL] [gfx1250] Run a4w4 grouped MoE as a8w4 on gfx1250-strict (A0 has no wmma-f4-insts) - #8670

Merged
zufayu merged 1 commit into
mainfrom
hotfix/strict-a4w4-moe-a8w4-fallback
Nov 25, 2026
Merged

zufayu merged 1 commit into
mainfrom
hotfix/strict-a4w4-moe-a8w4-fallback

Conversation

@zufayu

@zufayu zufayu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stop-gap for #8527. On MI450 A0 (gfx1250-strict), the FlyDSL grouped MoE now runs a4w4 as a8w4 (fp8 activations, same mxfp4 weights). The fp4-activation TDM GEMM now refuses to build for gfx1250-strict instead of producing a kernel that outputs NaN.

Motivation

Changes

  • aiter/ops/flydsl/grouped_moe_gfx1250.py (grouped_gemm_gfx1250_a8w4):
    • On gfx1250-strict, an a4w4 request switches to a8w4: q_dtype_a becomes fp8, and the CSV lookup uses the fp8 key.
    • The a8w4 GEMM uses the A0-legal scaled 16x16x128 f8f6f4 WMMA.
    • Both formats read the same preshuffled mxfp4 weights and scales (the op test shuffles both identically), so no model change is needed.
    • Pre-quantized fp4 activations (EP/MoRI dispatch) raise NotImplementedError instead of being re-quantized.
    • A one-time warning is logged.
  • aiter/ops/flydsl/kernels/mxfp4_preshuffle_gfx1250_tdm.py (build_gemm_a8w4_tdm_task):
    • It raises NotImplementedError when a_is_fp4 and the FlyDSL compile target (get_rocm_arch(), which AOT sets via FLYDSL_GPU_ARCH) is gfx1250-*.
    • This also covers the other callers (grouped_gemm_mxfp4.py, mega_moe_gfx1250/s1f_stage1.py).
  • No change on any non-strict arch.

Performance (if applicable)

Hardware Workload/configuration Before After Change
MI450 A0 (gfx1250-strict) grouped a4w4 MoE, E256 T16384 topk6 K4096 inter512 silu NaN output (not usable) runs as a8w4 functional fix; not benchmarked

On A0, fp8 activations move twice the activation bytes of fp4. That cost goes away once the A0-safe a4w4 kernel lands. Other archs are unchanged.

Testing

  • Unit tests added or updated — validated with the existing op_tests/flydsl_tests/test_flydsl_grouped_gemm.py (see below)
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X
  • Tested on MI450 A0 (gfx1250-strict) and on gfx1250 (non-strict)

Documentation

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

The change is an internal dispatch fallback plus a build guard; both are explained in code comments.

Dependencies

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

Breaking Changes

None. Only gfx1250-strict behavior changes: a4w4 used to give NaN and now runs as a8w4. Pre-quantized fp4 activations on strict used to give NaN and now raise.

PR Self-Review

Reviewed revision

0f7682b

Behavior and intent

  • On gfx1250-strict, grouped_gemm_gfx1250_a8w4 routes an a4w4 MoE to the a8w4 path.
  • The fp4-activation TDM GEMM builder raises for a gfx1250-strict target.
  • The existing behavior is insufficient: the strict target cannot encode the 32x16x128 f4 WMMA, and FlyDSL does not surface the LLVM error. The kernel is silently built without its matmul and returns NaN, so a4w4 models on A0 fail or produce garbage.

Validation and unverified scope

Command:

op_tests/flydsl_tests/test_flydsl_grouped_gemm.py --scenario verify --data-format {a4w4,a8w4} \
  --experts 256 --tokens 16384 --topk 6 --model-dim 4096 --inter-dim 512 --act silu --no-check-aot-cache

MI450 A0, native gfx1250-strict. Image rocm/atom-dev:ub26-dcgpu-rk-10.3.0a20261117.bkc.20261117-pyt2.14.0-tri-main-a81d6911-atomsrc-gfx1250-b1120, HIP 7.18.26456, flydsl 0.5.3, 1 GPU.

case before (main) after (this PR)
a4w4 80× wmma-f4-insts errors, mxfp4_tdm_fp4_* dispatched, logits_diff NaN, FAIL 0 errors, 1 fallback warning, mxfp4_tdm_fp8_* + fp8 quant dispatched, logits_diff 0 / 3.2e-5, PASS
a8w4 – logits_diff 0 / 4.0e-6, PASS (same kernels as the a4w4 fallback)
guard check: fallback bypassed via monkeypatch – builder raises NotImplementedError; no requires target feature line

gfx1250 non-strict (ROCm 10.1, HIP 26315):

  • a4w4: same kernels (mxfp4_tdm_fp4_*), logits_diff 0 / 3.7e-6, identical to main. The fallback does not trigger.

Lint: black and ruff are clean. The patch was validated on main 7c132b81 and rebased onto 7abfa2a8. That rebase only touched one Gluon util file, and both changed files are byte-identical to the validated ones.

Unverified:

  • Full-model serving on A0 (DSV4-Flash TP4 startup and accuracy).
  • The pre-quantized EP/MoRI path; it now raises, but this was not exercised.
  • The mega_moe s1f_stage1 and grouped_gemm_mxfp4 callers; they are covered by the builder guard but were not run.
  • A strict AOT wheel in run-only mode: aot/flydsl/moe.py still skips strict fp4 rows, so the a8w4 fallback kernels are not precompiled. This is a follow-up.
  • Performance of the fallback.

PR-specific question

The most important boundary is detecting strict. The fallback keys on get_gfx(), the GPU_ARCHS-aware exact identity (gfx1250-strict; base_gfx_arch() folds it to gfx1250). The builder guard keys on FlyDSL's actual compile target (get_rocm_arch()).

  • If ROCm reports plain gfx1250 on A0 (old ROCr, or HSA_DISABLE_GFX12_STRICT=1), neither path triggers. Code then compiles for gfx1250 and runs the errata instruction, which is the pre-existing behavior and out of scope here.
  • Evidence: strict is detected natively (rocminfo/torch/FlyDSL all report gfx1250-strict) and takes the fallback. Non-strict gfx1250 is byte-for-byte unchanged in kernels and numerics.
  • The guard was exercised by bypassing the dispatch fallback; it raised before any LLVM codegen.

Changed op tests

None.

Follow-ups (not in this PR)

  1. A0-safe a4w4 FlyDSL kernel ([FlyDSL] [gfx1250-strict] grouped FP4 MoE (mxfp4_preshuffle_gfx1250_tdm) emits wmma_scale_f32_32x16x128_f4 on A0 — runtime JIT fails with "requires target feature 'wmma-f4-insts'" #8527), which replaces this fallback.
  2. AOT: precompile the a8w4 fallback kernels for strict fp4 rows instead of skipping them.
  3. FlyDSL: fail the compile on LLVM backend errors instead of returning a kernel without its matmul (being reported to the FlyDSL owners with a standalone repro).

🤖 Generated with Claude Code

… has no wmma-f4-insts)

On MI450 A0 (gfx1250-strict) the strict target drops wmma-f4-insts (A0
errata). The fp4-activation branch of the grouped TDM GEMM always emits
v_wmma_scale_f32_32x16x128_f4, so LLVM reports "requires target feature
'wmma-f4-insts'". FlyDSL does not fail the compile, and the kernel is built
without its matmul, dispatched, and returns NaN. Every a4w4 MoE on A0
(e.g. DSV4-Flash) is affected. Refs #8527.

Stop-gap until an A0-safe a4w4 kernel exists:
- grouped_moe_gfx1250: on gfx1250-strict, run a4w4 as a8w4. Activations
  are quantized to fp8 and the GEMM uses the A0-legal 16x16x128 f8f6f4
  scaled WMMA. Both formats use the same preshuffled mxfp4 weights and
  scales. Pre-quantized fp4 activations raise NotImplementedError.
- mxfp4_preshuffle_gfx1250_tdm: build_gemm_a8w4_tdm_task raises when
  a_is_fp4 and the FlyDSL target is gfx1250-strict. No caller
  (grouped_gemm_mxfp4, mega_moe s1f_stage1) can then get the NaN kernel.

Non-strict gfx1250 is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zufayu
zufayu requested a review from a team November 25, 2026 09:15
@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 8670 --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

aiter-bot commented Nov 25, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 0f7682b204bc · 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

- On gfx1250-strict, `grouped_gemm_gfx1250_a8w4` routes an a4w4 MoE to the a8w4 path.
- The fp4-activation TDM GEMM builder raises for a gfx1250-strict target.
- The existing behavior is insufficient: the strict target cannot encode the 32x16x128 f4 WMMA, and FlyDSL does not surface the LLVM error. The kernel is silently built without its matmul and returns NaN, so a4w4 models on A0 fail or produce garbage.

Validation and unverified scope

Command:
```
op_tests/flydsl_tests/test_flydsl_grouped_gemm.py --scenario verify --data-format {a4w4,a8w4} \
  --experts 256 --tokens 16384 --topk 6 --model-dim 4096 --inter-dim 512 --act silu --no-check-aot-cache
```

**MI450 A0, native gfx1250-strict.** Image `rocm/atom-dev:ub26-dcgpu-rk-10.3.0a20261117.bkc.20261117-pyt2.14.0-tri-main-a81d6911-atomsrc-gfx1250-b1120`, HIP 7.18.26456, flydsl 0.5.3, 1 GPU.

| case | before (main) | after (this PR) |
|---|---|---|
| a4w4 | 80× `wmma-f4-insts` errors, `mxfp4_tdm_fp4_*` dispatched, logits_diff NaN, FAIL | 0 errors, 1 fallback warning, `mxfp4_tdm_fp8_*` + fp8 quant dispatched, logits_diff 0 / 3.2e-5, PASS |
| a8w4 | – | logits_diff 0 / 4.0e-6, PASS (same kernels as the a4w4 fallback) |
| guard check: fallback bypassed via monkeypatch | – | builder raises `NotImplementedError`; no `requires target feature` line |

**gfx1250 non-strict** (ROCm 10.1, HIP 26315):
- a4w4: same kernels (`mxfp4_tdm_fp4_*`), logits_diff 0 / 3.7e-6, identical to main. The fallback does not trigger.

Lint: black and ruff are clean. The patch was validated on main `7c132b81` and rebased onto `7abfa2a8`. That rebase only touched one Gluon util file, and both changed files are byte-identical to the validated ones.

**Unverified:**
- Full-model serving on A0 (DSV4-Flash TP4 startup and accuracy).
- The pre-quantized EP/MoRI path; it now raises, but this was not exercised.
- The `mega_moe s1f_stage1` and `grouped_gemm_mxfp4` callers; they are covered by the builder guard but were not run.
- A strict AOT wheel in run-only mode: `aot/flydsl/moe.py` still skips strict fp4 rows, so the a8w4 fallback kernels are not precompiled. This is a follow-up.
- Performance of the fallback.

PR-specific question

The most important boundary is detecting strict. The fallback keys on `get_gfx()`, the GPU_ARCHS-aware exact identity (`gfx1250-strict`; `base_gfx_arch()` folds it to `gfx1250`). The builder guard keys on FlyDSL's actual compile target (`get_rocm_arch()`).

- If ROCm reports plain `gfx1250` on A0 (old ROCr, or `HSA_DISABLE_GFX12_STRICT=1`), neither path triggers. Code then compiles for gfx1250 and runs the errata instruction, which is the pre-existing behavior and out of scope here.
- Evidence: strict is detected natively (rocminfo/torch/FlyDSL all report `gfx1250-strict`) and takes the fallback. Non-strict gfx1250 is byte-for-byte unchanged in kernels and numerics.
- The guard was exercised by bypassing the dispatch fallback; it raised before any LLVM codegen.

Changed op tests

None.

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.

@zufayu
zufayu requested a review from coderfeli November 25, 2026 09:16
@zufayu
zufayu requested a review from yadaish November 25, 2026 09:29
@zufayu
zufayu merged commit 8b98c82 into main Nov 25, 2026
75 of 77 checks passed
@zufayu
zufayu deleted the hotfix/strict-a4w4-moe-a8w4-fallback branch November 25, 2026 17:32
zufayu added a commit that referenced this pull request Nov 27, 2026
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: zufayu <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
zufayu pushed a commit that referenced this pull request Dec 3, 2026
…250-strict (#9058)

gfx1250-strict (MI450 A0 errata) has no wmma-f4-insts. The fp4-activation
grouped TDM GEMM emits v_wmma_scale_f32_32x16x128_f4, which LLVM drops on that
target after printing "requires target feature 'wmma-f4-insts'", leaving a
kernel without the matmul (NaN output, #8527).

When the FlyDSL target is gfx1250-strict, emit each 32x16x128 f4 WMMA as two
v_wmma_scale_f32_16x16x128_f8f6f4 with FP4 operands, one per 16-row half of
the weight operand and the accumulator, following the lowering proposed in
llvm/llvm-project#246606. The weight scale VGPR is shared, with ROW0/ROW1
selecting each half. The activation scale select stays wm % 2; forcing ROW0
as the LLVM lowering does reads the wrong lanes for odd wm (rel_l2 6.4e-2 vs
2.7e-3 with per-token-varying scales on A0).

This replaces the NotImplementedError guard from #8670. The plain gfx1250
target is unchanged (same 32x16x128 f4 instructions, bit-identical results).

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

3 participants