Repository navigation
[Config] [Perf] Retune 48 large-batch BF16 GEMM rows for gfx950 - #8317
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
|
@yzhou103 @demonsan could you take a look when you have a moment? This only swaps the kernel in existing gfx950 BF16 GEMM rows; the description has the per-row numbers on MI355X and MI350X, including the other M values each row serves. It is a fork PR, so the workflows need a maintainer's approval to start. Thanks! |
For 48 gfx950 (256 CU) shapes with M from 1984 to 66576 the tuned BF16 GEMM row names a FlyDSL kernel that is slower at that size than a library kernel. Replace those rows in place with the tuner's winner: torch (hipBLASLt) for 44 shapes and the asm 256x256 kernel for 4. Rows only. No key is added or removed, and every other line of the 8 tables is unchanged. Signed-off-by: Saptarshi Majumder <[email protected]>
518c7d3 to
c972232
Compare
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 |
|
@yifehuan could you take a look at this one when you have a moment? It is the same kind of change as #8423: it only swaps the kernel in 48 existing gfx950 BF16 GEMM rows (large-batch rows go from FlyDSL to |
|
@yifehuan @yzhou103 one gap of the description is closed (description only, the head is unchanged): I replayed the production call on an MI350X with main's rows and with these 48 rows, 3 rounds on four devices. The 48 shapes are 1.29x faster (geometric mean, 1.02x to 2.10x), the 200 sampled other call sizes that 25 of the rows serve are 1.43x faster (1.01x to 2.75x), and nothing is slower than main there. Before this the MI350X evidence was one tuner run. |
|
@demonsan thanks for the review, and @yifehuan thanks for starting the workflows. The one red shard of the Aiter Test (Standard Tests 8/0) did not fail in a test: its runner dropped out at 17:59 UTC ("The self-hosted runner lost communication with the server"), in the same minute as shards of other pull requests, so there is no log for it. The other seven shards, Checks, Triton Test and OPUS Test passed. Could one of you re-run the failed job? Nothing needs to change in the branch. |
…4098) (cherry picked from commit b34b6b8) Rebase onto main 12-03: kimik3_bf16_tuned_gemm.csv conflicted with main's gfx950 row updates (#8317 / #8245 / #8915). Replayed by row key: the 32 gfx1250 rows this commit adds are inserted; its 15 gfx950 edits were number formatting only (a CSV round-trip) and are left as main has them. Same rows as the PR head 3b64098.
Summary
Retunes 48 gfx950 (256 CU) rows of the BF16 GEMM tables, in place. All 48 are large-batch rows (M from 1984 to 66576) that name a FlyDSL kernel on main. At these sizes a library kernel is faster, so 44 rows move to
torch(hipBLASLt) and 4 to the asm kernelbf16gemm_bf16_tn_256x256. Rows only: no code change, and no key is added or removed.On MI355X the production call
aiter.tuned_gemm.gemm_a16w16gets 1.32x faster at these shapes (geometric mean; 1.04x to 2.10x). On MI350X one tuner run measures 1.33x for the same rows (1.04x to 2.05x), and a replay of the production call gives 1.29x (1.02x to 2.10x); no row and no sampled call size is slower than main there.Served through vLLM 0.33.0 at tensor-parallel 1, a model of the Llama-3.3-70B architecture prefills 3.7% to 4.5% faster when a prefill step holds 1,025 to 2,048 token rows, and is unchanged at the other step sizes (details under Performance).
Motivation
The gfx950 BF16 tables hold many FlyDSL rows for large batches: at main
e359f953d, where this work started, 422 rows with M >= 1536 named a FlyDSL or Triton kernel. Those tiles are strong at decode sizes. At prefill sizes a number of the rows are slower than the library path that an untuned shape takes anyway (torch). Example:minimax_m3_eagle, M = 32768, N = 2304, K = 6144 takes 1408 us with main's row and 673.5 us withtorch.These rows are reached from serving. With AITER enabled on gfx950, vLLM sends unquantized linear layers to
aiter.tuned_gemm.tgemm.mm(read at vLLM main52fae19fb), and there M is the number of token rows in the batch, so these sizes are prefill batches.#5159 reports the same for three gptoss rows, and #7479 for the Llama-3.1-405B table.
Changes
aiter/configs/model_configs/:minimax_m3_mxfp4_bf16_tuned_gemm.csv(23),minimax_m3_eagle_bf16_tuned_gemm.csv(10),llama70B_bf16_tuned_gemm.csv(5),dsv4_bf16_tuned_gemm.csv(3),kimik3_bf16_tuned_gemm.csv(3),glm5_bf16_tuned_gemm.csv(2),gptoss_bf16_tuned_gemm.csv(1),qwen32B_bf16_tuned_gemm.csv(1).torch44, asm 4 (bf16gemm_bf16_tn_256x256).libtype,solidx,splitK,us,kernelName,err_ratio,tflopsandbwchange. Every other line of the 8 files is byte-identical, and no key is added or removed.llama405B_bf16_tuned_gemm.csvthat qualify the same way. [Config] [Perf] Retune Llama-3.1-405B BF16 GEMM config for gfx950 #7479 retunes that whole table, so this PR does not touch the file.Performance (if applicable)
Production call
aiter.tuned_gemm.gemm_a16w16(x, w, bias, otype)on random data. Before = main8eed98cce. After = that main with this PR's rows. Each arm runs in its own process, the arms take turns, 5 rounds. A CUDA graph holds 2 to 50 calls (about 20 ms) and is timed two ways: one buffer set replayed ("warm"), and rotating copies of all inputs asaiter.test_commonmakes them ("cold", which is what the tuner measures). Per round the time is the median of 5 repeats of 8 replays, and a round counts only when that median is within 3% of its fastest repeat. The ratio is the median over the rounds.At 8 of the 598 timed cases the repeats of one arm differ by more than 3% in every round (the kernel itself varies), so no round passes that filter. For those the ratio is taken over all rounds; main's fastest repeat against the new row's slowest repeat is still at least 1.00x there.
--compare, median of three runsminimax_m3_eagle: 32768 x 2304 x 6144, warmllama70B: 16384 x 8192 x 3584, warmkimik3: 2048 x 20480 x 7168, warmqwen32B: 2048 x 12800 x 5120, warmminimax_m3_mxfp4: 2997 x 6144 x 24576 with bias, warmglm5: 8192 x 160 x 6144, warmgptoss: 2048 x 201088 x 2880, warmdsv4: 14336 x 2048 x 7168, warmBy table (geometric means):
minimax_m3_mxfp4minimax_m3_eaglellama70Bdsv4kimik3glm5gptossqwen32BAll 48 rows
Times are the warm replay on MI355X. "Tuner" is main's row against the new row in the tuner's own
--compare(MI355X: median of three runs; MI350X: one run).dsv4t128x128x64x4_ks1_w4x4x1_bias0_ktail0_gm0_pfttorchdsv4t256x256x64x2_ks1_w2x4x1_bias0_ktail0_gm4_phttorchdsv4t256x256x64x2_ks1_w2x4x1_bias0_ktail0_gm4_phttorchglm5t128x32x64x4_ks1_w2x1x1_bias0_ktail0_gm4_pfttorchglm5t256x256x64x2_ks1_w2x4x1_bias0_ktail0_gm4_phttorchgptosst128x128x64x2_ks1_w2x2x1_bias0_ktail0_gm4_pfttorchkimik3t128x128x64x3_ks1_w4x4x1_bias0_ktail0_gm0_pfttorchkimik3t256x64x128x2_ks1_w2x2x1_bias0_ktail0_gm0_phtkimik3t64x256x64x2_ks1_w2x4x1_bias0_ktail0_gm4_pfttorchllama70Bt256x256x64x2_ks1_w2x4x1_bias0_ktail0_gm4_phttorchllama70Bt256x128x64x2_ks1_w2x2x1_bias0_ktail0_gm0_phttorchllama70Bt128x128x128x2_ks1_w2x2x1_bias0_ktail0_gm4_pfttorchllama70Bt128x128x64x5_ks1_w2x2x1_bias0_ktail0_gm4_pftllama70Bt128x128x128x2_ks1_w2x2x1_bias0_ktail0_gm0_phttorchminimax_m3_eaglet64x64x128x4_ks1_w2x2x1_bias0_ktail0_gm0_pfttorchminimax_m3_eaglet128x128x64x4_ks1_w4x2x1_bias0_ktail0_gm0_pfttorchminimax_m3_eaglet128x128x64x2_ks1_w2x4x1_bias0_ktail0_gm4_pfttorchminimax_m3_eaglet64x256x128x2_ks1_w4x4x1_bias0_ktail0_gm0_pfttorchminimax_m3_eaglet256x64x64x3_ks1_w4x1x1_bias0_ktail0_gm4_pfttorchminimax_m3_eaglet256x256x64x2_ks1_w2x4x1_bias0_ktail0_gm4_phttorchminimax_m3_eaglet128x128x64x2_ks1_w2x4x1_bias0_ktail0_gm4_phttorchminimax_m3_eaglet128x128x64x2_ks1_w2x2x1_bias0_ktail0_gm4_phttorchminimax_m3_eaglet64x256x64x4_ks1_w2x4x1_bias0_ktail0_gm0_pfttorchminimax_m3_eaglet128x128x64x4_ks1_w2x2x2_bias0_ktail0_gm0_pftminimax_m3_mxfp4t128x256x64x3_ks1_w4x4x1_bias1_ktail0_gm0_pfttorchminimax_m3_mxfp4t96x128x64x2_ks1_w2x2x1_bias1_ktail0_gm4_pfttorchminimax_m3_mxfp4t256x256x64x2_ks1_w2x4x1_bias1_ktail0_gm0_phttorchminimax_m3_mxfp4t128x256x64x2_ks1_w2x4x1_bias1_ktail0_gm0_phttorchminimax_m3_mxfp4t128x256x64x2_ks1_w2x4x1_bias1_ktail0_gm0_phttorchminimax_m3_mxfp4t256x256x64x2_ks1_w2x4x1_bias1_ktail0_gm0_phttorchminimax_m3_mxfp4t128x256x64x3_ks1_w4x4x1_bias1_ktail0_gm0_pfttorchminimax_m3_mxfp4t128x128x64x2_ks1_w2x4x1_bias1_ktail0_gm4_pfttorchminimax_m3_mxfp4t256x256x64x2_ks1_w2x4x1_bias1_ktail0_gm0_phttorchminimax_m3_mxfp4t256x256x64x2_ks1_w2x4x1_bias1_ktail0_gm0_phttorchminimax_m3_mxfp4t256x256x64x2_ks1_w2x4x1_bias1_ktail0_gm0_phttorchminimax_m3_mxfp4t128x256x64x3_ks1_w4x4x1_bias1_ktail0_gm0_pfttorchminimax_m3_mxfp4t128x128x64x2_ks1_w2x2x1_bias1_ktail0_gm0_pfttorchminimax_m3_mxfp4t256x256x64x2_ks1_w2x4x1_bias1_ktail0_gm4_phttorchminimax_m3_mxfp4t128x128x64x2_ks1_w4x2x1_bias1_ktail0_gm4_pfttorchminimax_m3_mxfp4t128x256x64x2_ks1_w2x4x1_bias1_ktail0_gm4_phttorchminimax_m3_mxfp4t128x256x64x2_ks1_w2x4x1_bias1_ktail0_gm4_phttorchminimax_m3_mxfp4t256x256x64x2_ks1_w2x4x1_bias1_ktail0_gm4_phttorchminimax_m3_mxfp4t128x256x64x2_ks1_w2x4x1_bias1_ktail0_gm4_phttorchminimax_m3_mxfp4t128x256x64x2_ks1_w2x4x1_bias1_ktail0_gm0_phttorchminimax_m3_mxfp4t256x256x64x2_ks1_w2x4x1_bias1_ktail0_gm4_phttorchminimax_m3_mxfp4t256x256x64x2_ks1_w2x4x1_bias1_ktail0_gm4_phttorchminimax_m3_mxfp4t256x256x64x2_ks1_w2x4x1_bias1_ktail0_gm0_phttorchqwen32Bt128x256x64x3_ks1_w4x4x1_bias0_ktail0_gm0_pftOther M. A call whose M has no row of its own is padded by the lookup (
getPaddedM, fine step first, then the next power of two; above 8192 with N > 4096 it uses the M = 8192 row). So 25 of the 48 rows also serve M values other than their own. For each of them I timed 22 such M, evenly spread over the range it serves up to M = 65536, with the same method. A row is in this PR only if none of its sampled M is slower than main in either timing.Other M served by 25 rows
dsv4dsv4dsv4glm5glm5gptosskimik3kimik3kimik3llama70Bllama70Bllama70Bllama70Bllama70Bminimax_m3_eagleminimax_m3_eagleminimax_m3_eagleminimax_m3_eagleminimax_m3_eagleminimax_m3_eagleminimax_m3_eagleminimax_m3_eagleminimax_m3_eagleminimax_m3_eagleqwen32BServing. The Llama-3.3-70B-Instruct architecture (BF16; random weights, so this is a timing run only) under vLLM 0.33.0 with
VLLM_ROCM_USE_AITER=1, tensor-parallel 1 on one MI355X, prefix caching off. The released image (amd-aiter 0.1.26) names the same kernels as main in the five llama70B rows of this PR, so one server ran and its BF16 table was switched between the image's rows (before) and the rows of this PR (after) from phase to phase: 16 phases in the order A B B A; the change is the mean over the 8 adjacent pairs with its standard error. A request is a prompt of an exact number of token ids and one generated token.--max-num-batched-tokens 2048, latency--max-num-batched-tokens 2048, prompt tokens per secondAt tensor-parallel 1 one GEMM per layer is on a changed row, the QKV projection, and only in prefill steps of 1,025 to 2,048 token rows. The controls are step sizes that no changed row serves. In the first run 17,280 lookups per arm resolved to a changed row, FlyDSL before and
torchafter.At tensor-parallel 8 the changed rows are the down projection (2,049 to 4,096, 16,257 to 16,384 and 32,641 to 32,768 rows) and the QKV projection (16,385 to 32,768 rows). That configuration was not served. The four GEMMs of one layer (QKV, O, gate_up, down) through
tgemm.mmon one MI355X, with the same two tables:Testing
Measured on MI355X and MI350X (gfx950, 256 CUs); the rows are gfx950 rows with cu_num 256, so MI250X and MI300X do not read them.
python3 -m unittest op_tests.tuning_tests.test_csv_validation op_tests.tuning_tests.test_config_shape_collision: 52 tests OK on this branch and on main at8eed98cce.Documentation
Tuned-config rows only. The table format and the lookup are unchanged.
Dependencies
Breaking Changes
None. The results at these shapes change in the last bits because another kernel computes them; against a float32 reference the new rows are not less accurate than main's rows at any measured shape (see Validation).
PR Self-Review
Reviewed revision
c972232
Behavior and intent
Configuration only. For gfx950 with 256 CUs, 48 BF16 GEMM rows with M from 1984 to 66576 named a FlyDSL kernel that is slower at that size than a library kernel. The rows now name
torch(44) or the asm 256x256 kernel (4), which is what upstream's tuner picks when every library type races. The existing behavior is insufficient because a tuned row should not be slower than the path an untuned shape takes, and here it was, by 1.04x to 2.10x on MI355X. No dispatch code changes and no key changes, so the lookup returns a row for exactly the same calls as before.Validation and unverified scope
How the rows were chosen, every step with upstream's tuner or the production call:
e359f953dwith M >= 1536 that name a FlyDSL or Triton kernel.python3 csrc/gemm_a16w16/gemm_a16w16_tune.py -i <shapes> -o <scratch table> --libtype torch,asm --b-non-temporal auto --all --compare --shape_grouped --mp 1 -o2 <profile>on MI355X, three runs: in 172 rows at least one run would update the row.--libtype allfor those 172, three runs, every shape on three different GPUs: the tuner would update 114 rows in all three runs (its own 3% rule, main's row against the winner in the production-call benchmark).7c2fa4dae: 63 of the 87 are at least 1.03x there. 14 are slower than main's row on MI350X, 3 are within 3%, and 7 FlyDSL winners were not raced there; all of these are left out.8eed98cce, with and without this PR's rows, 5 rounds, at the rows' own M and at the other M they serve (8 per row first, then 22 per row for the rows still in). A row stays if it is at least 1.03x at its own M and no sampled other M is below 1.00x, warm and cold: 48 rows.Main's row is the same row at
7c2fa4dae,e359f953dand8eed98ccefor every one of these keys, so the three sets of measurements describe the same change.Rebased onto main
73960daf4on 20 November, which carries the fix oftests/test_ar_rmsnorm_routing.py(#8313), a test that was broken on the previous base; the diff is unchanged. Main did not changeaiter/configs, the BF16 lookup or the tuning tests between8eed98cceand that commit, so the tables that were measured and tested are the tables of this head.Software: MI355X runs use the public image
vllm/vllm-openai-rocm:v0.33.0(amd-aiter 0.1.26, torch 2.13.0+rocm10.0.0) with main'saiter/andcsrc/laid over the installed package and FlyDSL 0.5.0; the asm kernel and its launcher are unchanged between v0.1.26 and main. The MI350X tuner run used amd-aiter 0.1.25 with main's sources laid over, torch 2.12.0+rocm10.0.0 and FlyDSL 0.5.0. The MI350X replay (23 November) used the same image and overlay as the MI355X runs: main8eed98cceagainst that main with this PR's rows, each arm in its own process, the arms in turn, 3 rounds on four devices, the 48 rows' own M and 200 other call sizes that they serve; in every case the call resolved to main's row in one arm and to the new row in the other, and the output check passed.Checks:
F.linearon the same inputs), share of elements outside rtol = atol = 0.01: at most 0.0486 with main's rows and 0.0000 with the new rows; outside rtol = atol = 0.05 (the tuner's tolerance): at most 0.0043 and 0.0000.git diff --numstatshows 48 insertions and 48 deletions in 8 files.python3 -m unittest op_tests.tuning_tests.test_csv_validation op_tests.tuning_tests.test_config_shape_collision: 52 tests OK on this branch and on main at8eed98cce, none skipped.op_tests.tuning_tests.test_a16w16_tuned_config_lookup: 14 of its 15 tests pass on this branch and on main at8eed98cce.test_gfx1250_legacy_wrapper_routingfails the same way on both in my setup (main's sources over the 0.1.26 build):ValueError: A and B must be on the same ROCm device. It is a gfx1250 routing test and does not read these rows.Unverified: served accuracy (the serving run uses random weights); serving at tensor-parallel 8 (layer timing only); M values between the sampled ones for the rows that also serve other M, and M above 65536 for the 1 row that serves every larger M; gfx950 partitions with another cu_num, gfx942 and gfx1250 (they have their own rows, which this PR does not touch).
PR-specific question
Keys consumed: gfx950, cu_num 256, dtype and outdtype bf16, no scale, no bpreshuffle, at the 48 (M, N, K, bias) keys listed under Performance. Readers: (1)
get_GEMM_A16W16_tuned_configinaiter/tuned_gemm.py, forgemm_a16w16andtgemm.mmcalls with the row's own M or with an M that pads to it; (2) the AOT replayaiter/aot/flydsl/gemm.py, which compiles the FlyDSL kernels that rows name and now has 48 fewer rows to compile for; (3) the tuner, which reads the table as its base.aiter/ops/opus/policy.pyreads only OPUS rows of this family, and none of these rows was or is an OPUS row. Evidence that unrelated shapes keep their selection: the lookup key contains N, K, bias and the dtypes unpadded, and M only through the padded-M walk, so a row can serve only calls of its own (N, K, bias) group. No key is added or removed, so the mapping from a call to a row is unchanged for every call; only the content of these 48 rows differs. All other lines of the 8 files are byte-identical, and the collision guard passes on the merged family. For the calls that do change, the M values that pad to a changed row were enumerated by replaying the walk on the table family and are measured in the "Other M" table.Changed op tests
None.