Skip to content

Add GQA workspace estimation - #32617

Open
Ti-Tai Wang (titaiwangms) wants to merge 17 commits into
microsoft:mainfrom
titaiwangms:titaiwangms/gqa-workspace-estimation
Open

Ti-Tai Wang (titaiwangms) wants to merge 17 commits into
microsoft:mainfrom
titaiwangms:titaiwangms/gqa-workspace-estimation

Conversation

@titaiwangms

Copy link
Copy Markdown
Contributor

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

@titaiwangms
Ti-Tai Wang (titaiwangms) marked this pull request as ready for review September 15, 2026 22:06
Copilot AI balanced review requested due to automatic review settings September 15, 2026 22:06
@titaiwangms Ti-Tai Wang (titaiwangms) added ep:CUDA issues related to the CUDA execution provider memory labels Sep 15, 2026

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 Level-2 kernel override lacks direct tests of its configuration translation and virtual dispatch.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds conservative CUDA GroupQueryAttention workspace estimation and exposes it through Level-1 accounting and Level-2 declarations.

Changes:

  • Adds checked preparation/backend recipes and bounded route aggregation.
  • Integrates estimates into CUDA partition accounting and kernel workspace declarations.
  • Expands workspace and windowed-cache regression coverage.
File summaries
File Description
onnxruntime/test/providers/cuda/test_cases/group_query_attention_workspace_test.cc Expands preparation-recipe tests.
onnxruntime/test/providers/cuda/test_cases/group_query_attention_workspace_mea_unfused_test.cc Tests MEA, unfused, and composed recipes.
onnxruntime/test/providers/cuda/test_cases/group_query_attention_workspace_header_test.cc Extends shared-header checks.
onnxruntime/test/providers/cuda/test_cases/group_query_attention_workspace_estimate_test.cc Tests bounds and estimator adapters.
onnxruntime/test/contrib_ops/group_query_attention_op_test.cc Adds windowed CUDA regressions.
onnxruntime/core/providers/cuda/cuda_execution_provider.cc Adds Level-1 GQA accounting.
onnxruntime/contrib_ops/cuda/bert/group_query_attention.h Declares Level-2 workspace support.
onnxruntime/contrib_ops/cuda/bert/group_query_attention.cc Implements declaration and bounded runtime sizing.
onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace.h Defines workspace recipe types.
onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace.cc Models preparation allocations.
onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace_xqa_flash.cc Records Flash route metadata.
onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace_routes.cc Composes complete route recipes.
onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace_mea_unfused.cc Implements MEA and unfused recipes.
onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace_estimate.h Declares estimator adapters.
onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace_estimate.cc Parses graph/kernel facts into bounds.
onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace_bounds.h Defines bounded estimation inputs.
onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace_bounds.cc Aggregates reachable backend envelopes.
onnxruntime/contrib_ops/cuda/bert/group_query_attention_impl.cu Applies effective windowed KV length.
docs/annotated_partitioning/attention_workspace_estimation.md Documents GQA estimation behavior.
Review details
  • Files reviewed: 19/19 changed files
  • Comments generated: 1
  • Review effort level: Balanced

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

Comment thread onnxruntime/contrib_ops/cuda/bert/group_query_attention.cc

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.

🔵 Needs a closer look

Backend dispatch and memory-bound calculations directly affect partition acceptance across a large CUDA route matrix.

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

Copilot AI and others added 13 commits September 16, 2026 19:32
Add MEA and unfused workspace recipes and compose one aligned concrete route root.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b24d04bb-12ab-41a0-8941-76eb9769005d
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Model the separate past-cache preservation allocation in complete workspace recipes and strengthen cross-recipe validation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Persist the Flash fast-decode witness and reject impossible windowed alias preparation states.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cross-check separate-past preparation against XQA and Flash fast-decode backends.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
Add conservative graph-free route bounds, Level-1 accounting, and a single aligned Level-2 workspace declaration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Avoid overflow while validating rotary cache dimensions and document and test the heuristic-independent Flash fast-decode envelope across the full dynamic sequence domain.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Document aliasing and non-windowed capacity preconditions, explain the graph-free route envelopes, and qualify Level 1 versus Level 2 head-sink sizing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Construct the CUDA GQA kernel and verify virtual workspace declaration, prepacked head-sink translation, and unavailable-shape behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

Valid partial-RoPE models are rejected by the estimator, and the XQA kernel test lacks an SM80 capability gate.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 19/19 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment thread onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace_estimate.cc Outdated
Match runtime rotary-cache validation, add the missing cctype include, and gate the XQA kernel declaration test on SM80.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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 estimator accepts cache geometry that the CUDA runtime rejects, and its primary fixtures exercise that invalid case.

Get a fresh assessment by requesting another Copilot review.

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

Comment thread onnxruntime/contrib_ops/cuda/bert/group_query_attention_workspace_estimate.cc Outdated
Require the bounded past cache capacity to match the sliding-window size, mirror the runtime past key/value capacity check, and make estimator fixtures use executable CUDA geometry.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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 Level-1 accounting integration lacks end-to-end coverage, and one test relies on a transitive standard-library include.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

onnxruntime/test/providers/cuda/test_cases/group_query_attention_workspace_estimate_test.cc:8

  • This file uses std::max at line 645 but does not include its declaring header, so it currently relies on transitive test/framework includes. Include <algorithm> directly to keep the test portable across standard-library configurations.
  • Files reviewed: 19/19 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread onnxruntime/core/providers/cuda/cuda_execution_provider.cc
Copilot AI and others added 2 commits September 16, 2026 21:57
Drive CUDA GetCapability across thresholds that distinguish the structured GQA workspace estimate from fallback accounting and verify strict rejection at the estimated resource count.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Declare the test dependencies directly and convert computed byte boundaries to the KiB units expected by capacity-aware partitioning.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Dynamic CUDA route envelopes directly affect partition memory accounting and warrant final human validation.

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

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.

3 participants