Skip to content

[FlyDSL] [Feature] Add MiniMax-M3 gfx950 dense MXFP8 per-1x32 preshuffle GEMM - #5817

Closed
amd-yashagar wants to merge 1 commit into
ROCm:mainfrom
vvagaytsev:feature/minimax-m3-mxfp8
Closed

amd-yashagar wants to merge 1 commit into
ROCm:mainfrom
vvagaytsev:feature/minimax-m3-mxfp8

Conversation

@amd-yashagar

@amd-yashagar amd-yashagar commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

MiniMax-M3 dense MXFP8 on gfx950 stores B in the MX-scale preshuffle layout, with per-1x32 E8M0 scales. Main already has flydsl_mxscale_preshuffle_gemm, but that entry defaults to coarse block scales (1x128 / 128x128) and its AOT only compiles that mode. This PR adds the MiniMax-M3 TP4 tune table and a dispatch that runs the existing kernel with blockscale=False, so packed A, shuffled B (shuffle_weight (16, 16)), and shuffle_scale_a16w4 scales are used as stored.

Technical Details

Two commits:

  1. Per-1x32 dispatch and tune table. gemm_mxscale_preshuffle calls the existing kernel with blockscale=False. get_mxscale_preshuffle_config returns an exact (gfx, cu_num, M, N, K, a_dtype, b_dtype) row, or nothing. require_tuned=True errors when the row is missing. Optional splitk_workspace keeps the split-K buffer address stable for CUDA graphs. CSV: aiter/configs/model_configs/minimax_m3_dense_mxfp8_mxscale_preshuffle_tuned_gemm.csv (147 fp8×fp8 rows, gfx950, cu_num=256, M=1…16384 including 8320, N×K 1536/2304/2560×6144 and 6144×768/2048/3072/6144). AOT for this mode is python -m aiter.aot.flydsl.mxscale_preshuffle. aiter.aot.flydsl.gemm is unchanged and still compiles blockscale=True.
  2. Tuner and GPU test use that same entry. tile_m must be a multiple of 32. tile_m=16 stays on the coarse block-scale path.

Test Plan

  • CPU: python3 -m pytest op_tests/tuning_tests/test_mxscale_preshuffle.py and python3 -m unittest op_tests.tuning_tests.test_config_shape_collision.TestConfigShapeCollision.test_mxscale_preshuffle
  • GPU (gfx950): python op_tests/test_flydsl_mxscale_preshuffle.py (and -s 1,2560,6144 4,1536,6144)
  • Tuner (optional): python op_tests/tuners/tune_mxscale_preshuffle.py

Test Result

  • CPU: 9 signature tests passed. Config merge for mxscale_preshuffle_tuned_gemm passed. All 147 tuned rows have errRatio=0.0.
  • GPU (gfx950), checkAllclose atol=0.01 rtol=0.01, error 0: tuned and explicit fp8 1×2560×6144; explicit fp8 and fp4 32×8192×8192; explicit fp8 split-K 2 and 4 on 8×2048×7168.

Submission Checklist

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5817 --add-label <label>

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 opt this PR out.

@amd-yashagar
amd-yashagar force-pushed the feature/minimax-m3-mxfp8 branch from 89a1a5a to 62e9d20 Compare September 24, 2026 09:25
@amd-yashagar
amd-yashagar force-pushed the feature/minimax-m3-mxfp8 branch 2 times, most recently from ade0c42 to 42fbbc3 Compare October 6, 2026 08:43
@amd-yashagar
amd-yashagar force-pushed the feature/minimax-m3-mxfp8 branch from 42fbbc3 to 98b9bd9 Compare October 15, 2026 13:42
@amd-yashagar amd-yashagar changed the title Feature/minimax m3 mxfp8 [FlyDSL] [Feature] Add MiniMax-M3 gfx950 dense MXFP8 per-1x32 preshuffle GEMM Oct 15, 2026
@johannes-graner
johannes-graner self-requested a review October 16, 2026 07:16

@johannes-graner johannes-graner 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.

Thanks for this. The 1x32 shuffled-scale path through the existing FlyDSL mxscale kernel is a sensible way to serve the MiniMax-M3 dense layers.

Below are the items I would like to see addressed before merge, with a few exceptions:

  • Items 10 and 11 are up to you. They can go in this PR or a follow-up.
  • Item 12, listed last under Lower importance, is a nit.
  1. AOT jobs fail on fused_split_k
  2. Scale-size check does not match the mfma_tile layout
  3. Test passes on wrong output and times only a cache-hot loop
  4. Tests skip M=8320 and do not cover the new contracts
  5. Define the splitk_workspace contract
  6. Output dtype is not part of the tuned-row lookup
  7. Share accepted-row validation between runtime and AOT
  8. Fold _lookup_tuned into get_mxscale_preshuffle_config
  9. Decode is slower than the existing gemm_a8w8_mxfp8_bpreshuffle

Up to you:

  1. Wrapper input validation
  2. Shared test and tuner fixtures

Lower importance:

  1. Tuner help text lists fp6

"k": int(row["K"]),
"cu_num": int(row.get("cu_num", "0")),
"gfx": row.get("gfx", "").strip(),
**parsed,

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.

Item 1: AOT jobs fail on fused_split_k (category: correctness)

**parsed passes the parsed kernel name into _compile_to_cache, and the parse result carries a fused_split_k key that _compile_to_cache (81-94) does not accept. Every one of the 147 jobs from the MiniMax table fails, so nothing is prebuilt.

OpKind.GEMM already compiles the same builder (aiter/aot/flydsl/gemm.py). It currently rejects the shuffled 1x32 fake-scale geometry (gemm.py:755-759). Extending it with that geometry would remove both this separate op kind and this keyword mismatch. That route is preferred over patching the argument here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: _compile_to_cache now accepts fused_split_k and rejects True (row-layout only). CSV parsing goes through a shared validator that also rejects _fsk on this path. Covered by a mocked AOT compile test.

return None if ki is None else ki.name


def _mx_scale_nbytes(rows: int, k: int) -> int:

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.

Item 2: Scale-size check does not match the mfma_tile layout (category: correctness)

_mx_scale_nbytes computes pad32(rows) * (K // 32). The mfma_tile layout pads the K/32 dimension to a multiple of 8, i.e. K to 256: scale_shape(..., "mfma_tile", 32) in aiter/ops/inverse_rope_group_quant.py:67-85 gives pad32(rows) * pad8(K / 32). For K that is not a multiple of 256 (e.g. 128, 384), a correctly laid out scale buffer is rejected. The AOT fake scales (aiter/aot/flydsl/mxscale_preshuffle.py:109,112) use the same formula.

Please derive the size from one shared layout helper. Reuse scale_shape if it fits; otherwise move it to a common module that both this file and the quantizer import.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: scale nbytes use the same pad as shuffle_scale_a16w4 (_mx_mfma_tile_1x32_scale_shape). AOT dummy scales and the runtime check share that helper. MiniMax K is already a multiple of 256, so serving shapes are unaffected.


def _record(ret, candidates, ref, flops, nbytes):
for name, fn in candidates.items():
y, us = run_perftest(fn)

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.

Item 3: Test passes on wrong output and times only a cache-hot loop (category: tests)

  • The result of checkAllclose is logged but never asserted, so the script exits 0 when the output is wrong. Please fail on a mismatch.
  • run_perftest(fn) times a zero-argument closure. run_perftest rotates only positional arguments, so every iteration reads the same A, B and scales. On gfx950 the largest weight here, 6144x6144 (about 39 MB with scales), fits in the 256 MB last-level cache. The reported time is therefore cache-hot. Over the 49 shapes in item 9, the hot time was 0.73x the cold time (geomean).
  • Please pass the tensors positionally. Set num_rotate_args so that rotations times the per-call footprint exceeds the cache, and set num_iters >= num_rotate_args.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: the GPU test now asserts on checkAllclose (err == 0). Tensors are passed as args into run_perftest so auto-rotate can deepcopy past L2.

e.g.: -s 1,2560,6144 4,1536,6144""",
)
args = parser.parse_args()
wanted = set(args.mnk)

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.

Item 4: Tests skip M=8320 and do not cover the new contracts (category: tests)

  • The wanted filter drops M=8320 without a message, although the table has 7 rows at M=8320.
  • The new behaviour is not tested:
    • a require_tuned=True miss;
    • rejection of an invalid splitk_workspace;
    • a non-bf16 output against a bf16 row (item 6);
    • scale buffers at K not a multiple of 256 (item 2).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: _TUNED_MNK now includes all 7 CSV rows at M=8320 plus a decode / mid / prefill sample. Added CPU tests for require_tuned miss, fp16 Out vs bf16 kernelName, bad splitk_workspace, and noncontiguous Out.

blocks in the compact broadcast layout the kernel reads (no aiter helper
builds those; no aiter op passes them). The op does NOT repack them.

splitk_workspace, when set, is the caller-owned fp32 partial slab for a

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.

Item 5: Define the splitk_workspace contract (category: API)

The validation at 343-358 checks shape, dtype, device and contiguity. It does not say whether the buffer may be shared across calls, how long it must live, or whether two streams may use it at once. The sglang caller pools workspaces by size, and the pool key includes neither the stream nor the graph bucket, so several M buckets share one buffer. That is safe only if calls are ordered on one stream. We have not shown a race. Please state the contract in the docstring:

  • exclusive use for the duration of the kernel;
  • same-stream ordering for reuse;
  • the minimum size per (M, N, split-K).

Please also check the size against that minimum.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the docstring: splitk_workspace must be contiguous fp32 (split_k, M, N) on A's device, exclusive for the launch duration, and reusable on the same stream after GEMM+reduce (including CUDA-graph replay). The exact shape/dtype/device/contiguous check was already there; added a unit test for a bad workspace.

_TUNED_CACHE: dict = {}


def _lookup_tuned(M, N, K, a_dtype, b_dtype, tuned_file=None):

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.

Item 8: Fold _lookup_tuned into get_mxscale_preshuffle_config (category: structure)

The public function (567-580) only adds defaults, keyword-only arguments and int() conversion around _lookup_tuned. Could the lookup become the body of get_mxscale_preshuffle_config, with the private function removed? The wrapper at 627 would then call the public function. The loader/selection split in aiter/ops/gemm_op_a8w8.py:923-969 is the pattern to follow if the CSV loading needs its own cached function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done: folded _lookup_tuned into get_mxscale_preshuffle_config; the wrapper calls that.

@@ -0,0 +1,148 @@
gfx,cu_num,M,N,K,a_dtype,b_dtype,libtype,kernelId,splitK,us,kernelName,tflops,bw,errRatio
gfx950,256,1,1536,6144,fp8,fp8,flydsl,-1,2,11.182910,flydsl_mxpsh_32x32x256_F8_F8_B16_w4_x0_sk2,1.6878,844.7175,0.0

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.

Item 9: Decode is slower than the existing gemm_a8w8_mxfp8_bpreshuffle (category: performance)

We compared this path with the existing gemm_a8w8_mxfp8_bpreshuffle on the 5 (N,K) pairs its MiniMax table covers (aiter/configs/model_configs/minimax_m3_a8w8_mxfp8_bpreshuffle_tuned_gemm.csv).

  • Setup: gfx950 at this head; both kernels on their tuned rows; pre-quantized inputs.
  • Timing: cache-defeated, with inputs rotated over more than 512 MiB.
  • M values: 1, 8, 32, 64, 512, 2048 and 8192.
  • Both kernels passed an atol=rtol=0.01 check against a dequantized fp32 reference.

Results, as baseline time / this PR's time (above 1 means this PR is faster):

M range Shapes Geomean Shapes where this PR is slower
Decode (M <= 64) 20 0.75 20
Prefill (M >= 512) 15 0.99 6
  • The worst case is M=1, 2560x6144: 14.1 us here against 7.9 us for the existing kernel.
  • This PR is faster at M=512 on all 5 pairs. It is slower at M=2048 and 8192 on the N=6144 pairs.

Both kernels are the same FlyDSL mxscale family. They differ in scale layout and in the tuned tile. For example, at 6144x6144 with M=1, this table picks 32x32x256 with split-K 8. The existing table picks 16x64x256 with fused split-K 4. That points to tile selection rather than the 1x32 layout, but we have not verified this.

Please either retune the decode rows to at least match the existing kernel, or explain why this path should be used where it is slower. The pairs 1536x6144 and 6144x768 have no rows in the existing table, so this PR is the only tuned MXFP8 path for them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No retune in this PR. The cold decode comparison is against row-scale gemm_a8w8_mxfp8_bpreshuffle (unshuffled scales; that path can use tile_m=16 / fused split-K). This entry is a different host contract: packed A, shuffled B, shuffle_scale_a16w4 scales, tile_m multiple of 32, no _fsk. Same device kernel family, but the configs are not interchangeable. Happy to retune decode for the mfma_tile table in a follow-up if useful.

Packed A, shuffled B, and ``shuffle_scale_a16w4`` scales. Exact CSV rows
win; ``require_tuned`` refuses a heuristic when the signature is missing.
"""
M = int(A.shape[0])

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.

Item 10: Wrapper input validation (category: API)

Up to you whether this goes in this PR or a follow-up. The sglang caller does not hit these cases, but the wrapper is a public entry point.

  • N is taken from Out.shape[-1]. An undersized Out, Out with incompatible storage, or noncontiguous inputs are not rejected before the raw dispatch at 699-716.
  • The tuner still builds candidates without explicit scale arguments (op_tests/tuners/tune_mxscale_preshuffle.py:136), so the coarse-scale constraints apply to 1x32 candidates. The wrapper itself now passes _MXFP8_MFMA_1X32 (662-664).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added contiguous checks on A/B/Out, Out dtype, and Out [M, N] with M == A.shape[0] before dispatch (on top of the existing scale nbytes / tile_m % 32 checks).

return fp4_utils.mxfp4_to_f32(codes) * scale_f32


def generate_data(

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.

Item 11: Shared test and tuner fixtures (category: code reuse)

Up to you whether this goes in this PR or a follow-up. _dequant and the quantize/preshuffle fixtures (46-80) duplicate those in op_tests/test_flydsl_mxscale_preshuffle.py:93,119-120. A shared helper module would keep the tuner and the test on the same reference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Leaving the shared fixtures as-is for this pass; happy to dedupe tuner vs test helpers in a follow-up.

"bw",
"errRatio",
],
description="tune FlyDSL mxscale preshuffle GEMM (a4w4/a6w4/a8w8)",

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.

Item 12: Tuner help text lists fp6 (category: documentation, nit, lower importance)

The description advertises a6w4, but _quant (35) rejects fp6. Please clarify whether fp6 is planned or drop it from the help text.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed: tuner help is now a4w4/a8w8 only (quantizer still rejects fp6).

Host dispatch, tune table, and AOT for shuffle_scale_a16w4 scales on the
existing mxscale_preshuffle kernel. AOT accepts fused_split_k=False;
scale nbytes match the mfma_tile pad. Shared row parse, out-dtype miss,
folded lookup, input checks, and broader GPU/CPU coverage for review.
@amd-yashagar
amd-yashagar force-pushed the feature/minimax-m3-mxfp8 branch from a98b765 to 2cecb98 Compare October 30, 2026 10:36
@aiter-bot

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 2cecb986273a · 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 permissions and untrusted-input boundary does this CI change have, and can fork PR code or text reach a privileged execution path?
  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_mxscale_preshuffle.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/tuners/tune_mxscale_preshuffle.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/tuning_tests/test_config_shape_collision.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/tuning_tests/test_csv_validation.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/tuning_tests/test_mxscale_preshuffle.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.

@amd-yashagar

amd-yashagar commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

aiter main now covers what this PR added: gemm_a8w8_blockscale(isBpreshuffled=True) takes the raw 1x32 E8M0 scales and runs FlyDSL kernels from the tuned MiniMax-M3 table, and sgl-project/sglang#44497 now calls that path instead of this one. Closing in favour of main. The large-M MiniMax-M3 rows (M=8320) that main's table lacks are in #7829.

amd-yashagar added a commit to vvagaytsev/sglang that referenced this pull request Nov 19, 2026
With --fp8-gemm-backend=aiter on gfx950, a native MXFP8 checkpoint
(MiniMax-M3) resolves to gfx95_mxfp8_aiter_1x32. Load time shuffles the
weight (16, 16) in place where aiter's preshuffled kernel takes it and
keeps the [N, K/32] ue8m0 scales as loaded; apply runs
aiter_mxfp8_blockscaled_linear, i.e. aiter's gemm_a8w8_blockscale with
its tuned MiniMax-M3 table and its own split-K buffers.

This drops the ROCm/aiter#5817 entry it used before: the shuffled-scale
quant kernel, the exact-tune gating, the decode-graph checks and the
sglang-owned split-K workspace. aiter main covers every M itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants