Skip to content

[Config] [Perf] Retune Llama-3.1-405B BF16 GEMM config for gfx950 - #7479

Merged
demonsan merged 9 commits into
ROCm:mainfrom
afriedri-amd:config/llama405b-bf16-retune-gfx950
Nov 30, 2026
Merged

demonsan merged 9 commits into
ROCm:mainfrom
afriedri-amd:config/llama405b-bf16-retune-gfx950

Conversation

@afriedri-amd

@afriedri-amd afriedri-amd commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR retunes aiter/configs/model_configs/llama405B_bf16_tuned_gemm.csv for gfx950 (256 CU). 155 of 156 rows change. No code changes.

On upstream main, vLLM Llama-3.1-405B BF16 TP8 serving at concurrency 32 goes from 904.6 to 994.6 output tok/s (+10.0%). gsm8k accuracy does not change.

Motivation

#5145 regenerated this table, together with 12 other model tables. Many of its rows select kernels that are slower than the us column records.

For example, gate_up (M=32, N=13312, K=16384) records 78.5 µs for its FlyDSL kernel. That kernel measures 96–108 µs, and the best available kernel measures 78–81 µs.

As a result, vLLM Llama-3.1-405B BF16 serving lost about 7% throughput compared with vLLM v0.29, which used the table from before #5145.

Changes

  • Replace the 156-row table with a retune on gfx950/256 CU, keeping the same columns and row order.
    • 155 rows change. 112 rows select a different kernel; 43 rows keep their kernel and update only us, err_ratio, tflops and bw.
    • Rows by backend: FlyDSL 65, torch 63, asm 26, triton 1, opus 1.
  • The one OPUS row, (M=128, N=53248, K=16384), uses local kid 136. The tuner wrote the old global kid 6401, which stopped resolving after [HIP] [CK] [OPUS] OPUS global kid to local kid #6937 moved OPUS to local ids. The runtime loader would drop the row, and test_opus_a16w16_policy_parity failed in CI. It is the same kernel, opus_gemm_mono_tile_512x128x256x64_2x4_16x16x32_0x0x0_nooob_4g_safe, so us and the other columns are unchanged.
  • Keep the current row for (M=16384, N=53248, K=16384). That is a TP1 shape, and no candidate passed in the retune.
  • No code, kernel or dependency changes.

Performance (if applicable)

vLLM 0.33.0rc1.dev484, Llama-3.1-405B-Instruct BF16, TP8, --gpu-memory-utilization 0.85. vllm bench serve random dataset: 1024 input and 1024 output tokens, --ignore-eos, concurrency 32, 320 prompts.

Hardware Workload/configuration Before After Change
MI350X ×8 upstream main a2ea45340 + this PR, FlyDSL 0.4.1: output tok/s 904.6 994.6 +10.0%
MI350X ×8 same: median TPOT (ms) 32.46 29.28 −9.8%
MI350X ×8 same: mean TTFT (ms) 3069 2988 −2.6%
MI350X ×8 aiter 0.1.27, FlyDSL 0.4.0: output tok/s 898.6 996.0 +10.8%
MI355X ×8 aiter 0.1.27, FlyDSL 0.4.0, dummy weights: output tok/s 925.2 1024.3 +10.7%

For reference, vLLM v0.29, which predates #5145, gives 966.1 tok/s on MI350X and 998.6 tok/s on MI355X.

GEMM time per decoder layer (qkv + o + gate_up + down), in µs. Single MI350X, upstream main a2ea45340, CUDA graph of 40 calls over 4 rotating weight sets, CUDA events, median of 5:

M Before After Change
1 167.0 145.9 −12.6%
32 173.0 148.4 −14.2%
128 230.9 191.4 −17.1%
512 678.9 450.3 −33.7%
1024 1156.8 720.5 −37.7%
1056 1011.9 1045.2 +3.3%
2048 1449.2 1437.0 −0.8%
8192 5591.7 5488.9 −1.8%

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

No unit tests changed, because this PR only changes data. The existing config tests pass (see Validation).

MI250X and MI300X are not affected: every row is keyed gfx950,256, so gfx90a and gfx942 never read these rows. Tested on MI350X and MI355X.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

The change is tuned data only. Behavior and interfaces do not change.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None.

PR Self-Review

Reviewed revision

f17298b

Behavior and intent

The BF16 GEMM dispatch (aiter.tuned_gemm → get_GEMM_A16W16_config) now selects a different kernel for 112 Llama-3.1-405B shapes on gfx950/256 CU.

The current rows from #5145 select kernels that are 10–20% slower than their recorded us, and slower than other available kernels. That causes a 7–10% end-to-end throughput loss for Llama-3.1-405B BF16 serving.

The retune uses the same tuner (csrc/gemm_a16w16/gemm_a16w16_tune.py) and the same candidate set and correctness check. The only difference is how it measures time; see "Validation and unverified scope".

Validation and unverified scope

All on commit 77bb03492 over upstream a2ea45340, FlyDSL 0.4.1, MI350X, unless stated otherwise. The later commits merge main into the branch, and f17298b4a changes the OPUS row's solidx from 6401 to 136 (see Changes). With 6401 the runtime dropped that row. It is a TP1 gate_up shape, so the TP8 measurements below never used it. The PR diff is still this one file:

  • python3 -m unittest op_tests.tuning_tests.test_csv_validation op_tests.tuning_tests.test_config_shape_collision op_tests.tuning_tests.test_a16w16_tuned_config_lookup: 54 tests passed.

  • TUNE_TEST_FAMILY=csrc_bf16 TUNE_TEST_CONFIG=aiter/configs/model_configs/llama405B_bf16_tuned_gemm.csv python3 -m unittest op_tests.tuning_tests.test_run_config.TestRunConfigCustom: passed, 156 of 156 shapes OK.

  • Merged runtime config, diffed with AITER_CONFIGS.get_config_file("AITER_CONFIG_GEMM_BF16", ...) on upstream main and on this branch:

    • 5541 rows on each side, 0 duplicate keys, 0 keys added or removed;
    • 112 changed selections, all of them in this file;
    • 5385 other keys unchanged.
  • At f17298b4a: every OPUS row in the shipped *bf16_tuned_gemm.csv files (1224 rows) resolves through get_kernel_instance(gfx, "a16w16", solidx, cu_num) to an instance whose name matches kernelName. That is the check test_opus_a16w16_policy_parity makes.

  • No "not recognized … falling back" message for any FlyDSL kernel name, in the microbenchmark or in the vLLM server logs.

  • Microbenchmark of the four TP8 shapes at 26 values of M (1–8192): results in the Performance table. Two single-op rows are more than 5% slower, both at M=96 (padded to the M=128 row): qkv 24.3 → 26.8 µs and o 17.2 → 19.9 µs.

  • vLLM end to end at concurrency 32: results in the Performance table. Each arm ran in a fresh container, with no other GPU processes during the measured run.

  • gsm8k (lm-eval 0.4.13, 5-shot, 1319 questions), MI350X with real weights, aiter 0.1.27 stack:

    flexible-extract strict-match
    before 0.9553 ± 0.0057 0.9477 ± 0.0061
    after 0.9568 ± 0.0056 0.9522 ± 0.0059

    No change within noise. The largest err_ratio in the new table is 0.032.

Tuning method:

  • The stock tuner did not work on torch 2.13 / ROCm 10, on either MI350X or MI355X:
    • torch-profiler timing returned no valida data after post process for most candidates, and later failed with HSA_STATUS_ERROR_OUT_OF_RESOURCES;
    • --mp 8 filled all GPUs, after which candidates failed silently.
  • For this retune, aiter.test_common.run_perftest was replaced with CUDA-graph replay of 40 calls over at least 1 GiB of rotated argument copies, timed by CUDA events (median of 5). The tuner ran as 8 single-GPU --mp 1 processes.
  • I will report these tuner problems in a separate issue.

Unverified or not covered:

  • gsm8k was not run on the upstream main stack; it was run on the aiter 0.1.27 stack with the same table.
  • MI355X was not tested on upstream main. On the aiter 0.1.27 stack it was tested with dummy weights. A separate MI355X TP8 retune selected the same kernel for 37 of 52 rows and gave 1021.4 vs 1024.3 tok/s, so one table is sufficient for both SKUs.
  • Concurrency 1, 8 and 128 were not run.
  • The TP1–TP4 shapes in this file (N, K other than the four TP8 pairs) were checked only by the tuner and run_config, not end to end.
  • At M≈1056 (padded to the M=2048 row), per-layer GEMM time is 3.3% slower. An intermediate M row is a possible follow-up.

PR-specific question

Which workload keys use these changes: only the BF16 GEMM keys (gfx=gfx950, cu_num=256, M, N, K, bias=False, dtype=torch.bfloat16, outdtype=torch.bfloat16, scaleAB=False, bpreshuffle=False), with:

  • N, K one of the 12 Llama-3.1-405B pairs: (2304, 16384), (4608, 16384), (9216, 16384), (13312, 16384), (16384, 2048), (16384, 4096), (16384, 6656), (16384, 8192), (16384, 13312), (16384, 26624), (26624, 16384), (53248, 16384);
  • M one of the 13 rows, from 1 to 32768.

Runtime M values round up to those rows. These are the qkv, o, gate_up and down projections at TP1, TP2, TP4 and TP8.

Why other shapes keep their previous selection:

  • The PR changes only this file.
  • No key in this file is present in any other *bf16_tuned_gemm*.csv, and the shape-collision test passes.
  • I built the merged runtime BF16 config with AITER_CONFIGS.get_config_file on upstream main and on this branch. The key sets are identical (5541 rows each). Only 112 selections change, all keyed in this file, and the other 5385 keys keep the same libtype, solidx, splitK and kernelName.
  • gfx942, gfx90a and other cu_num values have no rows here, so they are not affected.

Changed op tests

None.


🤖 Generated with Claude Code

https://claude.ai/code/session_017JGuDSsfinKAQhqUaGzpK7

Retune all rows of model_configs/llama405B_bf16_tuned_gemm.csv on
gfx950/256 CU (155 of 156 rows change; the TP1 row
(16384, 53248, 16384) keeps its current entry because no candidate
passed in the retune). Many current rows select kernels that measure
10-20% slower than their recorded us. With this table, vLLM
Llama-3.1-405B BF16 TP8 serving at concurrency 32 goes from 902 to
999 output tok/s on aiter main (MI350X). gsm8k accuracy is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017JGuDSsfinKAQhqUaGzpK7
Signed-off-by: Andy Friedrich <[email protected]>
@github-actions

github-actions Bot commented Nov 4, 2026

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 (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 7479 --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.

@aiter-bot

aiter-bot commented Nov 4, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision f17298b4a3df · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

The BF16 GEMM dispatch (`aiter.tuned_gemm` → `get_GEMM_A16W16_config`) now selects a different kernel for 112 Llama-3.1-405B shapes on gfx950/256 CU.

The current rows from #5145 select kernels that are 10–20% slower than their recorded `us`, and slower than other available kernels. That causes a 7–10% end-to-end throughput loss for Llama-3.1-405B BF16 serving.

The retune uses the same tuner (`csrc/gemm_a16w16/gemm_a16w16_tune.py`) and the same candidate set and correctness check. The only difference is how it measures time; see "Validation and unverified scope".

Validation and unverified scope

All on commit `77bb03492` over upstream `a2ea45340`, FlyDSL 0.4.1, MI350X, unless stated otherwise. The later commits merge `main` into the branch, and `f17298b4a` changes the OPUS row's `solidx` from 6401 to 136 (see Changes). With 6401 the runtime dropped that row. It is a TP1 gate_up shape, so the TP8 measurements below never used it. The PR diff is still this one file:

- `python3 -m unittest op_tests.tuning_tests.test_csv_validation op_tests.tuning_tests.test_config_shape_collision op_tests.tuning_tests.test_a16w16_tuned_config_lookup`: 54 tests passed.
- `TUNE_TEST_FAMILY=csrc_bf16 TUNE_TEST_CONFIG=aiter/configs/model_configs/llama405B_bf16_tuned_gemm.csv python3 -m unittest op_tests.tuning_tests.test_run_config.TestRunConfigCustom`: passed, 156 of 156 shapes OK.
- Merged runtime config, diffed with `AITER_CONFIGS.get_config_file("AITER_CONFIG_GEMM_BF16", ...)` on upstream main and on this branch:
  - 5541 rows on each side, 0 duplicate keys, 0 keys added or removed;
  - 112 changed selections, all of them in this file;
  - 5385 other keys unchanged.
- At `f17298b4a`: every OPUS row in the shipped `*bf16_tuned_gemm.csv` files (1224 rows) resolves through `get_kernel_instance(gfx, "a16w16", solidx, cu_num)` to an instance whose name matches `kernelName`. That is the check `test_opus_a16w16_policy_parity` makes.
- No "not recognized … falling back" message for any FlyDSL kernel name, in the microbenchmark or in the vLLM server logs.
- Microbenchmark of the four TP8 shapes at 26 values of M (1–8192): results in the Performance table. Two single-op rows are more than 5% slower, both at M=96 (padded to the M=128 row): qkv 24.3 → 26.8 µs and o 17.2 → 19.9 µs.
- vLLM end to end at concurrency 32: results in the Performance table. Each arm ran in a fresh container, with no other GPU processes during the measured run.
- gsm8k (lm-eval 0.4.13, 5-shot, 1319 questions), MI350X with real weights, aiter 0.1.27 stack:

  | | flexible-extract | strict-match |
  |---|---|---|
  | before | 0.9553 ± 0.0057 | 0.9477 ± 0.0061 |
  | after | 0.9568 ± 0.0056 | 0.9522 ± 0.0059 |

  No change within noise. The largest `err_ratio` in the new table is 0.032.

Tuning method:
- The stock tuner did not work on torch 2.13 / ROCm 10, on either MI350X or MI355X:
  - torch-profiler timing returned `no valida data after post process` for most candidates, and later failed with `HSA_STATUS_ERROR_OUT_OF_RESOURCES`;
  - `--mp 8` filled all GPUs, after which candidates failed silently.
- For this retune, `aiter.test_common.run_perftest` was replaced with CUDA-graph replay of 40 calls over at least 1 GiB of rotated argument copies, timed by CUDA events (median of 5). The tuner ran as 8 single-GPU `--mp 1` processes.
- I will report these tuner problems in a separate issue.

Unverified or not covered:
- gsm8k was not run on the upstream main stack; it was run on the aiter 0.1.27 stack with the same table.
- MI355X was not tested on upstream main. On the aiter 0.1.27 stack it was tested with dummy weights. A separate MI355X TP8 retune selected the same kernel for 37 of 52 rows and gave 1021.4 vs 1024.3 tok/s, so one table is sufficient for both SKUs.
- Concurrency 1, 8 and 128 were not run.
- The TP1–TP4 shapes in this file (N, K other than the four TP8 pairs) were checked only by the tuner and `run_config`, not end to end.
- At M≈1056 (padded to the M=2048 row), per-layer GEMM time is 3.3% slower. An intermediate M row is a possible follow-up.

PR-specific question

**Which workload keys use these changes:** only the BF16 GEMM keys `(gfx=gfx950, cu_num=256, M, N, K, bias=False, dtype=torch.bfloat16, outdtype=torch.bfloat16, scaleAB=False, bpreshuffle=False)`, with:
- N, K one of the 12 Llama-3.1-405B pairs: (2304, 16384), (4608, 16384), (9216, 16384), (13312, 16384), (16384, 2048), (16384, 4096), (16384, 6656), (16384, 8192), (16384, 13312), (16384, 26624), (26624, 16384), (53248, 16384);
- M one of the 13 rows, from 1 to 32768.

Runtime M values round up to those rows. These are the qkv, o, gate_up and down projections at TP1, TP2, TP4 and TP8.

**Why other shapes keep their previous selection:**
- The PR changes only this file.
- No key in this file is present in any other `*bf16_tuned_gemm*.csv`, and the shape-collision test passes.
- I built the merged runtime BF16 config with `AITER_CONFIGS.get_config_file` on upstream main and on this branch. The key sets are identical (5541 rows each). Only 112 selections change, all keyed in this file, and the other 5385 keys keep the same `libtype`, `solidx`, `splitK` and `kernelName`.
- gfx942, gfx90a and other `cu_num` values have no rows here, so they are not affected.

Changed op tests

None.

---

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_017JGuDSsfinKAQhqUaGzpK7

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@afriedri-amd
afriedri-amd marked this pull request as ready for review November 4, 2026 22:04
@afriedri-amd
afriedri-amd requested a review from a team November 4, 2026 22:04
@github-actions github-actions Bot changed the title [Perf] Retune Llama-3.1-405B BF16 GEMM config for gfx950 [Config] [Perf] Retune Llama-3.1-405B BF16 GEMM config for gfx950 Nov 4, 2026
@github-actions github-actions Bot added the Config label Nov 4, 2026
@zufayu
zufayu requested a review from demonsan November 5, 2026 01:19
afriedri-amd and others added 2 commits November 20, 2026 15:23
… row

ROCm#6937 moved OPUS to local kernel ids. The retuned row still carried the
old global id 6401, which no longer resolves, so the runtime loader dropped
the row and test_opus_a16w16_policy_parity failed. Same kernel
(opus_gemm_mono_tile_512x128x256x64_2x4_16x16x32_0x0x0_nooob_4g_safe) is
local kid 136 on gfx950/256 CU.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@demonsan demonsan 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

@demonsan
demonsan merged commit cf0af5f into ROCm:main Nov 30, 2026
65 checks passed
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.

3 participants