microsoft / microsoft/onnxruntime
[Feature Request] Shape inference for GroupQueryAttention Op
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 184
Description
### Describe the feature request
For WebNN EP, the graph builder does not accept input and output with dynamic shape. So after FreeDimensionOverride it is expected that all shape / dims are static.
There was already a shape inference function for `GroupQueryAttention` Op in `BaseGroupQueryAttentionTypeAndShapeInference()` of `onnxruntime/core/graph/contrib_ops/bert_defs.cc`. However, the `use_max_past_present_buffer` parameter is set to -1 for each case, as in the following code:
https://github.com/microsoft/onnxruntime/blob/81cd6eacd0121711c2e6e6f8d1fc0cefcd81de99/onnxruntime/core/graph/contrib_ops/bert_defs.cc#L319-L323
So I was wondering if it is possible to pass an argument/flag to give it a chance to perform shape inference, at least when the shared buffer is used by some EPs.
### Describe scenario use case
When some EPs use shared buffer for key / value cache, they pass the flag/argument to set the `use_max_past_present_buffer` to `1`, which will enable the shape inference for GroupQueryAttention Ops.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in onnxruntime/core/graph/contrib_ops/bert_defs.cc at BaseGroupQueryAttentionTypeAndShapeInference() and the GroupQueryAttention definitions around the referenced lines. Trace how use_max_past_present_buffer is supplied for shared-buffer cases, then verify that passing 1 enables static input and output shape inference for the affected execution providers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100