Repository navigation
[HIP] [Tune] GLM-5 MQA logits: retune with clean_logits=False, add GLM-5.3-Flash rows - #7580
amd-sriram wants to merge 14 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
NOT 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 |
There was a problem hiding this comment.
🟡 Changes recommended
Affected Q>KV configurations give queries empty windows, making tuning and grading unrepresentative of pooled prefill and requiring corrected per-query bounds and retuning.
1 open issue
What changed in this PR
This PR extends AITER’s MQA logits tuning tables for GLM-5.3-Flash and missing GLM-5 decode ranges, while aligning prefill tuning with vLLM’s clean_logits=False usage.
Changes:
- Adds
--clean_logits {0,1}, defaulting to 0, with window-only grading when cleanup is disabled. - Adds short-KV prefill configurations and block-32/block-64 decode configurations for standard and multi-token prediction workloads.
- Expands tuning input CSVs without changing production dispatch logic or table formats.
| File | Description |
|---|---|
csrc/mqa_logits/mqa_logits_tune.py |
Adds the cleanup flag and threads it through grading and timing. |
aiter/configs/model_configs/paged_mqa_logits_untuned_glm5.csv |
Expands decode tuning shapes and contexts. |
aiter/configs/model_configs/paged_mqa_logits_tuned_glm5.csv |
Adds gfx950 decode configurations and updates selected native-MTP rows. |
aiter/configs/model_configs/glm5_untuned_mqa_logits.csv |
Adds short-KV prefill tuning shapes. |
aiter/configs/model_configs/glm5_tuned_mqa_logits.csv |
Adds 22 short-KV prefill configurations. |
Review effort: Balanced
| 32,128,2048,512 | ||
| 32,128,1024,1024 | ||
| 32,128,2048,1024 | ||
| 32,128,4096,1024 |
There was a problem hiding this comment.
Supply representative per-query bounds for both tuning and
--run_config, then retune the affected rows where Q exceeds KV
Fixed in 115714e: build_inputs now gives pooled windows when seq_len > seq_len_kv, end = (row + 1) * seq_len_kv // seq_len, as in vLLM's indexer. The Q > KV rows were retuned on these inputs in 0036642 (6 rows changed). A/B against main on the 71 dumped prefill shapes: -15.8% geomean, none slower.
…default vLLM calls aiter.mqa_logits with clean_logits=False (vllm#51314). The tuner timed every candidate with the default clean_logits=True, which adds the -inf fill to the Triton path, so the GLM-5 table picks FlyDSL variants that are 2-7% slower than Triton without the fill. Add --clean_logits (default 0) and grade only inside each row's window when the fill is off. Signed-off-by: Sriram Kumar <[email protected]>
…GLM-5.3-Flash rows Prefill: retime the 24 rows with clean_logits=False (vLLM's call) and add long-context (KV 128k-262k) and Flash pooled-KV (KV 512-2048) rows. Decode: add kv_block_size=32 rows (GLM-5.3-Flash index cache, next_n 1-2) and batch 512/1024 rows for MTP. Signed-off-by: Sriram Kumar <[email protected]>
Five rows did not beat main's pick on the median of five interleaved runs (prefill 4096x8192, 256x16384, 256x32768, 256x131072; decode block 32 batch 16 next_n 2). They now hold exactly the config main picks for those shapes. Signed-off-by: Sriram Kumar <[email protected]>
Main's GLM-5 rows are unchanged. Added rows were picked on real vLLM shapes (GLM-5.3 and GLM-5.3-Flash, TP4, AITER_LOG_TUNED_CONFIG dumps) and kept only if no real shape they serve is more than 1% slower than main, then checked on held-out shapes: - prefill KV 512 / 1024 rows (GLM-5.3-Flash pooled KV) and 256x131072 - prefill KV 2048 rows that copy main's KV 4096 configs, so shapes with KV 2048-4095 keep main's picks - decode kv_block_size 32, next_n 1 rows (GLM-5.3-Flash); batch 48 holds the default config Signed-off-by: Sriram Kumar <[email protected]>
… real shapes Held-out real shapes showed the KV 1024 rows for seq >= 4096 and the KV 1984-2047 band lose to main's pick; those rows now carry main's config. Dropped 256x131072 (no gain) and the decode block-32 batch 128 / 256 rows (same config as batch 64). Signed-off-by: Sriram Kumar <[email protected]>
(2,2) measured +3.2% with triton in the A/B on the shapes where this table differs from main; the new seq_len_kv=2 row keeps main's flydsl pick there, and the seq_len_kv=6 rows repeat the 512 band so every other shape picks as before. Signed-off-by: Sriram Kumar <[email protected]>
(11,11) measured +7% with triton in the 8-round A/B; the new seq_len_kv=11 rows give it main's flydsl pick and repeat the 512 band so every other shape picks as before. Signed-off-by: Sriram Kumar <[email protected]>
- kv_block_size=32, next_n=2 (Flash MTP1): batch 1/32/224/256. - kv_block_size=64, next_n=1 above batch 256 (MTP3 flattened; GLM-5.3 and Flash share the key): 272/384/400/512/572/784. Batch 384 and 572-783 keep main's pick, where the new one measured slower on GLM-5.3.
With vllm#59421 raising the native-decode next_n cap, Flash MTP3/MTP5 decode runs the paged kernel natively at kv_block_size=64, next_n=4/6, batch 1-127. That key is shared with GLM-5.3 native MTP. - New rows for batch 1-127 at next_n 4 and 6. Gluon ChunkK=256 WavePerEU=4 stays fastest at batch % 4 == 0; FlyDSL wins in between. - Main's batch-128+ rows are unchanged. - Picked so no shape is >1% slower than main at either context (Flash 2048;15000, GLM-5.3 8192;60000).
…lock 64) Rows for next_n 4/6 at batch 129-255 and next_n 1 at batch 65-127 and above 256, from a full batch grid at both GLM-5 contexts. Existing rows are unchanged. Signed-off-by: Sriram Kumar <[email protected]>
The retuned decode rows lost up to 19% at ctx 2048 for some next_n 4/6 batches (FlyDSL wins at 8k-60k, loses at 2k; context is not in the lookup key). Every measured batch that was slower than main now has its own row with main's pick or a pick that is no slower than main at any measured context, plus a row at the next batch that restores the previous pick.
539599c to
153d154
Compare
build_inputs gave every query a causal window ending at row + seq_len_kv - seq_len + 1, so with seq_len > seq_len_kv the first seq_len - seq_len_kv queries had empty windows. Pooled prefill (GLM-5.3-Flash) grows each query's bound in pooled units instead: row i sees (i + 1) * seq_len_kv // seq_len keys. The tuner and --run_config use the same inputs.
glm5_untuned_mqa_logits.csv lacked the 8 shapes at seq_len_kv 2, 6 and 11. paged_mqa_logits_untuned_glm5.csv lacked 92 tuned keys and some contexts of 8 others (310 rows). The tuners only visit input rows, so --all could not retune them.
Rows where seq_len > seq_len_kv were tuned with empty query windows. Retuned on the pooled-KV inputs from the previous commit: 6 rows change. On 71 prefill shapes dumped from GLM-5.x serving (KV 6-1977), geomean 13.83 -> 11.64 us (-15.8%); every shape faster than main.
There was a problem hiding this comment.
🟡 Changes recommended
The pooled-window branch is still skipped by the test driver, and the shared reference bounds can mask formula errors, so explicit boundary assertions and numerical checks are needed.
2 open issues
2 resolved since last review
Review effort: Balanced
| if seq_len > seq_len_kv: | ||
| # Pooled KV (one key per seq_len // seq_len_kv tokens, as in GLM-5.3-Flash): | ||
| # vLLM's indexer grows each query's bound in pooled units, so row i sees | ||
| # (i + 1) * seq_len_kv // seq_len keys and the last row sees all of them. | ||
| cu_ends = (rows + 1) * seq_len_kv // seq_len |
There was a problem hiding this comment.
+1 on testing the pooled windows
Agree with Copilot here. main() still skips every seq_len > seq_len_kv pair, and the tuner grades against run_torch with the same cu_ends, so nothing would catch a wrong window formula. I ran every pooled row in the tables against the reference on MI355X and the kernels are fine; it's only the formula that has no check. A small check of the bounds would cover it, something like this (a sketch, I haven't run it):
def check_pooled_windows():
"""Pooled KV: row i ends at (i + 1) * seq_len_kv // seq_len."""
for seq_len, seq_len_kv in ((4096, 1024), (1000, 251)):
ends = build_inputs(seq_len, seq_len_kv)["cu_ends"].tolist()
assert ends[0] == 0, ends[:4] # leading rows see no key
assert ends[-1] == seq_len_kv, ends[-4:] # last row sees every key
assert all(a <= b for a, b in zip(ends, ends[1:]))
test_mqa_logits(4096, 1024)called from main() next to the other checks. (1000, 251) covers a ratio that isn't a whole number. It might also be worth a line in the docstring that this matches vLLM only for a fresh prefill: vLLM's end is (start_pos + 1 + i) // COMPRESS_RATIO (indexer.py#L513-L516), so chunked prefill windows look different.
|
@aiter-bot review |
@zufayu — please take a look. Re-comment |
|
Which vLLM change makes vLLM read these tables? I checked vLLM main (8e7295e, Dec 2), and the GLM-5 indexer doesn't go through Could you name #60294 and #60042 in the description, next to #59421? Both are approved already, so this is mostly so readers know what turns the rows on, and which vLLM the end-to-end numbers came from. |
|
Merge order with #7412 #7412 (draft, @vpietila-amd) rewrites main's 24 rows in |
|
On your question about the native next_n 4/6 rows I'd keep them as rows. I checked the table against the rule you suggested (gluon when |
| gfx950,256,32,128,256,11,triton,,,, | ||
| gfx950,256,32,128,1024,11,triton,,,, | ||
| gfx950,256,32,128,2048,11,flydsl,mfma32x32x64_bkv64_r2_w4_lds3,,, | ||
| gfx950,256,32,128,256,512,triton,,,, |
There was a problem hiding this comment.
Could the new rows get their timings?
22 of the new rows here (lines 2-23) and 7 in paged_mqa_logits_tuned_glm5.csv (lines 6, 15, 17, 19, 22, 24, 156) have an empty us, and the per-backend columns are empty too. Main's tables have a time on every row. The description explains why several of them exist (keeping main's pick, or holding the default config), so it's mostly the numbers that are missing. Without them, --run_config reports these rows as ok no matter what: run_config only computes drift when csv_us > 0. There's also nothing stored to compare a later retune against.
Could you fill us and triton_us / flydsl_us (or gluon_us) from your A/B runs? If some rows were placed by hand, a line in the description saying which ones would help too.
This row is a good example of why it helps. On MI355X I timed it against main's pick (FlyDSL mfma32x32x64_bkv64_r1_w2_lds2), same GPU, interleaved, clean_logits=False. Triton is about 5% slower at the row's own shape, (256, 512): 4.94-5.04 vs 4.71-4.81 us over two runs of 11 and 15 rounds. It's 10% slower at (256, 1000). But it's 7-25% faster at the other shapes in its range: (300, 700), (512, 512), (700, 900), (900, 600) and (1000, 1000). So the pick is a reasonable trade-off overall, but the table doesn't show that.
| Candidates are timed with ``--clean_logits`` (default 0, as vLLM calls the op): | ||
| the -inf fill outside each row's window is a separate cost on the Triton path, | ||
| so a table tuned with it on can pick a kernel that is slower without it. |
There was a problem hiding this comment.
Small doc note: the table is tuned for clean_logits=False
The flip side of tuning at clean_logits=False is that aiter.mqa_logits still defaults to clean_logits=True, and the lookup has no clean_logits key. On MI355X, with clean_logits=True, the Triton picks here were 29-36% slower than main's FlyDSL picks at (256, 6), (256, 11), (1024, 11) and (256, 512). They stayed 9-16% faster at (1024, 512) and (1024, 1024). Nothing in aiter calls it that way, and vllm-project/vllm#60294 passes False, so this is just worth a sentence:
| Candidates are timed with ``--clean_logits`` (default 0, as vLLM calls the op): | |
| the -inf fill outside each row's window is a separate cost on the Triton path, | |
| so a table tuned with it on can pick a kernel that is slower without it. | |
| Candidates are timed with ``--clean_logits`` (default 0, as vLLM calls the op): | |
| the -inf fill outside each row's window is a separate cost on the Triton path, | |
| so a table tuned with it on can pick a kernel that is slower without it. The | |
| lookup has no clean_logits key, so callers that keep ``mqa_logits``'s default | |
| ``clean_logits=True`` can get a slower pick on rows that chose Triton. |

Summary
Add tuned rows for the GLM-5.3-Flash MQA logits shapes, with and without MTP, and fill the GLM-5 decode batches between main's rows that MTP3/MTP5 hit (block 64). These shapes had no rows and fell back to the table's smallest row or to the default config. The prefill tuner now times candidates with
clean_logits=Falseby default, which is how vLLM calls the op;--clean_logits 1keeps the old timing. Main's rows are unchanged, except sixkv_block_size=64,next_n4/6 rows at batch 8 or below. Those rows sit inside the new native-MTP ranges; this PR replaces or drops them.Motivation
kv_block_size=32(pooled KV). The decode table had no block-32 rows, so every Flash decode call used the default config (AITER_LOG_TUNED_CONFIG=1:from default (no tuned row)).seq_len_kv2-1977 (pooled KV). That is below the table's smallest KV (4096), so every Flash prefill call took the 4096 rows.mqa_logitswithclean_logits=False([ROCm][Perf] Skip cleaning sparse prefill MQA logits vllm-project/vllm#51314). The tuner timed withTrue, which adds the-inffill to every candidate and biased picks toward FlyDSL.next_n=2; every call took the default config.next_n=1, at batch = requests × 4 (MTP3, up to 1024) or × 6 (MTP5, up to 1536). Main has rows at 1/2/4/…/256 only: batch 65-127 took the batch-64 row and batches above 256 the batch-256 row.next_n4/6, batch 1-256 (one per decode request). There, main's rows (tuned at GLM-5 contexts, batches 1/2/4/…/128) are up to 2x slower than the best config.Changes
csrc/mqa_logits/mqa_logits_tune.py:--clean_logits {0,1}(default 0). With 0, the grade compares the causal window only.op_tests/test_mqa_logits.py: whenseq_len > seq_len_kv,build_inputsgives each query a pooled key window (end = (row + 1) * seq_len_kv // seq_len), as vLLM's indexer does for compressed KV. Before, those queries had empty windows, so the tuner timed and graded little work.glm5_tuned_mqa_logits.csv: 22 rows forseq_len_kv2-2048 (24 -> 46 rows). The rows atseq_len_kv2 and 11 keep main's pick, where the new pick measured slower. 0036642 retunes theseq_len > seq_len_kvrows on the pooled windows; 6 rows change.paged_mqa_logits_tuned_glm5.csv(72 -> 286 rows):kv_block_size=32,next_n=1(Flash, no MTP): batch 2 / 4 / 8 / 16 / 48 / 64. The batch-48 row holds the default config, so batch 48-63 run as on main.kv_block_size=32,next_n=2(Flash MTP1): batch 1 / 32 / 224 / 256. The batch-256 row holds the default config.kv_block_size=64,next_n=1, above batch 256 (flattened MTP3/MTP5; Flash and GLM-5.3 share this key): batch 258 / 272 / 384 / 388 / 400 / 512 / 572 / 772 / 784. Batch 384-387 and 572-771 keep main's pick, because the new pick measured slower on GLM-5.3.kv_block_size=64,next_n=1, batch 65 / 96 / 97 (flattened MTP3/MTP5 at 11-31 requests; also GLM-5.3 decode without MTP at batch 65-127). Batch 96 keeps main's pick.kv_block_size=64,next_n4 and 6 (native MTP3/MTP5, vllm#59421): rows for batch 1-127, plusnext_n=4batch 154 / 178 / 181 / 184 / 187 / 190 / 193 / 205 andnext_n=6batch 129 / 147 / 154 / 248.ChunkK=256 WavePerEU=4is fastest at batch % 4 == 0; FlyDSL is fastest between those batches.next_n=4178 / 184 / 190,next_n=6248) end the new row before them where it would be slower.next_n=4batch 2/4/8 andnext_n=6batch 1/2/8 are replaced or dropped, because they sit inside the new ranges.next_n4/6 batches, and the lookup has no context key.The block-64 gap rows (
next_n=1batch 65-127 and above 256,next_n4/6 above 128) come from a full batch grid:next_n4/6 at batch 1-256, andnext_n=1at batch 1-256 plus every MTP3/MTP5 flattened batch up to 1536, each at both contexts. A row is added only if it is at least 2% faster over the batches it covers at both contexts, and no covered batch is more than 1% slower than the earlier table. Existing rows are unchanged.Other shapes come from
AITER_LOG_TUNED_CONFIG=1dumps of vLLM serving GLM-5.3-Flash on MI355X, TP4, with no MTP and with MTP1/3/5, flattened and native. The indexer is replicated (heads=32on every rank), so TP does not change the shapes.Performance (if applicable)
Kernel A/B against main's tables, MI355X (gfx950, 256 CU). Every shape whose config differs from main, at each context listed in its row, interleaved reps per shape. Decode at 153d154 (5 reps, 16 GPUs); prefill at 0036642 on the pooled windows (7 reps, 4 GPUs):
next_n4/6 batch 171-243 at context 2048, andnext_n=1block 32 batch 240 at 15000. The same batches are faster at their other contexts (by up to 7.7%).struct.error. They fail with main's table too.The tables below compare each earlier revision with the one after it.
Kernel level on MI355X (gfx950, 256 CU), on every real shape from the dumps, comparing the table before each change with the table after it:
How to read the table:
Method:
AITER_CONFIG_MQA_LOGITS/AITER_CONFIG_PAGED_MQA_LOGITS, and prefill runs withclean_logits=False.Checks on the worst shapes and the noise floor:
The rows only apply where vLLM's decode path runs:
next_n=1. Thenext_n4/6 rows are then unused, and thenext_n=1rows (batch 65-127 and above 256) apply.VLLM_ROCM_INDEXER_NATIVE_DECODE_MAX_NEXT_N=8), thenext_n4/6 rows apply, and thenext_n=1rows above batch 256 are unused.End to end, vLLM serving on MI355X TP4:
next_n≥ 2 or batch > 256, and 9e999dd adds block-64 rows while Flash uses block 32.next_n=1rows at batch 65-127 that GLM-5.3 without MTP looks up.Both models are within noise. For Flash, the kernel gains at batch 2-64 are a small share of the decode step.
Accuracy:
Testing
Tested on MI355X only (the rows are gfx950-keyed).
Documentation
Tuner flag is documented in its
--helpand module docstring.Dependencies
Breaking Changes
None. Lookup and table format are unchanged.
PR Self-Review
Reviewed revision
0036642
Behavior and intent
Only table rows and the tuner's default timing mode change; the op's dispatch code is untouched.
next_n=1at batch 65-127 and above 256;next_n4/6 between main's rows (batch 1-255).Validation and unverified scope
Kernel A/B against main's tables on every changed shape (first table under Performance). Earlier: kernel A/B with
bench.py(earlier table vs new table) on one MI355X node, on every dumped shape plus a batch grid at both contexts for the shared block-64 keys. The worst shapes are listed above.Row selection was checked two ways:
AITER_LOG_TUNED_CONFIG=1in the bench confirms the rows taken.next_n4/6 rows, an offline lookup over the new table matches the picked config at every batch 1-127.End-to-end serving was measured on 7f0289a, without MTP. GLM-5.3 was re-measured on 9e999dd.
Unverified:
seq_len_kv≤ 2048.next_n≥ 3: Flash native MTP decode uses block 64, so no dump hit that key.PR-specific question
The native
next_n4/6 rows add about 120 rows, because gluon and FlyDSL alternate every few batches. Is that table size fine, or should the alternation be a rule in the dispatcher instead (gluon at batch % 4 == 0, FlyDSL otherwise)?Changed op tests
op_tests/test_mqa_logits.py:build_inputsnow gives pooled key windows whenseq_len > seq_len_kv, matching vLLM's compressed-KV indexer. The tuner and--run_configshare this function, so before the change, rows with more queries than keys were tuned on mostly empty windows. The test's own runs keepseq_len <= seq_len_kv, so their inputs are unchanged;python op_tests/test_mqa_logits.pypassed on MI355X (err 0 for all four default shapes).