Skip to content

[Config] small-M shapes for Kimi-K3 BF16 GEMMs for gfx950 - #5903

Merged
yifehuan merged 4 commits into
ROCm:mainfrom
samutamm:kimi-k3-small-m-gemm
Oct 13, 2026
Merged

yifehuan merged 4 commits into
ROCm:mainfrom
samutamm:kimi-k3-small-m-gemm

Conversation

@samutamm

@samutamm samutamm commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Tunes 51 additional bf16 GEMM shapes for Kimi K3 (aiter/configs/model_configs/kimik3_bf16_tuned_gemm.csv), focused on small-M decode/low-concurrency shapes (M=1-256). Small M corresponds to decode (one new token per request per forward pass, or a few with speculative decoding), which is called on every generation step for the lifetime of every request - so this is where tuning has real impact for decode-latency-sensitive serving (interactive chat, agentic/tool-calling loops), unlike a single large-M prefill shape which is only hit once per request.

Technical Details

  • 51 shapes added, each measured with a real end-to-end speedup over the current default kernel dispatch, on a single gfx950 node. Mean speedup 1.20x, median 1.19x, range 0.99x-1.74x.
  • Adds matching untuned rows for all 51 shapes to kimik3_bf16_untuned_gemm.csv, so a future retune run correctly skips them instead of re-searching from scratch.

Benchmark methodology - the canonical tuner script's --run_config benchmark mode (csrc/gemm_a16w16/README.md, "Common Options"):

# default-kernel baseline (force fallback: --run_config alone does not clear AITER_CONFIG_GEMM_BF16)
AITER_CONFIG_GEMM_BF16=<empty_header_only.csv> \
  python3 csrc/gemm_a16w16/gemm_a16w16_tune.py -i <shapes.csv> --run_config

# tuned-kernel benchmark (reads shapes + kernel choice straight from the tuned CSV)
python3 csrc/gemm_a16w16/gemm_a16w16_tune.py --run_config <tuned_shapes.csv>

Test Plan

  • python3 -m unittest op_tests.tuning_tests.test_config_shape_collision -v - run against this exact diff.
  • python3 -m pytest op_tests/test_opus_a16w16_policy_parity.py -q - run against this exact diff, rebased onto main.
  • All 51 shipped shapes passed checkAllclose (atol/rtol=0.05) against the torch reference during the --run_config benchmark passes, both default and tuned.

Test Result

  • test_config_shape_collision: 22 passed, clean for the bf16_tuned_gemm family.
  • test_opus_a16w16_policy_parity: 19 passed, clean.
  • Validation summary for the 51 shipped shapes:
    • libtype breakdown: 49 FlyDSL, 1 ASM, 1 torch
    • 51/51 passed accuracy and benchmark checks (default + tuned, status=OK)
    • maximum recorded tuning error ratio: 0.0234 (threshold: 0.05)
    • tuned and untuned CSV keys are unique (test_config_shape_collision)

Submission Checklist

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5903 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@samutamm
samutamm marked this pull request as ready for review September 28, 2026 07:22
@samutamm
samutamm requested a review from a team September 28, 2026 07:22
@samutamm
samutamm force-pushed the kimi-k3-small-m-gemm branch 2 times, most recently from 7aaa14a to 1d368cd Compare September 28, 2026 08:35
@zufayu
zufayu requested a review from yifehuan September 29, 2026 00:32
@github-actions github-actions Bot changed the title [Config] small-M shapes for Kimi-K3 BF16 GEMMs for gfx950 [OPUS] small-M shapes for Kimi-K3 BF16 GEMMs for gfx950 Sep 30, 2026
@github-actions github-actions Bot added OPUS and removed Config labels Sep 30, 2026
@samutamm
samutamm force-pushed the kimi-k3-small-m-gemm branch from da45a90 to 853fdaf Compare September 30, 2026 14:39
@samutamm

Copy link
Copy Markdown
Contributor Author

@yifehuan Is 853fdaf valid thing to do? I noticed it changed this PR from Config to Opus. I can revert it and see and remove conflicting shape instead?

@samutamm
samutamm marked this pull request as draft October 12, 2026 05:12
samutamm and others added 3 commits October 12, 2026 08:47
The new tuned config row for this shape selects opus kernel 9 instead
of the legacy 21177, which the exhaustive selection-diff test didn't
yet account for.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@samutamm
samutamm force-pushed the kimi-k3-small-m-gemm branch from 853fdaf to 603eeb1 Compare October 12, 2026 07:52
@samutamm samutamm changed the title [OPUS] small-M shapes for Kimi-K3 BF16 GEMMs for gfx950 [config] small-M shapes for Kimi-K3 BF16 GEMMs for gfx950 Oct 12, 2026
@samremes

Copy link
Copy Markdown
Contributor

@samutamm FYI for M<5: #4114

@samremes samremes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@samremes
samremes marked this pull request as ready for review October 12, 2026 12:09
Copilot AI balanced review requested due to automatic review settings October 12, 2026 12:09
@github-actions github-actions Bot changed the title [config] small-M shapes for Kimi-K3 BF16 GEMMs for gfx950 [Config] small-M shapes for Kimi-K3 BF16 GEMMs for gfx950 Oct 12, 2026
@github-actions github-actions Bot added Config and removed OPUS labels Oct 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Some untuned shapes are inadvertently excluded from future tuning, and one claimed shape lacks a tuned entry.

3 open findings
What changed in this PR

Adds gfx950 BF16 GEMM tuning data for Kimi-K3, primarily targeting small-M decode workloads.

Changes:

  • Adds new FlyDSL, ASM, and torch tuning selections.
  • Expands the Kimi-K3 untuned shape inventory.
  • Updates or removes existing tuning records.
File Description
kimik3_bf16_untuned_gemm.csv Updates candidate shapes for future tuning.
kimik3_bf16_tuned_gemm.csv Adds and replaces gfx950 tuned configurations.
kimi_bf16_tuned_gemm.csv Removes one existing Kimi tuning record.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@yifehuan yifehuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, It's ok, Sorry for the late reply! Reverting the parity-test change was the right call, It doesn't matter

@yifehuan
yifehuan merged commit 6059fa0 into ROCm:main Oct 13, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants