Repository navigation
[HIP] [OPUS] [FlyDSL] gfx950 MXFP8 bmm: 1x32 weight scales, grouped XCD order, MiniMax-M3 configs - #6060
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The shared rowwise test input weakens existing square-block scale-indexing coverage, and one public layout description incorrectly implies 1x128 support.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Extends the gfx950 FlyDSL MXFP8 GEMM path for MiniMax-M3’s 1x32 weight scales and improves tile ordering.
Changes:
- Adds 1x32 scale support across kernel, dispatch, and AOT.
- Adds grouped XCD swizzling and conditional split-K LDS storage.
- Adds MiniMax-M3 tuning rows and test coverage.
| File | Description |
|---|---|
op_tests/test_gemm_group32_interface.py |
Tests 1x32 routing and 1x128 rejection. |
op_tests/test_flydsl_batched_gemm.py |
Adds 1x32 numerical coverage. |
aiter/ops/flydsl/kernels/bmm_a8w8_mxscale_gfx950.py |
Implements scale loading, XCD swizzling, and LDS sizing. |
aiter/ops/flydsl/batched_gemm_a8w8.py |
Registers gfx950 1x32 dispatch. |
aiter/ops/flydsl/batched_gemm_a8w8_gfx950.py |
Extends parsing, validation, and launch configuration. |
aiter/ops/batched_gemm_op_a8w8.py |
Documents the public 1x32 contract. |
aiter/configs/model_configs/minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv |
Adds 324 MiniMax-M3 tuned configurations. |
aiter/aot/flydsl/gemm.py |
Adds 1x32 AOT compilation wiring. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
41fb2df to
2e00a4d
Compare
2e00a4d to
70f36c1
Compare
|
@valarLip could you please take a look at these changes when you have a moment? |
|
@coderfeli could you please take a look at this PR? |
i would like this style more, thank you both for your great works @andrei-kochin @sshlyapn |
valarLip
left a comment
There was a problem hiding this comment.
I checked this at 2471108c. The new 1x32 path computes correctly. I ran it on gfx950 against a dequantized fp32 reference, and everything passed with a max relative error under 3e-3. The cases covered:
- K % 128 == 64 (half step, byte-slot scale panel);
- a 1x128 x_scale with a 1x32 w_scale;
- batch 3/5 with
_xcd4/_xcd3on a padded grid; - split-K with
_sps; - heuristic picks.
The PR's own route/rejects/1x32 tests (97) also pass. All 342 CSV rows parse and pass check_bmm_config, they don't collide with the existing mxscale tables, and the swizzle is a bijection for every M/N/batch I tried.
I see this has been split into #6439/#6440/#6441. The points below should carry over to whichever of those holds the same code.
1. Most of the large-M rows in the new CSV cannot be reached
get_mxscale_bpreshuffle_config looks up M, then getPaddedM(gl=0), then getPaddedM(gl=1):
- gl=0 only rounds M > 4096 up to a multiple of 128;
- gl=1 clamps any
M > 8192 && N > 4096to 8192.
So for the 14 shapes with N > 4096, the 12288/16384/24576/32768/49152 rows are used only when M equals the bucket exactly.
Here is the real lookup at N = K = 6144 on this head:
| runtime M | row used |
|---|---|
| 12288 | 12288 (t192x256x128_nb3_bd2_xcd4) |
| 12300, 16000, 20000, 30000, 40000, 100000 | 8192 (t256x256x128_nb2_bd1_xcd4) |
| 24576 | 24576 |
For N = 1536 (gl=1 rounds to the next power of 2), M = 100000 misses entirely and falls back to the heuristic.
The "24k-128k: 1.33-1.35x" in the description therefore mostly applies only at the exact tuned M. Possible fixes:
- tune at the M values
getPaddedMactually produces; - or keep only one large-M row per shape and drop the rest, so the table doesn't suggest coverage it lacks.
2. The heuristic change also moves the 32x32 / 128x128 paths
The description says "no change to the 32x32 / 128x128 paths". However, pick_bmm_kernel_name now returns _xcd4 instead of _xcd for every b_direct pick, whatever the w_scale block. An untuned DeepSeek-V4 shape such as b=1, M=4096, N=1536, K=1024 with 128x128 scales now gets t256x256x128_w1x4_nb2_sk1_bd1_xcd4.
I ran 8 such cases (32x32 and 128x128, b = 1/3/5/16) on GPU and they are numerically correct, so this is not a bug. It is a behaviour change on those paths, though, and in this PR they are covered only indirectly through the heuristic. Please say so in the description, and either back it with a perf number for a DSV4 shape or keep _xcd for the square blocks.
3. Some configs the parser and checker accept are not what they say
-
Split-K drops the XCD order without saying so. In the kernel,
splits > 1takes the 1-D split branch first, soxcd_order/xcd_swizzlenever apply.check_bmm_configstill accepts e.g...._sk2_bd1_xcd4, which compiles and caches as a separate kernel identical to..._sk2_bd1. Neither the heuristic nor this CSV produces that combination today. A tuner sweeping the flags would, and its timing would be credited to a swizzle that never ran. Rejectingsplits > 1 and xcd_orderincheck_bmm_configcloses this. -
Kernel names have more than one spelling.
_xcd(?P<xcd_swizzle>\d*)accepts digits the builder never emits. On this head:_xcd0parses to swizzle 0 and rebuilds as_xcd;_xcd04rebuilds as_xcd4;_xcd1is accepted and kept as its own name, althoughxcd_swizzle > 1is the only case that re-tiles, so it is the same kernel as_xcdcompiled twice.
Restricting the regex to
_xcd(?:[2-9]|[1-9]\d+)?and rejectingxcd_swizzle == 1keeps one name per kernel. That matters for CSV/AOT dedup. -
The shape check got looser.
_scale_block(n, w_scale.shape[1], ..., W_SCALE_ROWS)now accepts a 1-row w_scale without looking at the K edge. A directrun_bmm_a8w8_mxfp8_gfx950call with a 1x128 w_scale ([B, N, K/128]) used to fail there with a message naming the block. It now gets through and only fails later inpick_bmm_kernel_name/check_bmm_config, with "no kernel config runs" or a generic scale-block error. Checkingw_scale_n == 1 implies w_scale_k == 32at this point would keep the early, clear error.
4. Duplication in the new swizzle
- The M-group re-tiling (
num_wgid_in_group/first_pid_m/group_size_m/wgid_in_group) repeatsxcd_remap_bx_byinmfma_preshuffle_pipeline.pyline for line. A shared helper keeps a future tail-group fix from landing in only one place. - When
xcd_swizzle > 1, thebid_x, bid_y, bid_zassignment just above is overwritten in full, so it only adds reading cost. Computing the N-fastest mapping in anelsebranch would make clear which mapping is in effect. - The
xcd_swizzle < 0 or (xcd_swizzle and not xcd_order)rule is written twice, inbmm_kernel_nameandcheck_bmm_config. If the rule is tightened (as in section 3), it must change in both places.
5. Tests
- Wasted work in
test_batched_gemm. Each a8w8 candidate now has its ownw_blkand reference. On gfx950, which has no a8w4,w_bnkandref = run_torch_wo_a(o_mbn, w_bnk, dtype)are still generated and computed but never used. That is a full-size randn and a BF16 einsum per case (up to M = 16384, b = 16) for nothing. They could be built only when a8w4 is a candidate. - A missing reject case. The rewritten
test_mxscale_bpreshuffle_rejects_row_scalescovers a 1x128 weight block. Nothing covers a 1x32 weight paired with a 128-wide (column-major) x_scale, which the 2-D route must also reject. Today_RUNNERShas no("gfx950", "1x32", True)entry. If one is added, or if thek // x_scale.shape[-1] == 128check changes, no test would fail.
| gfx950,256,2048,6144,6144,1x32,flydsl,bmm,1,76.382,flydsl_bmm_mxfp8_mfma_t256x192x128_w1x4_nb2_sk1_bd1_xcd4,2024.28,1009.01,0.0 | ||
| gfx950,256,4096,6144,6144,1x32,flydsl,bmm,1,145.303,flydsl_bmm_mxfp8_mfma_t128x256x128_w1x4_nb3_sk1_bd2_xcd4,2128.23,792.91,0.0 | ||
| gfx950,256,8192,6144,6144,1x32,flydsl,bmm,1,275.907,flydsl_bmm_mxfp8_mfma_t256x256x128_w1x4_nb2_sk1_bd1_xcd4,2241.61,694.06,0.0 | ||
| gfx950,256,12288,6144,6144,1x32,flydsl,bmm,1,403.02,flydsl_bmm_mxfp8_mfma_t192x256x128_w1x4_nb3_sk1_bd2_xcd4,2301.9,664.43,0.0 |
There was a problem hiding this comment.
This row (and the 16384/24576/32768/49152 ones for N > 4096) is reached only at exactly this M. getPaddedM gl=0 rounds M to a multiple of 128 and gl=1 clamps M > 8192 && N > 4096 to 8192. So M = 12300, 16000, 20000, 30000, 40000 or 100000 at N = K = 6144 all use the 8192 row above. See section 1 of the review.
There was a problem hiding this comment.
Yes, for N>4096 shapes, untuned M above 8192 falls back to the 8192 row through find_padded_m_row. However, those prefill M values are tuned at common max num batched tokens settings (8k, 12k, 16k, 24k, 32k, 48k, 64k). Full chunked-prefill steps run at exactly that M, so they hit these rows
| # The XCD tile order wants the N x batch tiles in 8s, as split K does. | ||
| xcd_order = cfg["b_direct"] and runs({**cfg, "xcd_order": True}) | ||
| return bmm_kernel_name(**cfg, splits=splits, xcd_order=xcd_order) | ||
| xcd = {"xcd_order": True, "xcd_swizzle": 4} |
There was a problem hiding this comment.
This applies to every b_direct pick, so untuned 32x32 / 128x128 (DeepSeek-V4) shapes move from _xcd to _xcd4 too. For example, b=1, M=4096, N=1536, K=1024 with 128x128 scales now gets t256x256x128_w1x4_nb2_sk1_bd1_xcd4. It is numerically fine on GPU, but it contradicts "no change to the 32x32 / 128x128 paths" in the description.
There was a problem hiding this comment.
I actually verified this as default for 32x32 and 128x128 as well, and noticed neutral to positive impact, but I limited swizzle back only for 1x32 weight scales to minimize the changes for now
| raise ValueError( | ||
| "[FlyDSL gfx950] a column-major x_scale is 1x128 blocks at batch 1" | ||
| ) | ||
| if xcd_swizzle < 0 or (xcd_swizzle and not xcd_order): |
There was a problem hiding this comment.
This doesn't reject splits > 1 with xcd_order, but the kernel's split branch ignores the XCD order entirely. ..._t64x128x128_w1x4_nb3_sk2_bd1_xcd4 passes here and compiles as a separate kernel identical to ..._sk2_bd1, so a tuner would credit its timing to a swizzle that never ran. The same rule also lives in bmm_kernel_name, so both copies would need to change.
There was a problem hiding this comment.
Thanks, fixed, split K combined with a swizzle number is now rejected
| r"_t(?P<tile_m>\d+)x(?P<tile_n>\d+)x(?P<tile_k>\d+)" | ||
| r"_w(?P<m_warp>\d+)x(?P<n_warp>\d+)_nb(?P<num_buffers>\d+)_sk(?P<splits>\d+)" | ||
| r"(?:_bd(?P<b_ahead>\d+))?(?P<b_nt>_nt)?(?P<xcd_order>_xcd)?(?P<per_stage>_sps)?$" | ||
| r"(?:_bd(?P<b_ahead>\d+))?(?P<b_nt>_nt)?(?P<xcd_order>_xcd(?P<xcd_swizzle>\d*))?" |
There was a problem hiding this comment.
\d* admits names the builder never emits: _xcd0 rebuilds as _xcd, _xcd04 as _xcd4, and _xcd1 is kept although swizzle 1 doesn't re-tile, so it is the same kernel as _xcd under a second name and cache entry. Something like _xcd(?:[2-9]|[1-9]\d+)?, plus rejecting xcd_swizzle == 1, keeps one name per kernel.
| scale_args = ( | ||
| _scale_block(k, x_scale.shape[2], "x_scale K"), | ||
| _scale_block(n, w_scale.shape[1], "w_scale N"), | ||
| _scale_block(n, w_scale.shape[1], "w_scale N", W_SCALE_ROWS), |
There was a problem hiding this comment.
With W_SCALE_ROWS the N edge may now be 1 whatever the K edge is, so a 1x128 w_scale ([B, N, K/128]) passes here. Before this PR it failed at this line with a message naming the block; now it fails later, in pick_bmm_kernel_name / check_bmm_config, with a vaguer error. Checking that a 1-row w_scale is 1x32 here keeps the early error.
There was a problem hiding this comment.
Fixed. It now fails up front with "a 1-row w_scale must be 1x32 blocks"
| tile = bid_x % 8 * per_xcd + bid_x // 8 | ||
| rest = tile // (N // tile_n) | ||
| bid_x, bid_y, bid_z = rest % m_tiles, tile % (N // tile_n), rest // m_tiles | ||
| if const_expr(xcd_swizzle > 1): |
There was a problem hiding this comment.
These lines repeat xcd_remap_bx_by (mfma_preshuffle_pipeline.py) line for line. A shared helper would keep a tail-group fix in one place. Also, in this branch the bid_x, bid_y, bid_z computed on the line above are all overwritten, so the N-fastest mapping could move to an else branch.
There was a problem hiding this comment.
Applied, I unified and reused the logic between implementations
| @@ -198,7 +200,7 @@ def test_batched_gemm(b, m, n, k, dtype, layout): | |||
| y_out = y_phys | |||
|
|
|||
| ref = run_torch_wo_a(o_mbn, w_bnk, dtype) | |||
There was a problem hiding this comment.
On gfx950 (no a8w4) every a8w8 candidate uses its own refs[name], so w_bnk and this ref are never read. That is a full-size randn and a BF16 einsum per case (up to M=16384, b=16). They could be built only when a8w4 is a candidate.
There was a problem hiding this comment.
Fixed. They're built only when a8w4 runs, and each candidate uses its own reference
| ) | ||
| with pytest.raises(NotImplementedError, match="1x32"): | ||
| gemm_op_a8w8.gemm_a8w8_blockscale_bpreshuffle(*_mxscale_operands(w_rows=1)) | ||
| with pytest.raises(NotImplementedError, match="1x128"): |
There was a problem hiding this comment.
This covers a 1x128 weight block. Nothing covers a 1x32 weight paired with a 128-wide (column-major) x_scale, which must also be rejected. Adding ("gfx950", "1x32", True) to _RUNNERS, or changing the k // x_scale.shape[-1] == 128 check, would currently go unnoticed.
There was a problem hiding this comment.
Added a reject test
valarLip
left a comment
There was a problem hiding this comment.
Re-checked at bb68f70. The kernel side looks right to me:
- the 1x32 panel row mapping;
- half-step K;
- dropping the LDS flag at
splits == 1; - the
_xcd<g>names round-trip, and the swizzled tile map is a bijection on every padded grid / batch > 1 / short last group I simulated; - the new CSV's 342 rows all parse, and they merge with the dsv4 / dsv41 tables without a duplicate key.
What remains is in table loading and dispatch. Inline comments point at the lines.
1. The new w_scale_block check in _load_mxscale_bpreshuffle_tuned can fail the whole table
Both of these reproduce on CPU (pandas + AITER_CONFIGS.update_config_files):
- A merged table fills the missing column with
0, not a blank.update_config_filesfills columns a source lacks with_FILL_DEFAULTS.get(c, 0)(aiter/jit/core.py). So merging a table from before the column (viaAITER_CONFIG_GEMM_A8W8_BLOCKSCALE_MXSCALE_BPRESHUFFLE=new.csv:old.csv, or amodel_configs/file) givesw_scale_block = '0', and the loader raisesw_scale_block ['0'] not in (...). Every gfx950 E8M0 bpreshuffle GEMM in the process then fails, where on the base those rows just never matched.with_mxscale_w_scale_block's docstring describes this case as blank cells, but the merge never produces them. drop_duplicates()runs before the blanks are filled. A shape with one blank row and one128x128row passes the duplicate check, which sees NaN and'128x128'as different keys. After the fill they share a key, andto_dict("index")raisesDataFrame index must be unique for orient='index'on the first call.
Normalising before both checks would avoid each failure: treat 0/blank as the default first, then de-duplicate and check.
2. A blank w_scale_block means 128x128 at runtime but 1x32 in AOT for blockscale-table mxfp8 rows
The runtime loader now reads a blank cell as 128x128 for every row of the blockscale table. AOT parse_csv changed the default only for kernelId=bmm rows. Its kernelId=mxfp8 branch still uses row.get("w_scale_block") or "1x32". So for such a row, AOT compiles the 1x32 build while runtime runs 128x128 and JIT-compiles on first use.
3. 1x32 FlyDSL rows and non-bf16 outputs
The batched tuner no longer rejects FlyDSL for 1x32, so it can now write libtype=flydsl 1x32 rows. It times bf16 only, and the table has no dtype key. A tuned 1x32 FlyDSL row then raises Out must be bf16 (a RuntimeError from the runner) for an fp32 or fp16 call. On the base, every 1x32 call went to OPUS, which writes fp32.
The new bf16 check covers only the untuned branch, and raises NotImplementedError there, so the same condition surfaces as two exception types. Checking it once where libtype == "flydsl" (and falling back to OPUS when a kid runs the shape) would cover tuned and untuned 1x32 alike.
4. Smaller points
-
Pairing check order. In
_gemm_mxscale_bpreshuffle, the x_scale/w_scale pairing check comes after the lookup and the libtype check. As a result, a call whose row will be discarded anyway (for example, 1x128 x_scale with 1x32 w_scale):- still logs "untuned" on a miss;
- raises
NotImplementedErrorif the row isn't FlyDSL; - silently drops the row if it is FlyDSL.
Checking the pairing first avoids all three.
-
_opus_1x32_bpreshuffle_kidrepeats the kid search thatbmm_a8w8_mxscale_opus_bpreshufflealready runs whenkernelId=None. Its cache key includes M, so decode sees a fresh search per M. -
test_mxscale_table_tuner_times_bmmgenerates candidates for N=4608 (bmm_candidates(1, 4608, 6144, block)) but validates them with N=6144 (check_bmm_config(6144, 6144, ...)). -
test_batched_untuned_1x32_runs_flydsl_where_opus_cannotclears_opus_1x32_bpreshuffle_kidat the end, not in afinally. A failing assert leaves kids computed under the fakedgfx950in the module cache, whose key has no gfx. -
test_mxscale_bpreshuffle_32_wide_w_blockscale_xis parametrized overrow=[None, BMM_ROW]. With a 1x128 x_scale and a 1x32 / 32x32 w_scale, dispatch always drops the row, so 6 of its 12 GPU cases run the same heuristic kernel twice. -
GPU coverage of the new untuned 1x32 routing. The new 1x32 GPU case in
test_flydsl_batched_gemm.pycallsrun_bmm_a8w8_mxfp8directly. The public entry's new untuned routing (OPUS kid, else FlyDSL when K % 128 != 0) is covered only by the CPU mock test. -
Duplicated
check_bmm_configwrapper. "trycheck_bmm_config/except ValueError→ bool" now exists four times:batched_gemm_a8w8_gfx950._runs, the batched tuner's_runs,runs_row_majorin the 2-D tuner, and the test's_bmm_legal. Exporting_runswould leave one. -
AOT FlyDSL depends on the OPUS policy. It now gets block → (rows, cols) from
opus.policy.mxscale_bmm_groups_of_block, whose error reads "unsupported OPUS MXFP8 BMM scale block". That mapping fits better ingemm_op_commonnext tomxscale_w_scale_block. -
Launcher docstring. It says
xcd_swizzle > 0re-tiles. The code branches on> 1, andxcd_swizzle_runsrejects 1.
| table for preshuffled weights.""" | ||
| path = AITER_CONFIGS.AITER_CONFIG_GEMM_A8W8_BLOCKSCALE_MXSCALE_BPRESHUFFLE_FILE | ||
| df = pd.read_csv(path).drop_duplicates() | ||
| df = with_mxscale_w_scale_block(pd.read_csv(path).drop_duplicates(), path) |
There was a problem hiding this comment.
Two ways this raises for the whole table (both reproduced on CPU): a merge with a table from before the column fills it with 0, which this check rejects; and drop_duplicates() runs before the blanks become 128x128, so a blank row and a 128x128 row of one shape end up with the same key and to_dict("index") raises. See section 1.
There was a problem hiding this comment.
Fixed. 0 and blank cells now read as the default (mxscale_w_scale_block_cell) before the duplicate check. A table merged with an older one loads, and a blank row plus a 128x128 row of the same shape loads with a warning; the first row is used.
| layouts = ( | ||
| (False, True) | ||
| if row.get("w_scale_block", "128x128").strip() == "128x128" | ||
| if (row.get("w_scale_block") or "128x128").strip() == "128x128" |
There was a problem hiding this comment.
Only the bmm branch moved to a 128x128 default. The kernelId=mxfp8 branch above still reads a blank as 1x32, while the runtime loader now reads it as 128x128 for every row of this table (section 2).
There was a problem hiding this comment.
Fixed. AOT and the runtime share mxscale_w_scale_block_cell now: a blank cell is 128x128 in the blockscale table and 1x32 in the mxfp8 table.
| kid = _opus_1x32_bpreshuffle_kid(g, m, n, k, dtype) | ||
| if kid is not None: | ||
| libtype = "opus" | ||
| elif dtype != dtypes.bf16: |
There was a problem hiding this comment.
This covers untuned 1x32 only. With the tuner now writing 1x32 FlyDSL rows (timed in bf16, no dtype key), a tuned one raises the runner's RuntimeError('Out must be bf16') for fp32/fp16, which OPUS served on the base. One check where libtype == "flydsl" would cover both (section 3).
There was a problem hiding this comment.
Done. There is one check where libtype is flydsl, for tuned and untuned rows and every w_scale block. Non-bf16 output goes to OPUS when one of its kids runs the shape; otherwise it raises NotImplementedError.
| # (1x128 with 128x128, else 1x32); bmm reads every other pairing too, its | ||
| # heuristic picks. | ||
| if x_block != (_BLOCKSCALE_X_BLOCK if w_scale_block == "128x128" else 32): | ||
| config = backend = None |
There was a problem hiding this comment.
Checking the pairing before the lookup would skip the 'untuned' warning and the libtype check for a row that is dropped here anyway.
There was a problem hiding this comment.
Done, the pairing is checked before the lookup.
| return _batched_gemm_a8w8_mxscale_impl(x, wo_a, x_scale, w_scale, dtype=dtype) | ||
|
|
||
|
|
||
| @functools.lru_cache(maxsize=1024) |
There was a problem hiding this comment.
bmm_a8w8_mxscale_opus_bpreshuffle runs this same kid search when kernelId=None, and with M in the key decode searches per M.
There was a problem hiding this comment.
This search is the FlyDSL fallback from r4334427972: dispatch has to know whether an OPUS kid runs the shape before choosing OPUS, and with kernelId=None OPUS raises ValueError instead of falling back. The kid found here is passed on as kernelId (already at bb68f70), so OPUS only validates it and doesn't search again. M stays in the key because the pick depends on M (1x32: kid 9713 from M>=64 with >=256 wide tiles, 9703 from M>=256). Each M is searched once and cached; OPUS's own kernelId=None path searches on every call. The helper is now _opus_bpreshuffle_kid, since the non-bf16 check also uses it.
| batched._batched_gemm_a8w8_mxscale_bpreshuffle_impl( | ||
| *operands, dtype=torch.float16 | ||
| ) | ||
| batched._opus_1x32_bpreshuffle_kid.cache_clear() |
There was a problem hiding this comment.
Not in a finally: a failing assert above leaves kids computed under the faked gfx950 in the cache, whose key has no gfx.
There was a problem hiding this comment.
Fixed, the cache clears are in finally.
| @pytest.mark.parametrize("m,n,k", [(1, 1536, 1024), (37, 5120, 1536), (300, 512, 5120)]) | ||
| @pytest.mark.parametrize("row", [None, BMM_ROW]) | ||
| @pytest.mark.parametrize("w_rows", [1, 32]) | ||
| def test_mxscale_bpreshuffle_32_wide_w_blockscale_x(monkeypatch, m, n, k, row, w_rows): |
There was a problem hiding this comment.
With a 1x128 x_scale and a 1x32 / 32x32 w_scale, dispatch always drops the row, so row=BMM_ROW reruns the row=None case.
There was a problem hiding this comment.
Fixed, removed the row parameter.
| return names | ||
| row_major = {**scale_args, "x_scale_transposed": False} | ||
|
|
||
| def runs_row_major(name): |
There was a problem hiding this comment.
The fourth copy of try check_bmm_config / except → bool (with batched_gemm_a8w8_gfx950._runs, the batched tuner's _runs and the test's _bmm_legal).
There was a problem hiding this comment.
Done. bmm_config_runs in batched_gemm_a8w8_gfx950 is now the only wrapper; both tuners and the test use it.
| rows, cols = (int(v) for v in w_scale_block.split("x")) | ||
| if rows != cols: | ||
| raise ValueError(f"{kernel_name}: no AOT wiring for a {w_scale_block} w_scale") | ||
| from aiter.ops.opus.policy import mxscale_bmm_groups_of_block |
There was a problem hiding this comment.
FlyDSL AOT now depends on the OPUS policy for this mapping, and its error says 'unsupported OPUS MXFP8 BMM scale block'. It fits better in gemm_op_common next to mxscale_w_scale_block.
There was a problem hiding this comment.
Done. mxscale_bmm_groups_of_block is in gemm_op_common now, with a neutral error message; opus.policy imports it from there.
| contiguous run of tiles so neighbours share its L2. x_scale_k and | ||
| w_scale_n x w_scale_k are the e8m0 block edges, each 32 or 128. | ||
| w_scale_n may also be 1 with w_scale_k 32 (1x32), a scale per B row. | ||
| xcd_swizzle > 0 re-tiles the xcd_order run M-major in groups of |
There was a problem hiding this comment.
The code branches on xcd_swizzle > 1, and xcd_swizzle_runs rejects 1.
There was a problem hiding this comment.
Fixed, it says xcd_swizzle >= 2.
…iMax-M3 configs - Accept 1x32 (OCP MX) w_scale [B, N, K/32] in the gfx950 mxscale bmm, dispatch and AOT paths; 32x32 / 128x128 are unchanged. - Add xcd_swizzle (_xcd<g> names): M-major groups of g tiles inside each XCD's run; the b_direct heuristic now picks _xcd4. - Reserve the split-K flag in LDS only when K is split. - Add the MiniMax-M3 1x32 tuned CSV (TP1/2/4, M 1..64k). Signed-off-by: Sergei Shliapnikov <[email protected]>
…split-K swizzle names at parse time, and pass splits to the LDS layout.
- Tune bmm 1x32 in the --mxscale_table tuner and point the README there. - Share bmm_candidate_names between tuners; split variants drop swizzle and xcd order. - Add FlyDSL runners for column-major 1x32 and 32x32 x_scale. - Fall back to FlyDSL for untuned 1x32 when OPUS has no kid for the shape. - Keep tuned rows on their tuned x_scale block; AOT covers every dispatched layout. - Move the swizzle rule to xcd_swizzle_runs and the name suffix to bmm_config_name. - check_bmm_config returns the LDS layout used by the launcher.
bb68f70 to
c65f871
Compare
- Read a blank or merge-filled 0 w_scale_block cell as the default in the runtime loader and AOT alike; a blank row repeating a 128x128 shape loads. - gfx950 flydsl writes bf16 only: non-bf16 output runs OPUS's kid, tuned row or not, and raises when no kid runs the shape. - Check the x/w scale pairing before the table lookup. - Move mxscale_bmm_groups_of_block to gemm_op_common; export bmm_config_runs as the one check_bmm_config -> bool wrapper. - Tests: try/finally cache clears, N=4608 in the tuner test, drop the redundant row parametrize, GPU check of the public untuned 1x32 entry.
c65f871 to
94d5d6a
Compare
valarLip
left a comment
There was a problem hiding this comment.
Re-checked at 94d5d6a. This looks good to merge once the four small points below are addressed. Inline comments point at the lines.
The two loader failures from the last round are fixed. Blank or 0 cells are normalised before the check, and duplicates are dropped after the normalisation. Both of last round's repros now load. On the kernel side, I found nothing wrong in the 1x32 scale path:
- the panel sizing;
- the global→LDS offsets;
- the per-row scale read;
- the split-K flag being reserved only when K is split;
- the
xcd_swizzletile map, which is a bijection with padded tiles still guarded.
All 2394 gfx950 bmm kernelNames in the shipped CSVs parse and pass check_bmm_config. The MiniMax CSV duplicates no shape, and AOT compiles what the runtime runs.
- The public docstring of
batched_gemm_a8w8_mxscale_bpreshuffleis stale for 32x32 / 128x128. It still says these blocks run "flydsl's heuristic off the table". On gfx950, though, any non-bf16 output now goes to OPUS, even over a tuned FlyDSL row, and raisesNotImplementedErrorwhen no OPUS kid runs the shape. Only the private_impldocstring says so. - The README states OPUS's K limit for 1x32. It says that for
1x32, "K a multiple of 128". FlyDSL now runs 1x32 at K ≡ 64 (mod 128), e.g. K = 576, which the group32 interface test asserts, so the tuner can produce such rows. _load_mxscale_bpreshuffle_tunedkeeps the first of two rows with the same key, not the faster one. A blank cell (read as 128x128) and an explicit128x128row of the same shape are different raw cells, so both survive the merge's lowest-usdedup. Themodel_configsglob is unsorted, so which row comes first can differ between machines. Sorting byusbeforeduplicated(...)would match the merge's rule._launch_configreturnsNonefor names that break the swizzle rule (e.g._sk2_..._xcd4,_xcd1), and runtime and AOT then disagree. At runtime,_require_configraises "unrecognised kernelName" for such a tuned row instead of falling back to the heuristic. AOT skips the same row silently. No shipped row has such a name. But a warning on both sides, plus a heuristic fallback at runtime, would make a bad hand-edited row visible without breaking the shape.
| where one of its kids runs the shape (N a multiple of 16, K of 128, bf16 | ||
| or fp32 out), else flydsl (bf16 out). | ||
| * gfx950, 32x32 or 128x128: the tuned row's libtype, opus or flydsl, | ||
| whichever was faster at that shape; flydsl's heuristic off the table. |
There was a problem hiding this comment.
On gfx950 a non-bf16 output now goes to OPUS here, even over a tuned FlyDSL row, and raises NotImplementedError when no OPUS kid runs the shape; only the _impl docstring says so.
There was a problem hiding this comment.
Done. The public docstring now has a gfx950 "any block" bullet: flydsl writes bf16 only, so another output runs OPUS (bf16 or fp32), even over a tuned flydsl row, and raises NotImplementedError where no OPUS kid runs the shape.
| have shape `[b,n/32,k/32]`. Per-row weight quantization (`1x32`) uses | ||
| weight scales `[b,n,k/32]` and activation scales `[m,b,k/32]`. It is supported | ||
| by OPUS kids 9700--9710 and 9713; the joint tuner skips FlyDSL candidates for this block. | ||
| by OPUS kids 9700--9710 and 9713, and by FlyDSL. |
There was a problem hiding this comment.
Line 62 below still says 1x32 needs K a multiple of 128, which is OPUS's limit; FlyDSL runs K = 576 (asserted in the group32 test).
There was a problem hiding this comment.
Fixed. For 1x32 it now says K a multiple of 64: OPUS needs 128, and FlyDSL also runs K = 64 mod 128 (e.g. 576).
| f"{path}: {int(repeated.sum())} rows repeat a tuned shape; " | ||
| f"using the first row of each." | ||
| ) | ||
| df = df[~repeated] |
There was a problem hiding this comment.
Keeps the first row, whose position depends on the unsorted model_configs glob. Sorting by us first would keep the faster one, as the merge does.
There was a problem hiding this comment.
Done. The loader sorts by us before dropping repeated keys, so the fastest row wins, as in the merge. The blank + 128x128 test now gives the later row the lower us and checks that it's the one used.
| cfg["xcd_order"] = xcd_order is not None | ||
| cfg["xcd_swizzle"] = int(xcd_swizzle or 0) | ||
| cfg["scale_preload"] = per_stage is None | ||
| if not xcd_swizzle_runs(cfg["xcd_swizzle"], cfg["xcd_order"], cfg["splits"]): |
There was a problem hiding this comment.
A tuned row named e.g. ..._sk2_..._xcd4 then makes _require_config raise at runtime, while AOT skips it silently. A warning on both sides and a heuristic fallback at runtime would surface it without breaking the shape.
There was a problem hiding this comment.
Done. Raising at runtime and skipping silently in AOT was already upstream's behaviour for any kernelName that doesn't parse; this PR only made more names unparseable (_xcd1, _sk<n>_xcd<g>). Now, for such a name, the gfx950 runner warns once and runs the heuristic's pick, and AOT prints Unknown FlyDSL BMM kernel name: ..., skipping. test_bmm_unrecognised_tuned_name_warns_and_runs_heuristic covers both.
- Document in the public batched entry that gfx950 non-bf16 output runs OPUS for every w_scale block, even over a tuned flydsl row. - README: 1x32 K is a multiple of 64 (FlyDSL runs K = 64 mod 128). - The mxscale loader keeps the fastest of repeated rows, as the merge does. - A gfx950 bmm kernelName that does not parse warns and runs the heuristic's pick at runtime; AOT warns instead of skipping silently.
|
Thanks @valarLip! All four points are addressed |
Conflicts: - aiter/ops/batched_gemm_op_a8w8.py: take upstream's scoped (gfx, cu_num) lookup from _device_arch_and_cu; keep our routing (untuned 1x32 tries an OPUS kid and falls back to FlyDSL when none runs the shape; non-bf16 tuned flydsl rows go to OPUS or raise). - csrc/opus_gemm/opus_bmm_mxscale_tune.py: keep upstream's local BMM_BLOCK_DATA_KIDS (1x32 -> 235); BMM_DATA_KIDS stays removed. op_tests/test_gemm_group32_interface.py: also patch _arch._device_arch_and_cu in the two CPU-tensor routing tests, since the impl now resolves the arch scope from the input device.
#6362, which this branch was stacked on, landed squashed as fc0a013. Every file except the 12 of the replay commit is therefore taken as main has it, which also leaves the PR's diff against main at those 12. Conflicts: - aiter/aot/flydsl/gemm.py: #6060 taught the hand-written AOT the gfx950 1x32 BMM (mxscale_bmm_groups_of_block) and to read a blank or 0 w_scale_block cell as the runtime's loaders do (mxscale_w_scale_block_cell). The replay calls the public entries, which take the scale block from the caller's w_scale, so none of that code returns. The cell reading does: _blocks() reads a cell through mxscale_w_scale_block_cell, 1x32 for the mxfp8 table and 128x128 for the others, as their loaders default. A 0 cell made it raise before. Main also brought #6060's BMM changes and #6946's launcher cache, which this branch had not been validated against. Ten rows from the tables they touch (gfx950 1x32, 32x32 and 128x128 through the 2D and batched entries, gfx950 mxfp8, gfx1250 batched and a8w8 bpreshuffle) replay into a cache that --check accepts, and on gfx950 the real calls of those rows and of the sizes between them (9 calls) all run from it under FLYDSL_RUNTIME_RUN_ONLY=1. Co-authored-by: Cursor <[email protected]>
…shuffled GEMM (opt-in) ATOM_MXFP8_1X32_PRESHUFFLE=1 (default 0) holds native FP8 weights with 1x32 E8M0 scales (16, 16)-preshuffled on gfx950, so native_quant_linear's existing AITER call (gemm_a8w8_blockscale, isBpreshuffled=True) runs them on FlyDSL's MXFP8 bmm / mxpsh kernels, picked by AITER's mxscale bpreshuffle tuned table, instead of the Triton group32 GEMM. Weight bytes and scales stay the checkpoint's, so the output is bit-identical. The target is the MiniMax-M3.1 DSpark draft, whose MXFP8 linears may not be re-quantized; AITER already ships MiniMax-M3 1x32 rows for its shapes (ROCm/aiter#6060). weight_is_stored_preshuffled answers for both the load and the weight sync. Tests: truth table, dispatch, and a gfx950 bit-exact comparison against the row-major path.
…ITER's group32 GEMM Native FP8 weights with 1x32 E8M0 scales (MXFP8; e.g. the MiniMax-M3.1 DSpark draft, whose linears are kept as shipped) are now (16, 16)-preshuffled on gfx950, like the 32x32 group32 weights already are, under the same ATOM_GROUP32_WEIGHT_PRESHUFFLE switch. native_quant_linear's existing AITER call then runs them on FlyDSL's MXFP8 bmm / mxpsh kernels instead of the Triton group32 GEMM. Weight bytes and scales stay the checkpoint's, so the output is bit-identical. AITER ships MiniMax-M3 1x32 rows for these shapes (ROCm/aiter#6060). gfx1250 keeps 1x32 weights row-major. Tests: truth table, dispatch, and a gfx950 bit-exact comparison against the row-major path.
#6362, which this branch was stacked on, landed squashed as fc0a013. Every file except the 12 of the replay commit is therefore taken as main has it, which also leaves the PR's diff against main at those 12. Conflicts: - aiter/aot/flydsl/gemm.py: #6060 taught the hand-written AOT the gfx950 1x32 BMM (mxscale_bmm_groups_of_block) and to read a blank or 0 w_scale_block cell as the runtime's loaders do (mxscale_w_scale_block_cell). The replay calls the public entries, which take the scale block from the caller's w_scale, so none of that code returns. The cell reading does: _blocks() reads a cell through mxscale_w_scale_block_cell, 1x32 for the mxfp8 table and 128x128 for the others, as their loaders default. A 0 cell made it raise before. Main also brought #6060's BMM changes and #6946's launcher cache, which this branch had not been validated against. Ten rows from the tables they touch (gfx950 1x32, 32x32 and 128x128 through the 2D and batched entries, gfx950 mxfp8, gfx1250 batched and a8w8 bpreshuffle) replay into a cache that --check accepts, and on gfx950 the real calls of those rows and of the sizes between them (9 calls) all run from it under FLYDSL_RUNTIME_RUN_ONLY=1. Co-authored-by: Cursor <[email protected]>
…ITER's group32 GEMM Native FP8 weights with 1x32 E8M0 scales (MXFP8; e.g. the MiniMax-M3.1 DSpark draft, whose linears are kept as shipped) are now (16, 16)-preshuffled on gfx950, like the 32x32 group32 weights already are, under the same ATOM_GROUP32_WEIGHT_PRESHUFFLE switch. native_quant_linear's existing AITER call then runs them on FlyDSL's MXFP8 bmm / mxpsh kernels instead of the Triton group32 GEMM. Weight bytes and scales stay the checkpoint's, so the output is bit-identical. AITER ships MiniMax-M3 1x32 rows for these shapes (ROCm/aiter#6060). gfx1250 keeps 1x32 weights row-major. Tests: truth table, dispatch, and a gfx950 bit-exact comparison against the row-major path.
…ffled GEMM The MiniMax-M3.1 DSpark draft keeps its linears as shipped: MXFP8, FP8 E4M3 with a 1x32 E8M0 scale, read as native group32 weights. Row-major, they ran on the Triton group32 GEMM (gemm_afp8wfp8, default config). The draft now asks for its qkv / o / gate_up / down weights to be (16, 16)-preshuffled (needs_preshuffled_weight), and weight_is_stored_preshuffled honours that for a 1x32 weight on gfx950 under ATOM_GROUP32_WEIGHT_PRESHUFFLE. native_quant_linear's existing AITER call then runs them on FlyDSL's MXFP8 bmm, whose MiniMax-M3 1x32 tuned rows (ROCm/aiter#6060) cover these shapes. Only the layout changes: the output is bit-identical. Every other 1x32 weight, and every other arch, stays row-major. Tests: the 1x32 truth table, load-vs-sync parity on the native group32 branch, and a gfx950 bit-exact check at the draft's TP4 shapes.


Motivation
#5896 added the gfx950 FlyDSL MXFP8 e8m0 GEMM/bmm, but only for square weight-scale blocks (32x32, 128x128, DeepSeek-V4/V4.1). OCP MX checkpoints such as MiniMax-M3 carry 1x32 weight scales (one e8m0 per weight row per 32 K), so they could not use it. This PR extends the same kernel, with no new kernel and no change to the 32x32 / 128x128 paths.
Resolves: #5916
Changes
w_scale[B, N, K/32]is accepted (W_SCALE_ROWS = (1, 32, 128)).The kernel reads the B-scale panel one row per B row, the same way it reads A's.
This is wired through dispatch (
_RUNNERS,gemm_a8w8_blockscale_bpreshuffle) and AOT.x_scale: no repack, independent of config.xcd_swizzle(_xcd<g>in kernel names): inside each XCD's contiguous run of tiles(
xcd_order), tiles are re-ordered M-major in groups ofgM tiles, asxcd_remap_bx_bydoes. Fewer B column blocks are live per XCD, so L2 reuse improves.b_directconfigs now picks_xcd4instead of_xcd._xcdCSV rows parse and run unchanged.few large tiles fit.
model_configs/minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csvtest_flydsl_batched_gemm.pyadds a 1x32 case (weight magnitudes change everyrow).
test_gemm_group32_interface.pyroutes 1x32 and checks that 1x128 is still rejected.Performance (MI355, gfx950, 256 CU)
vLLM MiniMaxAI/MiniMax-M3-MXFP8 performance (TP4, 8k/1k random dataset):
Speedup of this PR (tuned CSV) over each MXFP8 1x32 baseline: geomean over the 18 M3 shapes.
Above 1 means this PR is faster.
rocm_native._mxfp8_linear_kernelwith vLLM main's own tile selection, Triton 3.7.1.gemm_afp8wfp8as of [Triton/Gluon] Unify afp8wfp8 GEMM kernels #5862, which unified [Triton/Gluon] [JIT] [Feature] Add tuned native group32 A8W8 Triton GEMM for gfx950 #5750's group32 kernel into it. AITER ships no MiniMax-M3 tables for it, so its configs were tuned on the same shapes with the same protocol, in an earlier interleaved run.Effect of the tile order alone: 15 tuned
_xcd4rows were re-timed with the same config,changing only the tile order to
_xcd(#5896's order) or to no XCD order._xcd4vs_xcd: never slower, 0.3-27% faster._xcd4vs no XCD order: about equal at M <= 16k (-1% to +5%, one +20% case),5-26% faster at M >= 32k.
Protocol:
Tests
op_tests/test_gemm_group32_interface.py: 146 passed.op_tests/test_flydsl_batched_gemm.py, 1x32 / 32x32 / 128x128 a8w8:Not a duplicate
bmm_a8w8_mxscale.