onnx: add com.microsoft GroupQueryAttention handler#2292
Open
czoli1976 wants to merge 1 commit into
Open
Conversation
Prefill-only GroupQueryAttention lowered onto tract Sdpa: reshapes Q/K/V to 4D, applies an explicit lower-triangular causal mask, and returns present_key/present_value (the reshaped K/V). Sdpa handles the grouped-query head sharing (kv_num_heads < num_heads). Decode-step KV cache, internal rotary (do_rotary), local-window attention and softcap are rejected with clear errors. Validated against onnxruntime across head_size 8/16/64, several num_heads/kv_num_heads ratios (incl. multi-query kv=1) and batch>1: attention output matches to <=3.6e-7 and present_key/present_value are bit-exact. ORT's GroupQueryAttention prefill is standard causal grouped-query attention; the seqlens_k input is the 0-indexed position of the last token (total_sequence_length - 1), not the token count. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
fb9487c to
7c80e09
Compare
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.
GroupQueryAttention (prefill): causal grouped-query attention over unpacked query/key/value, lowered onto tract's
Sdpa(which already handles thekv_num_heads < num_headshead sharing), withpresent_key/present_valueoutputs. Decode-step KV cache (past_key/past_value), internal rotary (do_rotary), local-window attention and softcap are rejected with clear errors.Validated bit-close vs onnxruntime: attention output ≤3.6e-7 and
present_key/present_valuebit-exact, across head_size 8/16/64, severalnum_heads/kv_num_headsratios (incl. multi-querykv_num_heads=1) and batch>1. Full ONNX node suite: 4428 passed / 0 failed (op is purely additive). clippy + fmt clean.Note for reviewers: ORT's GroupQueryAttention prefill is standard causal grouped-query attention — its
seqlens_kinput is the 0-indexed position of the last token (total_sequence_length - 1), not the token count.Part of com.microsoft contrib-op coverage for ORT-exported LLMs (sibling to #2287–#2291).
🤖 Generated with Claude Code