Skip to content

[FlyDSL] [MoE] gfx942: check the CK swiglu_limit limits after the FlyDSL backend - #8178

Merged
HaonanWang98 merged 1 commit into
mainfrom
hwang/gfx942-flydsl-silu-limit-guard
Nov 18, 2026
Merged

HaonanWang98 merged 1 commit into
mainfrom
hwang/gfx942-flydsl-silu-limit-guard

Conversation

@HaonanWang98

Copy link
Copy Markdown
Contributor

Summary

#7361 and #7820 merged on the same day. #7361's swiglu_limit guard in get_2stage_cfgs runs before #7820's gfx942 FlyDSL path, so for a clamped per-token FP8 SiLU on gfx942:

  • An inter_dim that is not a multiple of 128 raises, although the FlyDSL backend applies the clamp. DeepSeek-V4.1-Flash at TP4 on MI308X (inter_dim 576) fails at warmup with fused_moe cannot apply swiglu_limit=10.0 for QuantType.per_Token SiLU at inter_dim=576; the runtime-limit CK stage1 needs a multiple of 128.
  • Tuned impl__flydsl_gfx942__ rows are dropped as unable to apply the limit.

This PR:

  • Keeps tuned impl__flydsl_gfx942__ rows for gfx942 per-token FP8.
  • Checks the CK limits (FP8 only, inter_dim % 128 == 0) after the FlyDSL resolution, so they apply only when CK takes the clamp. Under EP, which the FlyDSL backend does not take, V4.1's 576 still raises, so test_num_local_tokens_dispatch checks EP with the Qwen shape.

Test

On MI308X:

#7361's guard ran before #7820's gfx942 FlyDSL path, so a clamped per-token
FP8 SiLU at an inter_dim that is not a multiple of 128 raised (DeepSeek-V4.1-Flash
TP4 on MI308X, inter_dim 576) and tuned impl__flydsl_gfx942__ rows were dropped,
although that backend applies the clamp. Keep those rows, and check the CK limits
only when no FlyDSL backend takes the call.
@HaonanWang98
HaonanWang98 requested a review from a team November 18, 2026 09:29
@github-actions github-actions Bot changed the title [MoE] gfx942: check the CK swiglu_limit limits after the FlyDSL backend [FlyDSL] [MoE] gfx942: check the CK swiglu_limit limits after the FlyDSL backend Nov 18, 2026
@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 8178 --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 46914fdfdaac · 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 — 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_flydsl_moe_gfx942.py
  • 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.

@HaonanWang98
HaonanWang98 merged commit a53213d into main Nov 18, 2026
@HaonanWang98
HaonanWang98 deleted the hwang/gfx942-flydsl-silu-limit-guard branch November 18, 2026 15:53
HaonanWang98 added a commit to ROCm/ATOM that referenced this pull request Nov 18, 2026
…y refused

- V4.1's MoE refuses an FP4PTPC layer whose shared expert did not fuse, and
  the draft refuses unconverted routed experts; this replaces
  validate_fp4ptpc_recipe. Expert parallel and data parallel are refused.
- A Linear refuses an MXFP4 online source, as before; only MoE experts
  convert from MXFP4. MXFP4 sources are not streamed, as before.
- Recipe: the AITER pin is ROCm/aiter#8178's merge commit.
ZLkanyo009 added a commit that referenced this pull request Nov 19, 2026
…r the plan cache

aiter/fused_moe.py conflicted with #7606 (a3d077b, NVFP4 routed-expert
MoE for gfx950), and #8178 (a53213d) changed it too.

- #7606 adds w1_global_scale / w2_global_scale and passes has_global_scale
  to get_2stage_cfgs, which then selects the NVFP4 full_impl. The conflict
  was in that call: this branch records it as cfg_args / cfg_kwargs for the
  plan, so has_global_scale goes into cfg_kwargs. A call with either global
  scale neither reads nor stores a plan: the scales are not in the plan key,
  and a cached fp8 plan would otherwise skip the check that global scales
  need fp4x2 weights. NVFP4 calls return through full_impl before a plan
  could be stored anyway.
- #8178 moves the CK swiglu_limit checks after the gfx942 FlyDSL backend,
  inside get_2stage_cfgs. A plan hit calls get_2stage_cfgs with the recorded
  arguments (swiglu_limit included) every time, and a full_impl stores no
  plan, so the new order applies to every call. Merged without changes.

New op test checks: an fp8 plan does not serve a call with global scales;
NVFP4 calls reach the full_impl (stubbed) on every eager call and store no
plan; swiglu_limit calls resolve every time where a backend takes them, and
an error raised by get_2stage_cfgs reaches a plan hit.
HaonanWang98 added a commit to ROCm/ATOM that referenced this pull request Nov 19, 2026
* feat(dsv41): DeepSeek-V4.1-Flash on MI308X (gfx942)

Runs the FP4PTPC checkpoint on gfx942, with and without DSpark: per-channel FP8 dense linears and shared expert (fused into FusedMoE's shared slot), routed experts converted from FP4 to per-channel FP8 at load and run on AITER's FlyDSL fused_moe with swiglu_limit, native group32 layers in BF16, gfx942 FP8 index formats, CSA decode split-KV and DSpark on gfx94x.

* dsv41: require the FP4PTPC recipe; guard the BF16 fallback

FP4PTPC without its routed experts converted to per-channel FP8 is refused with the recipe; the BF16 fallback asserts it gets no x_scale; the a8w4 attention test's take() mock returns what it is given.

* dsv4: a BF16 shared-expert w2 takes the unfused activation

The fused clamp-act-mul quantizes w2's input for a native group32 w2; where that w2 runs in BF16 (gfx942 at TP1/TP2) it must not.

* dsv41: the FP4PTPC recipe needs a routed-expert layer pattern

make_v4_quant_config converts the routed experts only on a layer pattern; a global ptpc_fp8 spec leaves them MXFP4.

* dsv41: third review round

The DP+EP guard reads Config.enable_expert_parallel; a native group32 linear records its BF16 fallback once (runs_bf16) and callers gate on it; Fp8MoEMethod takes fnuz_fixup; the FP4 online source reuses dequant_fp4_e2m1; the FP4PTPC recipe check uses online_pattern_spec; tests for CSA split-KV vs unsplit, the padded-source trim, the DP+EP guard and the fp4ptpc compile key.

* tests: skip the FP4PTPC recipe test without AITER

Its QuantizationConfig resolves AITER's QuantType; the non-GPU CI has no AITER.

* dsv41: per-expert trim test; comments for the BF16 fallback

The per-expert online-quant loop gets the padded MXFP4 source case; comments on wo_a, the native group32 weight and the shared-expert copy say what runs_bf16 and FNUZ do.

* dsv41: the loader asks the built FusedMoE; no getattr defenses

V4.1 models answer the loader's shared-expert rename from the FusedMoE they built (fuses_shared_expert), in place of a moe_quant_config probe; FusedMoEMethodBase declares need_normalize_e4m3fn_to_e4m3fnuz; MoE._fuse_shared_into_routed is read directly; the FP4PTPC recipe check also needs FP8.

* dsv41: V4.1 publishes quant_config; PTPC shared staging is its own class

- The V4.1 backbone and DSpark draft expose their MoE quant config as
  `quant_config`, which the loader's shared-expert rename already reads
  (as V4's); `fuses_shared_expert` and its loader hunk go.
- A `runs_bf16` linear returns on every `process_weights_after_loading`.
- `Config.compute_hash` loses the `fp4ptpc` factor: the text-config field
  is keyed by `_hf_architecture_factor` already.
- `PtpcSharedStaging` takes the per-channel FP8 shared expert;
  `Mxfp8SharedIntoMxfp4` and the MiniMax tests are main's again.
- `QueryRows.take` passes a None scale through; the BF16-Q branches go.
- Tests: the draft's BF16 `project_context`, the MXFP4 hidden-pad/bias
  refusal, a None-scale take.

* moe: rename the shared-expert staging instead of splitting it

`Mxfp8SharedIntoMxfp4` (which also stages the per-channel FP8 shared
expert with `ptpc`) becomes `SharedExpertStaging` in
`fused_moe/shared_expert_staging.py`; `PtpcSharedStaging` goes. The
`--load_dummy` return applies to the PTPC staging only. The PTPC tests use
the MiniMax test's FusedMoE stand-in.

* dsv41: read shared_expert_staging directly; test the quant_config contract

- FusedMoE.weight_loader reads the declared `shared_expert_staging`; the
  rollout test double declares it too.
- A test that the backbone and the draft publish `quant_config` and that
  the loader's `_fuse_shared_expert` asks with it; the comments say so.
- DualRMSNormPerToken overrides only the launch: the reshape, allocation
  and return are DualRMSNormBF16's.

* linear: ask AITER whether a group32 GEMM exists (needs ROCm/aiter#8086)

native_group32_runs_bf16 asks gemm_a8w8_blockscale_group32_supported for a
32x32 weight in the layout weight_is_stored_preshuffled keeps, instead of
matching the arch name.

* dsv41: a BF16 main_proj takes the joined DSpark taps unquantized

Main's in-place tap quantization (#3131) handed the draft's main_proj FP8
taps also where it runs in BF16 (gfx94x), which refuses them.

* dsv41: test the BF16 wo_a projection and the BF16 context-KV fallback

- `_project_out` with a BF16 `wo_a`: inverse RoPE and the strided bmm
  against the CPU rotation and a grouped einsum (GPU, two groups).
- `_context_kv_fusion` keeps BF16 shards per stage.
- `_project_taps`' docstring covers the BF16 `main_proj`.

* dsv41: the _project_out docstring covers the BF16 wo_a

* dsv41: FP4PTPC review fixes: fused-act scale layout, streaming, loader hook, validation, docs

- Expert: the fused clamp-act-mul only for a w2 that reads its group32 or
  1x128 x_scale; a per-channel w2 quantizes its own input.
- A per-channel shared expert is not staged into streamed routed experts, and
  FP4PTPC refuses ATOM_ONLINE_QUANT_STREAMING up front.
- A runs_bf16 weight keeps weight_loader_process.
- validate_fp4ptpc_recipe checks every layer; online quantization of the
  native checkpoint is refused again.
- _project_out calls the RoPE module; paged_2src shares paged_decode's
  _cu_count and returns one split for an empty step.
- The draft's wkv_shard view stays out of _modules.
- Recipe: gfx942 (MI308X) section and the AITER pin; MXFP4 sources in the
  online quantization docs.

* dsv41 recipe: the BF16 fallback's memory per GPU at TP4

* dsv41: refuse the FP4PTPC layouts that are not run; MXFP4 linears stay refused

- V4.1's MoE refuses an FP4PTPC layer whose shared expert did not fuse, and
  the draft refuses unconverted routed experts; this replaces
  validate_fp4ptpc_recipe. Expert parallel and data parallel are refused.
- A Linear refuses an MXFP4 online source, as before; only MoE experts
  convert from MXFP4. MXFP4 sources are not streamed, as before.
- Recipe: the AITER pin is ROCm/aiter#8178's merge commit.

* linear: only FP8 native linears ask AITER's group32 query; document the AITER floor

- A native W4A8 linear no longer calls native_group32_runs_bf16.
- Docs: native group32 FP8 linears need ROCm/aiter#8086 on every arch (the
  V4.1 performance guide, ATOM_GROUP32_WEIGHT_PRESHUFFLE, the MiniMax-M3
  recipe, native_quant_linear); MXFP4 sources are never streamed, and a
  Linear refuses one.
ZhiweiYan-96 added a commit to ROCm/ATOM that referenced this pull request Nov 19, 2026
PR 3102 moved from 483d8fe to 85999b8 (FP4PTPC review fixes; V4.1
refuses an FP4PTPC layer whose shared expert did not fuse and a draft
with unconverted routed experts). The recipe's numbers were measured at
483d8fe; say that the new head is checked by the plugin's CPU unit
tests only. ROCm/aiter#8178 (a53213dc4, the AITER 3102's recipe now
pins) moves the swiglu_limit check after the gfx942 FlyDSL path; the
plugin has not been run on it yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vedenev-amd added a commit that referenced this pull request Nov 19, 2026
#8178 changed get_2stage_cfgs so that per-token FP8 + clamped SiLU on
gfx942 uses the FlyDSL full_impl path (stage1=None) instead of CK stage1.
The test asserted stage1.func is ck_moe_stage1 without guarding against
the None case, crashing on MI300X CI.

Accept both outcomes: if stage1 is None assert full_impl is set
(FlyDSL took over), otherwise keep the existing CK assertions.
jhinpan added a commit to jonahbernard/aiter that referenced this pull request Nov 20, 2026
ROCm#8178 sends a gfx942 per_Token FP8 SiLU with an active swiglu_limit and no
tuned CK row to the FlyDSL whole-graph backend, which applies the clamp, and
checks the CK limits only when no FlyDSL backend takes the call.
test_plain_fp8_swiglu_limit_dispatch still assumed CK stage 1: it read
md.stage1.keywords on a FlyDSL result (AttributeError on MI300X), and it
expected NotImplementedError for per_Token at inter_dim 192, which FlyDSL
now serves.

The first two hunks are ROCm#8294's change. The inter_dim 192 expectation is the
assertion that ROCm#8294's own MI300X run still fails on.
vedenev-amd added a commit that referenced this pull request Nov 23, 2026
…for #8178"

This reverts commit 7cb2fdc. test_plain_fp8_swiglu_limit_dispatch is not
part of this PR; it fails on main since #8178 and #8350 fixes it there.
Keeping a partial fix here made the PR fail at a different assertion than
main, which hid that the failure is the same one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vedenev-amd added a commit that referenced this pull request Nov 23, 2026
MI300X shard 5 fails on main since #8178 (fixed by #8350); this PR's gfx942
test passed on MI300X in run 45177648946.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zufayu added a commit to jatseng-ai/aiter that referenced this pull request Nov 24, 2026
On gfx942 a clamped per-token FP8 SiLU that CK can clamp (FP8, inter_dim a
multiple of 128) is routed to the FlyDSL whole-graph default from ROCm#7820 /
ROCm#8178. That backend's metadata has stage1=None, so
test_plain_fp8_swiglu_limit_dispatch, which reads md.stage1.keywords,
crashes with AttributeError: 'NoneType' object has no attribute 'keywords'
-- MI300X shard 5 on main, most recently run 45246107786.

The route is also the wrong one for these calls: the whole-graph backend
clamps the BF16 activations it reads, a different quantization point from
the per-token path the call and the tuned rows from ROCm#7361 ask for. (The
accuracy claim in ROCm#8334 about that backend is retracted; it is accurate
against its own reference, see ROCm#8350.)

Keep the whole-graph default only where CK rejects the shape (inter_dim
not a multiple of 128, including V4.1-Flash at 576). The new predicate is
the same one the NotImplementedError gate below uses, which is what
defines what CK's runtime-limit stage-1 accepts. A tuned
impl__flydsl_gfx942__ row still wins. This does not revert ROCm#7361.

Fixes ROCm#8334

Co-authored-by: Cursor <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
zufayu added a commit to jatseng-ai/aiter that referenced this pull request Nov 24, 2026
On gfx942 a clamped per-token FP8 SiLU that CK can clamp (FP8, inter_dim a
multiple of 128) is routed to the FlyDSL whole-graph default from ROCm#7820 /
ROCm#8178. That backend's metadata has stage1=None, so
test_plain_fp8_swiglu_limit_dispatch, which reads md.stage1.keywords,
crashes with AttributeError: 'NoneType' object has no attribute 'keywords'
-- MI300X shard 5 on main, most recently run 45246107786.

The route is also the wrong one for these calls: the whole-graph backend
clamps the BF16 activations it reads, a different quantization point from
the per-token path the call and the tuned rows from ROCm#7361 ask for. (The
accuracy claim in ROCm#8334 about that backend is retracted; it is accurate
against its own reference, see ROCm#8350.)

Keep the whole-graph default only where CK rejects the shape (inter_dim
not a multiple of 128, including V4.1-Flash at 576). The new predicate is
the same one the NotImplementedError gate below uses, which is what
defines what CK's runtime-limit stage-1 accepts. A tuned
impl__flydsl_gfx942__ row still wins. This does not revert ROCm#7361.

Fixes ROCm#8334

Co-authored-by: Cursor <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
zufayu added a commit that referenced this pull request Nov 24, 2026
On gfx942 a clamped per-token FP8 SiLU that CK can clamp (FP8, inter_dim a
multiple of 128) is routed to the FlyDSL whole-graph default from #7820 /
#8178. That backend's metadata has stage1=None, so
test_plain_fp8_swiglu_limit_dispatch, which reads md.stage1.keywords,
crashes with AttributeError: 'NoneType' object has no attribute 'keywords'
-- MI300X shard 5 on main, most recently run 45246107786.

The route is also the wrong one for these calls: the whole-graph backend
clamps the BF16 activations it reads, a different quantization point from
the per-token path the call and the tuned rows from #7361 ask for. (The
accuracy claim in #8334 about that backend is retracted; it is accurate
against its own reference, see #8350.)

Keep the whole-graph default only where CK rejects the shape (inter_dim
not a multiple of 128, including V4.1-Flash at 576). The new predicate is
the same one the NotImplementedError gate below uses, which is what
defines what CK's runtime-limit stage-1 accepts. A tuned
impl__flydsl_gfx942__ row still wins. This does not revert #7361.

Fixes #8334

Co-authored-by: Cursor <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
vedenev-amd added a commit that referenced this pull request Nov 25, 2026
MI300X shard 5 fails on main since #8178 (fixed by #8350); this PR's gfx942
test passed on MI300X in run 45348931160, attempt 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vedenev-amd added a commit that referenced this pull request Dec 2, 2026
* [FlyDSL] gfx942 a8w4 MoE stage1 fp8 kernel

* Raise on non-gfx942 instead of assert

* Add Triton MXFP8 quant for a8w4 (FNUZ-correct, a8w4 byte order)

* gfx942 a8w4: fused_moe wiring, tuned rows, op test

- moe_kernels: register the _g942 stage-1 names (flydsl_moe1_afp8_wfp4_bf16_*_g942*)
  and route fp8 x fp4 stage 1 on gfx942 to gemm1_a8w4_gfx942 (bf16 sorted
  intermediate, consumed by the unchanged a16w4 stage 2).
- fused_moe: no inter-stage requant for the _g942 stage 1 (a2/a2_scale = None).
- gemm1_a8w4_gfx942: x_layout="moe_sort" reads x / scales as produced by
  fused_dynamic_mxfp8_quant_moe_sort; exponent rule bitwise equal to it.
- kimik3_a8w4_tuned_fmoe.csv: 32 gfx942 (cu 304) rows, inter 384/512,
  M 1..32768 except M=3 (fused_moe pads 3 -> 4); input shapes in
  kimik3_a8w4_gfx942_untuned_fmoe.csv.
- op_tests/test_flydsl_moe_a8w4_gfx942.py: a16w4 vs a8w4 through fused_moe.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* op test a8w4 gfx942: scale atol with the MoE output

checkAllclose(rtol=atol=1e-2) reported err ~0.22 for both a16w4 and a8w4:
the MoE output is O(1e3) and the paths and the torch reference round the
bf16 intermediate differently (1-3 bf16 ulps, <= 1.2 % of max|ref| on all
8 shapes). atol = 2e-2 * max|ref| gives err 0 for both paths; cos checks
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* gfx942 a8w4: quantise x inside stage 1 for M=1,2 (_qi kernels)

At M=1 the separate fused_dynamic_mxfp8_quant_moe_sort launch cost more
than the fp8 stage 1 saved, so a8w4 lost to a16w4 (0.96x). The new
x_layout="bf16" stage-1 variant reads bf16 x and quantises each K tile
to MXFP8 straight into LDS in A8W4_K8_ORDER, bitwise equal to the
separate quant:
- x of tile kt+1 is loaded before compute_tile(kt), quantised after it;
- block amax via maxnum + DPP quad swaps (no NaN-propagating max, no
  LDS swizzle with a full lgkmcnt wait);
- padding rows of the M tile are not quantised (their LDS is zeroed once).

Registry: every _g942 name gets a _qi variant (x_layout="bf16");
fused_moe skips the separate x quant for _qi rows and passes bf16 x.
CSV: gfx942 M=1,2 rows use the _qi stage 1; inter 384 M=1 uses the
a16w4 t16x256x128_atomic stage 2.

MI300X, whole MoE vs a16w4 at M=1: 1.05x (inter 512), 1.11-1.16x
(inter 384), was 0.96x / 1.00x. Non-_qi kernels compile to the same ISA
as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* gfx942 a8w4: MI325X only; LDS swizzle in _qi kernels; _qi rows for M<=8

- Enable the gfx942 a8w4 stage 1 on MI325X only (PCI device id 0x74A5, read
  from sysfs); elsewhere raise NotImplementedError. On MI300X a8w4 is slower
  than a16w4 at large M and the tuned CSV rows are shared by both cards.
  The op test skips on other gfx942 parts.
- XOR-swizzle the A tile in LDS (as gemm2) only in the _qi kernels, where the
  in-kernel quant hit LDS bank conflicts; other kernels unchanged.
- With that, _qi also wins at M=4, 8: switch those CSV rows to _qi.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* gfx942 a8w4: allow MI325X VF; fix gate comment and error text

- Add 0x74B9 (MI325X VF, SR-IOV guests) to the MI325X allow-list.
- The PciChipId comment: chip_info.py's hardcoded 10019 is wrong on ROCm
  7.2.4 / 7.13 / 7.14 (PciChipId is 10020), hence sysfs.
- Error text: MI300X numbers of this PR (0.81-0.89x at M>=1024).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* gfx942 a8w4: skip _g942 stage 1 in FlyDSL MoE AOT; skip its rows off MI325X in test_moe_2stage

- aot/flydsl/moe.py: the `_g942` stage-1 kernels are built by
  gemm1_a8w4_gfx942 (JIT on first use); the AOT stage-1 compile would build
  the gfx950 mixed-MoE kernel for them and fail (wheel build: 64 failed).
- test_moe_2stage.py: tuned-CSV rows are selected by cu_num only, so on MI300X
  (cu 304) the gfx942 a8w4 rows were picked up and the MI325X-only stage 1
  raises; skip them where a8w4_gfx942_supported() is False
  (test_flydsl_moe_a8w4_gfx942.py covers them on MI325X).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [FlyDSL] a8w4 gfx942: drop unused x layouts, @flyc.jit runtime if, fix tests

- Remove x_layout="a8w4", x_scale="row" and the Triton MXFP8 quantiser from
  gemm1_a8w4_gfx942 (no production caller or test reached them). The gfx942 ISA
  is bitwise identical on 5 variants (moe_sort and _qi, k_wave 1/2/4).
- _if_then: a local @flyc.jit dispatch instead of a raw scf.IfOp.
- test_moe_2stage: always skip _g942 rows; the CSV sweep prepares neither the
  a8w4 relayout nor the separated gate/up layout they need, so they aborted
  the run on MI325X. test_flydsl_moe_a8w4_gfx942.py covers them.
- test_flydsl_moe_a8w4_gfx942: set AITER_SITUV2_A8W4 to 1 or 0 explicitly and
  restore the caller's value; add M = 1024 and 4096.

The merge with main (previous commit) resolves the fused_moe_2stages conflict with
#6165 and rejects prequantized_a1 together with the gfx942 a8w4 stage 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fixes for item1 and item 2

* item 3

* item 4

* [FlyDSL] a8w4 gfx942: prebuild the _g942 stage-1 kernels in the AOT replay

main's AOT now replays fused_moe for every tuned row, with caller inputs built per quant
family. For fp8 x fp4 it built the gfx950 gate/up-interleaved a16w4 weights, so all 360
replays of the gfx942 rows hit the W1-layout check and failed. A _g942 row now gets
separated gate/up W1 relaid and tagged by shuffle_{weight,scale}_a8w4_gfx942, and
a8w4_gfx942_supported() passes in an AOT replay, which has no device to check and
compiles for the arch GPU_ARCHS names. The replay of kimik3_a8w4_tuned_fmoe.csv for
gfx942 is now 360 ok / 0 failed, so these kernels are prebuilt instead of JIT-compiled
on first use (review item 7).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: name things in comments, not PR numbers

Review item 11: comments referred to "the a16w4 port", "the a8w4 port" and
"the #6144 table", which only make sense to someone who followed the
development history. They now name the function or constant they mean
(compile_gemm1_a16w4_port, compile_gemm1_a8w4_gfx942,
_FP4_E2M1_FP8_LUT_LO / _HI). Comments only, no code change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: tune the _g942 stage-1 kernels with the MoE tuner

Review item 5: the tuner rejected per_1x32 on anything but gfx950, so the
shipped gfx942 a8w4 rows could not be regenerated with it. On gfx942 it now
tunes the _g942 stage-1 kernels together with the a16w4 stage 2. The _qi
kernels get the bf16 x and the others the output of the HIP MXFP8 quant; the
separate x-quant launch time is added to the moe_sort kernels and the _qi
rows are marked xbf16, as is already done for per_1x128. The gfx950
inter-stage fp8 cast is not added, because the a16w4 stage 2 reads the bf16
intermediate. Timing and selection are unchanged. On MI325X it picks a _qi
stage 1 at every M <= 8, for both inter dims.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: key the kernel cache on a source hash, not a hand-bumped rev

The hand-bumped `rev` tag in the kernel name did not invalidate anything in FlyDSL 0.3.4.1:
the kernel name is not part of FlyDSL's cache key, and the key follows the functions the
kernel body calls but not one reached two calls deep. With the decoder in _fp4x8_to_fp8x8
(called from _gemm1_body_a8w4) changed to give wrong numbers, the cached binary was still
served and the test passed; with an empty cache the same edit fails it (cos diff 0.024).

As pa_decode does in implementation_cache_tag, the factory now hashes the sources the
device code comes from once per process, and the kernel and launcher bodies read the hash,
which puts it into the key. The same helper edit now rebuilds the kernel and fails the test,
an unchanged file still hits the cache, and no tag has to be bumped by hand (review item 9).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: cache the stage-1 compile factory again

The source-hash change (63c794a) put _source_tag between the @functools.cache line and
compile_gemm1_a8w4_gfx942, so the hash function got the decorator twice and the factory none.
Every stage-1 call then built a new launcher, which FlyDSL loads from its disk cache and
unloads again when the launcher is dropped. On MI325X this made an eager fused_moe call on the
a8w4 path take 37.6 ms instead of 0.33 ms (M = 1, inter 512), and CUDA-graph capture of it
failed with hipErrorStreamCaptureUnsupported on hipModuleUnload, so the path could not run
under the graphs vLLM uses for decode. The a16w4 path was unaffected.

The factory is cached again (one compiled launcher per config) and _source_tag keeps a single
decorator. The stage-1 kernel test, which runs on every gfx942, now also captures the launch in
a CUDA graph and checks that the replay gives the same output: it fails on 63c794a for both
kernels and passes with this change. The full op test passes on MI325X (exit 0). This was not
pushed when found, so CI has not run it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] moe_2stage_a16wmix: share the stage-1 XCD tile map and grid size

The a16w4 stage 1 (gemm1.py) and the gfx942 a8w4 stage 1 each carried their own copy of the
bijective XCD round-robin + M-group swizzle and of the flattened grid size (review item 10).
Both now come from utils.py (xcd_tile_map, gemm1_grid, NUM_XCD); gemm1_a16w4_grid stays as the
public name the package exports. The divisions of the valid-tile bound still happen where the
caller builds the map, as they did inline, so the generated code is unchanged.

Checked by dumping the final ISA of every production config through the AOT replay of the
tuned CSVs that use these kernels (kimik2_i4, kimik3_a16w4, kimik3_a8w4, kimik3_i4,
minimax_m3_a16w4), before and after, with the source-hash suffix of the _g942 kernel names
stripped and nothing else ignored: identical for all 46 a16w4 and 17 _g942 stage-1 kernels on
gfx942 and all 82 a16w4 stage-1 kernels on gfx950 (21 and 31 of the a16w4 ones use the XCD
swizzle); the stage-2 and reduction kernels compiled alongside are identical too. No registered _g942
name uses the XCD swizzle, so that branch of the a8w4 kernel is covered only through the
shared helper. The a8w4 op test passes on MI325X and the AOT replay of
kimik3_a8w4_tuned_fmoe.csv builds 360 gfx942 and 732 gfx950 jobs without failures.

The k_wave reduction and the epilogue stay separate: gemm1.py keeps its accumulators in
memrefs (fx.memref_load_vec / acc.store) while the a8w4 kernel keeps them as SSA values, so
sharing them would mean rewriting one of the kernels rather than moving code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: use the stable FlyDSL APIs where the ISA stays the same

Review item 8 asked the gfx942 a8w4 stage 1 to move off FlyDSL calls outside the stable API.
Each swap was applied on its own and the final ISA of the 17 _g942 stage-1 kernels of
kimik3_a8w4_tuned_fmoe.csv's gfx942 rows (AOT replay, FLYDSL_DUMP_IR) compared with the
previous commit, source-hash suffix stripped and nothing else ignored:

- .shrui(n) -> >> n (both results are masked to bits the arithmetic shift leaves alone):
  17/17 identical.
- gpu.thread_id / gpu.block_id -> fx.thread_idx.x / fx.block_idx.x: 17/17 identical.
- _raw(x) -> x.ir_value() at all 25 sites (the buffer resource is already an ir.Value, so its
  wrapper is dropped; tensor_shim._to_raw is no longer imported): 17/17 identical.
- rocdl.mfma_f32_16x16x32_fp8_fp8 -> fx.make_mma_atom(fx.rocdl.MFMA(16, 16, 32,
  fx.Float8E4M3FNUZ)) + fx.gemm on register fragments: 17/17 identical.

Not taken: the output store through fx.rocdl.make_buffer_tensor + BufferCopy16b changes one
instruction in every kernel. BufferCopy takes a bf16 element index, so a masked row can no
longer get buffer_store's byte offset 0x7FFFFFFF (v_bfrev_b32 -2); it gets 0x7FFFFFFE
(v_mov_b32 with a literal). The store itself and its addressing are unchanged, but the ISA is
not identical, so buffer_ops.create_buffer_resource_from_addr / buffer_store stay.

perm_b32, cvt_pk_fp8_f32 and readfirstlane have no stable FlyDSL wrapper (they are not in
rocdl.__all__ in FlyDSL 0.3.4.1); a one-line comment at their uses says so. With all of this
the final ISA of the 17 kernels is identical to the previous commit's, the a8w4 op test passes
on MI325X, and the AOT replay of kimik3_a8w4_tuned_fmoe.csv builds 360 gfx942 and 732 gfx950
jobs without failures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Read the gfx942 a8w4 PCI chip id from sysfs via a shared chip_info helper

The a8w4 gfx942 stage-1 dispatch is gated on the PCI device id so it only
enables on MI325X, and reading that id through hipDeviceGetAttribute(PciChipId)
is unreliable because the attribute ordinal is not stable across ROCm releases
(10019 before HIP 7.1, 10020 after, and 10019 returns a bogus 0x200 on ROCm
7.2.4 / 7.13 / 7.14). The sysfs `device` file holds the id directly, so move
that sysfs read into chip_info as a reusable get_pci_chip_id_sysfs() and have
a8w4_gfx942_supported() use it instead of its own inlined copy. The existing
hipDeviceGetAttribute path (_get_pci_chip_id, attribute 10019/10020) is left
untouched so the MI308 device-name gate keeps its current behaviour.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* gfx942 a8w4: adopt tuner-picked rows where the whole-MoE A/B wins

Update the tuned rows for the _g942 stage-1 / a16w4 stage-2 kernels to the
in-PR tuner's picks for the 12 shapes where a whole-MoE CUDA-graph A/B
confirms a speedup over the previously shipped rows: M=1,2,8 at inter 512
and 384, and inter-384 M=256,1024,2048,4096,8192,16384 (2.4-8.0% faster).
M=4 and inter-384 M=512 are kept on the existing graph-measured rows, where
the tuner regresses (M=512 +4.8%, M=4 +0.6-0.8%). inter-512 large-M, inter-384
M=16..128 and M=32768 were not re-tuned and keep their current rows. The
swapped rows are numerically equivalent to the ones they replace (cos ~1e-6,
no NaN); only the kernel/tile choice changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* [FlyDSL] a8w4 gfx942: decide the stage-1 arch at runtime with get_gfx_runtime

The gfx942 a8w4 decision was made in four places from two helpers: the stage-1 launcher
(twice) and the compile factory used FlyDSL's get_rocm_arch(), which follows
FLYDSL_GPU_ARCH / ARCH, and the tuner used get_gfx(), which follows GPU_ARCHS. The launcher
and the tuner now use chip_info.get_gfx_runtime(), which reads the live device and answers
the single GPU_ARCHS target in an AOT replay. The launcher's second "gfx942 only" check is
dropped; compile_gemm1_a8w4_gfx942 keeps the one hard check against its compile target
(review item 15).

The op test passes on MI325X (non-_g942 fp8 x fp4 name still refused, 24/24 fused_moe
checks) and the AOT replay of the gfx942 kimik3_a8w4 rows builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: read the MI325X chip id through chip_info._get_pci_chip_id

main (#5182) fixed _get_pci_chip_id to pick the PciChipId attribute from the HIP
runtime version, which was the reason this PR read the PCI id from sysfs instead. That
left chip_info with two chip-id readers that failed differently (the sysfs one raised
OSError and the gate then guessed from the device name). The sysfs reader and the name
fallback are removed; the MI325X ids sit next to MI308_CHIP_IDS, and the a8w4 gate reads
the id through _get_pci_chip_id and fails closed if it cannot (review item 16).

On MI325X with ROCm 7.2 _get_pci_chip_id returns 0x74a5, as the sysfs read did. With the
reader stubbed, the gate is on for 0x74A5 / 0x74B9 and off for 0x74A1 and for a failed
read. The op test passes (24/24 fused_moe checks) and the AOT replay of the gfx942
kimik3_a8w4 rows builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: one predicate for the _g942 stage-1 kernels

Whether a stage-1 kernel is the gfx942 a8w4 one was written out in six places: the
stage-1 dispatch, fused_moe, the AOT replay and the tuner compared in_dtype with the
"a8w4_gfx942" string, the op test did too, and test_moe_2stage.py looked for "_g942" in
the name (review item 17). moe_kernels.py now exports is_a8w4_gfx942_kernel(name or
params) and A8W4_GFX942_IN_DTYPE, and all of them use it, so a rename or a second gfx942
a8w4 family changes one line. The tuner's _is_a8w4_g942 stays: it decides per shape,
from arch and dtypes, which candidate family to sweep, before any kernel name exists.

Checked: true for all 128 _g942 names (by name and by params), false for the other 5965
registered kernels and for None / {} / an unknown name; the op test passes and the AOT
replay of the gfx942 kimik3_a8w4 rows builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: check the stage-1 inputs in one helper, not in fused_moe_2stages

The gfx942 a8w4 input checks (W1 / W1-scale layout tag in both directions, no
caller-prequantized A for a _g942 stage 1, bf16 / fp16 x only for the _qi kernels) were
spread over about 40 lines of fused_moe_2stages, next to the shared a16w4 logic (review
item 18). They are now check_a8w4_gfx942_inputs in moe_kernels.py, beside
is_a8w4_gfx942_kernel, called once before the stage-1 input is prepared. The checks and
their messages are unchanged.

Checked: each of the seven input combinations (good _qi and moe_sort inputs, untagged W1,
tagged W1 with an a16w4 stage 1, untagged a16w4, prequantized A, fp8 x on a _qi row)
passes or raises as before; the op test passes (24/24 fused_moe checks, including the
fp8-x and mixed-layout cases) and the AOT replay of the gfx942 kimik3_a8w4 rows builds
360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: bound the x-scale buffer descriptor

Every buffer descriptor in the gfx942 a8w4 stage 1 was bounded except the one for the
MXFP8 x scales, which set num_records to 0xFFFFFFFF, so hardware bounds checks never
applied to those reads (review item 20). The kernel reads scale rows below cumsum[0] only,
and fused_dynamic_mxfp8_quant_moe_sort allocates pad32(sorted rows) x _ms_npad bytes, so
the descriptor is now bounded at pad32(cumsum[0]) x _ms_npad, the same source the output
descriptor uses. An indexing slip would now read zeros instead of neighbouring memory.

Checked on MI325X: the bound never exceeds the quantiser's allocation (M 1 to 32768,
BM 16 / 32); the 12 CSV _g942 kernels give bitwise-identical output (36/36); the `_qi`
kernels compile to identical ISA (they do not read the scale buffer), the moe_sort ones
gain 12 to 15 scalar setup instructions with the same VGPR count; whole fused_moe a8w4
time is unchanged (new/old 0.999 to 1.001, 6 interleaved runs, M 16 / 128 / 1024 / 2048,
inter 384 / 512). The op test passes and the AOT replay builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: drop the source-hash cache tag, FlyDSL 0.5.0 tracks the helpers

The source-hash tag (_source_tag, read as `_ = _a8w4_src_tag` in the kernel and launcher
bodies and appended to the kernel name) worked around FlyDSL 0.3.4.1's cache key, which
did not follow a helper reached two calls deep. main now pins FlyDSL 0.5.0 (#7600), which
dropped the same pattern from pa_decode (review item 21).

Re-ran the repro at 0.5.0 without the tag: with _fp4x8_to_fp8x8 (called from
_gemm1_body_a8w4) broken, the same cache got a new entry and the kernel-only test failed
as it should (cos diff 0.024, as with an empty cache), and an unchanged file still hit the
cache. So the tag, its reads and its name suffix are removed. The factory keeps its
functools.cache. Final ISA of all 17 _g942 kernels is identical to the previous commit
apart from the name, outputs of the 12 CSV kernels are bitwise identical, the op test
(including its CUDA-graph replay check) passes, and the AOT replay builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: keep the kernel module to the kernel, move the oracle and relayouts out

The torch MXFP8 oracle, the W1 relayouts and their layout tag are host-side tensor
helpers, so they now live next to the other shuffles in aiter/ops/shuffle.py and the
shared exponent rule in fp4_utils, where the tuner imports it as well. The op test
builds its own oracle from that rule, and the kernel entry point is exported from the
moe_2stage_a16wmix package like the a16w4 ones. Outputs of the 12 tuned kernels are
bitwise unchanged and AOT replay compiles all 360 rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: make the stage-1 op test fail on one wrong block scale

A cos-diff bound of 1e-3 passed outputs with one zeroed column, so test_stage1_kernel
now requires every element within checkAllclose's default tolerances and proves it on
a W1 whose up scale is doubled for one 32-wide block of one column. W1 is scaled by
1/8, which keeps the FP4 codes and keeps every output below SiTUv2's saturation at
100, where about 1 % of the outputs sat before and hid such errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: say why the output descriptor and store stay on buffer_ops

The reasons were only in the PR thread, so the next FlyDSL pin bump would have to
rediscover why these two calls were not moved to make_buffer_tensor / BufferCopy16b.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* FlyDSL a8w4 gfx942: raise on GUGU input in shuffle_weight/scale_a8w4_gfx942

Both relayout functions require GGUU (separated gate/up) layout as input.
A GUGU-preshuffled (gate_up_interleave=True) W1 passes the relayout silently
and receives the a8w4_gfx942_layout tag, but half its bytes are misplaced
relative to the GGUU order the stage-1 kernel reads, giving wrong output
without an error. Add an explicit ValueError check on the gate_up_interleave
attribute so the mislayout is caught at relayout time.

* FlyDSL a8w4 gfx942: assert err == 0 in test_moe_a8w4_gfx942, add self-check

The checkAllclose result was recorded but never asserted, so a localized
output error (e.g. one wrong token) could pass silently. Add assert err == 0
after each checkAllclose call in the candidates loop.

Add a self-check that zeroes one output row and confirms the tolerance catches
it (err > 0), so the check cannot go silent if the tolerance is too loose.
Remove the weaker assert on a8w4 cos < 1e-3 (superseded by err == 0).

* FlyDSL a8w4 gfx942: extend test_stage1_kernel to cover all CSV tile families

The M=1 kernel name in main() was stale since 5d7e4e1: the CSV M=1 rows
now use t16x32x256_g942_kw2_qi, not t16x32x128_g942_kw4_qi. Fix it.

test_stage1_kernel hardcoded tile_m=16 and asserted it, so BM=32 kernels
(t32x*) could not be tested. Remove the tile_m==16 assertion; derive tile_m
from the kernel params instead.

Add five more calls in main() to cover each distinct tile family in
kimik3_a8w4_tuned_fmoe.csv that was not reached on MI300X CI runners:
TILE_K=256 (t16x128x256_g942), bnt0 (t16x128x128_g942_bnt0_kw2),
BM=32 (t32x128x128_g942), and BM=32+TILE_K=256 (t32x128x256_g942_bnt0).

* FlyDSL a8w4 gfx942: apply black formatting to test file

* FlyDSL a8w4 gfx942: fix pre-existing ruff errors in gemm1.py and gemm.py

gemm1.py imported gemm1_grid from .utils but never used it (F401); remove it.
gemm1.py called _udiv and _umod from .utils but did not import them (F821);
add them to the import list.
aiter/aot/flydsl/gemm.py has a shebang but was not executable (EXE001);
set the executable bit.

* FlyDSL a8w4 gfx942: fix pre-existing ruff errors in gemm1.py

gemm1.py imported gemm1_grid from .utils but never used it (F401); remove it.
gemm1.py called _udiv and _umod from .utils but did not import them (F821);
add them to the import list.

* FlyDSL a8w4 gfx942: mark aiter/aot/flydsl/gemm.py executable (ruff EXE001)

The file has a #!/usr/bin/env python3 shebang but was not marked executable
(mode 100644). Set the executable bit (100755) to match. Pre-existing lint
error caught by ruff 0.16.0.

* Revert "FlyDSL a8w4 gfx942: mark aiter/aot/flydsl/gemm.py executable (ruff EXE001)"

This reverts commit f9f5db0.

* Revert "Revert "FlyDSL a8w4 gfx942: mark aiter/aot/flydsl/gemm.py executable (ruff EXE001)""

This reverts commit 2b777e7.

* FlyDSL a8w4 gfx942: fix test_plain_fp8_swiglu_limit_dispatch for #8178

#8178 changed get_2stage_cfgs so that per-token FP8 + clamped SiLU on
gfx942 uses the FlyDSL full_impl path (stage1=None) instead of CK stage1.
The test asserted stage1.func is ck_moe_stage1 without guarding against
the None case, crashing on MI300X CI.

Accept both outcomes: if stage1 is None assert full_impl is set
(FlyDSL took over), otherwise keep the existing CK assertions.

* [FlyDSL] a8w4 gfx942: keep _qi stage 1 rows at M <= 8 so pre-quantised x is accepted above that

The inter-384 M = 256 row used a _qi stage 1, which quantises x itself and refuses MXFP8
x + a1_scale, so a caller passing pre-quantised x at 129-256 tokens got a ValueError
although the contract promises the passthrough from M = 16 on. The row goes back to the
moe_sort kernel it had before the tuner swap. The op test now checks that the CSV uses
_qi only up to M = 8, and accepts a refused pre-quantised x only there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: check every _qi stage 1 of the CSV on full M tiles

The only _qi case in CI was M = 1 with 8 experts, so each M tile held one real row,
where the A swizzle and the per-row x-scale slots are the identity; a mismatch between
the in-kernel quant's write and the read would have passed. test_stage1_kernel now
also runs all five _qi kernels of the CSV with 2 experts / top 2 and 16 tokens, so
every tile row is real. A read without the swizzle, or x-scales written to the
neighbouring row, fails these cases and still passes the M = 1 one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: tag the a16w4 scale preshuffle with its gate/up order

shuffle_scale_a8w4_gfx942 refuses a gate/up-interleaved (GUGU) scale by its
gate_up_interleave tag, but only shuffle_weight set that tag, so a GGUU W1 paired with a
GUGU W1 scale passed both relayouts and gave wrong output without an error.
shuffle_scale now tags its interleave-branch output the way shuffle_weight does, and the
op test checks that both relayouts refuse a GUGU input.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: check all twelve CSV stage-1 kernels on every gfx942

Two kernels of the CSV, t16x128x128_g942_kw2 (inter-384 M = 256 and 512) and
t32x128x128_g942_bnt0 (eight large-M rows), were checked only through fused_moe on
MI325X, which CI does not have. test_stage1_kernel now runs them too, and main() asserts
that every stage-1 kernel in the CSV was run, so a row with a new kernel cannot slip
past the MI300X runners.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Revert "FlyDSL a8w4 gfx942: fix test_plain_fp8_swiglu_limit_dispatch for #8178"

This reverts commit 7cb2fdc. test_plain_fp8_swiglu_limit_dispatch is not
part of this PR; it fails on main since #8178 and #8350 fixes it there.
Keeping a partial fix here made the PR fail at a different assertion than
main, which hid that the failure is the same one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Retrigger CI without the ci:mi300x label.

MI300X shard 5 fails on main since #8178 (fixed by #8350); this PR's gfx942
test passed on MI300X in run 45177648946.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Retrigger CI without the ci:mi300x label.

MI300X shard 5 fails on main since #8178 (fixed by #8350); this PR's gfx942
test passed on MI300X in run 45348931160, attempt 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: tune the _g942 stage 1 with TUNE_ONLY unset, and fail loudly when the selection leaves it out

With TUNE_ONLY unset the tuner asked the flydslv2 generator first; it has no arch check, so it returned tasks for a gfx942 a8w4 row, TUNE_ONLY became "flydslv2", and the a8w4 branch, which only queues the FlyDSL `_g942` stage 1, then queued nothing and reported no error. The default now skips flydslv2 for these rows, and a TUNE_ONLY or OPUS_ONLY that excludes flydsl raises instead of tuning nothing. A CPU test drives tune() with the generators mocked: 0 queued stage-1 tasks before, all `_g942` ones after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: offer the _qi stage 1 to the tuner only up to 8 tokens

A `_qi` stage 1 quantises x itself and refuses pre-quantised x, so the CSV keeps it to M <= 8, but the tuner offered all 52 `_qi` names at every M and a re-tune could again pick one for M = 256, breaking test_csv_qi_rows and the pre-quantised x path there. The limit now lives in moe_kernels.A8W4_GFX942_QI_MAX_TOKEN, used by the tuner and the op test. A CPU test checks that the tuner offers `_qi` at 8 tokens and none at 9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: refuse a stage-1 tile over the 64 KiB LDS at compile time and keep it out of the tuner

At K = 7168 a BM 32, TILE_K 256, k_wave 4 `_qi` tile needs 73728 B of LDS (double-buffered A plus its f32 scales). Nothing checked it: the compiler only printed "local memory (73728) exceeds limit (65536)", FlyDSL went on, and the launch failed with hipErrorIllegalState, which says nothing about LDS and can leave the GPU context unusable. a8w4_gfx942_stage1_lds_bytes now sizes the tile, compile_gemm1_a8w4_gfx942 raises a ValueError over the limit, and the tuner skips those tiles. K = 3584 (Kimi-K3) has no such tile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: refuse a moe_sort stage 1 with TILE_K other than 128 or 256

load_x_scale_moe_sort builds one E8M0 base from y0 // 8 for the whole tile, which holds only while every block of the tile is in the same 8-block group, i.e. TILE_K 128 or 256. The check only asked for a multiple of 128, so a direct call with 384 or 512 built a kernel that read the wrong scale for half the blocks, up to a 256x error, without any message. The registered names use 128 and 256 only; compile now raises for the others, and a CPU test covers it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: stop a tuner run off MI325X with one up-front error

The tuner recognised a gfx942 a8w4 row by the arch alone, while the runtime path also requires a8w4_gfx942_supported(), so on an MI300X every `_g942` candidate raised NotImplementedError on its own and nothing said the shape is MI325X-only. The a8w4 branch now checks the gate once and raises with that message before queuing anything.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: apply swiglu_limit to the silu stage 1, as the a16w4 one does

With act="silu" the epilogue called gate_up_act with no SiTU parameters, so a finite swiglu_limit was ignored, while the a16w4 stage 1 clamps gate and up with clamp_gate_up before the unclamped SiLU and runtime_swiglu_limit documents that a positive SiLU limit is applied. The silu path now builds the parameters and clamps the same way (+inf without a limit). test_stage1_kernel takes act and limit and checks silu with limit 1.0 against torch: equal with the change, 84 % of the elements outside the tolerance without it. The shipped rows are SiTUv2 and unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: gate the op test on the running GPU, not on GPU_ARCHS

get_gfx() follows GPU_ARCHS and takes its last entry, so with GPU_ARCHS="gfx942;gfx950" the test decided it was on gfx950 and skipped everything on a real MI325X, still exiting 0. It now uses get_gfx_runtime(), as the dispatcher does, for the gate and for the gfx column: with that GPU_ARCHS on MI325X the old test ran 0 stage-1 checks, the new one all 14.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: make the stage-1 shape checks raise, so python -O keeps them

The eleven shape checks in compile_gemm1_a8w4_gfx942 were asserts, which python -O removes; with D_INTER not a multiple of TILE_N, for example, the kernel would then floor NUM_N_BLOCKS and leave the last columns of the intermediate unwritten, and the `_g942` branch returns before any upstream tile check. They now raise ValueError through one helper, with the same conditions, messages and order. A test compiles a bad shape in a python -O subprocess: it raises now and passed silently before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Drop the gfx942 a8w4 FlyDSL rows for M >= 1024 so main's asm 1-stage rows (#8211) serve those keys again.

The main merge kept both rows for the same 12 keys and the first one, ours, won, so test_moe_mxfp4fp8_gfx942_asm.py failed on MI300X. Measured on MI325X in one process, eager wall clock, A/B/B/A pairs, null control within 0.9%: asm is 20-33% faster on all 12 keys and won every pair. The FlyDSL rows for M = 1..512, where main has no gfx942 row, stay. The untuned CSV drops the same tokens so a re-tune reproduces the tuned CSV, and the op test runs fused_moe only at M served by FlyDSL rows (1..512); the stage-1 kernel checks are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Justify the MI325X-only a8w4 gate with the MI300X numbers at the M the rows still serve, now that #8211 serves M >= 1024.

The gate docstring, the NotImplementedError and the op test's skip message cited the 0.81-0.89x slowdown at M >= 1024, where the _g942 stage 1 no longer runs. On MI300X a8w4 is also slower than a16w4 at M = 128-512 (0.92-0.99x at inter 384), which is what the texts now give. The "MI325X only" substring the tests match is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Drop test_a8w4_gfx942_tune_sources.py: no CI job runs it, and review suggested removing tests that only serve local validation.

It held the unit tests of the review-round-3 tuner fixes; they passed at bd616e3 and d9ab86b (10 tests), and the result is posted in the review thread. The op test test_flydsl_moe_a8w4_gfx942.py stays, as the only numeric check of the _g942 stage-1 kernels on the MI300X CI runners.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Vedenev <[email protected]>
zufayu pushed a commit that referenced this pull request Dec 3, 2026
…e/prefill kernels (#6277)

* [ASM] [MLA] Fix and optimize the gfx942 MLA decode/prefill kernels

Replace 20 gfx942 MLA code objects with fixed and optimized builds and add
one new kernel (32 heads, qlen 1). Kernel names, kernargs and grids are
unchanged, so every existing caller dispatches as before.

Bugs fixed (stock behavior):
- KV loads above 4 GiB: buffer_load offsets were page_id * stride in 32 bits
  (some kernels also took a 24-bit page id), so pools over 4 GiB read other
  tokens' KV. KV now loads with 64-bit global addresses in every kernel.
- Other 32-bit offset overflows (output/split data, kv_indptr, LSE, Q).
- Missing s_waitcnt before using load results (prologue KV tile, V transpose
  LDS reads, fp8 descales) -> stale data under memory pressure.
- MFMA -> VALU read hazard in the softmax (nondeterministic results).
- LDS races and missing barriers in the a8w8 qseqlen 1/2/4 kernels.
- 32x1 / 64x1 kernels: S == 1 null split pointer fault; the 32-head kernel
  ran one token per workgroup and was not causal for qlen > 1.
- qseqlen-2 a8w8 causal mask, PS empty work items, kv_scale handling in the
  paged qseqlen-4 PS kernel, reads of unwritten splits for qlen >= 9.

Dispatch: gqa_ratio 32, bf16, non-persistent now selects the new
MLA_A16W16_1TG_4W_32mx1_16nx1_Coex0_Msk1_QH16_Q1 kernel when
max_seqlen_q == 1 (new mla_asm.csv row) and the causal any-qlen kernel
otherwise.

Performance matches or beats stock on most measured shapes (up to ~20%
faster); the 64-bit KV addressing costs up to ~1.5% on a few memory-bound
shapes of the a8w8 qseqlen-4 kernels.

Tested on MI300X against an fp32/fp64 reference and a bit-exact oracle,
including KV pools above 4 GiB, injected stalls and 1 h soak runs, and with
op_tests (test_mla.py incl. the CI invocations, test_mla_persistent.py,
test_mla_sparse.py and the other MLA op_tests): all pass.

Signed-off-by: Jonah Bernard <[email protected]>

* [MLA] Extend test_mla_ltx.py gfx942 coverage to every fixed kernel

The gfx942 kv_address check now covers each MLA .co this PR fixes,
except the page_size 64 ds32 kernel. GFX942_PRESETS maps each preset
to the modes (nps / ps / prefill) that reach its kernels. The default
gfx942 run sweeps all of them: 84 cases, 20 kernels.

- FP8 and A16W8 configs, qlen 1-8, 8/16/32/64/128 heads
- mla_prefill_fwd (causal prefill) mode
- causal reference for qlen > 1; FP8-Q tolerance 6e-2
- persistent metadata uses the real Q/KV dtypes on gfx942
  (gfx950 keeps BF16)

gfx950 defaults and presets are unchanged.

Signed-off-by: Jonah Bernard <[email protected]>

* test_mla_ltx: cover the gfx942 page-64 ds32 MLA kernel at 4 GiB

Add qh16_ds32_q1/q2/q4 presets (uint8 KV) for
mla_a16w8_qh16_m16x4_n16x1_coex0_mask1_ps_page64_ds32. The harness packs fp8
nope, fp32 block scales and bf16 rope into 64-token pages and runs the
kv_address cases on them: one page below, across and above the 4 GiB boundary
(page 102,300), plus a 65-page context the metadata splits in two.

Signed-off-by: Jonah Bernard <[email protected]>

* [MLA] Pick the bf16 32-head qSeqLen 1 kernel only on gfx942

asm_mla.cu set config_max_seqlen_q = 1 for bf16 32-head non-persistent
decode with max_seqlen_q == 1 on every arch, but only the gfx942
mla_asm.csv has a qSeqLen 1 row for that config. get_heuristic_kernel_mla
needs an exact match, so gfx950 failed with "cannot get heuristic kernel".
Gate it on arch_id == "gfx942"; other archs use qSeqLen 0 as before.

Signed-off-by: Jonah Bernard <[email protected]>

* [ASM] [MLA] Fix the gfx950 MLA kernels and test the fp8 msk0 kernel in CI

Rebuild 12 gfx950 MLA .co files from the same sources as the gfx942
kernels in this PR (the .text matches the gfx942 builds). KV is read with
64-bit global loads, so pools above 4 GiB no longer wrap, and the
nondeterminism, the non-causal 64-head kernel, the 1-split fault in the
64-head kernel and the bf16-Q/fp8-KV PS fault are fixed.
mla_a8w8_qh128_m32x4_n16x2_msk0 has no gfx942 counterpart: it is the
fp8 128-head msk1 source built with MASK = 0. Kernel names and
mla_asm.csv rows are unchanged.

aiter_test.sh: on gfx950, add a test_mla.py run of non-causal fp8 decode
with qlen 2 and 4 (128 heads), which is the only path that reaches the
msk0 kernel.

Signed-off-by: Jonah Bernard <[email protected]>

* [HIP] [MLA] Add the missing barrier in mla_reduce_v1's massive row loop

In mla_reduce_v1_impl_massive (4 or more splits), warp 0 writes the LSE
scales of a row to p_lds_lse_scale, and every warp then reads them to
scale its part of the output. The row loop had no barrier after the
output pass, so when a block reduces more than one row (qlen > 1, or
folded heads), warp 0 could overwrite the scales with the next row's
while warp 1 was still reading them. Warp 1's dims (256-511) of that
row were then combined with the wrong row's weights.

This is the remaining failure in #6731: with this PR's stage-1 kernels,
the issue's repro (32 heads, qlen 4, 5 splits) gave 167 wrong calls in
400,000 on MI300X, each one token and one head in dims 256-511 only.
With the barrier: 0 in 400,000.

Signed-off-by: Jonah Bernard <[email protected]>

* [MLA] Add a test_mla_reduce case for the row-loop barrier

The previous commit's race needs many splits, many rows per workgroup and
a full GPU; none of the existing cases has all three, so they pass with
or without the barrier. The new case (16 heads, dv 512, 32 tiles x 64
splits x 32 rows) failed on every run without the barrier on MI300X (50
of 50, plus both dtypes of the full test on two GPUs) and passes with it.

Signed-off-by: Jonah Bernard <[email protected]>

* [ASM] [MLA] Apply the causal mask in bf16 128-head decode with qlen > 1

The non-persistent bf16 128-head decode always ran
mla_dec_stage1_bf16_a16w16_subQ128_mqa128, which has no causal mask, so
causal decode with qlen > 1 attended to future tokens (#6733).

Run mla_pfl_bf16_a16w16_causal_subQ128_mqa128 for that case instead. It is
the masked build of the same kernel and takes the decode arguments
unchanged. It skips splits past a query's last token, so stage 2 now uses
the per-query split count for it.

gfx950 ships the same two kernels (identical .text), so the fix covers it
too; it was only tested on gfx942.

Signed-off-by: Jonah Bernard <[email protected]>

* [Test] test_ar_norm_precedence: give the stand-in should_fly_allreduce_rmsnorm

#5670 made fused_allreduce_rmsnorm ask each communicator
should_fly_allreduce_rmsnorm() before the paths this test checks. The
CustomAllreduce stand-in from #8022 binds only the other routing gates,
so the custom_fused case past the Gluon limit raised AttributeError.
#8022's last CI ran on a base without #5670.

Bind the real gate with _fly_rms=None, which is its value on gfx1250,
where the FlyDSL fused engine does not build.

(cherry picked from commit 06ae37f)

* [Test] test_moe_2stage: accept the gfx942 FlyDSL clamped SiLU route

#8178 sends a gfx942 per_Token FP8 SiLU with an active swiglu_limit and no
tuned CK row to the FlyDSL whole-graph backend, which applies the clamp, and
checks the CK limits only when no FlyDSL backend takes the call.
test_plain_fp8_swiglu_limit_dispatch still assumed CK stage 1: it read
md.stage1.keywords on a FlyDSL result (AttributeError on MI300X), and it
expected NotImplementedError for per_Token at inter_dim 192, which FlyDSL
now serves.

The first two hunks are #8294's change. The inter_dim 192 expectation is the
assertion that #8294's own MI300X run still fails on.

* Revert "[Test] test_moe_2stage: accept the gfx942 FlyDSL clamped SiLU route"

This reverts commit fdcd7bd.

* [fused_moe] Keep CK-capable clamped SiLU off the gfx942 FlyDSL default

The whole-graph batch-1 and decode kernels clamp BF16 activations, so a
per-token call that CK can clamp was missing the per-token reference and
crashing the dispatch test on stage1 being None.

Co-authored-by: Cursor <[email protected]>
(cherry picked from commit ca91b9f)

* [MLA] Route gfx950 128-head bf16 causal qlen>1 decode to the masked prefill kernel too

mla_asm_decode_remap only forced ps=0 (and thus the masked-prefill-kernel
selection for causal qlen>1) on gfx942, so gfx950 kept running the plain
persistent decode kernel for this case, which has no per-query causal mask.
Meanwhile mla.py's masked_qh128_bf16 (which drives CAUSAL_PER_QUERY for the
stage-2 reduction) was already set for both gfx942 and gfx950, so stage 2
believed splits past each query's causal horizon were skipped on gfx950 too,
even though stage 1 never skipped them there.

gfx950 already ships and dispatches mla_pfl_bf16_a16w16_causal_subQ128_mqa128.co
(hsa/gfx950/mla/mla_asm.csv) with the 64-bit KV addressing fix from this PR,
so extending the gate just routes to an existing, already-tested kernel.

* Revert "[MLA] Route gfx950 128-head bf16 causal qlen>1 decode to the masked prefill kernel too"

This reverts commit 2cd4f38.

Forcing ps=0 for gfx950 128-head bf16 decode breaks every persistent
128-head bf16 decode on gfx950. The gfx950 block at the end of
mla_asm_decode_remap still tests `persistent`, not `ps`, and remaps the
shape to gqa 32 / qSeqLen 4. The lookup then asks for (gqa 32, ps 0,
qSeqLen 4), which hsa/gfx950/mla/mla_asm.csv does not have, so
test_mla_persistent.py, test_mla_persistent_round_robin.py and
test_mla_sparse.py fail on MI35X with "cannot get heuristic kernel!
... gqa:32 ps:0 ... qseqlen:4".

The CAUSAL_PER_QUERY concern does not need this change.
masked_qh128_bf16 only feeds the stage-2 reduction in the
non-persistent branch of mla_decode_fwd. That branch passes
num_kv_splits_indptr, so persistent is false and ps is already 0 on
gfx950: causal qlen > 1 already selects
mla_pfl_bf16_a16w16_causal_subQ128_mqa128 there. Persistent decode
reduces with mla_reduce_v1 and runs the qh32_qseqlen4 *_ps kernels,
which have causal and msk0 variants.

* [CI] [MLA] Gate the gfx950-only msk0 test on the live GPU arch

get_gfx() returns the last GPU_ARCHS entry. With GPU_ARCHS="gfx950;gfx942"
the gate read gfx942 on a gfx950 GPU and skipped the test; with
"gfx942;gfx950" it would run the gfx950-only kernel on gfx942.
get_gfx_runtime() reads the arch from rocminfo and ignores GPU_ARCHS.

---------

Signed-off-by: Jonah Bernard <[email protected]>
Co-authored-by: amd-bartgips <[email protected]>
Co-authored-by: Jin Pan <[email protected]>
Co-authored-by: jatseng-ai <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Jin Pan <[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