Repository navigation
[HIP] [FlyDSL] Refactor gfx950 A16W16 GEMM with centralized policy selection and tuning - #5145
Merged
Merged
Conversation
xytpai
marked this pull request as draft
August 31, 2026 10:29
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
xytpai
marked this pull request as ready for review
September 2, 2026 17:55
Collaborator
|
Approved and merged with following up requested. Don't forget to fix. |
jiacao-amd
pushed a commit
to jiacao-amd/aiter
that referenced
this pull request
Sep 12, 2026
Conflict was kimik3_bf16_tuned_gemm.csv only, and it was textual rather than semantic. ROCm#5145 retuned 184 rows of that file in place while this branch adds 7; the edits interleave in the same region, so git could not align the hunks. The two sets do not overlap. Every row ROCm#5145 retuned is outdtype=bfloat16 and every row this branch adds is outdtype=float32, and outdtype is part of the index get_GEMM_A16W16_config_ builds, so the two address disjoint keys. The merged-front GEMM writes an FP32 accumulator it slices router logits out of, which is why its rows are the fp32 ones. Resolved by key instead of by hunk: upstream's value for every row upstream has, this branch's 7 added rows kept, upstream's row order preserved. Verified that upstream neither reordered nor added/removed rows, that this branch only appends and never edits a pre-existing row, and that no added key collides with an upstream key -- if any of those had failed the resolution would not be mechanical. Result is 536 rows, 536 unique keys, no ragged rows. ROCm#5145 also refactored tuned_gemm.py, but only along the flydsl branch (get_flydsl_splitk_hgemm_kernel_params was renamed and the kernel parameter schema changed). This branch's rows are all libtype=hipblaslt and its code touches only hipb_create_extension, _hipb_mm and get_GEMM_A16W16_config, whose signature is unchanged. get_padded_m and the [None, 0, 1] lookup loop are also untouched, so the M=8 -> padded 16 assumption behind the M=16 row still holds. Co-Authored-By: Claude Opus 5 <[email protected]>
amd-bishwoadhikari
added a commit
to amd-bishwoadhikari/aiter
that referenced
this pull request
Sep 19, 2026
Adds a gfx950 a16w16 (BF16) tuned GEMM table for MiniMax-M3-MXFP4. No such table exists in-tree today: ROCm#4835 covers A8W8-bpreshuffle and MXFP8 fMoE only, and minimax_m3_eagle_bf16_tuned_gemm.csv is the EAGLE draft model with zero (N,K) overlap. These shapes currently fall back to the runtime heuristic on MI355X. Named minimax_m3_mxfp4_bf16_{tuned,untuned}_gemm.csv after the pattern of minimax_m3_eagle_bf16_tuned_gemm.csv, with the variant token between model and dtype, so the file names the checkpoint the shapes came from rather than claiming the generic M3 BF16 slot. get_config_file() globs *bf16_tuned_gemm*.csv, so the longer prefix is still merged. 96 rows: 82 flydsl, 13 asm, 1 triton. Shapes were harvested from vLLM serving logs for the TP8 decode path plus the TP2 qkv_proj sparse family, then tuned with the a16w16 tuner at --update_improved --min_improvement_pct 0.5, so a shape appears only where tuning beat the incumbent dispatch. Every M is an exact getPaddedM gl=0 bucket, so no row is unreachable at dispatch. All rows were re-tuned after ROCm#5145. That change regenerated the flydsl kernel namespace from flydsl_gemmN_* to flydsl_hgemm_*, and main's catalog rejects the old names -- a row carrying one is accepted by the CSV reader, falls through to the untuned path, and still returns correct results, so nothing in the test suite reports it. Each of the 82 flydsl kernelNames here was checked to parse under main's catalog, and each row was confirmed to resolve through get_GEMM_A16W16_config to the kernel it names. hipBLASLt was excluded from the candidate set deliberately. A hipBLASLt winner is pinned to a solidx, which is a property of the build rather than the model, and hipb_gemm passes it to hipb_mm without validation -- unlike flydsl, which gets a catalog-name check with graceful fallback. Re-tuning the same shapes on an identical image yielded a different solidx for 8 of 8 with us within ~2%, so the index is arbitrary among near-ties. This matches in-tree practice: no BF16 table currently ships a hipblaslt row. 31 shapes whose only winner was hipBLASLt were re-tuned with it excluded rather than dropped. Two shapes, (48, 3072, 6144) and (48, 6144, 1536) on gfx950, already exist in glm5_bf16_tuned_gemm.csv and are dropped from this table rather than contested. Duplicate keys are fatal rather than cosmetic -- update_config_files() auto-resolves to the lowest us, rewrites the source CSVs on disk, and raises RuntimeError -- so the two tables cannot both carry a shape. This change adds files only and modifies no existing config. Verified zero duplicate keys across the full merge set (default table plus every model_configs BF16 table): 20 files, 5257 rows, 5257 distinct. Not ready to merge. The table sums to a 17.4% aggregate improvement across the 96 shapes in microbenchmark, but end-to-end TP8 serving throughput regresses ~3.8% against a ~1.8% noise floor, measured in both arm orders. The mechanism is not yet established and the rows should not land until it is. Signed-off-by: Bishwo Adhikari <[email protected]>
amd-bishwoadhikari
added a commit
to amd-bishwoadhikari/aiter
that referenced
this pull request
Sep 19, 2026
Adds minimax_m3_mxfp4_bf16_{tuned,untuned}_gemm.csv under model_configs --
96 rows for gfx950 / cu_num=256, 82 flydsl, 13 asm, 1 triton. Two new files;
no existing file is modified.
No in-tree table covers these shapes: ROCm#4835 is A8W8-bpreshuffle and MXFP8 fMoE
only, and minimax_m3_eagle_bf16_tuned_gemm.csv is the EAGLE draft model with
zero (N,K) overlap.
Shapes came from vLLM serving logs (TP8 decode linears, lm_head, TP2 qkv_proj)
and were tuned at --update_improved --min_improvement_pct 0.5, so a row exists
only where tuning beat the incumbent dispatch. Tuned post-ROCm#5145: every flydsl
kernelName is flydsl_hgemm_* and parses under main's catalog, since a
pre-ROCm#5145 name ships and silently never dispatches. hipblaslt and opus are
excluded -- a hipblaslt solidx is build-specific and passed to hipb_mm
unvalidated, and no in-tree BF16 table ships one.
(48,3072,6144) and (48,6144,1536) belong to glm5_bf16_tuned_gemm.csv and are
dropped here rather than contested; duplicate keys raise RuntimeError in
update_config_files(). Merge set verified clean: 20 files, 5257 rows, 5257
distinct keys.
Aggregate 1929.41us -> 1593.12us (17.4%) in microbenchmark. Not ready to merge:
end-to-end TP8 serving throughput regresses ~3.8% against a ~1.8% noise floor,
measured in both arm orders, and the mechanism is not yet established.
Signed-off-by: Bishwo Adhikari <[email protected]>
amd-bishwoadhikari
added a commit
to amd-bishwoadhikari/aiter
that referenced
this pull request
Sep 22, 2026
Adds minimax_m3_mxfp4_bf16_{tuned,untuned}_gemm.csv under model_configs --
96 rows for gfx950 / cu_num=256, 82 flydsl, 13 asm, 1 triton. Two new files;
no existing file is modified.
No in-tree table covers these shapes: ROCm#4835 is A8W8-bpreshuffle and MXFP8 fMoE
only, and minimax_m3_eagle_bf16_tuned_gemm.csv is the EAGLE draft model with
zero (N,K) overlap.
Shapes came from vLLM serving logs (TP8 decode linears, lm_head, TP2 qkv_proj)
and were tuned at --update_improved --min_improvement_pct 0.5, so a row exists
only where tuning beat the incumbent dispatch. Tuned post-ROCm#5145: every flydsl
kernelName is flydsl_hgemm_* and parses under main's catalog, since a
pre-ROCm#5145 name ships and silently never dispatches. hipblaslt and opus are
excluded -- a hipblaslt solidx is build-specific and passed to hipb_mm
unvalidated, and no in-tree BF16 table ships one.
(48,3072,6144) and (48,6144,1536) belong to glm5_bf16_tuned_gemm.csv and are
dropped here rather than contested; duplicate keys raise RuntimeError in
update_config_files(). Merge set verified clean: 20 files, 5257 rows, 5257
distinct keys.
Aggregate 1929.41us -> 1593.12us (17.4%) in microbenchmark. Not ready to merge:
end-to-end TP8 serving throughput regresses ~3.8% against a ~1.8% noise floor,
measured in both arm orders, and the mechanism is not yet established.
Signed-off-by: Bishwo Adhikari <[email protected]>
jiacao-amd
pushed a commit
to jiacao-amd/aiter
that referenced
this pull request
Sep 22, 2026
Conflict was kimik3_bf16_tuned_gemm.csv only, and it was textual rather than semantic. ROCm#5145 retuned 184 rows of that file in place while this branch adds 7; the edits interleave in the same region, so git could not align the hunks. The two sets do not overlap. Every row ROCm#5145 retuned is outdtype=bfloat16 and every row this branch adds is outdtype=float32, and outdtype is part of the index get_GEMM_A16W16_config_ builds, so the two address disjoint keys. The merged-front GEMM writes an FP32 accumulator it slices router logits out of, which is why its rows are the fp32 ones. Resolved by key instead of by hunk: upstream's value for every row upstream has, this branch's 7 added rows kept, upstream's row order preserved. Verified that upstream neither reordered nor added/removed rows, that this branch only appends and never edits a pre-existing row, and that no added key collides with an upstream key -- if any of those had failed the resolution would not be mechanical. Result is 536 rows, 536 unique keys, no ragged rows. ROCm#5145 also refactored tuned_gemm.py, but only along the flydsl branch (get_flydsl_splitk_hgemm_kernel_params was renamed and the kernel parameter schema changed). This branch's rows are all libtype=hipblaslt and its code touches only hipb_create_extension, _hipb_mm and get_GEMM_A16W16_config, whose signature is unchanged. get_padded_m and the [None, 0, 1] lookup loop are also untouched, so the M=8 -> padded 16 assumption behind the M=16 row still holds.
amd-bishwoadhikari
added a commit
to amd-bishwoadhikari/aiter
that referenced
this pull request
Sep 23, 2026
…yDSL winners
Update minimax_m3_mxfp4_bf16_{tuned,untuned}_gemm.csv with portable FlyDSL
GEMM configurations discovered during tuning on gfx950 (MI355X):
- Expands table coverage from 96 to 112 rows (+16 new shapes across gate_up_proj,
qkv_dense, o_proj, and ViT mlp).
- Updates 3 existing shapes in-place (qkv_sparse at M=16, 32, 48) with faster
FlyDSL configs.
- All kernels conform to post-ROCm#5145 catalog naming (flydsl_hgemm_*).
- Clean merge verified: 0 duplicate keys across in-tree model configs.
Co-Authored-By: Claude Code <[email protected]>
Signed-off-by: Bishwo Adhikari <[email protected]>
mjkvaak-amd
added a commit
to mjkvaak-amd/aiter
that referenced
this pull request
Sep 25, 2026
…fx950 Qwen3.8-2.4T-A95B served at TP8 executes seven bf16 GEMM families that have no tuned entry, so every one of them falls back to rocBLAS. Add 26 rows covering the five families where a portable backend is measurably faster than that fallback, tuned on gfx950 / cu_num=256. N=8192 K=256 12 rows MoE down-projection / GDN out_proj N=4608 K=8192 4 rows Gated DeltaNet in_proj_qkvz N=512 K=8192 4 rows MoE router gate N=32 K=8192 3 rows Gated DeltaNet in_proj_ba N=31040 K=8192 3 rows lm_head, vocab 248320 sharded TP8 This supersedes ROCm#5183, which shipped 75 rows of which 63 were hipBLASLt. Review asked for hipBLASLt to be dropped because its solution indices are build-specific. Re-picking from that PR's tuning data left 15 rows worth only +0.35% end to end, so ROCm#5183 was closed. Re-tuning against the gfx950 A16W16 FlyDSL kernels added in ROCm#5145 changes the answer: 26 rows, +5.1%. No row uses hipBLASLt or opus. Both dispatch on an integer index into an external library (hipblaslt solidx, opus kernelId), which is the fragility the review objected to. flydsl and asm are looked up by kernelName and the kernels live in AITER itself; flydsl additionally falls through to the default when a named kernel is absent from the build. triton is solidx=0 with kernelName=auto. Every row is required to beat the kernel AITER picks with no tuned entry, measured on the same build, so no row can be slower than today's behaviour. Shapes where nothing portable beat the fallback are deliberately left out rather than filled in. That is why 26 rows replace 75. Winners were selected as the fastest candidate within err_ratio <= 0.005 rather than on speed alone; the tuner's default 0.05 would have picked split-k kernels an order of magnitude further from the reference. 23 of the 26 rows are exactly 0.0; the three split-k rows are 0.0020-0.0048. Measured under vLLM on amd/Qwen3.8-2.4T-A95B-Quark-MXFP4, TP8, MI355X, 8k/1k at concurrency 4-256, arms differing only by this table: geometric mean output throughput +5.1%, geometric mean mean-TTFT -9.6%. Signed-off-by: Mikko Tukiainen <[email protected]> Co-authored-by: Cursor <[email protected]>
yzhou103
pushed a commit
that referenced
this pull request
Sep 25, 2026
…#5758) * [Perf] [Config] [gfx950] Add MiniMax-M3-MXFP4 BF16 tuned GEMM configs Adds minimax_m3_mxfp4_bf16_{tuned,untuned}_gemm.csv under model_configs -- 96 rows for gfx950 / cu_num=256, 82 flydsl, 13 asm, 1 triton. Two new files; no existing file is modified. No in-tree table covers these shapes: #4835 is A8W8-bpreshuffle and MXFP8 fMoE only, and minimax_m3_eagle_bf16_tuned_gemm.csv is the EAGLE draft model with zero (N,K) overlap. Shapes came from vLLM serving logs (TP8 decode linears, lm_head, TP2 qkv_proj) and were tuned at --update_improved --min_improvement_pct 0.5, so a row exists only where tuning beat the incumbent dispatch. Tuned post-#5145: every flydsl kernelName is flydsl_hgemm_* and parses under main's catalog, since a pre-#5145 name ships and silently never dispatches. hipblaslt and opus are excluded -- a hipblaslt solidx is build-specific and passed to hipb_mm unvalidated, and no in-tree BF16 table ships one. (48,3072,6144) and (48,6144,1536) belong to glm5_bf16_tuned_gemm.csv and are dropped here rather than contested; duplicate keys raise RuntimeError in update_config_files(). Merge set verified clean: 20 files, 5257 rows, 5257 distinct keys. Aggregate 1929.41us -> 1593.12us (17.4%) in microbenchmark. Not ready to merge: end-to-end TP8 serving throughput regresses ~3.8% against a ~1.8% noise floor, measured in both arm orders, and the mechanism is not yet established. Signed-off-by: Bishwo Adhikari <[email protected]> * [Perf] [Config] [gfx950] Update MiniMax-M3-MXFP4 BF16 configs with FlyDSL winners Update minimax_m3_mxfp4_bf16_{tuned,untuned}_gemm.csv with portable FlyDSL GEMM configurations discovered during tuning on gfx950 (MI355X): - Expands table coverage from 96 to 112 rows (+16 new shapes across gate_up_proj, qkv_dense, o_proj, and ViT mlp). - Updates 3 existing shapes in-place (qkv_sparse at M=16, 32, 48) with faster FlyDSL configs. - All kernels conform to post-#5145 catalog naming (flydsl_hgemm_*). - Clean merge verified: 0 duplicate keys across in-tree model configs. Co-Authored-By: Claude Code <[email protected]> Signed-off-by: Bishwo Adhikari <[email protected]> --------- Signed-off-by: Bishwo Adhikari <[email protected]> Co-authored-by: Claude Code <[email protected]>
yifehuan
pushed a commit
that referenced
this pull request
Sep 26, 2026
…fx950 (#5835) Qwen3.8-2.4T-A95B served at TP8 executes seven bf16 GEMM families that have no tuned entry, so every one of them falls back to rocBLAS. Add 26 rows covering the five families where a portable backend is measurably faster than that fallback, tuned on gfx950 / cu_num=256. N=8192 K=256 12 rows MoE down-projection / GDN out_proj N=4608 K=8192 4 rows Gated DeltaNet in_proj_qkvz N=512 K=8192 4 rows MoE router gate N=32 K=8192 3 rows Gated DeltaNet in_proj_ba N=31040 K=8192 3 rows lm_head, vocab 248320 sharded TP8 This supersedes #5183, which shipped 75 rows of which 63 were hipBLASLt. Review asked for hipBLASLt to be dropped because its solution indices are build-specific. Re-picking from that PR's tuning data left 15 rows worth only +0.35% end to end, so #5183 was closed. Re-tuning against the gfx950 A16W16 FlyDSL kernels added in #5145 changes the answer: 26 rows, +5.1%. No row uses hipBLASLt or opus. Both dispatch on an integer index into an external library (hipblaslt solidx, opus kernelId), which is the fragility the review objected to. flydsl and asm are looked up by kernelName and the kernels live in AITER itself; flydsl additionally falls through to the default when a named kernel is absent from the build. triton is solidx=0 with kernelName=auto. Every row is required to beat the kernel AITER picks with no tuned entry, measured on the same build, so no row can be slower than today's behaviour. Shapes where nothing portable beat the fallback are deliberately left out rather than filled in. That is why 26 rows replace 75. Winners were selected as the fastest candidate within err_ratio <= 0.005 rather than on speed alone; the tuner's default 0.05 would have picked split-k kernels an order of magnitude further from the reference. 23 of the 26 rows are exactly 0.0; the three split-k rows are 0.0020-0.0048. Measured under vLLM on amd/Qwen3.8-2.4T-A95B-Quark-MXFP4, TP8, MI355X, 8k/1k at concurrency 4-256, arms differing only by this table: geometric mean output throughput +5.1%, geometric mean mean-TTFT -9.6%. Signed-off-by: Mikko Tukiainen <[email protected]> Co-authored-by: Cursor <[email protected]>
Merged
5 tasks done
This was referenced Oct 12, 2026
3 of 10 tasks
afanfa
added a commit
to afanfa/aiter
that referenced
this pull request
Nov 9, 2026
…efactor ROCm#5145 replaced the FlyDSL bf16 GEMM kernels with a gfx950-only implementation. The 53 MI300A (gfx942, cu_num=228) rows that recorded flydsl_gemm2/3/4/5_* kernels no longer parse, so lookup skipped them and fell back to the default path; renaming them is not an option because the new FlyDSL A16W16 backend has no gfx942 candidates. Retuned those 53 shapes on the remaining gfx942 backends (asm, opus, skinny, torch) with --compare --update_improved --min_improvement_pct 3, against the production fallback the stale rows produce. 47 shapes beat it and were confirmed in a second independent --run_config A/B; each stale row is replaced in place by its retuned row (30 opus, 17 asm). The other 6 shapes did not clear 3% and are removed, so they keep the default: M=80/96, N=512, K=4096 M=2048, N=6144, K=2048 M=8192/16384, N=2048, K=6144 M=8192, N=6144, K=2048 Second-run improvement over the fallback: 6.1% to 82.8%; 30-46% for the M<=16 decode shapes and 68-80% for most of the rest. All rows pass the tuner's accuracy check (max err_ratio 0.031). Triton was excluded: aiter's Triton A16W16 kernel faults on gfx942 with Triton 3.8 / ROCm 7.14 in the tuning environment. None of the 53 rows used Triton, and the 12 existing MI300A Triton rows are untouched. Measured on 4x MI300A (gfx942, 228 CU), ROCm 7.14, torch 2.14. Co-authored-by: Cursor <[email protected]>
afanfa
added a commit
to afanfa/aiter
that referenced
this pull request
Nov 9, 2026
Four of the six shapes left on the default in the previous commit are large fp32-output GEMMs that ROCm#5145 made 2.2-2.7x slower than their old FlyDSL rows. On gfx942 only one OPUS kernel supports fp32 output, so the asm/opus/torch search could not beat the fallback for them. hipBLASLt can. Tuned with --with-hipblaslt and the same compare gate (>= 3% vs the production fallback), then confirmed in a second independent --run_config A/B: M N K out fallback us hipBLASLt us 2048 6144 2048 fp32 672.9 147.8 8192 2048 6144 fp32 3443.4 506.7 8192 6144 2048 fp32 2791.1 501.4 16384 2048 6144 fp32 6622.9 985.8 96 512 4096 bf16 10.7 10.1 All four large shapes also beat their old FlyDSL records. M=80 N=512 K=4096 still has no winner and keeps the default. hipBLASLt rows store a library solution index, which is specific to the hipBLASLt version. These were tuned on ROCm 7.14 (4x MI300A, gfx942, 228 CU); hipb_mm raises if the index is unknown to the installed hipBLASLt, so re-tune them if MI300A moves to a different ROCm. Co-authored-by: Cursor <[email protected]>
afanfa
added a commit
that referenced
this pull request
Nov 11, 2026
* [HIP] Identify MI300A and resolve gfx942 CU counts correctly
gfx942 covers three SKUs with different CU counts -- MI300X (304), MI300A
(228) and MI308X (80) -- but AITER could not tell them apart, and two
separate bugs made a 228-CU part unusable with tuned configs.
_get_pci_chip_id() queried the device id by numeric ordinal:
hipDeviceAttributePciChipId = 10019
The AMD-specific block of hipDeviceAttribute_t is an unnumbered enum, so
those ordinals shift whenever an attribute is inserted ahead of them. On
ROCm 7.2, counting the enum in hip_runtime_api.h gives 10018 =
NumberOfXccs, 10019 = MaxAvailableVgprsPerThread and 10020 = PciChipId,
so the call returned 512 on every device and the MI308 chip-id check
could never match -- MI308X has been reported as "MI300". The C++ side
uses the symbolic name and was always correct, so this is Python-only.
Resolve the id via hipDeviceGetPCIBusId plus sysfs instead, which is
stable across ROCm versions, and return None rather than raising when it
is unavailable.
get_build_targets() used GFX_CU_NUM_MAP verbatim whenever GPU_ARCHS was
set, and that table holds one canonical CU count per arch (gfx942 -> 304,
the MI300X SPX value). On a 228-CU MI300A, GPU_ARCHS=gfx942 therefore
resolved to ('gfx942', 304), gen_instances.py filtered every (gfx942,
228) row out of the tuning CSV, and those kernels were never compiled.
The failure surfaced much later as
kernel '...' is not present in the compiled registry
on 73 of 80 blockscale shapes. Prefer the live CU count when a requested
target's arch matches the running GPU and CU_NUM was not set explicitly.
An explicit CU_NUM still wins and cross-compiles are unaffected:
GPU_ARCHS=gfx942 (on MI300A) [('gfx942', 304)] -> [('gfx942', 228)]
GPU_ARCHS=gfx942 CU_NUM=304 [('gfx942', 304)] -> unchanged
GPU_ARCHS=gfx950 (cross) [('gfx950', 256)] -> unchanged
GPU_ARCHS='gfx942;gfx950' -> [(942,228),(950,256)]
This is not MI300A-specific. build_targets.py's own comment notes that
DPX/QPX/CPX partition modes change the visible CU count, so MI300X in any
non-SPX mode hits the same cliff.
Also adds 0x74A0 as the MI300A chip id so get_device_name() returns
"MI300A", and registers 228 -> gfx942 in the legacy cu_num backfill.
Verified on 4x MI300A (gfx942:sramecc+:xnack-, 228 CU, ROCm 7.2, torch
2.13): chip id 0x74a0, get_device_name() "MI300A", get_cu_num() 228.
op_tests/tuning_tests test_tuner_infra, test_csv_validation,
test_config_shape_collision and test_compare_logic pass (68 tests,
37 subtests).
Co-authored-by: Cursor <[email protected]>
* [Tune] Resolve the fp8 e4m3 flavor to the arch-native encoding on ingest
Only one e4m3 encoding exists per chip: gfx942 implements e4m3fnuz (max
240, exponent bias 8) and gfx950 implements OCP e4m3fn (max 448, bias 7).
aiter/utility/dtypes.py already knows this via defaultDtypes, but the
shipped untuned shape lists name the OCP flavor unconditionally:
aiter/configs/untuned_fmoe.csv 22 occurrences
aiter/configs/a8w8_untuned_gemm.csv 40 of 65 shapes
model_configs/a8w8_blockscale_untuned_fmoe_*.csv 16-32 each
On gfx942 every such row aborts with "Unsupported dtype:
torch.float8_e4m3fn" out of _aiter_dtype_id, because _torch_to_aiter_dtype
is built from the arch-native alias and only ever contains one flavor. The
practical effect is that two thirds of the a8w8 GEMM shape list and the
entire fp8 MoE model coverage could not be tuned at all on any MI300-class
part -- which is why no MI300 rows exist for GLM-5.x, qwen3, minimax or
dsv3.
Add dtypes.normalize_fp8_dtype(), which maps either e4m3 encoding onto the
one the running chip implements. e5m2 and non-fp8 dtypes pass through
unchanged, and it declines to act when the arch is unknown (fp8 falls back
to uint8) rather than reinterpreting fp8 data as integers.
Apply it on ingest in FmoeTuner.get_untuned_gemm_list and
GemmA8W8Tuner.get_untuned_gemm_list, plus the two string->dtype conversion
sites in the MoE tuner. Normalizing on ingest rather than at point of use
matters: applied late, the tuned row is written as e4m3fnuz while the
untuned frame still says e4m3fn, so the tuner cannot match its own result
and reports the shape as never tuned.
q_dtype_w is part of the a8w8 dispatch key, so normalizing on ingest also
keeps the emitted rows and the tuned/untuned bookkeeping agreeing on one
dtype.
Verified on MI300A (gfx942, e4m3fnuz): all 40 previously-rejected a8w8
shapes now tune, and end-to-end against the default kernel path they win
between 1.10x and 2.41x.
Co-authored-by: Cursor <[email protected]>
* [Tune] Add MI300A (gfx942, cu_num=228) configs for GEMM and fused MoE
MI300A could not reach a single tuned row before this. AITER keys every
tuned kernel on (gfx, cu_num); MI300A reports (gfx942, 228), a pair that
appeared in no row of any tuning CSV, so every GEMM and MoE lookup missed
and fell through to the CU-blind shape heuristics. Three of the four
tables touched here had no gfx942 rows at all -- a8w8_blockscale was
6630 rows of pure gfx950, and bf16 was gfx1250 and gfx950 only.
Adds 527 measured rows:
a8w8_blockscale_tuned_gemm.csv 78 rows 2.393x
a8w8_tuned_gemm.csv 64 rows 1.529x
bf16_tuned_gemm.csv 377 rows 1.367x
model_configs/mi300a_tuned_fmoe.csv 8 rows 1.136x
Existing rows are untouched: the diff is 528 insertions and zero
deletions, and the pre-existing rows in all three modified files are
byte-identical.
Method. Every row was A/B'd end-to-end through the production op with
--run_config, never on the tuner's own us, which is measured by a
separate harness and is not comparable (at token=1 the MoE tuner reported
72us for a kernel whose real end-to-end cost was 83us against a 41us
default). A row ships only if it is numerically clean and beats the
default by at least 3% in two independent runs -- once in the A/B and
again after installation, with the module rebuilt so the tuned kernels
are actually compiled in. The second run matters: five bf16 rows cleared
the first measurement at 1.033-1.060x and came back at 0.944-1.022x on
the second, one of them 5.6% slower than the default it would have
replaced. All five sit in the same N=256/512 K=4096 family. Dropping them
raised the bf16 aggregate from 1.364x to 1.367x.
Losing rows are omitted rather than corrected. Lookup is exact-match, so
an absent shape keeps the existing default, which is the safe outcome:
51 of 433 bf16 rows, 5 of 13 MoE rows and 2 of 80 blockscale rows were
dropped this way. 14 of the bf16 drops were cases where the tuner's pick
was actually slower than the default, clustered at M = 1, 2, 4.
Largest wins: bf16 M=64 N=128 K=6144 fp32-out at 42.6 -> 8.1us (5.26x);
blockscale M=1024 N=7168 K=256 at 39.0 -> 13.9us (2.82x); a8w8 M=64
N=7168 K=8192 fp8 at 82.9 -> 34.4us (2.41x).
Not covered. Nine bf16 shapes (N=50016, K=6144, fp32 out, M=192..16384)
failed every candidate with err_ratio=1.0 under --mp 4; at M=16384 the
fp32 output alone is ~3.3 GB with four workers concurrent, so this looks
like memory pressure rather than a kernel fault. They keep the default.
Paged attention and MLA are not tuned here.
Measured on 4x MI300A (gfx942:sramecc+:xnack-, 228 CU, 6 XCC, 94 GiB
unified, ROCm 7.2, torch 2.13.0+rocm7.2), one GCD pinned for all
benchmarks. Depends on the fp8 e4m3 ingest fix in the preceding commit,
without which two thirds of the a8w8 shape list cannot be tuned on gfx942.
Co-authored-by: Cursor <[email protected]>
* [Tune] Add unit tests for GPU SKU resolution and fp8 flavor normalization
Covers the new functionality in the two preceding commits. Level 1, no GPU
required, so it runs in CI without MI300-class hardware: the device queries
and the live-GPU probes are mocked.
TestDeviceName get_device_name() maps chip ids to MI300A /
MI308 / MI300, leaves gfx950 and gfx1250 alone,
and does not crash when the id is unreadable.
TestPciChipId the id is read via hipDeviceGetPCIBusId plus
sysfs and returns None on failure. Asserts
hipDeviceGetAttribute is never called -- that is
the actual regression guard, since its ordinal
comes from an unnumbered enum and shifted
between ROCm releases.
TestLegacyCuNumBackfill 228/304/80 -> gfx942 and 256 -> gfx950, for
both int and str cu_num.
TestBuildTargets the live CU count wins over the GFX_CU_NUM_MAP
default, an explicit CU_NUM still overrides it,
cross-compiling for a non-live arch keeps the
table default, multi-arch refines only the
matching target, and a missing GPU falls back to
the table. Also covers the MI308X/partition-mode
case, which is the same mechanism.
TestNormalizeFp8Dtype both e4m3 encodings resolve to the arch-native
one, idempotently; e5m2, bf16, fp32 and int8
pass through; an unknown arch passes through
rather than reinterpreting fp8 data as uint8.
TestShippedShapeLists... every fp8 shape in the shipped untuned lists
resolves to the native encoding, which is the
property that makes them tunable on gfx942.
TestTunedConfigArch... every tuned row keyed cu_num=228 is also keyed
gfx942, so the build-time codegen filter and the
runtime lookup cannot disagree.
23 tests, all passing on MI300A. Registered in the suite README table.
Co-authored-by: Cursor <[email protected]>
* [CI] Run the arch-resolution tests in the level 0+1 tuning suite
test_arch_resolution.py was added alongside the SKU-resolution and fp8
normalization changes but was not wired into CI, so it would never have
run there: the level 0+1 job names its test modules explicitly rather
than discovering them.
Adds it to the module list in tuning-tests.yaml and to the two places
that document that list, so the three stay in sync.
CI-style invocation on MI300A now reports 88 tests:
python3 -m unittest op_tests.tuning_tests.test_csv_validation \
op_tests.tuning_tests.test_tuner_infra \
op_tests.tuning_tests.test_mp_tuner_logic \
op_tests.tuning_tests.test_a6w6_tuning \
op_tests.tuning_tests.test_arch_resolution -v
The single failure, test_mp_tuner_logic's
test_worker_records_start_only_when_task_leaves_queue, is pre-existing
and unrelated: it allows a spawn-context worker 5s to record a start
timestamp, but each spawned worker re-imports aiter, measured at 8.23s
on this machine. It reproduces unchanged at f2f8ed9.
Co-authored-by: Cursor <[email protected]>
* Fix Black formatting
* Addressing co-pilot recommendations
* Style fix
* [Tune] Move the MI300A fmoe rows into the generic tuned_fmoe.csv
model_configs/ is partitioned by model -- ds_v3, glm5_1, qwen3_235b,
kimik2, minimax_m3 and so on. mi300a_tuned_fmoe.csv was named for a
hardware SKU, which does not belong in that namespace.
The rows were never model-specific to begin with: they come from the
generic aiter/configs/untuned_fmoe.csv shape list and span three
unrelated geometries (6144/4096/E8, 2304/1536/E8 and 7168/256/E256/topk8).
Their tuned counterpart is the generic aiter/configs/tuned_fmoe.csv, which
already carries MI308X rows for two of those three geometries; the MI300A
rows now sit beside them, distinguished by cu_num exactly as intended.
Rewritten into that file's schema, which predates the gfx column:
gfx dropped; _ensure_gfx_column backfills it from cu_num via
gfx_from_cu_num, where 228 -> gfx942 (added earlier in this
branch). Verified the mapping is present rather than assumed.
xbf16, flat dropped; both are 0 in all 8 rows, which is exactly what
fused_moe assumes when the columns are absent (the reads are
guarded by `if "xbf16" in cfg` / `if "flat" in cfg`).
_tag empty, matching all 617 existing rows; it only filters
"flydsl_fallback" entries.
Checked for key collisions against the existing rows before appending:
none. The merged fmoe inventory now resolves to gfx942/cu228 x8,
gfx942/cu304 x83, gfx942/cu80 x962 and gfx950/cu256 x1417, with all 8
MI300A rows reachable.
No measurements change; this is a relocation. The 1.136x aggregate quoted
in the commit that added these rows still stands, but the path named there
is now aiter/configs/tuned_fmoe.csv.
Co-authored-by: Cursor <[email protected]>
* [Tune] Share the fp8 e4m3 normalization across all tuner families
Addresses two review comments.
1. The normalization was local to GemmA8W8Tuner, but
GemmA8W8BpreShuffleTuner inherits the base CSV loader and its tuning
paths return [] for any row whose q_dtype_w != dtypes.fp8. On gfx942
the e4m3fn rows in the bpreshuffle shape lists were therefore skipped
with a warning rather than resolved, leaving that GEMM family
untunable. The scale is not marginal -- 781 rows across six shipped
lists:
a8w8_bpreshuffle_untuned_gemm_kimik3.csv 427
a8w8_bpreshuffle_untuned_gemm_glm5.2.csv 142
a8w8_bpreshuffle_untuned_gemm_glm47.csv 96
a8w8_bpreshuffle_untuned_gemm_minimax_m3.csv 80
a8w8_bpreshuffle_untuned_gemm_glm5_3_flash.csv 20
a8w8_blockscale_bpreshuffle_untuned_gemm_mm2.5.csv 16
Two other lists (glm5_a8w8_bpreshuffle, qwen38_flash_next) already
spell e4m3fnuz by hand, which is the same problem worked around
per-file.
Moved into TunerCommon.get_untuned_gemm_list so every family -- a8w8,
bpreshuffle, blockscale, batched and fmoe -- resolves on ingest, and
dropped the two now-redundant per-tuner overrides. Verified on the
kimik3 list: all 427 rows resolve to e4m3fnuz, 0 would be skipped.
The resolver also no longer uses eval(). These cells come from CSV
files whose path is caller-supplied, so eval() made the tuner a
code-execution sink; it now looks the dtype up by name and returns
anything unrecognised untouched. Covered by a test that feeds it
"__import__('os').system(...)" among other junk.
2. TestTunedConfigArchConsistency required a literal gfx column, which
tuned_fmoe.csv does not have -- it is keyed on cu_num alone and has
its arch backfilled by gfx_from_cu_num at load time. The assertion
failed for the 8 MI300A rows moved there in 2516405, so the Level 1
suite could not pass. Confirmed before fixing: 527 cu_num=228 rows
scanned, 8 failing, all in tuned_fmoe.csv.
The test now asserts on the *resolved* arch, which is what dispatch
actually keys on, and uses the literal column only when present. A
companion test pins the legacy cu_num-only path explicitly and will
fail loudly if tuned_fmoe.csv ever grows a gfx column.
Also streams the tuned CSVs instead of materializing them, as suggested
in an earlier review note, and extends the shape-list coverage to the
bpreshuffle and model_configs families via globs so newly added lists are
picked up automatically.
Three TestPciChipId cases had to change too: _load_hip_runtime() is
lru_cached, so patching ctypes.CDLL underneath it is a no-op once the
real library has been loaded. They now patch the loader itself, and the
new cases cover a missing symbol (AttributeError), a RuntimeError from
the Windows DLL search, and an absent /sys/bus/pci.
28 tests pass. CI level 0+1 on MI300A: 172 tests, the only failure the
pre-existing test_mp_tuner_logic spawn-timing case, plus 23 errors from
flydsl being absent in this harness. Black clean.
Co-authored-by: Cursor <[email protected]>
* [CI] Collapse nested with in test_arch_resolution to satisfy Ruff
Ruff SIM117 flagged the nested subTest / mock.patch context managers in
TestPciChipId.test_returns_none_when_hip_cannot_be_loaded. pre-checks runs
ruff with --exit-zero but pipes into reviewdog with -fail-on-error=true,
so the warning failed the job. Combine them into a single with statement.
ruff 0.16.0 (the version CI pins) is clean on every Python file in this
PR, and black is unchanged.
* [OPUS] Key the pre-PR codegen parity model on cu_num
test_shipped_tuned_selection_diff_is_exhaustive failed with
"assert 10301 == 10300" once the MI300A (gfx942, cu_num=228) rows from
this PR were shipped alongside upstream's MI308X (gfx942, cu_num=80) rows.
_pre_pr_codegen_tuned_map models the removed opus_gemm_lookup.h as a single
(arch, M, N, K, outdtype) table built from every shipped row, last write
wins. That is not what the pre-PR codegen did: gen_instances.py filtered
the tuned CSV to the host's cu_num before emitting the table,
if cu_num is not None:
tune_df = tune_df[tune_df["cu_num"] == cu_num].reset_index()
so each build saw exactly one cu_num per arch. Merging both gfx942 SKUs
into one table made the test compare MI300A's tuned kernel against the one
MI308X picked for the same shape -- dsv4_bf16_tuned_gemm.csv sorts after
bf16_tuned_gemm.csv, so its cu_num=80 row overwrote the cu_num=228 one.
Five shipped shapes are affected, all gfx942, each with a distinct
measured winner per SKU:
M N K cu_num=80 (MI308X) cu_num=228 (MI300A)
1 2048 4096 10301 10300
2 2048 4096 10301 10300
4 2048 4096 10301 10300
8 2048 4096 10301 10300
256 1024 4096 10210 10201
Both selections are correct for their hardware. Rewriting the MI300A rows
to MI308X's kids would make the test pass by shipping a kernel that was
never measured on MI300A, overriding the one that won the A/B there.
Key the codegen model on cu_num, matching the per-host filter and the
companion _pre_pr_python_tuned_map, which already includes cu_num. Also
make the assertion name the key and both kids on failure.
Reproduced the CI failure against the previous version of the test
(1 failed, 18 passed); all 19 pass now. ruff 0.16.0 and black clean.
Co-authored-by: Cursor <[email protected]>
* Keep table-default CU target when adding the live GPU's CU count
A multi-arch wheel built on an MI300A host replaced (gfx942, 304) with
(gfx942, 228) and lost the MI300X instances. Add the live target next to
the default instead. Also drop a stray comment in FmoeTuner.
Co-authored-by: Cursor <[email protected]>
* Reconcile MI300A blockscale kernel IDs; pin both fp8 directions in tests
Six gfx942/228 CK-Tile rows in a8w8_blockscale_tuned_gemm.csv stored
kernelIds that no longer match their kernelName in the current registry
(2->20, 3->21, 4->22). Dispatch resolves by name, but ID-based
reproduction would pick a different candidate.
The fp8 normalization tests only exercised the host's native encoding, so
CI on MI35X never covered fn->fnuz (gfx942). Add subcases that patch the
native alias to each e4m3 flavor; the real-host checks stay.
Co-authored-by: Cursor <[email protected]>
* [Tune] Retune MI300A bf16 GEMM rows left stale by the FlyDSL A16W16 refactor
#5145 replaced the FlyDSL bf16 GEMM kernels with a gfx950-only
implementation. The 53 MI300A (gfx942, cu_num=228) rows that recorded
flydsl_gemm2/3/4/5_* kernels no longer parse, so lookup skipped them and
fell back to the default path; renaming them is not an option because
the new FlyDSL A16W16 backend has no gfx942 candidates.
Retuned those 53 shapes on the remaining gfx942 backends (asm, opus,
skinny, torch) with --compare --update_improved --min_improvement_pct 3,
against the production fallback the stale rows produce. 47 shapes beat
it and were confirmed in a second independent --run_config A/B; each
stale row is replaced in place by its retuned row (30 opus, 17 asm).
The other 6 shapes did not clear 3% and are removed, so they keep the
default:
M=80/96, N=512, K=4096
M=2048, N=6144, K=2048 M=8192/16384, N=2048, K=6144
M=8192, N=6144, K=2048
Second-run improvement over the fallback: 6.1% to 82.8%; 30-46% for the
M<=16 decode shapes and 68-80% for most of the rest. All rows pass the
tuner's accuracy check (max err_ratio 0.031).
Triton was excluded: aiter's Triton A16W16 kernel faults on gfx942 with
Triton 3.8 / ROCm 7.14 in the tuning environment. None of the 53 rows
used Triton, and the 12 existing MI300A Triton rows are untouched.
Measured on 4x MI300A (gfx942, 228 CU), ROCm 7.14, torch 2.14.
Co-authored-by: Cursor <[email protected]>
* [Tune] Recover MI300A large fp32-out bf16 GEMMs with hipBLASLt
Four of the six shapes left on the default in the previous commit are
large fp32-output GEMMs that #5145 made 2.2-2.7x slower than their old
FlyDSL rows. On gfx942 only one OPUS kernel supports fp32 output, so the
asm/opus/torch search could not beat the fallback for them.
hipBLASLt can. Tuned with --with-hipblaslt and the same compare gate
(>= 3% vs the production fallback), then confirmed in a second
independent --run_config A/B:
M N K out fallback us hipBLASLt us
2048 6144 2048 fp32 672.9 147.8
8192 2048 6144 fp32 3443.4 506.7
8192 6144 2048 fp32 2791.1 501.4
16384 2048 6144 fp32 6622.9 985.8
96 512 4096 bf16 10.7 10.1
All four large shapes also beat their old FlyDSL records. M=80 N=512
K=4096 still has no winner and keeps the default.
hipBLASLt rows store a library solution index, which is specific to the
hipBLASLt version. These were tuned on ROCm 7.14 (4x MI300A, gfx942,
228 CU); hipb_mm raises if the index is unknown to the installed
hipBLASLt, so re-tune them if MI300A moves to a different ROCm.
Co-authored-by: Cursor <[email protected]>
* [Tune] Drop the MI300A hipBLASLt bf16 rows
Review feedback: hipBLASLt rows store a solution index that is specific
to the hipBLASLt build, and lookup returns them without validation, so
an index unknown to the hipBLASLt in another container raises from
getAlgosFromIndex instead of falling back. Remove the five rows added in
2c64c88; these shapes go back to the default path:
M=96, N=512, K=4096
M=2048, N=6144, K=2048 M=8192, N=6144, K=2048
M=8192, N=2048, K=6144 M=16384, N=2048, K=6144
This reverts commit 2c64c88.
Co-authored-by: Cursor <[email protected]>
---------
Co-authored-by: Cursor <[email protected]>
vpietila-amd
pushed a commit
that referenced
this pull request
Nov 12, 2026
* [HIP] Identify MI300A and resolve gfx942 CU counts correctly
gfx942 covers three SKUs with different CU counts -- MI300X (304), MI300A
(228) and MI308X (80) -- but AITER could not tell them apart, and two
separate bugs made a 228-CU part unusable with tuned configs.
_get_pci_chip_id() queried the device id by numeric ordinal:
hipDeviceAttributePciChipId = 10019
The AMD-specific block of hipDeviceAttribute_t is an unnumbered enum, so
those ordinals shift whenever an attribute is inserted ahead of them. On
ROCm 7.2, counting the enum in hip_runtime_api.h gives 10018 =
NumberOfXccs, 10019 = MaxAvailableVgprsPerThread and 10020 = PciChipId,
so the call returned 512 on every device and the MI308 chip-id check
could never match -- MI308X has been reported as "MI300". The C++ side
uses the symbolic name and was always correct, so this is Python-only.
Resolve the id via hipDeviceGetPCIBusId plus sysfs instead, which is
stable across ROCm versions, and return None rather than raising when it
is unavailable.
get_build_targets() used GFX_CU_NUM_MAP verbatim whenever GPU_ARCHS was
set, and that table holds one canonical CU count per arch (gfx942 -> 304,
the MI300X SPX value). On a 228-CU MI300A, GPU_ARCHS=gfx942 therefore
resolved to ('gfx942', 304), gen_instances.py filtered every (gfx942,
228) row out of the tuning CSV, and those kernels were never compiled.
The failure surfaced much later as
kernel '...' is not present in the compiled registry
on 73 of 80 blockscale shapes. Prefer the live CU count when a requested
target's arch matches the running GPU and CU_NUM was not set explicitly.
An explicit CU_NUM still wins and cross-compiles are unaffected:
GPU_ARCHS=gfx942 (on MI300A) [('gfx942', 304)] -> [('gfx942', 228)]
GPU_ARCHS=gfx942 CU_NUM=304 [('gfx942', 304)] -> unchanged
GPU_ARCHS=gfx950 (cross) [('gfx950', 256)] -> unchanged
GPU_ARCHS='gfx942;gfx950' -> [(942,228),(950,256)]
This is not MI300A-specific. build_targets.py's own comment notes that
DPX/QPX/CPX partition modes change the visible CU count, so MI300X in any
non-SPX mode hits the same cliff.
Also adds 0x74A0 as the MI300A chip id so get_device_name() returns
"MI300A", and registers 228 -> gfx942 in the legacy cu_num backfill.
Verified on 4x MI300A (gfx942:sramecc+:xnack-, 228 CU, ROCm 7.2, torch
2.13): chip id 0x74a0, get_device_name() "MI300A", get_cu_num() 228.
op_tests/tuning_tests test_tuner_infra, test_csv_validation,
test_config_shape_collision and test_compare_logic pass (68 tests,
37 subtests).
Co-authored-by: Cursor <[email protected]>
* [Tune] Resolve the fp8 e4m3 flavor to the arch-native encoding on ingest
Only one e4m3 encoding exists per chip: gfx942 implements e4m3fnuz (max
240, exponent bias 8) and gfx950 implements OCP e4m3fn (max 448, bias 7).
aiter/utility/dtypes.py already knows this via defaultDtypes, but the
shipped untuned shape lists name the OCP flavor unconditionally:
aiter/configs/untuned_fmoe.csv 22 occurrences
aiter/configs/a8w8_untuned_gemm.csv 40 of 65 shapes
model_configs/a8w8_blockscale_untuned_fmoe_*.csv 16-32 each
On gfx942 every such row aborts with "Unsupported dtype:
torch.float8_e4m3fn" out of _aiter_dtype_id, because _torch_to_aiter_dtype
is built from the arch-native alias and only ever contains one flavor. The
practical effect is that two thirds of the a8w8 GEMM shape list and the
entire fp8 MoE model coverage could not be tuned at all on any MI300-class
part -- which is why no MI300 rows exist for GLM-5.x, qwen3, minimax or
dsv3.
Add dtypes.normalize_fp8_dtype(), which maps either e4m3 encoding onto the
one the running chip implements. e5m2 and non-fp8 dtypes pass through
unchanged, and it declines to act when the arch is unknown (fp8 falls back
to uint8) rather than reinterpreting fp8 data as integers.
Apply it on ingest in FmoeTuner.get_untuned_gemm_list and
GemmA8W8Tuner.get_untuned_gemm_list, plus the two string->dtype conversion
sites in the MoE tuner. Normalizing on ingest rather than at point of use
matters: applied late, the tuned row is written as e4m3fnuz while the
untuned frame still says e4m3fn, so the tuner cannot match its own result
and reports the shape as never tuned.
q_dtype_w is part of the a8w8 dispatch key, so normalizing on ingest also
keeps the emitted rows and the tuned/untuned bookkeeping agreeing on one
dtype.
Verified on MI300A (gfx942, e4m3fnuz): all 40 previously-rejected a8w8
shapes now tune, and end-to-end against the default kernel path they win
between 1.10x and 2.41x.
Co-authored-by: Cursor <[email protected]>
* [Tune] Add MI300A (gfx942, cu_num=228) configs for GEMM and fused MoE
MI300A could not reach a single tuned row before this. AITER keys every
tuned kernel on (gfx, cu_num); MI300A reports (gfx942, 228), a pair that
appeared in no row of any tuning CSV, so every GEMM and MoE lookup missed
and fell through to the CU-blind shape heuristics. Three of the four
tables touched here had no gfx942 rows at all -- a8w8_blockscale was
6630 rows of pure gfx950, and bf16 was gfx1250 and gfx950 only.
Adds 527 measured rows:
a8w8_blockscale_tuned_gemm.csv 78 rows 2.393x
a8w8_tuned_gemm.csv 64 rows 1.529x
bf16_tuned_gemm.csv 377 rows 1.367x
model_configs/mi300a_tuned_fmoe.csv 8 rows 1.136x
Existing rows are untouched: the diff is 528 insertions and zero
deletions, and the pre-existing rows in all three modified files are
byte-identical.
Method. Every row was A/B'd end-to-end through the production op with
--run_config, never on the tuner's own us, which is measured by a
separate harness and is not comparable (at token=1 the MoE tuner reported
72us for a kernel whose real end-to-end cost was 83us against a 41us
default). A row ships only if it is numerically clean and beats the
default by at least 3% in two independent runs -- once in the A/B and
again after installation, with the module rebuilt so the tuned kernels
are actually compiled in. The second run matters: five bf16 rows cleared
the first measurement at 1.033-1.060x and came back at 0.944-1.022x on
the second, one of them 5.6% slower than the default it would have
replaced. All five sit in the same N=256/512 K=4096 family. Dropping them
raised the bf16 aggregate from 1.364x to 1.367x.
Losing rows are omitted rather than corrected. Lookup is exact-match, so
an absent shape keeps the existing default, which is the safe outcome:
51 of 433 bf16 rows, 5 of 13 MoE rows and 2 of 80 blockscale rows were
dropped this way. 14 of the bf16 drops were cases where the tuner's pick
was actually slower than the default, clustered at M = 1, 2, 4.
Largest wins: bf16 M=64 N=128 K=6144 fp32-out at 42.6 -> 8.1us (5.26x);
blockscale M=1024 N=7168 K=256 at 39.0 -> 13.9us (2.82x); a8w8 M=64
N=7168 K=8192 fp8 at 82.9 -> 34.4us (2.41x).
Not covered. Nine bf16 shapes (N=50016, K=6144, fp32 out, M=192..16384)
failed every candidate with err_ratio=1.0 under --mp 4; at M=16384 the
fp32 output alone is ~3.3 GB with four workers concurrent, so this looks
like memory pressure rather than a kernel fault. They keep the default.
Paged attention and MLA are not tuned here.
Measured on 4x MI300A (gfx942:sramecc+:xnack-, 228 CU, 6 XCC, 94 GiB
unified, ROCm 7.2, torch 2.13.0+rocm7.2), one GCD pinned for all
benchmarks. Depends on the fp8 e4m3 ingest fix in the preceding commit,
without which two thirds of the a8w8 shape list cannot be tuned on gfx942.
Co-authored-by: Cursor <[email protected]>
* [Tune] Add unit tests for GPU SKU resolution and fp8 flavor normalization
Covers the new functionality in the two preceding commits. Level 1, no GPU
required, so it runs in CI without MI300-class hardware: the device queries
and the live-GPU probes are mocked.
TestDeviceName get_device_name() maps chip ids to MI300A /
MI308 / MI300, leaves gfx950 and gfx1250 alone,
and does not crash when the id is unreadable.
TestPciChipId the id is read via hipDeviceGetPCIBusId plus
sysfs and returns None on failure. Asserts
hipDeviceGetAttribute is never called -- that is
the actual regression guard, since its ordinal
comes from an unnumbered enum and shifted
between ROCm releases.
TestLegacyCuNumBackfill 228/304/80 -> gfx942 and 256 -> gfx950, for
both int and str cu_num.
TestBuildTargets the live CU count wins over the GFX_CU_NUM_MAP
default, an explicit CU_NUM still overrides it,
cross-compiling for a non-live arch keeps the
table default, multi-arch refines only the
matching target, and a missing GPU falls back to
the table. Also covers the MI308X/partition-mode
case, which is the same mechanism.
TestNormalizeFp8Dtype both e4m3 encodings resolve to the arch-native
one, idempotently; e5m2, bf16, fp32 and int8
pass through; an unknown arch passes through
rather than reinterpreting fp8 data as uint8.
TestShippedShapeLists... every fp8 shape in the shipped untuned lists
resolves to the native encoding, which is the
property that makes them tunable on gfx942.
TestTunedConfigArch... every tuned row keyed cu_num=228 is also keyed
gfx942, so the build-time codegen filter and the
runtime lookup cannot disagree.
23 tests, all passing on MI300A. Registered in the suite README table.
Co-authored-by: Cursor <[email protected]>
* [CI] Run the arch-resolution tests in the level 0+1 tuning suite
test_arch_resolution.py was added alongside the SKU-resolution and fp8
normalization changes but was not wired into CI, so it would never have
run there: the level 0+1 job names its test modules explicitly rather
than discovering them.
Adds it to the module list in tuning-tests.yaml and to the two places
that document that list, so the three stay in sync.
CI-style invocation on MI300A now reports 88 tests:
python3 -m unittest op_tests.tuning_tests.test_csv_validation \
op_tests.tuning_tests.test_tuner_infra \
op_tests.tuning_tests.test_mp_tuner_logic \
op_tests.tuning_tests.test_a6w6_tuning \
op_tests.tuning_tests.test_arch_resolution -v
The single failure, test_mp_tuner_logic's
test_worker_records_start_only_when_task_leaves_queue, is pre-existing
and unrelated: it allows a spawn-context worker 5s to record a start
timestamp, but each spawned worker re-imports aiter, measured at 8.23s
on this machine. It reproduces unchanged at f2f8ed9.
Co-authored-by: Cursor <[email protected]>
* Fix Black formatting
* Addressing co-pilot recommendations
* Style fix
* [Tune] Move the MI300A fmoe rows into the generic tuned_fmoe.csv
model_configs/ is partitioned by model -- ds_v3, glm5_1, qwen3_235b,
kimik2, minimax_m3 and so on. mi300a_tuned_fmoe.csv was named for a
hardware SKU, which does not belong in that namespace.
The rows were never model-specific to begin with: they come from the
generic aiter/configs/untuned_fmoe.csv shape list and span three
unrelated geometries (6144/4096/E8, 2304/1536/E8 and 7168/256/E256/topk8).
Their tuned counterpart is the generic aiter/configs/tuned_fmoe.csv, which
already carries MI308X rows for two of those three geometries; the MI300A
rows now sit beside them, distinguished by cu_num exactly as intended.
Rewritten into that file's schema, which predates the gfx column:
gfx dropped; _ensure_gfx_column backfills it from cu_num via
gfx_from_cu_num, where 228 -> gfx942 (added earlier in this
branch). Verified the mapping is present rather than assumed.
xbf16, flat dropped; both are 0 in all 8 rows, which is exactly what
fused_moe assumes when the columns are absent (the reads are
guarded by `if "xbf16" in cfg` / `if "flat" in cfg`).
_tag empty, matching all 617 existing rows; it only filters
"flydsl_fallback" entries.
Checked for key collisions against the existing rows before appending:
none. The merged fmoe inventory now resolves to gfx942/cu228 x8,
gfx942/cu304 x83, gfx942/cu80 x962 and gfx950/cu256 x1417, with all 8
MI300A rows reachable.
No measurements change; this is a relocation. The 1.136x aggregate quoted
in the commit that added these rows still stands, but the path named there
is now aiter/configs/tuned_fmoe.csv.
Co-authored-by: Cursor <[email protected]>
* [Tune] Share the fp8 e4m3 normalization across all tuner families
Addresses two review comments.
1. The normalization was local to GemmA8W8Tuner, but
GemmA8W8BpreShuffleTuner inherits the base CSV loader and its tuning
paths return [] for any row whose q_dtype_w != dtypes.fp8. On gfx942
the e4m3fn rows in the bpreshuffle shape lists were therefore skipped
with a warning rather than resolved, leaving that GEMM family
untunable. The scale is not marginal -- 781 rows across six shipped
lists:
a8w8_bpreshuffle_untuned_gemm_kimik3.csv 427
a8w8_bpreshuffle_untuned_gemm_glm5.2.csv 142
a8w8_bpreshuffle_untuned_gemm_glm47.csv 96
a8w8_bpreshuffle_untuned_gemm_minimax_m3.csv 80
a8w8_bpreshuffle_untuned_gemm_glm5_3_flash.csv 20
a8w8_blockscale_bpreshuffle_untuned_gemm_mm2.5.csv 16
Two other lists (glm5_a8w8_bpreshuffle, qwen38_flash_next) already
spell e4m3fnuz by hand, which is the same problem worked around
per-file.
Moved into TunerCommon.get_untuned_gemm_list so every family -- a8w8,
bpreshuffle, blockscale, batched and fmoe -- resolves on ingest, and
dropped the two now-redundant per-tuner overrides. Verified on the
kimik3 list: all 427 rows resolve to e4m3fnuz, 0 would be skipped.
The resolver also no longer uses eval(). These cells come from CSV
files whose path is caller-supplied, so eval() made the tuner a
code-execution sink; it now looks the dtype up by name and returns
anything unrecognised untouched. Covered by a test that feeds it
"__import__('os').system(...)" among other junk.
2. TestTunedConfigArchConsistency required a literal gfx column, which
tuned_fmoe.csv does not have -- it is keyed on cu_num alone and has
its arch backfilled by gfx_from_cu_num at load time. The assertion
failed for the 8 MI300A rows moved there in 2516405, so the Level 1
suite could not pass. Confirmed before fixing: 527 cu_num=228 rows
scanned, 8 failing, all in tuned_fmoe.csv.
The test now asserts on the *resolved* arch, which is what dispatch
actually keys on, and uses the literal column only when present. A
companion test pins the legacy cu_num-only path explicitly and will
fail loudly if tuned_fmoe.csv ever grows a gfx column.
Also streams the tuned CSVs instead of materializing them, as suggested
in an earlier review note, and extends the shape-list coverage to the
bpreshuffle and model_configs families via globs so newly added lists are
picked up automatically.
Three TestPciChipId cases had to change too: _load_hip_runtime() is
lru_cached, so patching ctypes.CDLL underneath it is a no-op once the
real library has been loaded. They now patch the loader itself, and the
new cases cover a missing symbol (AttributeError), a RuntimeError from
the Windows DLL search, and an absent /sys/bus/pci.
28 tests pass. CI level 0+1 on MI300A: 172 tests, the only failure the
pre-existing test_mp_tuner_logic spawn-timing case, plus 23 errors from
flydsl being absent in this harness. Black clean.
Co-authored-by: Cursor <[email protected]>
* [CI] Collapse nested with in test_arch_resolution to satisfy Ruff
Ruff SIM117 flagged the nested subTest / mock.patch context managers in
TestPciChipId.test_returns_none_when_hip_cannot_be_loaded. pre-checks runs
ruff with --exit-zero but pipes into reviewdog with -fail-on-error=true,
so the warning failed the job. Combine them into a single with statement.
ruff 0.16.0 (the version CI pins) is clean on every Python file in this
PR, and black is unchanged.
* [OPUS] Key the pre-PR codegen parity model on cu_num
test_shipped_tuned_selection_diff_is_exhaustive failed with
"assert 10301 == 10300" once the MI300A (gfx942, cu_num=228) rows from
this PR were shipped alongside upstream's MI308X (gfx942, cu_num=80) rows.
_pre_pr_codegen_tuned_map models the removed opus_gemm_lookup.h as a single
(arch, M, N, K, outdtype) table built from every shipped row, last write
wins. That is not what the pre-PR codegen did: gen_instances.py filtered
the tuned CSV to the host's cu_num before emitting the table,
if cu_num is not None:
tune_df = tune_df[tune_df["cu_num"] == cu_num].reset_index()
so each build saw exactly one cu_num per arch. Merging both gfx942 SKUs
into one table made the test compare MI300A's tuned kernel against the one
MI308X picked for the same shape -- dsv4_bf16_tuned_gemm.csv sorts after
bf16_tuned_gemm.csv, so its cu_num=80 row overwrote the cu_num=228 one.
Five shipped shapes are affected, all gfx942, each with a distinct
measured winner per SKU:
M N K cu_num=80 (MI308X) cu_num=228 (MI300A)
1 2048 4096 10301 10300
2 2048 4096 10301 10300
4 2048 4096 10301 10300
8 2048 4096 10301 10300
256 1024 4096 10210 10201
Both selections are correct for their hardware. Rewriting the MI300A rows
to MI308X's kids would make the test pass by shipping a kernel that was
never measured on MI300A, overriding the one that won the A/B there.
Key the codegen model on cu_num, matching the per-host filter and the
companion _pre_pr_python_tuned_map, which already includes cu_num. Also
make the assertion name the key and both kids on failure.
Reproduced the CI failure against the previous version of the test
(1 failed, 18 passed); all 19 pass now. ruff 0.16.0 and black clean.
Co-authored-by: Cursor <[email protected]>
* Keep table-default CU target when adding the live GPU's CU count
A multi-arch wheel built on an MI300A host replaced (gfx942, 304) with
(gfx942, 228) and lost the MI300X instances. Add the live target next to
the default instead. Also drop a stray comment in FmoeTuner.
Co-authored-by: Cursor <[email protected]>
* Reconcile MI300A blockscale kernel IDs; pin both fp8 directions in tests
Six gfx942/228 CK-Tile rows in a8w8_blockscale_tuned_gemm.csv stored
kernelIds that no longer match their kernelName in the current registry
(2->20, 3->21, 4->22). Dispatch resolves by name, but ID-based
reproduction would pick a different candidate.
The fp8 normalization tests only exercised the host's native encoding, so
CI on MI35X never covered fn->fnuz (gfx942). Add subcases that patch the
native alias to each e4m3 flavor; the real-host checks stay.
Co-authored-by: Cursor <[email protected]>
* [Tune] Retune MI300A bf16 GEMM rows left stale by the FlyDSL A16W16 refactor
#5145 replaced the FlyDSL bf16 GEMM kernels with a gfx950-only
implementation. The 53 MI300A (gfx942, cu_num=228) rows that recorded
flydsl_gemm2/3/4/5_* kernels no longer parse, so lookup skipped them and
fell back to the default path; renaming them is not an option because
the new FlyDSL A16W16 backend has no gfx942 candidates.
Retuned those 53 shapes on the remaining gfx942 backends (asm, opus,
skinny, torch) with --compare --update_improved --min_improvement_pct 3,
against the production fallback the stale rows produce. 47 shapes beat
it and were confirmed in a second independent --run_config A/B; each
stale row is replaced in place by its retuned row (30 opus, 17 asm).
The other 6 shapes did not clear 3% and are removed, so they keep the
default:
M=80/96, N=512, K=4096
M=2048, N=6144, K=2048 M=8192/16384, N=2048, K=6144
M=8192, N=6144, K=2048
Second-run improvement over the fallback: 6.1% to 82.8%; 30-46% for the
M<=16 decode shapes and 68-80% for most of the rest. All rows pass the
tuner's accuracy check (max err_ratio 0.031).
Triton was excluded: aiter's Triton A16W16 kernel faults on gfx942 with
Triton 3.8 / ROCm 7.14 in the tuning environment. None of the 53 rows
used Triton, and the 12 existing MI300A Triton rows are untouched.
Measured on 4x MI300A (gfx942, 228 CU), ROCm 7.14, torch 2.14.
Co-authored-by: Cursor <[email protected]>
* [Tune] Recover MI300A large fp32-out bf16 GEMMs with hipBLASLt
Four of the six shapes left on the default in the previous commit are
large fp32-output GEMMs that #5145 made 2.2-2.7x slower than their old
FlyDSL rows. On gfx942 only one OPUS kernel supports fp32 output, so the
asm/opus/torch search could not beat the fallback for them.
hipBLASLt can. Tuned with --with-hipblaslt and the same compare gate
(>= 3% vs the production fallback), then confirmed in a second
independent --run_config A/B:
M N K out fallback us hipBLASLt us
2048 6144 2048 fp32 672.9 147.8
8192 2048 6144 fp32 3443.4 506.7
8192 6144 2048 fp32 2791.1 501.4
16384 2048 6144 fp32 6622.9 985.8
96 512 4096 bf16 10.7 10.1
All four large shapes also beat their old FlyDSL records. M=80 N=512
K=4096 still has no winner and keeps the default.
hipBLASLt rows store a library solution index, which is specific to the
hipBLASLt version. These were tuned on ROCm 7.14 (4x MI300A, gfx942,
228 CU); hipb_mm raises if the index is unknown to the installed
hipBLASLt, so re-tune them if MI300A moves to a different ROCm.
Co-authored-by: Cursor <[email protected]>
* [Tune] Drop the MI300A hipBLASLt bf16 rows
Review feedback: hipBLASLt rows store a solution index that is specific
to the hipBLASLt build, and lookup returns them without validation, so
an index unknown to the hipBLASLt in another container raises from
getAlgosFromIndex instead of falling back. Remove the five rows added in
2c64c88; these shapes go back to the default path:
M=96, N=512, K=4096
M=2048, N=6144, K=2048 M=8192, N=6144, K=2048
M=8192, N=2048, K=6144 M=16384, N=2048, K=6144
This reverts commit 2c64c88.
Co-authored-by: Cursor <[email protected]>
---------
Co-authored-by: Cursor <[email protected]>
Merged
3 of 10 tasks
yifehuan
pushed a commit
that referenced
this pull request
Dec 2, 2026
…ws on gfx950 (#8915) The rows of 6016 x 7168 and of 6288 x 7168 at 1, 2, 4, 8, 16 and 32 rows name the same tile with _bnt. They are older than the option (#5145, #6019 and #5903; the option is #7546), so the tuner never raced it for them. A decode step reads the weights of every layer once, and the tuner measures that: run_perftest gives every timed launch its own copy of the tensors. MI355X, one GPU, FlyDSL 0.5.3, the tuner's method (10 warm-up and 101 timed eager launches), 3 runs per kernel, the two kernels alternate, median, microseconds, row today -> _bnt: 1 x 6016 x 7168 16.31 -> 15.40 2 x 6016 x 7168 16.39 -> 15.53 4 x 6016 x 7168 16.46 -> 15.70 8 x 6016 x 7168 16.62 -> 16.02 16 x 6016 x 7168 17.93 -> 17.20 32 x 6016 x 7168 18.30 -> 16.93 1 x 6288 x 7168 16.78 -> 15.63 2 x 6288 x 7168 16.96 -> 15.57 4 x 6288 x 7168 17.00 -> 15.68 8 x 6288 x 7168 17.33 -> 16.27 16 x 6288 x 7168 18.34 -> 17.46 32 x 6288 x 7168 20.41 -> 19.68 That is 3.6 % to 8.2 % less time per launch. The six rows of 6016 x 7168 and the row of 32 x 6288 x 7168 were measured on main b4d0133. The other five rows were measured in a second session, on main 8b6b4b4 with those seven rows changed. solidx is the index of the new name in the tuner catalog; us, err_ratio, tflops and bw are the _bnt measurements. tgemm.mm selects these rows for 1 to 32 rows of both shapes. A caller that launches one weight tensor back to back while it fits the last-level cache can get slower. Measured with one weight tensor: +7.7 % for 32 x 6288 x 7168, +11.5 % and +12.8 % for 16 x 6016 x 7168, -3.9 % and -2.8 % for 32 x 6016 x 7168. The other nine rows were not measured in that state. Signed-off-by: Jin Pan <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
splitk_hgemmandsmall_m_hgemmimplementations.Tuned Info
Across 2,186 updated model-config entries, the new configurations deliver a 1.055× geometric-mean speedup and a 3.06% median latency reduction.
FlyDSL HGEMM is selected for 1,554 of 2,186 entries (71.09%).
Reference