Repository navigation
[Triton/Gluon] [Config] Tune gfx1250 a16w16 GEMMs for Kimi K2 - #6595
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.
🟡 Changes recommended
The new sparse configs replace intermediate default buckets with oversized tiles that add padded work.
1 open finding
What changed in this PR
Tunes gfx1250 Gluon A16W16 GEMM configurations for Kimi K2 workloads.
Changes:
- Adds shape-specific configurations for three GEMMs.
- Retunes selected buckets for the existing 2112 × 7168 configuration.
- Adjusts tile sizes, buffer counts, warp counts, and kernel selection.
| File | Description |
|---|---|
aiter/ops/triton/configs/gfx1250/gluon/gemm/gemm_a16w16/GEMM-A16W16-N=7168-K=2048.json |
Adds five tuned M buckets. |
aiter/ops/triton/configs/gfx1250/gluon/gemm/gemm_a16w16/GEMM-A16W16-N=4096-K=512.json |
Adds kv_b_proj shape tuning. |
aiter/ops/triton/configs/gfx1250/gluon/gemm/gemm_a16w16/GEMM-A16W16-N=3072-K=1536.json |
Adds five tuned M buckets. |
aiter/ops/triton/configs/gfx1250/gluon/gemm/gemm_a16w16/GEMM-A16W16-N=2112-K=7168.json |
Retunes small-M entries and large-M warp counts. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
This shape was tuned on a 96-CU partition, and gfx1250/96cu already has a tuned GEMM-A16W16-N=2112-K=7168.json (#6573), so the 256-CU file goes back to its main version. Co-authored-by: Cursor <[email protected]>
DEFAULT.json is a byte-identical copy of gfx1250/gluon/gemm/gemm_a16w16_persistent/DEFAULT.json, to start the 96-CU tree for the Kimi-K2 shapes tuned on a 96-CU partition. Co-authored-by: Cursor <[email protected]>
Pure git mv. These shapes were tuned on a 96-CU partition. Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The 12 reported Gluon correctness failures lack case details and baseline results, and GPU validation is unavailable here to determine whether the new configs introduce regressions.
1 open issue
2 resolved since last review
Review effort: Balanced
…aligned to BLOCK_SIZE_K The non-EVEN_K path masked the A/B data loads but loaded the e8m0 scales unmasked, so the last K iteration read scale groups past the end of the scale tensors. Garbage 0xFF bytes (NaN in e8m0) propagate through tl.dot_scaled even where the data is zero, producing NaN rows in the output, and fresh allocations can page-fault. Mask the scale loads and fill with 127 (scale 1.0), matching gemm_afp4wfp4 and batched_gemm_a16wfp4. Co-authored-by: Cursor <[email protected]>
One backend per PR: this PR keeps the gfx1250 96cu Gluon a16w16 and a16w16_persistent configs. The OPUS kernel registration, the Kimi-K2 OPUS rows in kimik2_bf16_tuned_gemm.csv and the policy parity test change move to the erizheng-bf16-gemm-opus branch. Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Twelve unresolved non-TN Gluon correctness failures lack baseline comparisons, and nine persistent-shape fallback changes on 96-CU gfx1250 lack benchmarks, requiring GPU validation unavailable in this review.
1 open issue
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The 12 unresolved non-TN Gluon correctness failures and fallback changes for nine unbenchmarked persistent shapes require baseline comparisons and gfx1250 96-CU validation to establish regression risk.
1 open issue
Review effort: Balanced
Done, the OPUS side tuning results are now in #7514 |
There was a problem hiding this comment.
🟡 Changes recommended
Several tuned GEMM buckets exceed gfx1250’s LDS limit for supported BF16 layouts and need retuning and validation through the public wrappers.
8 open issues
Retune the M=256 bucket to fit LDS for NT and TN · New Retune M≤1024 buckets to fit LDS for all layouts · New Retune M=32 and M=64 buckets to fit LDS for TT · New Retune small-M buckets to fit LDS for TT · New Retune the M=128 bucket to fit LDS for TT · New Retune the M=32 bucket to fit LDS for TT · New Retune the M=64 bucket to fit LDS for TT · New Preserve NUM_KSPLIT in baseline configs · New
1 resolved since last review
Review effort: Balanced
* [OPUS] Tune gfx1250 a16w16 GEMMs for Kimi K2 on 96 CUs Register the gfx1250 a16w16 kernels for 96 CUs as well as 256, so OPUS rows tuned on a 96-CU partition resolve. Add 20 OPUS rows to kimik2_bf16_tuned_gemm.csv for the four Kimi-K2 BF16 projection shapes, (N, K) = (2112, 7168), (3072, 1536), (4096, 512) and (7168, 2048), at M = 4, 8, 16, 8192 and 16384. The policy parity test keys its pre-PR codegen map by CU count too. With two gfx1250 CU tables, a same-shape row on 96 and 256 CUs would otherwise overwrite the other in that map. Split out of #6595, which keeps the Gluon configs. Co-authored-by: Cursor <[email protected]> * Addressing copilot review comment * Tune gfx1250 96cu OPUS a16w16 for extra Kimi-K2 shapes * Address reviewer comment --------- Co-authored-by: Cursor <[email protected]>



Summary
This PR adds tuned Gluon
gemm_a16w16andgemm_a16w16_persistentconfigs for Kimi-K2 BF16 GEMMs on gfx1250 96-CU partitions. It covers 12 (N, K) shapes:The OPUS rows for these shapes are in #7514.
Motivation
On a gfx1250 96-CU partition,
mainhas no tuned config for most of these GEMMs, or has one only for some M:gemm_a16w16: the 96cu tree has no file for (2048, 512), (3072, 1536), (4096, 512) or (7168, 2048), so those shapes useDEFAULT.jsonat every M. It has files for the other eight TP8 shapes, but five of them define only M ≤ 128,M_LEQ_8192andany, so M = 129–4096 usesDEFAULT.json. For the nine TP8 shapes, the configs in this PR differ from whatmainserves in 80 of 126 buckets, mostly at M ≥ 256.gemm_a16w16_persistent: there is no 96cu tree, so 96-CU devices read the plain tree. That tree was tuned on 256 CUs and has no file for any of these shapes, so they all use itsDEFAULT.json.Changes
All changes are limited to gfx1250 with
cu_num=96, underaiter/ops/triton/configs/gfx1250/96cu/gluon/gemm/. Selections on 256 CUs are the same as onmain.gemm_a16w16(96cu):M_LEQ_1toM_LEQ_8192, andany) and no fallback.M_LEQ_4,M_LEQ_8,M_LEQ_16,M_LEQ_8192andany, withDEFAULT_FALLBACK, so M = 1 and M = 17–4096 useDEFAULT.json.DEFAULT.jsonis unchanged.gemm_a16w16_persistent(96cu): a new tree with files for all 12 shapes, with the same bucket layout as above. ItsDEFAULT.jsonis a byte-for-byte copy of the plain tree's.Validation
get_gemm_configon the 96-CU device returned that config for every bucket.DEFAULT.jsondefines;DEFAULT.jsonis byte-identical to the plain one;gfx1250/96cu/gluon/gemm/changes.verify_configs.py --expect-tuned, the shape-collision unittest and the Gluon a16w16 and persistent correctness tests.Performance
q_b_proj, 1536 x 1536
kv_b_proj, 2048 x 512
o_proj, 7168 x 1024
dense gate_up, 4608 x 7168
dense down, 7168 x 2304
shared-expert down, 7168 x 256
fused q_a + kv_a, 2112 x 7168
shared-expert gate_up, 512 x 7168
MoE router, 384 x 7168
PR Self-Review
Reviewed revision
7a8722e
Behavior and intent
This PR adds tuned Gluon
gemm_a16w16andgemm_a16w16_persistentconfigs for 12 Kimi-K2 BF16 GEMM shapes on gfx1250 96-CU partitions. They are the nine TP8 shapes (1536, 1536), (2048, 512), (7168, 1024), (4608, 7168), (7168, 2304), (7168, 256), (2112, 7168), (512, 7168) and (384, 7168), and the three TP4 attention projections (3072, 1536), (4096, 512) and (7168, 2048).On
main, 96-CU devices mostly get untuned configs for these shapes. Ingemm_a16w16, four of the shapes have no 96cu file, and five more have no buckets for M = 129–4096, so those cases useDEFAULT.json.gemm_a16w16_persistenthas no 96cu tree, so it reads the 256-CU tree, which has none of these shapes.What changes:
gemm_a16w16(96cu): new or retuned files for all 12 shapes. The TP8 files cover all 14 M buckets. The TP4 files coverM_LEQ_4,M_LEQ_8,M_LEQ_16,M_LEQ_8192andany, and useDEFAULT.jsonfor the rest.gemm_a16w16_persistent(96cu): a new tree with the same 12 shapes and a byte-identical copy of the plainDEFAULT.json. 21 buckets use split-K.mainis +25% forgemm_a16w16and +35% for persistent, mostly at M ≥ 256.Nothing changes on 256-CU devices or other architectures. The OPUS rows are in #7514.
Side effects, on 96-CU gfx1250 only:
A CU tree is read whole, so the 9 shape files in the plain persistent tree no longer apply on 96 CUs: (1024, 7168), (128, 2880), (128, 4096), (128, 5120), (1280, 2880), (256, 7168), (2880, 1024), (2880, 4096) and (5120, 2880). Those shapes now use
DEFAULT.json.Configs are not keyed on memory layout, and tuning ran only on TN, the layout Kimi uses. Every bucket fits in LDS on TN. On other layouts, 15 bucket and layout pairs that work on
mainnow exceed LDS and raiseOutOfResources:gemm_a16w16: (2112, 7168)M_LEQ_256NT; (512, 7168)M_LEQ_256NT and TT; (512, 7168)M_LEQ_1024NT.M_LEQ_32andM_LEQ_64; (2048, 512)M_LEQ_256; (2112, 7168)M_LEQ_1toM_LEQ_16; (384, 7168)M_LEQ_128; (4608, 7168)M_LEQ_32; (512, 7168)M_LEQ_64; (7168, 1024)M_LEQ_64.The tuner's LDS filter leaves out layout padding and the persistent kernel's C buffer. These 15 pairs are not fixed at this revision.
Validation and unverified scope
Hardware: gfx1250, 96-CU partition, bf16.
get_gemm_configreturned the written config for every bucket.gemm_a16w16(x, w, config=..., persistent=...)at the bucket's largest M (16384 forany). I used every layout each kernel accepts and compared the output with an fp32torchmatmul. All 282 TN launches ran, and every launch that ran had relative error ≤ 1.72e-3. All 33 failures wereOutOfResourceson non-TN layouts: the 15 regressions above, plus 18 that also fail onmain.gfx1250/96cu/gluon/gemm/, parse as JSON and have everyDEFAULT.jsonkey. The 96cu persistentDEFAULT.jsonis byte-identical to the plain one.Unverified:
verify_configs.py --expect-tuned, the shape-collision unittest and the Gluon a16w16 op tests were not run at ef6beed, so theconfig=Nonelookup is untested at this revision.DEFAULT.json, fp16, and an end-to-end Kimi-K2 run.DEFAULT.jsonhas noNUM_KSPLIT, a future tuner sweep would benchmark the 21 split-K buckets at split 1. Runtime is unaffected.PR-specific question
These configs are read only by
gemm_a16w16inaiter/ops/triton/gemm/basic/gemm_a16w16.py, on the Gluon backend (the default on gfx1250), and only when the caller passes noconfig. Withpersistent=Falseit looks upGEMM-A16W16, and withpersistent=Trueit looks upGEMM-A16W16-PERSISTENT.tuned_gemmruns the non-persistent kernel for any shape and M that has no row in the BF16 tuned CSV, and it never selects the persistent kernel. Where a CSV row exists, the row takes precedence over these configs. Examples are the FlyDSL rows for (2112, 7168) at M = 64 and 256, and the OPUS rows in #7514.The workload key has four parts:
resolve_config_dir()pick the96cutree, and only if that tree has aDEFAULT.json;M_LEQ_xwith M ≤ x, otherwiseany. In the TP4 files, missing buckets come fromDEFAULT.json.Dtype and memory layout are not part of the key.
Unrelated shapes keep their previous selection:
git diff --name-onlyagainst the merge base lists 25 files, all undergfx1250/96cu/gluon/gemm/. 256-CU devices and other architectures therefore read the same files as onmain.gemm_a16w16tree,DEFAULT.jsonand every other shape file are unchanged, so every other shape resolves as before.DEFAULT.jsonis byte-identical (cmp) to the plain one that 96-CU devices read before. Persistent shapes without a plain-tree shape file therefore get the same config.The exception is the 9 plain-tree persistent shapes listed above, which now use
DEFAULT.jsonon 96 CUs.Changed op tests
None