[CUDA][WebGPU] Add packed sparse attention indexer for continuous batching - #32618
Open
kunal-vaishnavi with Copilot wants to merge 10 commits into
Open
kunal-vaishnavi with Copilot wants to merge 10 commits into
kunal-vaishnavi with Copilot wants to merge 10 commits into
Conversation
kunal-vaishnavi
added this pull request to stack #32530
September 15, 2026 22:11
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Copilot stopped work on behalf of
kunal-vaishnavi due to an error
September 15, 2026 22:20
Copilot stopped work on behalf of
kunal-vaishnavi due to an error
September 15, 2026 23:22
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
kunal-vaishnavi
marked this pull request as ready for review
September 16, 2026 02:51
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
CUDA compile errors and unresolved shape-validation and WebGPU aliasing defects block approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds a packed, fixed-capacity sparse-attention indexer for continuous batching and paged-attention models.
Changes:
- Defines the generic QSA/CSA schema and symbolic shape inference.
- Implements and registers CUDA and WebGPU kernels.
- Adds documentation and provider-focused tests.
File summaries
| File | Description |
|---|---|
onnxruntime/core/graph/contrib_ops/bert_defs.cc |
Defines schema and shape inference. |
onnxruntime/core/graph/contrib_ops/ms_opset.h |
Registers the schema. |
onnxruntime/contrib_ops/cpu/sparse/packed_sparse_attention_indexer_common.h |
Defines packed ABI constants. |
onnxruntime/contrib_ops/cpu/sparse/sparse_attention_indexer_common.h |
Makes shared helpers device-callable. |
onnxruntime/contrib_ops/cuda/cuda_contrib_kernels.cc |
Registers CUDA kernels. |
onnxruntime/contrib_ops/cuda/sparse/packed_sparse_attention_indexer.cc |
Implements CUDA host validation. |
onnxruntime/contrib_ops/cuda/sparse/packed_sparse_attention_indexer.h |
Declares the CUDA kernel. |
onnxruntime/contrib_ops/cuda/sparse/packed_sparse_attention_indexer_impl.cu |
Implements CUDA device kernels. |
onnxruntime/contrib_ops/cuda/sparse/packed_sparse_attention_indexer_impl.h |
Declares CUDA launch interfaces. |
onnxruntime/contrib_ops/cuda/sparse/sparse_attention_indexer_device_math.cuh |
Extracts shared CUDA math. |
onnxruntime/contrib_ops/cuda/sparse/sparse_attention_indexer_impl.cu |
Adopts shared CUDA helpers. |
onnxruntime/contrib_ops/webgpu/bert/packed_sparse_attention_indexer.cc |
Implements WebGPU programs. |
onnxruntime/contrib_ops/webgpu/bert/packed_sparse_attention_indexer.h |
Declares WebGPU programs. |
onnxruntime/contrib_ops/webgpu/webgpu_contrib_kernels.cc |
Registers the WebGPU kernel. |
onnxruntime/python/tools/symbolic_shape_infer.py |
Adds symbolic inference dispatch. |
onnxruntime/test/contrib_ops/packed_sparse_attention_indexer_op_test.cc |
Adds schema and numeric tests. |
onnxruntime/test/python/onnxruntime_test_python_symbolic_shape_infer.py |
Tests symbolic output shapes. |
docs/ContribOperators.md |
Adds generated schema documentation. |
docs/OperatorKernels.md |
Lists provider kernel support. |
docs/contrib_ops/packed_sparse_attention_indexer.md |
Documents the operator contract. |
docs/contrib_ops/webgpu/packed_sparse_attention_indexer.md |
Documents WebGPU support. |
Review details
Suppressed comments (4)
onnxruntime/contrib_ops/cuda/sparse/packed_sparse_attention_indexer_impl.cu:571
overflowedis not declared in the CSA kernel, so this is another CUDA compile failure. The guard should use the previously computedrejectedflag.
if (!overflowed) {
onnxruntime/contrib_ops/webgpu/bert/packed_sparse_attention_indexer.cc:984
- The CSA aliasing path binds both past KV/gate buffers as read-only inputs and their aliased present buffers as read-write outputs. Dawn rejects this mixed usage for one storage buffer, so the advertised state aliasing cannot run. Add per-buffer alias detection and access aliased history only through the corresponding output binding.
{past_kv_buffer, ProgramTensorMetadataDependency::Type},
{past_gate_buffer, ProgramTensorMetadataDependency::Type}})
.AddInput({past_state_lengths, ProgramTensorMetadataDependency::Type})
.AddOutputs({{present_key_state, ProgramTensorMetadataDependency::Type},
{present_kv_buffer, ProgramTensorMetadataDependency::Type},
onnxruntime/test/contrib_ops/packed_sparse_attention_indexer_op_test.cc:1089
- Like the QSA case, this “prefill followed by decode” test executes only one call with fabricated prior state. It cannot catch state handoff or aliasing defects between calls; execute prefill and decode sequentially using the first call's outputs.
TEST(PackedSparseAttentionIndexerTest, CsaPrefillThenDecodeIndependentState) {
CsaPackedProblem problem;
problem.cumulative_sequence_lengths = {0, 1, 4};
problem.past_state_lengths = {1, 1, 0, 0};
RunCsaPackedTest<float>(MakeCsaPackedProblem(std::move(problem)), 1.0e-5f);
onnxruntime/test/contrib_ops/packed_sparse_attention_indexer_op_test.cc:1104
- CSA's advertised WebGPU FP16 path is also untested because this provider-specific test instantiates only
float; the genericCsaFloat16case runs on CUDA. Add a WebGPU FP16 case.
TEST(PackedSparseAttentionIndexerWebGpuTest, CsaFloat) {
RunCsaPackedTest<float>(MakeCsaPackedProblem(), 1.0e-5f, ProviderKind::WebGpu);
}
- Files reviewed: 21/21 changed files
- Comments generated: 8
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…on-indexer-again' into copilot/copilotimplement-packed-sparse-attention-indexer Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
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
Adds
com.microsoft.PackedSparseAttentionIndexerversion 1 for packed, variable-length continuous batching, with CUDA and WebGPU implementations.The operator supports both QSA and CSA policies over flattened token inputs and per-request metadata while preserving fixed-capacity state across prefill and decode calls. It is designed to produce selection metadata compatible with
SparsePagedAttentionwithout changing the existing denseSparseAttentionIndexerABI or behavior.Key changes:
Validation performed:
onnxruntime_provider_testCPU build completed successfully.PackedSparseAttentionIndexerShapeInferenceTesttests passed.Motivation and Context
The existing
SparseAttentionIndexercontract uses dense[B, S, ...]inputs, dense masking, and growing contiguous state. OgaEngine-compatible paged-attention models instead use flattened packed tokens,cumulative_sequence_lengths, per-request past lengths, dynamic request scheduling, and fixed-address state.This separate operator bridges that contract mismatch for sparse paged attention while keeping the existing dense operator stable. QSA selections reference request-local positions in the main paged cache; CSA selections reference fixed-capacity auxiliary compressed state suitable for
SparsePagedAttentionlocal-plus-selected execution.Built on the sparse attention indexer work from #32528.