Skip to content

Fix QSA IndexShare reuse of held compressed-state prefixes - #34217

Open
bmehta001 wants to merge 3 commits into
mainfrom
fix/qsa-indexshare-held-state
Open

bmehta001 wants to merge 3 commits into
mainfrom
fix/qsa-indexshare-held-state

Conversation

@bmehta001

Copy link
Copy Markdown
Contributor

Description

Allow QSA IndexShare reuse to retain its captured compressed-state prefix while speculative query positions advance. Validate that the held prefix does not lie ahead of the current query, using 64-bit arithmetic, instead of requiring its key/buffer lengths to exactly describe the current query position.

All existing capacity, buffer geometry, negative-length, merged-count, cumulative-length, and status checks remain enforced. Refresh-mode validation and CSA behavior are unchanged.

Extend the existing CUDA regression across query past lengths 5-8 with the same held prefix and add negative/future-state cases. The former invalid case with an older prefix is legal in hold mode; replace its input with an out-of-range buffer length without weakening its rejection assertion.

Motivation and Context

Unblocks microsoft/onnxruntime-genai#2942. Matching the Python ORT binding and CUDA plugin to the native CI runtime exposed 14 IndexShare MTP failures previously hidden by missing schemas/kernels. After three failures, GenAI safely disables MTP and falls back to target-only decoding.

A standalone operator reproduction on A100 confirms the producer issue independently of GenAI: held state [0,1] passes at query past length 1 but is rejected at past length 2, even though ComputeReuse intentionally copies that state unchanged and performs no key projection.

Validation

  • The extended reuse regression fails against the unmodified CUDA plugin and passes after rebuilding only the changed kernel.
  • 24 ORT CUDA provider tests pass, covering QSA FP32/FP16/BF16, mixed state precision, capture, CSA reuse/advancement/rejection, and all indexer merge cases; no skips.
  • All 114 GenAI Engine Python tests pass with the rebuilt plugin and the unchanged CI core/runtime, including all 18 IndexShare cases; no skips or exclusions. The matching published plugin previously failed 14 of these cases.
  • Existing ORT lintrunner and git diff --check pass on Windows.

CUDA execution was verified on an idle A100 (sm80), using an offline build with QUICK_BUILD enabled. Windows CUDA build/runtime verification remains for CI; no local Windows CUDA toolchain is available.

Reuse intentionally holds compressed state while speculative query positions advance. Rejecting any prefix older than the current query incorrectly disables otherwise valid MTP chains. Keep metadata bounds and reject future prefixes, using 64-bit length arithmetic.

Files: onnxruntime/contrib_ops/cuda/sparse/packed_sparse_attention_indexer_impl.cu; onnxruntime/test/contrib_ops/packed_sparse_attention_indexer_op_test.cc.

Verify the regression fails before the fix and passes afterward. Validate 24 ORT CUDA tests and all 114 GenAI Engine tests on A100 without skips; run existing lintrunner on Windows.

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

Copilot-Session: 71f338fc-57ae-4336-8b1a-1ccf6d2ff1f7
Copilot AI balanced review requested due to automatic review settings November 14, 2026 00:05

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 review reports no active issues for the CUDA QSA held-prefix reuse change.

No open issues 🎉

What changed in this PR

Fixes CUDA QSA IndexShare reuse so a captured compressed-state prefix remains valid as speculative query positions advance, supporting GenAI’s multi-token prediction flow.

Changes:

  • Replaces exact state-position matching with a 64-bit check that the held prefix is not ahead of the query, preserving other validation and CSA behavior.
  • Extends reuse regression coverage across query past lengths 5–8, including negative lengths, invalid buffer lengths, and future-state rejection.
File Description
onnxruntime/​test/​contrib_ops/​packed_sparse_attention_indexer_op_test.cc Expands held-prefix reuse and invalid-state test scenarios.
onnxruntime/​contrib_ops/​cuda/​sparse/​packed_sparse_attention_indexer_impl.cu Allows older QSA prefixes while rejecting state ahead of the query.

Review effort: Balanced

bmehta001 and others added 2 commits November 13, 2026 20:48
Read verification counters back on their CUDA stream and report through host stdout so Windows CI can capture both FC stages without relying on device printf. Keep strict zero-miss checks and refresh operator documentation from the failing CI artifact.

Files changed:
- onnxruntime/contrib_ops/cuda/moe/qmoe_int3_tc.cuh
- onnxruntime/test/python/transformers/test_qmoe_shared_direct.py
- docs/OperatorKernels.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9a5970c4-dcda-48fb-91b5-0d4e93005a46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants