Skip to content

Bound windowed GQA workspace allocations - #32602

Merged
Ti-Tai Wang (titaiwangms) merged 4 commits into
microsoft:mainfrom
titaiwangms:titaiwangms/gqa-windowed-runtime-bound
Sep 17, 2026
Merged

Ti-Tai Wang (titaiwangms) merged 4 commits into
microsoft:mainfrom
titaiwangms:titaiwangms/gqa-windowed-runtime-bound

Conversation

@titaiwangms

Copy link
Copy Markdown
Contributor

Summary

  • Size sliding-window GroupQueryAttention Flash split workspace using the resident or staged KV extent instead of the unbounded absolute sequence length.
  • Size and launch the unfused fallback with the same effective KV length.
  • Preserve existing non-windowed behavior and all dispatch decisions.
  • Add host coverage for the effective-length calculation and CUDA regression coverage for T >> C on unfused and multi-token staged Flash routes.

Stack

Depends on #32454. The new change for this PR is commit c9a579a6e8; earlier commits belong to the existing GQA workspace-recipe stack.

This is a runtime allocation-reduction prerequisite for the subsequent GQA Level-1/Level-2 workspace-estimation PR. It does not add planner opt-in, planned-pointer access, root slicing, or estimator wiring.

Validation

  • CUDA provider test target built successfully.
  • CUDA internal module: 239 passed, 2 unrelated LeanAttention tests skipped.
  • Targeted GQA runtime tests: 5 passed, including windowed unfused T=64, C=8 and staged Flash T=64, C=8, S=3.
  • Changed-file lintrunner passed.
  • git diff --check passed.

@titaiwangms
Ti-Tai Wang (titaiwangms) force-pushed the titaiwangms/gqa-windowed-runtime-bound branch from c9a579a to c5cf405 Compare September 15, 2026 19:32
@titaiwangms
Ti-Tai Wang (titaiwangms) marked this pull request as ready for review September 15, 2026 19:44
Copilot AI balanced review requested due to automatic review settings September 15, 2026 19:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Flash regression geometry never changes its split workspace, so it cannot detect restoration of unbounded sizing.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Bounds windowed GQA Flash and unfused workspace usage to the resident or staged KV extent.

Changes:

  • Adds effective KV-length calculation and applies it to runtime sizing and launches.
  • Completes graph-free GQA workspace recipes.
  • Adds host/CUDA tests and design documentation.
File summaries
File Description
group_query_attention_workspace_test.cc Tests preparation and effective KV lengths.
group_query_attention_workspace_mea_unfused_test.cc Tests backend and complete-route recipes.
group_query_attention_workspace_header_test.cc Extends standalone-header checks.
group_query_attention_op_test.cc Adds windowed CUDA regressions.
group_query_attention.cc Bounds Flash and unfused allocations.
group_query_attention_workspace.h Defines workspace APIs and recipe types.
group_query_attention_workspace.cc Models preparation and past preservation.
group_query_attention_workspace_routes.cc Composes selected-route recipes.
group_query_attention_workspace_mea_unfused.cc Implements MEA and unfused recipes.
group_query_attention_impl.cu Launches unfused attention with effective length.
attention_workspace_estimation.md Documents GQA workspace composition.
Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new single-token windowed regression calculates an expected cache layout inconsistent with the runtime’s drifting eviction algorithm.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The bounded runtime dimensions, recipe calculations, validation, and regression coverage are consistent with the physical cache layout.

Review details
  • Files reviewed: 12/12 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@chilo-ms

Copy link
Copy Markdown
Contributor

Found two actionable issues:

  1. [P2] Complete recipes do not apply the runtime’s windowed KV bound —  onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace_routes.cc:131-150 . Flash receives  route.flash.total_sequence_length  unchanged, and unfused receives  route.unfused.total_sequence_length , while runtime first applies  min(total_sequence_length, resident/staged capacity)  at  group_query_attention.cc:509-512 . For  T=257, C=8, S=3 , runtime sizes against 11 rows, but a naturally populated complete route sizes against 257, defeating exact recipe parity and potentially rejecting valid constrained-memory plans. Normalize both backend lengths inside  GetGQACompleteWorkspaceRecipe  using  preparation.recipe.effective_kv_cache_capacity , and add windowed Flash/unfused parity tests.
  2. [P2] The unfused regression does not verify the allocation reduction —  onnxruntime/test/contrib_ops/group_query_attention_op_test.cc:3416 . Restoring the old  S_kv = total_sequence_length  allocation still produces identical outputs, so this test would pass despite regressing the PR’s main unfused behavior. Populate the existing  AttentionKernelDebugInfo::effective_kv_length_bound  field and assert  EffectiveKvLengthBound=8 , or verify the request through an instrumented/constrained allocator.

@titaiwangms
Ti-Tai Wang (titaiwangms) force-pushed the titaiwangms/gqa-windowed-runtime-bound branch from b189e6c to fbc8dad Compare September 16, 2026 20:11
@titaiwangms

Copy link
Copy Markdown
Contributor Author

Addressed both P2 findings in fbc8dadc70 (rebased onto current main):

  1. GetGQACompleteWorkspaceRecipe now applies the same windowed effective-KV-length policy as runtime before composing Flash and unfused recipes, using preparation's checked resident/staged capacity. The tests cover all policy branches for both backends: T > C+S, single-token C, T < C+S, and non-windowed raw T.
  2. GQA now emits EffectiveKvLengthBound from the actual runtime allocation extent. The CUDA regressions assert 8 for the single-token unfused case and 11 for the multi-token Flash case, in addition to the existing Flash split assertion.

Validation:

  • lintrunner and git diff --check: passed
  • targeted CUDA GQA runtime regressions: 5/5 passed
  • CUDA internal workspace suite: the new complete-route parity test passed; 247/250 passed overall, with 2 existing LeanAttention skips and the unrelated AllocatorTest.CUDAAllocatorFallbackTest failing because it attempted a 42.5 GB allocation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The bounded sizing matches runtime cache semantics and is covered by targeted host and CUDA regression tests.

Review details
  • Files reviewed: 12/12 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI and others added 4 commits September 17, 2026 15:56
Use the resident or staged cache extent when sizing Flash and unfused workspace for sliding-window GQA, while preserving non-windowed behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Expose the selected Flash split count in debug output and assert that staged C+S sizing avoids raw-length split workspace.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Assert the zero runtime encoding used when staged windowed KV sizing avoids split-KV workspace.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply the runtime windowed KV-length bound when composing Flash and unfused workspace recipes, and expose the effective allocation length in debug output. Cover staged, decode, below-capacity, and non-windowed route semantics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@titaiwangms
Ti-Tai Wang (titaiwangms) force-pushed the titaiwangms/gqa-windowed-runtime-bound branch from fbc8dad to dac27b1 Compare September 17, 2026 16:38
@titaiwangms
Ti-Tai Wang (titaiwangms) merged commit 0b48778 into microsoft:main Sep 17, 2026
89 of 90 checks passed
@titaiwangms
Ti-Tai Wang (titaiwangms) deleted the titaiwangms/gqa-windowed-runtime-bound branch September 17, 2026 18:45
Ti-Tai Wang (titaiwangms) added a commit that referenced this pull request Sep 18, 2026
## Description

Adds conservative Level-1 and Level-2 workspace estimation for CUDA
contrib `GroupQueryAttention`, tracking #29775.

This is PR4, the final GQA workspace-estimation PR in the current stack.
It depends on #32602, which bounds windowed runtime workspace by the
resident/staged KV extent.

The estimator:
- inventories all reachable GQA CUDA backend routes over dynamic shape
bounds;
- composes checked preparation and backend workspace recipes;
- uses `C` for single-token windowed decode and checked `C + S` for
multi-token staging;
- bounds Flash split workspace independently of the non-monotonic split
heuristic;
- reports non-windowed and reachable cuDNN cases as unavailable when no
sound graph-free bound exists;
- reports Level-1 `runtime_workspace_bytes`; and
- declares one operator-owned slot-0 Level-2 root with 256-byte
alignment.

This PR does not change runtime allocation topology, opt into
planner-owned allocation, or slice a planned root. Those remain
follow-up integration work.

## Validation

- Fresh Release CUDA build on A100 (SM80)
- CUDA internal module: 264 passed, 2 unrelated LeanAttention skips
- GQA workspace estimate/bounds tests: 18/18 passed
- GQA workspace recipe/arithmetic tests: 19/19 passed
- Lintrunner and `git diff --check` passed
- Deep route-dominance review swept 2.7M complete routes and 25.6M Flash
boundary points with no underestimation

## Stack

- Depends on #32602
- Tracks #29775

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ep:CUDA issues related to the CUDA execution provider memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

⌂ 换网址