Add sliding-window attention tuning support - #2439
Conversation
Include window size in tuning identity and performance tooling while keeping current sequence length runtime-only. Co-authored-by: Cursor <cursoragent@cursor.com>
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.69% +1.13%
===========================================
Files 120 121 +1
Lines 42852 43183 +331
Branches 7110 7182 +72
===========================================
+ Hits 35381 36142 +761
+ Misses 4815 4490 -325
+ Partials 2656 2551 -105
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| // Sliding-window size affects the generated kernel, but currentSeqLen is a | ||
| // runtime position and intentionally remains outside the tuning key. | ||
| // Omit the disabled value so existing attention keys retain their identity. |
There was a problem hiding this comment.
Nit: I think that we can drop this comment
|
|
||
| def read_db_from_legacy_key(self, legacy_key): | ||
| """Read a tuning DB written with a legacy key (canonicalized on read).""" | ||
| def read_db_from_key(self, key): |
There was a problem hiding this comment.
Why rename this function? Is it being used in non-legacy cases as well?
There was a problem hiding this comment.
Yes It was renamed because it now handles both legacy and current keys.
Keep the straightforward tuning-key condition self-documenting. Co-authored-by: Cursor <cursoragent@cursor.com>
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