Support attention bias with windowed CPU GQA - #32302
Merged
Merged
Conversation
Map cache-relative KV columns to absolute attention-bias positions so sliding-window GQA remains correct after eviction, including calls that supply explicit position IDs.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds absolute attention-bias indexing for CPU GQA with windowed KV caches.
Changes:
- Propagates per-batch absolute KV origins through all CPU attention paths.
- Keeps CUDA and WebGPU validation unchanged.
- Adds CPU regression and parity tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
group_query_attention.cc |
Derives and forwards bias offsets. |
gqa_attention_base.h |
Applies offsets across attention implementations. |
group_query_attention_helper.h |
Adds CPU opt-in validation support. |
group_query_attention_op_test.cc |
Adds deterministic regression coverage. |
test_gqa.py |
Adds flash/non-flash parity coverage. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Tianlei Wu (tianleiwu)
requested review from
Hariharan Seshadri (hariharans29),
kunal-vaishnavi and
Ti-Tai Wang (titaiwangms)
August 28, 2026 18:54
Validate absolute bias offsets before applying them, and keep quantized per-batch fallback decoding on the scratch layout required by the regular tiled kernel.
Xavier Dupré (xadupre)
approved these changes
Aug 31, 2026
adrastogi
pushed a commit
that referenced
this pull request
Sep 4, 2026
## Description Enables the CPU GroupQueryAttention implementation to use `attention_bias` with `sliding_window_cache`. This is needed by speculative decoding with sliding-window attention, including calls that provide explicit `position_ids` for RoPE. ## Summary of Changes ### CPU GQA | File | Change | |------|--------| | `onnxruntime/contrib_ops/cpu/bert/group_query_attention.cc` | Derives the absolute KV origin for each cache-relative batch and forwards it to attention implementations. | | `onnxruntime/contrib_ops/cpu/bert/gqa_attention_base.h` | Applies the absolute bias-column offset in quantized, unquantized, flash, and non-flash paths, with per-batch fallback for differing origins. | | `onnxruntime/contrib_ops/cpu/bert/group_query_attention_helper.h` | Allows windowed attention bias only for callers that explicitly support absolute bias offsets; CUDA and WebGPU behavior is unchanged. | ### Tests - Adds a deterministic CPU regression covering post-eviction bias indexing with explicit `position_ids`. - Extends windowed-cache parity coverage to combine attention bias, non-default explicit position IDs, repeated eviction, and forced non-flash dispatch. ## Testing - `cmake --build build/ci_cpu/Release --target onnxruntime_provider_test -j 8` - `build/ci_cpu/Release/onnxruntime_provider_test --gtest_filter=GroupQueryAttentionTest.WindowedCacheAttentionBiasWithPositionIds_CPU` - `ORT_GQA_DISABLE_FLASH_ATTENTION=1 build/ci_cpu/Release/onnxruntime_provider_test --gtest_filter=GroupQueryAttentionTest.WindowedCacheAttentionBiasWithPositionIds_CPU` - `clang-format --dry-run --Werror onnxruntime/contrib_ops/cpu/bert/group_query_attention_helper.h onnxruntime/contrib_ops/cpu/bert/gqa_attention_base.h onnxruntime/contrib_ops/cpu/bert/group_query_attention.cc onnxruntime/test/contrib_ops/group_query_attention_op_test.cc` - `python3 -m py_compile onnxruntime/test/python/transformers/test_gqa.py` ## Motivation and Context A windowed KV cache stores resident rows in cache-relative coordinates after eviction, while `attention_bias` remains indexed by absolute sequence position. The previous validation rejected the combination to avoid silently reading incorrect bias columns. This change carries the per-batch absolute cache origin into the CPU attention paths so resident column zero maps to the correct absolute bias column. Explicit `position_ids` remain consumed by RoPE before the cache-relative transition. ## Checklist - [x] Tests added/updated - [x] No breaking changes - [ ] Documentation updated (not applicable; no public API change)
Tianlei Wu (tianleiwu)
added a commit
that referenced
this pull request
Sep 10, 2026
This cherry-picks the following commits for the release: * #31704 * #32016 * #32042 * #32139 * #32210 * #32244 * #32302 * #32303 --------- Co-authored-by: Akshay Sonawane <111780983+apsonawane@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com> Co-authored-by: Tianlei Wu <tlwu@microsoft.com> Co-authored-by: Jaskaran Singh Nagi <jaskaran.singh.nagi@intel.com> Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com> Co-authored-by: Javier Martinez <javier.e.martinez@intel.com> Co-authored-by: Wayne <waynechuang@microsoft.com>
This was referenced Sep 10, 2026
This was referenced Sep 14, 2026
Open
Open
Closed
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.
Description
Enables the CPU GroupQueryAttention implementation to use
attention_biaswithsliding_window_cache. This is needed by speculative decoding with sliding-window attention, including calls that provide explicitposition_idsfor RoPE.Summary of Changes
CPU GQA
onnxruntime/contrib_ops/cpu/bert/group_query_attention.cconnxruntime/contrib_ops/cpu/bert/gqa_attention_base.honnxruntime/contrib_ops/cpu/bert/group_query_attention_helper.hTests
position_ids.Testing
cmake --build build/ci_cpu/Release --target onnxruntime_provider_test -j 8build/ci_cpu/Release/onnxruntime_provider_test --gtest_filter=GroupQueryAttentionTest.WindowedCacheAttentionBiasWithPositionIds_CPUORT_GQA_DISABLE_FLASH_ATTENTION=1 build/ci_cpu/Release/onnxruntime_provider_test --gtest_filter=GroupQueryAttentionTest.WindowedCacheAttentionBiasWithPositionIds_CPUclang-format --dry-run --Werror onnxruntime/contrib_ops/cpu/bert/group_query_attention_helper.h onnxruntime/contrib_ops/cpu/bert/gqa_attention_base.h onnxruntime/contrib_ops/cpu/bert/group_query_attention.cc onnxruntime/test/contrib_ops/group_query_attention_op_test.ccpython3 -m py_compile onnxruntime/test/python/transformers/test_gqa.pyMotivation and Context
A windowed KV cache stores resident rows in cache-relative coordinates after eviction, while
attention_biasremains indexed by absolute sequence position. The previous validation rejected the combination to avoid silently reading incorrect bias columns. This change carries the per-batch absolute cache origin into the CPU attention paths so resident column zero maps to the correct absolute bias column. Explicitposition_idsremain consumed by RoPE before the cache-relative transition.Checklist