Skip to content

[FlyDSL] [Perf] gfx950: 4-wave MXFP8 backend and MiniMax-M3.1 o_proj_full rows (stacked on #8582, #8578) - #8584

Closed
ganyi1996ppo wants to merge 4 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/mxfp8-4wave-dispatch
Closed

ganyi1996ppo wants to merge 4 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/mxfp8-4wave-dispatch

Conversation

@ganyi1996ppo

Copy link
Copy Markdown
Contributor

Summary

Stacked on #8582 (the persistent 4-wave MXFP8 kernel) and #8578 (o_proj_full 8-wave rows): the first commits of this branch are those PRs, review the top commit only; the diff shrinks as they land.

Makes the 4-wave kernel reachable through gemm_a8w8_blockscale(..., isBpreshuffled=True) / gemm_a8w8_mxfp8_bpreshuffle and puts it in the MiniMax-M3.1 TP4 o_proj_full (N6144 x K8192) rows, so the aiter-only path matches amd-kernels' ak_gemm for the sequence-parallel prefill.

  • aiter/ops/flydsl/gemm_a8w8_mxfp8_4wave.py (new): backend with the 8-wave module's shape: kernelName flydsl_mxfp8_4w_256x256x128_F8_F8_B16_xcd{0|1}[_nt] (make / parse), flydsl_mxfp8_4wave_gemm (raw row-major e8m0 scales in), launch_mxfp8_4wave_shuffled (for a producer that emits the kernel's scale layout), run_gemm_a8w8_mxfp8_4wave (the kernelName entry).
  • Scales: the kernel wants both scales in shuffle_scale_a16w4 order. A's is shuffled per call by one small Triton kernel (the torch 7-D permute copy costs 5-13 us at M 1024-16384, this 2.5-10 us, bit-identical, rows padded to 32 with 127 in the same pass); W's once per weight-scale tensor (cache keyed by device / pointer / shape / strides / _version, the entry holds the tensor so its storage cannot be freed and reused under the key, 512 entries). A caller that already has shuffled A scales (a quantizer emitting them) calls launch_mxfp8_4wave_shuffled and skips the 3-6 us; amd-kernels' numbers below do that.
  • Launch plan (same as amd-kernels' _fourwave_plan, generalized to get_cu_num()): one persistent round of 256x256 tiles; a remainder of R <= cus/2 parent tiles runs as one round of 128x128 (R <= cus/4) or 128x256 sub-tiles.
  • mxscale_preshuffle_kernels.run_gemm_a8w8_mxfp8_gfx950: routes the flydsl_mxfp8_4w_ prefix; a non-bf16 Out or a non-1x32 w_scale falls back to the mxpsh heuristic tile, as the 8-wave prefix does.
  • Tuner: a 4wave pipeline (4 candidates: xcd remap x non-temporal stores) in the 1x32 pipeline list, ids from 2_000_000; fits = N % 256 == 0, K % 256 == 0, K >= 512, 32-bit extents.
  • minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv: N6144 K8192 rows at M = 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536 -> 4-wave (the rows at 2048, 4096 and at M >= 8192 replace bmm / 8-wave rows; M <= 1024 rows unchanged). us is the measured public-path time.

Results (MI355X, gfx950; public path gemm_a8w8_blockscale(isBpreshuffled=True), graph of 8 cold weight copies, median us/call, A scale shuffle included)

M before (#8578 table) this PR amd-kernels
1536 94.1 77.8 69.2
2048 101.3 87.3 86.7
2304 176.7 93.1 92.1
3072 175.1 133.1 123.7
4096 194.1 158.5 152.6
4608 230.9 166.2 172.7
6144 350.1 221.7 220.1
8192 358.7 271.7 270.4
12288 589.6 415.7 411.9
16384 763.0 536.8 532.7
24576 1084.2 805.0 1023.5
32768 1443.2 1074.7 1358.2
49152 2174.6 1599.8 2023.6
65536 2908.6 2143.9 2702.9

Between the table's rows (M = 1088 ... 3840, 4608) the new path is 0-48% faster than before (e.g. 2304: 176.7 -> 93.1, 2816: 180.7 -> 125.8) and never slower; against amd-kernels it is within +0-9% for M 2048-16384 (the gap is the per-call A-scale shuffle, 3-6 us) and 21-26% faster above 16384 (amd-kernels' own table picks a slower row there). Output is bit-identical to amd-kernels' at every M >= 1280 above (pub_eq_ak); M = 1024 is a different kernel on both sides (unchanged rows, not bit-identical to ak's split kernel, as before).

Correctness

op_tests/test_mxfp8_gemm_4wave_dispatch.py (28 tests, all pass) plus #8582's 20: kernelName round trip, the launch plan (no remainder / 128x128 / 128x256 remainder, with and without XCD dealing), the Triton scale shuffle == shuffle_scale_a16w4 over padded rows (M 1 ... 8192, K 512 / 8192), run_gemm_a8w8_mxfp8_gfx950 with the 4-wave name bit-identical to the 8-wave kernel at (300, 512, 1024), (3072 / 4096 / 4100, 6144, 8192) (the three remainder-round plans) and (5120, 2560, 6144), both store modes, and the W-scale cache following an in-place scale update (version bump). The tuner's pipelines list the 4-wave candidates for (4096, 6144, 8192) and refuse N = 6000 / K = 256.

Notes for review

  • No AOT registration (aot_factory) for the 4-wave launcher yet: first use JIT-compiles it (a few seconds, cached in the FlyDSL cache). Follow-up.
  • A caller must have called the op once with a given w_scale tensor before CUDA-graph capture (the first call shuffles it; later calls hit the cache). ATOM's warm-up already runs each linear before capture; a producer that holds pre-shuffled scales can use launch_mxfp8_4wave_shuffled and has no cache.
  • Rows only for the o_proj_full shape: 6144x2048 / 6144x3072 / 6144x6144 / 2560x6144 also gain 5-12% at M >= 6144 in the same sweep, but their margin over the current rows is within the run-to-run noise at M < 6144, so they are left to the tuner (gemm_a8w8_mxfp8_bpreshuffle_tune.py now enumerates the 4-wave kernels).
  • The DBO plain-grid switch of amd-kernels (_PLAIN_GRID_MAX while two microbatches share the GPU) is not ported: grid_max is a parameter of the kernel, the policy belongs to the engine.

Review

Run by hand through the repo's review-pr triage (rules A1 A3 A4 B1 B3 B4 B6 B7 C4 C5 D1 D3 D8 D10 D12 D13 D14 E2 P1-P3 P5 P6): siblings / guards / aot-pairing / symbols / ci-coverage / flydsl-bounds checks clean. B4 (new dispatch value): the prefix is handled in run_gemm_a8w8_mxfp8_gfx950 with a documented fallback for non-bf16 out / non-1x32 scales, and the backend raises on a shape it cannot run instead of falling through; D13: the compiled-handle cache keys K, xcd, nt, tiles and grid size, and every launch passes the device as the specialization key; D14: operands are checked for device, contiguity, shape, dtype width and 32-bit extents before the raw-pointer launch, under torch.cuda.device; D3: no hipblaslt rows; D12: AOT not added (stated above); P6: base vs head measured back to back (tables above). Findings fixed before opening: a bf16-only / 1x32-only fallback for the 4-wave prefix (first version raised for an fp16 out), device check, rows restricted to the verified shape.

Technique credit: amd-kernels gemm/mxfp8_common/gemm.py (_fourwave_plan, scale preparation).

🤖 Generated with Claude Code

ganyi1996ppo and others added 3 commits November 24, 2026 08:22
…ave picks at M >= 8192 on gfx950

Replace the 7 FlyDSL bmm rows of the 6144x8192 1x32 shape at M = 8192 ... 65536
in model_configs/minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv
with FlyDSL 8-wave MXFP8 (256x256x128) picks. Config only, no code change;
output is bit-identical to the previous kernels.

Co-Authored-By: Claude <[email protected]>
…shuffle and MiniMax-M3.1 o_proj_full rows

The dispatcher half of the persistent 4-wave MXFP8 kernel: a gemm_a8w8_mxfp8_4wave backend
(kernelName flydsl_mxfp8_4w_..., raw scales in, shuffled in the backend), the tuner pipeline,
and N6144 x K8192 rows from M 1536 to 65536.

Co-Authored-By: Claude <[email protected]>
@ganyi1996ppo
ganyi1996ppo requested review from a team and a balanced review from Copilot November 24, 2026 14:25
@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 8584 --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 24, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 77cedd329c5f · 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. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  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_mxfp8_gemm_4wave.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_mxfp8_gemm_4wave_dispatch.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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical issues can crash valid inference calls, expose unfinished cached scales across streams, and corrupt output when unsupported shapes reach an unguarded kernel.

4 open issues
What changed in this PR

Connects the persistent 4-wave MXFP8 kernel from #8582 to AITER’s gfx950 GEMM dispatch and tuning, targeting faster MiniMax-M3.1 sequence-parallel prefill.

Changes:

  • Adds a backend wrapper with scale shuffling, weight-scale caching, and remainder-tile launch planning.
  • Registers four tuning candidates and selects 4-wave kernels for 15 N6144 × K8192 configuration rows.
  • Adds dispatch, scale-layout, cache-update, and numerical correctness tests.
File Description
op_tests/​test_mxfp8_gemm_4wave.py Stacked kernel tests for tile variants, scheduling, and numerical accuracy.
op_tests/​test_mxfp8_gemm_4wave_dispatch.py Tests backend naming, launch plans, scale shuffling, dispatch, and caching.
aiter/​ops/​flydsl/​mxscale_preshuffle_kernels.py Routes 4-wave names and falls back for unsupported output or scale formats.
aiter/​ops/​flydsl/​kernels/​mxfp8_gemm_4wave.py Stacked persistent 4-wave gfx950 kernel from #8582.
aiter/​ops/​flydsl/​gemm_tune/​flydsl_gemm_mxscale_preshuffle_common.py Adds the 4-wave tuning pipeline and shape eligibility checks.
aiter/​ops/​flydsl/​gemm_a8w8_mxfp8_4wave.py Implements backend wrappers, scale preparation, caching, and launch planning.
aiter/​configs/​model_configs/​minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv Selects 4-wave kernels for the targeted MiniMax prefill rows.

Review effort: Balanced



def _w_scale_shuffled(w_scale: Tensor) -> Tensor:
key = (
Comment on lines +176 to +179
hit = _W_SCALE_CACHE.get(key)
if hit is not None:
_W_SCALE_CACHE.move_to_end(key)
return hit[1]
Comment on lines +269 to +270
M, K = XQ.shape
N = WQ.shape[0]
Comment on lines +211 to +212
if Out.dtype != torch.bfloat16 or not Out.is_contiguous():
raise ValueError("[FlyDSL mxfp8 4wave] Out must be a contiguous bf16 tensor")
Copilot AI balanced review requested due to automatic review settings November 24, 2026 15:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical cache invalidation and cross-stream synchronization gaps can cause GEMMs to consume stale or unfinished scales, while missing launcher shape checks permit output-corrupting writes.

5 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Strided BF16 outputs are rejected by the tuned 4-wave runner

aiter/​ops/​flydsl/​mxscale_preshuffle_kernels.py:609

When a tuned row selects 4-wave, a caller-owned BF16 output such as backing[:, :6144] now raises because the runner requires contiguous Out. The public bpreshuffle API accepts this layout, and the previous 8-wave path supports it (gemm_a8w8_mxfp8_8wave.py:199-207,306-307). Preserve that support by using a contiguous temporary and copying back for strided outputs.

Medium severity GPU tests use incorrect availability and architecture gates

op_tests/​test_mxfp8_gemm_4wave_dispatch.py:54

The scale-shuffle tests allocate CUDA tensors without an availability guard, while the dispatch/cache tests use build-time get_gfx() and can skip supported gfx950 hardware when GPU_ARCHS='gfx950;gfx942'. Gate GPU cases with CUDA availability and get_gfx_runtime() for both script execution and pytest collection, while leaving the host-only name/plan tests runnable. Apply the runtime gate to all three dispatch/cache tests below.

Review effort: Balanced

Comment on lines +168 to +178
def _w_scale_shuffled(w_scale: Tensor) -> Tensor:
key = (
w_scale.device,
w_scale.data_ptr(),
tuple(w_scale.shape),
tuple(w_scale.stride()),
# inference tensors (created under torch.inference_mode(), e.g. weights loaded there)
# have no version counter; they cannot be updated in place outside inference mode
# either, so the pointer + the held tensor identify the content
-1 if w_scale.is_inference() else w_scale._version,
)
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Merged into #8582 (kernel and dispatch are the same kernel, now two parts on one branch). Closing in favour of #8582.

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