Add sliding-window attention tuning support#2439
Open
umangyadav wants to merge 1 commit into
Open
Conversation
Include window size in tuning identity and performance tooling while keeping current sequence length runtime-only. Co-authored-by: Cursor <[email protected]>
umangyadav
requested review from
bogdan-petkovic,
Copilot,
dhernandez0,
erizheng-amd,
justinrosner and
pabloantoniom
July 23, 2026 20:35
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class sliding-window attention support to rocMLIR tuning identities and the Python performance tooling, ensuring sliding-window kernels are keyed distinctly while keeping current_seq_len runtime-only.
Changes:
- Extend Rock (C++) and Python attention tuning identities/reporting to include
sliding_window_size, preserving legacy non-window keys. - Plumb
current_seq_leninto runtimerocmlir-gencommand generation while excluding it from tuning keys/DB identities. - Add/extend regression coverage across rocmlir-gen tuning keys, MIGraphX fusion keys, tuning-DB compatibility, and quick-tuning TSV handling.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| mlir/utils/performance/reportUtils.py | Adds SlidingWindowSize to attention report/test parameter columns. |
| mlir/utils/performance/perfRunner.py | Extends AttentionConfiguration with sliding_window_size + current_seqlen; emits them in runtime driver args (but not tuning keys). |
| mlir/utils/performance/parameterSweeps.py | Removes manual current_seq_len append since runtime arg emission moves into configs. |
| mlir/utils/performance/attentionSweeps.py | Generates and propagates sliding-window samples into attention sweep configurations. |
| mlir/utils/performance/analysis/quickTuningGen.py | Adds SlidingWindowSize to grouping columns and defaults legacy/mixed TSVs to 0. |
| mlir/test/rocmlir-gen/problem-key.mlir | Pins tuning-key behavior: window participates in key; current_seq_len does not. |
| mlir/test/perf-scripts/attention-tuning-db-compat.py | Expands compatibility tests for sliding-window keys and runtime-only current_seq_len. |
| mlir/test/fusion/mixr-attention-sliding-window-problem-key.mlir | Adds MIGraphX fusion tuning-key regression for sliding-window attention. |
| mlir/lib/Dialect/Rock/Tuning/RockTuningImpl.cpp | Adds conditional -sliding_window_size <N> emission to Rock attention tuning keys. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2439 +/- ##
===========================================
+ Coverage 82.57% 83.60% +1.04%
===========================================
Files 120 120
Lines 42852 42936 +84
Branches 7110 7140 +30
===========================================
+ Hits 35381 35896 +515
+ Misses 4815 4482 -333
+ Partials 2656 2558 -98
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sliding_window_sizein Rock and Python attention tuning identities, reports, and quick-tuning grouping.current_seq_lenthrough runtimerocmlir-gencommands while deliberately excluding it from tuning keys.Bugs fixed and error signatures
Sliding-window tuning-key collisions
The Rock tuning key previously omitted
slidingWindowSize. A windowed problem therefore emitted the same sequence around-split_kv 1 -num_heads_q ...as a non-windowed problem, and different window sizes also shared one identity. Tuning databases could consequently return a stale or suboptimal perf configuration for a materially different attention kernel.The key now conditionally emits
-sliding_window_size <N>after-split_kv. A disabled window remains omitted, so existing non-windowed tuning keys are unchanged.Python tuning-key and report mismatch
Once the C++ key contains the window, the old Python parser fails with:
ValueError: Unknown Attention config argument -sliding_window_size -> <N>Python reports and quick-tuning grouping also lacked a window column, which merged distinct window sizes into one problem identity. Older TSVs would either raise
KeyError: 'SlidingWindowSize', or—when concatenated with newer TSVs—receiveNaNand be silently dropped by pandasgroupby.AttentionConfiguration, report columns, and quick-tuning columns now carrySlidingWindowSize; missing andNaNlegacy values normalize to the disabled value0.Lost runtime sequence positions
current_seq_lenis a runtime KV-cache position, not a tuning dimension. Previously it was appended only insideparameterSweeps.test_config; commands and repro strings produced directly byAttentionConfigurationomitted it. A sliding-window command reconstructed through that path could fail Rock verification with:slidingWindowSize requires currentSeqLen to be setThe configuration now owns runtime argument emission, so
current_seq_lenappears exactly once in generated driver commands. It remains absent fromto_command_line()and C++ tuning keys, preventing per-position tuning-key fragmentation.Missing sweep and fusion coverage
Attention parameter sweeps never generated sliding-window cases, and the MIGraphX problem-key path did not verify that a folded sliding-window mask contributes its window—but not its runtime sequence position—to the key. The sweep now covers both plain and sliding-window KV-cache problems, and focused regression tests pin both key behavior and legacy compatibility.
Python lint gate
Changing
perfRunner.pyactivates the repository's full-file flake8 check. Two pre-existing inline dictionary expressions triggeredE201/E231; they are normalized without changing behavior so the Python lint gate remains clean.Compatibility
SlidingWindowSizecontinue to load as window size0.current_seq_lenremains runtime-only and never enters tuning DB identity or reports.Test plan
ninja -C build rocmlir-gen rocmlir-driverpython3 -m pytest -q mlir/utils/performance/tests(126 passed)clang-formatandclang-tidyflake8, YAPF, and syntax compilationgit diff --check origin/developMade with Cursor