Repository navigation
[FlyDSL] [Feature] Add MiniMax-M3 gfx950 dense MXFP8 per-1x32 preshuffle GEMM - #5817
amd-yashagar wants to merge 1 commit into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
89a1a5a to
62e9d20
Compare
ade0c42 to
42fbbc3
Compare
42fbbc3 to
98b9bd9
Compare
johannes-graner
left a comment
There was a problem hiding this comment.
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.
- AOT jobs fail on
fused_split_k - Scale-size check does not match the mfma_tile layout
- Test passes on wrong output and times only a cache-hot loop
- Tests skip M=8320 and do not cover the new contracts
- Define the
splitk_workspacecontract - Output dtype is not part of the tuned-row lookup
- Share accepted-row validation between runtime and AOT
- Fold
_lookup_tunedintoget_mxscale_preshuffle_config - Decode is slower than the existing
gemm_a8w8_mxfp8_bpreshuffle
Up to you:
- Wrapper input validation
- Shared test and tuner fixtures
Lower importance:
- Tuner help text lists fp6
| "k": int(row["K"]), | ||
| "cu_num": int(row.get("cu_num", "0")), | ||
| "gfx": row.get("gfx", "").strip(), | ||
| **parsed, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Item 3: Test passes on wrong output and times only a cache-hot loop (category: tests)
- The result of
checkAllcloseis 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_perftestrotates 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_argsso that rotations times the per-call footprint exceeds the cache, and setnum_iters >= num_rotate_args.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Item 4: Tests skip M=8320 and do not cover the new contracts (category: tests)
- The
wantedfilter drops M=8320 without a message, although the table has 7 rows at M=8320. - The new behaviour is not tested:
- a
require_tuned=Truemiss; - 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).
- a
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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 undersizedOut,Outwith 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).
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
a98b765 to
2cecb98
Compare
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
|
aiter main now covers what this PR added: |
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.
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:
Test Plan
Test Result
Submission Checklist