Skip to content

[FlyDSL] [gfx1250] Split 32x16x128 f4 WMMA into two 16x16x128 on gfx1250-strict - #9058

Merged
zufayu merged 1 commit into
mainfrom
jli/gfx1250-strict-a4w4-compat
Dec 3, 2026
Merged

zufayu merged 1 commit into
mainfrom
jli/gfx1250-strict-a4w4-compat

Conversation

@jli-melchior

@jli-melchior jli-melchior commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On gfx1250-strict (MI450 A0), the FlyDSL grouped a4w4 MoE GEMM now emits each v_wmma_scale_f32_32x16x128_f4 as two v_wmma_scale_f32_16x16x128_f8f6f4 with FP4 operands, so the fp4-activation kernel compiles and computes correctly on A0. Kernel side of #8527.

Motivation

gfx1250-strict has no wmma-f4-insts (A0 errata). mxfp4_preshuffle_gfx1250_tdm.py always emits the 32x16x128 f4 WMMA for fp4 activations. On a strict target, LLVM prints requires target feature 'wmma-f4-insts', drops the matmul and still returns a kernel. On A0 that kernel outputs NaN (#8527: 80 such errors, logits_diff=nan).

#8670 contained this two ways:

  • it raises NotImplementedError in the kernel builder;
  • it runs a4w4 as a8w4 in grouped_moe_gfx1250.py.

Neither runs fp4 activations on A0.

Changes

  • aiter/ops/flydsl/kernels/mxfp4_preshuffle_gfx1250_tdm.py:
  • One deviation from the LLVM lowering. The activation scale select stays wm % 2; the LLVM lowering forces ROW0.
    • With wmma_m_rep > 1, activation scales are loaded 32 rows per VGPR, so odd wm reads lanes 16:31.
    • Forcing ROW0 gives rel_l2 6.4e-2 instead of 2.7e-3 once per-token scales differ (see Validation). That still passes the test's 0.01 logits_diff gate.
  • The plain gfx1250 target is unchanged.

Not in this PR (follow-up):

  • the a4w4 -> a8w4 dispatch fallback in grouped_moe_gfx1250.py;
  • the AOT strict fp4 skips in aot/flydsl/moe.py and aot/flydsl/common.py (_STRICT_ERRATA_KERNEL_RE).

On a box that reports gfx1250-strict, the fallback still runs a8w4 until it is removed.

Performance (if applicable)

Hardware: MI450 A0 (ASIC rev 0), 1 GPU.

Workload: op_tests/flydsl_tests/test_flydsl_grouped_gemm.py --scenario kernel --data-format {a4w4,a8w4} --experts 256 --topk 6 --model-dim 4096 --inter-dim 512 --act silu, data/scale init uniform/auto. Kernel time in µs, gemm1 + gemm2, single run.

Hardware Workload/configuration Before After Change
MI450 A0 tokens=16384, strict, a4w4 vs a8w4 fallback (#8670) a8w4 fallback: 323.9 + 252.0 = 575.9 split a4w4: 253.9 + 286.8 = 540.7 -6.1%
MI450 A0 tokens=256, strict, a4w4 vs a8w4 fallback (#8670) a8w4 fallback: 49.8 + 31.4 = 81.2 split a4w4: 45.5 + 42.9 = 88.4 +8.9%
MI450 A0 tokens=16384, a4w4, native 32x16 f4 vs split 340.1 + 274.5 = 614.6 253.9 + 286.8 = 540.7 -12.0%
MI450 A0 tokens=256, a4w4, native 32x16 f4 vs split 57.9 + 37.5 = 95.4 45.5 + 42.9 = 88.4 -7.3%

How to read the table:

  • The native 32x16 f4 rows are not a real A0 baseline. This box's ROCm reports gfx1250, and the 32x16 f4 code object runs through the HSA B0-to-A0 translator (libhsa_hotswap_rocjitsu.so).
  • The a8w4 fallback is what [FlyDSL] [gfx1250] Run a4w4 grouped MoE as a8w4 on gfx1250-strict (A0 has no wmma-f4-insts) #8670 runs on strict today. Until the dispatch fallback is removed, the comparison that matters for production is split a4w4 vs a8w4.
  • Single runs, not repeated; treat differences under about 10% as noise.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X
  • Tested on MI450 A0 (gfx1250, ASIC rev 0)

Documentation

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

Internal codegen change; the comments at the call site describe it.

Dependencies

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

Breaking Changes

None. On gfx1250-strict, a direct fp4-activation build that used to raise NotImplementedError now builds a correct kernel.

PR Self-Review

Reviewed revision

66b7932

Behavior and intent

On a gfx1250-strict FlyDSL target, the fp4-activation TDM GEMM emits two v_wmma_scale_f32_16x16x128_f8f6f4 (FP4 x FP4) per former v_wmma_scale_f32_32x16x128_f4. Before this change it either compiled to a matmul-less NaN kernel (before #8670) or raised NotImplementedError (after #8670). Neither ran fp4 activations on A0.

Other targets emit the same code as before.

Validation and unverified scope

MI450 A0, 1 GPU, aiter main 163947e79 + this commit, flydsl 0.5.3. This box's ROCm reports gfx1250, so strict was forced:

GPU_ARCHS=gfx1250-strict FLYDSL_GPU_ARCH=gfx1250-strict \
python3 op_tests/flydsl_tests/test_flydsl_grouped_gemm.py --scenario verify \
  --data-format a4w4 --experts 256 --tokens 16384 --topk 6 --model-dim 4096 \
  --inter-dim 512 --act silu --no-check-aot-cache

Dispatch reads the hardware arch (gfx1250), so the a8w4 fallback does not trigger and the fp4 kernel itself is compiled for strict and run.

Case Before After
strict a4w4, guard from #8670 reverted 80x requires target feature, logits_diff NaN 0 errors, logits_diff 3.7143e-06
strict a4w4, main NotImplementedError passes, 3.7143e-06
gfx1250 a4w4 / a8w4 3.7143e-06 / 3.9576e-06 unchanged
strict a8w4 3.9576e-06 unchanged
  • ISA: extracted and disassembled the code objects.
    • strict (mach 0x4eb): the K4096 / K512 fp4 kernels have 64 / 96 v_wmma_scale_f32_16x16x128_f8f6f4 with MATRIX_FMT_FP4. Each of the four A/B scale-select combinations appears 16 times in the K4096 kernel. That is 2x the 32 / 48 32x16 instructions it replaces.
    • gfx1250 (mach 0x449): still 32 / 48 v_wmma_scale_f32_32x16x128_f4.
  • Per-token-varying scales: the default test data gives every activation row the same e8m0 scale, which hides scale-select bugs. A wrapper scaled each token's bf16 hidden state by a random 2^k, k in [-3, 3].
    • Strict split vs native gfx1250 are bit-identical at tokens = 1, 16, 256, 2048 and 16384 (e.g. 3.7212e-06 / rel_l2 2.7281e-03 at 16384).
    • Forcing the activation scale select to ROW0 gives 2.0748e-03 / rel_l2 6.44e-02.

Unverified:

  • A box that natively reports gfx1250-strict (ROCm 10.3 image).
  • The end-to-end ATOM / DeepSeek-V4-Flash run.
  • The other launch_gemm_a8w4_tdm callers: grouped_gemm_mxfp4.py and mega_moe_gfx1250/s1f_stage1.py. They share the code path but were not run separately.
  • Repeated, statistically stable perf numbers.
  • No op test was added, because the per-token scaling lives in a local wrapper, not in op_tests/.

PR-specific question

Most important boundary: which instruction the strict target gets. split_f4_wmma keys on the FlyDSL compile target (get_rocm_arch().startswith("gfx1250-")), not the runtime arch, so it follows the code object that is actually built.

  • The plain gfx1250 build keeps the 32x16 f4 instruction. Evidence: ISA counts above, and bit-identical results before and after.
  • The strict build has no 32x16 f4 left. Evidence: 0 requires target feature errors, and the disassembly.

Main failure mode: the activation scale select. Choosing the wrong lane half is silent and still passes the 0.01 gate. It is covered by the per-token-varying-scale comparison above: wm % 2 is bit-identical to native, ROW0 is 24x worse in rel_l2.

Changed op tests

None.

🤖 Generated with Claude Code

…250-strict

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]>
@jli-melchior
jli-melchior requested a review from a team December 2, 2026 09:45
@github-actions

github-actions Bot commented Dec 2, 2026

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 9058 --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.

@github-actions github-actions Bot added the FlyDSL label Dec 2, 2026
@aiter-bot

aiter-bot commented Dec 2, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 66b7932f66b7 · 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 a gfx1250-strict FlyDSL target, the fp4-activation TDM GEMM emits two `v_wmma_scale_f32_16x16x128_f8f6f4` (FP4 x FP4) per former `v_wmma_scale_f32_32x16x128_f4`. Before this change it either compiled to a matmul-less NaN kernel (before #8670) or raised `NotImplementedError` (after #8670). Neither ran fp4 activations on A0.

Other targets emit the same code as before.

Validation and unverified scope

MI450 A0, 1 GPU, aiter main `163947e79` + this commit, flydsl 0.5.3. This box's ROCm reports `gfx1250`, so strict was forced:

```bash
GPU_ARCHS=gfx1250-strict FLYDSL_GPU_ARCH=gfx1250-strict \
python3 op_tests/flydsl_tests/test_flydsl_grouped_gemm.py --scenario verify \
  --data-format a4w4 --experts 256 --tokens 16384 --topk 6 --model-dim 4096 \
  --inter-dim 512 --act silu --no-check-aot-cache
```

Dispatch reads the hardware arch (`gfx1250`), so the a8w4 fallback does not trigger and the fp4 kernel itself is compiled for strict and run.

| Case | Before | After |
|---|---|---|
| strict a4w4, guard from #8670 reverted | 80x `requires target feature`, logits_diff NaN | 0 errors, logits_diff 3.7143e-06 |
| strict a4w4, main | `NotImplementedError` | passes, 3.7143e-06 |
| gfx1250 a4w4 / a8w4 | 3.7143e-06 / 3.9576e-06 | unchanged |
| strict a8w4 | 3.9576e-06 | unchanged |

- **ISA:** extracted and disassembled the code objects.
  - strict (`mach 0x4eb`): the K4096 / K512 fp4 kernels have 64 / 96 `v_wmma_scale_f32_16x16x128_f8f6f4` with `MATRIX_FMT_FP4`. Each of the four A/B scale-select combinations appears 16 times in the K4096 kernel. That is 2x the 32 / 48 32x16 instructions it replaces.
  - gfx1250 (`mach 0x449`): still 32 / 48 `v_wmma_scale_f32_32x16x128_f4`.
- **Per-token-varying scales:** the default test data gives every activation row the same e8m0 scale, which hides scale-select bugs. A wrapper scaled each token's bf16 hidden state by a random 2^k, k in [-3, 3].
  - Strict split vs native gfx1250 are bit-identical at tokens = 1, 16, 256, 2048 and 16384 (e.g. 3.7212e-06 / rel_l2 2.7281e-03 at 16384).
  - Forcing the activation scale select to `ROW0` gives 2.0748e-03 / rel_l2 6.44e-02.

Unverified:
- A box that natively reports `gfx1250-strict` (ROCm 10.3 image).
- The end-to-end ATOM / DeepSeek-V4-Flash run.
- The other `launch_gemm_a8w4_tdm` callers: `grouped_gemm_mxfp4.py` and `mega_moe_gfx1250/s1f_stage1.py`. They share the code path but were not run separately.
- Repeated, statistically stable perf numbers.
- No op test was added, because the per-token scaling lives in a local wrapper, not in `op_tests/`.

PR-specific question

**Most important boundary:** which instruction the strict target gets. `split_f4_wmma` keys on the FlyDSL compile target (`get_rocm_arch().startswith("gfx1250-")`), not the runtime arch, so it follows the code object that is actually built.

- The plain gfx1250 build keeps the 32x16 f4 instruction. Evidence: ISA counts above, and bit-identical results before and after.
- The strict build has no 32x16 f4 left. Evidence: 0 `requires target feature` errors, and the disassembly.

**Main failure mode:** the activation scale select. Choosing the wrong lane half is silent and still passes the 0.01 gate. It is covered by the per-token-varying-scale comparison above: `wm % 2` is bit-identical to native, `ROW0` is 24x worse in rel_l2.

Changed op tests

None.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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.

@jli-melchior jli-melchior changed the title [FlyDSL] [gfx1250] Split 32x16x128 f4 WMMA into two 16x16x128 on gfx1… [FlyDSL] [gfx1250] Split 32x16x128 f4 WMMA into two 16x16x128 on gfx1250-strict Dec 2, 2026
@zufayu
zufayu merged commit d2539be into main Dec 3, 2026
57 checks passed
@zufayu
zufayu deleted the jli/gfx1250-strict-a4w4-compat branch December 3, 2026 01:40
XingerZhu added a commit that referenced this pull request Dec 3, 2026
Resolve the conflict in mxfp4_preshuffle_gfx1250_tdm.py: keep this branch's
VGPR-partition / preshuffled-output setup and main's split_f4_wmma
(gfx1250-strict, #9058); both sit in the same prologue and are independent.
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