Repository navigation
[Triton/Gluon] [GFX1250] MiniMax-M3 gfx1250 enabling - #3902
leonling-ll wants to merge 10 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
89c49b5 to
886ef71
Compare
886ef71 to
7020009
Compare
928e61e to
118609e
Compare
118609e to
6756f93
Compare
There was a problem hiding this comment.
Pull request overview
Adds MI455 (gfx1250) enablement pieces for MiniMax-M3 by expanding MoE routing score-mode support and introducing a shape-based GEMM fallback path for known-unsupported native “skinny” GEMMs.
Changes:
- Add
"sigmoid"score mode support to Triton MoE routing topk (Python wrapper + Triton kernel) and extend routing tests accordingly. - Add a gfx1250 “unsupported GEMM shapes” CSV mechanism and a dispatch check in
get_GEMM_A16W16_config()to avoid native skinny GEMM traps on those shapes. - Introduce the initial
bf16_unsupported_gemm_gfx1250.csvshape list.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| op_tests/triton_tests/moe/test_moe_routing.py | Extends routing reference + parametrized tests to cover "sigmoid" score mode cases. |
| aiter/tuned_gemm.py | Adds unsupported-shape CSV loading and a gfx1250 skinny-shape fallback decision in GEMM config selection. |
| aiter/ops/triton/moe/moe_routing/topk.py | Exposes "sigmoid" as a valid score_mode and allows bias with it. |
| aiter/ops/triton/_triton_kernels/moe/moe_routing/topk.py | Implements "sigmoid" score transform and bias-unbias handling inside the Triton topk routing kernel. |
| aiter/configs/bf16_unsupported_gemm_gfx1250.csv | New config file enumerating known-unsupported skinny GEMM shapes on gfx1250. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
615f8f8 to
4c4288f
Compare
bb76466 to
3887e43
Compare
a160b04 to
136c6eb
Compare
3f63ecb to
0ef6a48
Compare
a313d46 to
36c4a69
Compare
01c72d4 to
1f65d4e
Compare
95e9011 to
4e4eb94
Compare
4e4eb94 to
ae30ea7
Compare
ae30ea7 to
26feabd
Compare
26feabd to
9c8d61e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 46 out of 47 changed files in this pull request and generated 3 comments.
Suppressed comments (2)
aiter/tuned_gemm.py:98
- The default triton_fallback_path points to "configs/bf16_triton_gemm_gfx1250.csv", but that file is not present in the repository checkout. As a result, _load_triton_gemm_shapes() always returns an empty set and the feature is effectively disabled unless users supply AITER_GEMM_TRITON_CSV.
aiter/ops/triton/_triton_kernels/moe/moe_op_gemm_a16w4.py:10 - Duplicate import of _swiglu (imported on both lines 8 and 10). This is redundant and can confuse future edits (e.g., linting or refactors).
from aiter.ops.triton._triton_kernels.moe.activations import _swiglu
from aiter.ops.triton.utils._triton.pid_preprocessing import pid_grid
from aiter.ops.triton._triton_kernels.moe.activations import _swiglu
9c8d61e to
b4c7026
Compare
The non-grouped topk() path only supported 'softmax' and 'sqrtsoftplus', so routing(..., score_mode='sigmoid') failed with an assertion. The grouped path already implemented sigmoid; this brings the flat path to parity. - _apply_score_mode: add sigmoid branch (1/(1+exp(-x)) in fp32) - _topk: generalize bias-unbias step to any non-softmax score_mode, so the select-on-(score+bias)/return-unbiased-score pattern applies to sigmoid as well - topk(): allow 'sigmoid' in score_mode and bias assertions; document it - tests: add sigmoid reference transform + 3 sigmoid cases to test_routing_score_mode Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> fixup topk sigmoid score mode
On gfx1250, shuffle_scale_moe physically preshuffles MoE weight scales into the "GFX1250_SCALE" tile layout, but the a16w4 device kernel only decoded "CDNA4_SCALE" (or plain/unswizzled) scales -> it misread the shuffled scales, causing a GPU memory-access fault during warmup (previously papered over by forcing plain scales, which was still numerically wrong). Add a GFX1250_SCALE decode branch: - unswizzle_mx_scale_gfx1250 @triton.jit: pure reshape/permute that inverts aiter shuffle._shuffle_scale_tile_gfx1250 (permute(0,1,3,2,4)), ported from the gluon a8w4 kernel's unswizzle into plain triton. - CDNA4 and GFX1250 both preshuffle N by 32 into K, so the physical tile shape and addressing are identical; only the in-register unswizzle permute differs. Share the addressing branch, add GFX1250_SCALE unswizzle in both the main loop and the non-EVEN_K tail. Verified numerically (cos ~1.0) vs moe_gemm_torch at M3-exact dims (E=128, gemm1 N=6144 K=6144 swiglu, gemm2 N=6144 K=3072); see op_tests/triton_tests/moe/test_gfx1250_scale.py. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…on backend - Add per-shape gluon tuned configs for MiniMax-M3 GEMM shapes (N=128/6144/9216/9856/24576/200064) - Add default gluon config (gfx1250-GEMM-A16W16.json) with M_LEQ_16/32/64/any buckets - Pass backend="gluon" when fetching config for gluon path to select per-shape gluon configs - Benchmarked 138 M values (M>=6576) across 6 (N,K) shapes on 4 GPUs; gluon wins 399/402 vs triton even for odd M, so always use gluon on gfx1250 Co-Authored-By: Claude <[email protected]>
Tune A16W4 MoE gluon backend for gfx1250 MiniMax-M3 prefill
Add the gfx1250 Gluon _moe_gemm_a16w4 kernel and wire it into
moe_gemm_a16w4 with a backend selector (triton/gluon/auto) plus per-knob
AITER_MOE_A16W4_{TRITON,GLUON}_* env overrides.
Tune the large-block (block_m=128) gluon config for the MiniMax-M3 A16W4
routed GEMMs (N=6144, K in {6144,3072}): block_n=256, block_k=512,
num_warps=4, num_stages=2, num_buffers=1, xcd_swizzle=2 for K>=4096 else
8. ~16.5% lower total _moe_gemm_a16w4 kernel time across the 903 captured
shapes (rocprofv3), ~19.7% on the full fused path, 0 regressions,
bit-exact vs triton.
Default backend is "auto": block_m>=64 unswizzled prefill runs the tuned
gluon path, small block_m stays on triton. Swizzled scales stay on triton
(gluon has a pre-existing inf bug under swiglu + scale swizzling).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Tune A16W4 MoE decode (block_m=16) K tile for gfx1250 MiniMax-M3
Decode / tiny-M GEMMs (block_m=16) are memory-bandwidth bound and expert-sparse.
Tuned on the eager decode capture (M<=16, N=6144, K in {6144,3072}): a 512-deep
K tile beats the flat 256 on the deep gate/up projection (K>=4096) consistently
across decode M (~6-15% on that GEMM); the shallow down projection (K=3072) keeps
the 256 tile.
Validation on the decode-inclusive capture (2807 shapes): decode block_m=16 sum
-3.9%, overall -2.8%, prefill (block_m=128) unchanged, 0 regressions. Bit-exact
vs the 256 tile (block_k only changes K-loop chunking, not accumulation order).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
A16W4 MoE gfx1250: gluon kernel, config system, bench/tune tooling
Squashed A16W4 MoE work for gfx1250 (MiniMax-M3):
Kernel:
- gfx1250 gluon kernel fixes (LDS budget, decode warp-along-N layout, gather)
and hardware v_cvt_scale_pk8 scale_upcast on compact e8m0 scales (block16,
scale_sel=4, uint32 byte replication); shared matmul_launch_metadata helper.
- Add a disabled (constexpr-guarded) software scaled_upcast reference path.
- Public op: derive reduction_n from apply_swiglu; assert/use local block_m;
require routing_data.expt_data; drop unused kpack.
Config system:
- config arg + _get_config (backend/stage/tiling) with JSON tuned configs
(auto + triton + gluon-num-stage-{1,2,3} x BLOCK_M={16,32,64,128}), functional
defaults, prefill tuning (block_n=256).
Bench/tune tooling (bench_moe_gemm_a16w4.py):
- autotuning (--tune, gap/candidate filtering, correctness gate, fused mode),
per-GEMM selection (--gemm), --timing do_bench, --golden-cpu, and --swizzle
with arch defaults (CDNA4 on gfx950, compact on gfx1250).
Tests: shapes x experts x swizzle x epilogue matrix, per-expert reference,
--golden-cpu option (conftest).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A16W4 MoE gfx1250: migrate compact path off removed scale_upcast
The compact e8m0 upcast branch called gl.amd.gfx1250.scale_upcast
(v_cvt_scale_pk8), which the active triton no longer exposes. Migrate it
to the software scaled_upcast using the no-convert-layout variant: build
the expanded (BLOCK_K, BLOCK_N) e8m0 scale directly in the op output
layout (L_SCALE_W) via reshape/slice/expand_dims/broadcast -- no
_expand_mx_scale_k, no trans, no convert_layout.
Drop the now-unused SCALE_SEL / SCALE_REG_SHARE plumbing and the dead
NO_MUL_UPCAST reference branch.
Benchmarked faster than the convert_layout variant on MiniMax-M3
6144x6144: ~30-37% at decode, ~20% at GEMM1 prefill (GEMM2 prefill a
wash). All 841 gluon tests in test_moe_gemm_a16w4.py pass.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Add M_LEQ_32/64 (and merge redundant) buckets to per-shape gluon configs. Without these, M=17..8191 fell through to M_LEQ_8192 or any, using BLOCK_M=128/256 which wastes most of the tile for small batch decode captured by CUDAGraph (M=32/48/64/128). Co-Authored-By: Claude <[email protected]> Tune gluon A16W16 M_LEQ_64 configs for gfx1250 MiniMax-M3 Reduce BLOCK_M from 64 to 32 (or 16 for N=128) to increase grid parallelism at M=64. The old configs produced too few workgroups (as low as 1 for N=128), leaving most CUs idle. Benchmarked improvements (M=64, gluon backend): N=128 K=6144: 0.041 ms -> 0.010 ms (4.2x) N=9216 K=6144: 0.031 ms -> 0.022 ms (1.4x) N=6144 K=12288: 0.037 ms -> 0.028 ms (1.3x) N=9856 K=6144: 0.028 ms -> 0.023 ms (1.2x) Co-Authored-By: Claude <[email protected]> Tune gluon A16W16 configs for gfx1250 MiniMax-M3 M=32..4096 Fix performance anomalies in gluon bf16 GEMM configs for M=32..4096: - M_LEQ_32: all shapes had BN=256 BK=64 bandwidth_bound, causing 5-6x slowdown vs M=16. Fix: use high-BK compute_bound configs (BK=256/512). Measured 2.9-5.0x speedup across all N×K shapes. - M_LEQ_4096 (covers M=128..4096): BM=128 BN=256 BK=64 left only 1 M-tile with too many K iterations. Fix: BM=64 BN=64 BK=256 compute_bound. Measured 2.3-4.2x speedup. - N=9216/9856: added M_LEQ_128, M_LEQ_256, M_LEQ_4096 entries to prevent fallthrough to suboptimal "any" config (BK=64). - N=128 K=6144: added M_LEQ_128 (BM=32 BK=256) and fixed M_LEQ_4096 (BM=64 BK=256) to eliminate launch-overhead floor at ~46us. - Updated minimax_m3_bf16_tuned_gemm.csv with re-benchmarked values. All 91 shapes pass correctness (CPU fp32 ref, max abs err < 10). Co-Authored-By: Claude <[email protected]> fix minimax_m3_bf16_tuned_gemm.csv libtype gluon
fix format Clean up
The aiter triton kernel _gemm_a8w8_kernel miscompiles the 8-bit tl.dot at BLOCK_SIZE_K=128 with fp8 operands on gfx1250: the result is garbage (~1e20) that overflows the bf16 output to inf/NaN. It is data-independent (all-ones fp8 inputs with unit scales yield ~5.9e20 instead of K), fp8-specific (int8 at BK=128 is exact), and BK-specific (BK<=64 is exact, cos=1.0). num_stages/kpack/ matrix_instr_nonkdim have no effect. gfx1250-GEMM-A8W8.json has a single "any" entry with BLOCK_SIZE_K=128, so every fp8 a8w8 GEMM on gfx1250 hit this, silently producing NaN (e.g. ATOM's ptpc_fp8 dense recipe for MiniMax-M3). Clamp BLOCK_SIZE_K to 64 for fp8 operands on gfx1250 in the gemm_a8w8 wrapper, dtype- and arch-gated so int8 and other architectures are unaffected. Mirrors the existing _FORCE_GFX1250_EX BLOCK_SIZE_K=64 clamp in gemm_a8w8_blockscale.py. Adds regression test test_gemm_fp8_default_config_no_nan covering fp8e4m3/e5m2 over M3 dense shapes via the default (config=None) dispatch path. Verified on gfx1250: regression 8/8 pass (was 8/8 fail); existing fp8 triton 26 pass; int8 144 pass (unchanged); splitk 576 pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
k_descale/v_descale are normally one scalar for the whole cache, folded into qk_scale and into the output factor. Dynamic per-token fp8 KV quant (MiniMax-M3) instead produces one scale per cached token, which varies along the key axis and so cannot be hoisted out of either. Accept a [num_blocks, num_kv_heads, block_size] fp32 pair and fold K's scale onto the score columns and V's onto the softmax probabilities -- the latter strictly after the softmax denominator, which must see the unscaled probabilities. Implemented in: - the 3D gluon kernel (all-decode), staging the scale vectors through LDS via TDM alongside their KV tile; a per-lane global load of the [TILE_SIZE] column is catastrophically uncoalesced. - the Triton 2D kernel (prefill), which is where MiniMax-M3's dense fp8 layers land: bf16 q + fp8 KV fails is_2d_gluon_available()'s q_dtype == kv_cache_dtype check, and a prefill is not ALL_DECODE. Per-token descale requires the shuffled layout, where TILE_SIZE == BLOCK_SIZE makes each tile exactly one page and its scale row a contiguous, in-bounds slice. The host validates this and the 2D kernel static_asserts it so the two cannot drift apart. Paths that cannot honour a per-token descale reject it instead of silently dropping it and returning ~fp8_max/amax inflated results. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
b4c7026 to
7524d82
Compare
|
Close since no further requirements. |
This PR aims to support MiniMax-M3 functionally work and accuracy correct on MI455.
The main changes include:
sigmoidscore mode support intopkrouting pathGFX1250_SCALEpreshuffle formoe_gemm_a16w4cc: @Dewei-Wang-sh