Update optimizer opset version checks for latest ONNX opset 26 - #28966
Conversation
There was a problem hiding this comment.
Pull request overview
This PR expands ONNX Runtime optimizer pattern matching and unit tests to recognize newer ONNX operator schema versions (opset 23–25), aiming to keep attention fusions and reshape fusion behavior compatible with opset 25 models.
Changes:
- Broadened supported operator-version allowlists in optimizer fusions (e.g., Transpose/Reshape/Squeeze/Unsqueeze/Shape) to include newer schema versions up to opset 25.
- Added opset 25 coverage for MobileCLIP attention fusion and GroupQueryAttentionPreNorm fusion unit tests.
- Extended
ReshapeFusionOpsetTestto iterate additional opsets (19/21/23/24/25).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/core/optimizer/attention_fusion.cc | Updates MobileCLIP attention fusion pattern version checks for newer ONNX schemas. |
| onnxruntime/core/optimizer/attention_fusion_helper.h | Extends supported Transpose versions in GPT attention helper logic. |
| onnxruntime/core/optimizer/group_query_attention_pre_norm_fusion.cc | Expands supported Reshape versions in the GQA pre-norm fusion matcher. |
| onnxruntime/core/optimizer/reshape_fusion.cc | Updates Shape/Unsqueeze schema version handling in reshape fusion logic. |
| onnxruntime/test/optimizer/graph_transform_test.cc | Adds opset coverage (incl. 25) for attention and reshape fusion tests. |
| onnxruntime/test/optimizer/group_query_attention_pre_norm_fusion_test.cc | Adds opset 25 test for Qwen GQA pre-norm fusion. |
Comments suppressed due to low confidence (1)
onnxruntime/test/optimizer/graph_transform_test.cc:8241
ReshapeFusionOpsetTestnow iterates opsets 19/21/23/24/25, but theshape_test_for_opset15flag is mutated insidebuild_test_caseand then reused across iterations. After the first opset>=15 run, subsequent iterations build a Shape with start=1,end=2 and also switch to the (pre,pre) checker branch, so the newly added opsets are not actually validating the fusion path this test is meant to cover.
const std::vector<int> opsets{11, 12, 13, 14, 15, 18, 19, 21, 23, 24, 25};
bool shape_test_for_opset15 = false;
for (auto& opset : opsets) {
auto build_test_case = [&](ModelTestBuilder& builder) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
795f312 to
6907dd7
Compare
Add newer opset versions (19, 21, 23, 24, 25) to IsSupportedOptypeVersionAndDomain and MatchesOpSinceVersion checks in optimizers where the version bumps are type-constraint widenings only (no semantic changes): - attention_fusion.cc: Reshape, Transpose, Squeeze - attention_fusion_helper.h: Transpose - group_query_attention_pre_norm_fusion.cc: Reshape - reshape_fusion.cc: Unsqueeze, Shape Add corresponding tests at opset 25 for attention fusion, GQA pre-norm fusion, and extend ReshapeFusionOpsetTest to cover opsets 19-25. Fix ReshapeFusionOpsetTest to properly test the fusion path for all opsets including 19+. Previously, a mutable flag caused opsets after 18 to only test the no-fusion (partial Shape) path.
6907dd7 to
6a12338
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
onnxruntime/core/optimizer/reshape_fusion.cc:181
- The Shape(start/end) guard rejects any explicit
endattribute, even if it is set to the default "no slicing" value (e.g., INT64_MAX). That can unnecessarily block reshape-fusion for graphs that redundantly setendto the default. Consider treating anendattribute with a very large value (i.e., equivalent to full-shape) as acceptable, and only rejecting when start/end imply an actual slice.
// Opset 15+ added start/end attributes to Shape. Reject partial-shape queries.
if (shape.SinceVersion() >= 15) {
const ONNX_NAMESPACE::AttributeProto* start_attr = graph_utils::GetNodeAttribute(shape, "start");
const ONNX_NAMESPACE::AttributeProto* end_attr = graph_utils::GetNodeAttribute(shape, "end");
if (!((!start_attr || static_cast<int>(start_attr->i()) == 0) && (!end_attr))) {
return false;
}
Verdict: Approve, but
|
…nt-opset regression tests - Update version lists in attention_fusion.cc, attention_fusion_helper.h, and embed_layer_norm_fusion.cc to include opset versions up to 25/26. - Add programmatic current-opset regression tests that auto-detect when version lists need updating: Gelu, FastGelu, BiasGelu, LayerNorm, SkipLayerNorm, EmbedLayerNorm (3 formats), MobileClip MHA, GQA PreNorm. - Tests check for fused node first and report remaining op counts with guidance to update version lists or skip the opset.
- Replace .at(ONNX_DOMAIN) with find + ASSERT_TRUE in GQA test to avoid potential throw on missing domain (Copilot review, high). - Remove redundant TEST_RETURN_IF_NOT in DivMulFusionCurrentOpsetTest where the condition was already guaranteed by the enclosing if (Copilot review, low).
…usion with partial-shape queries
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
onnxruntime/core/optimizer/reshape_fusion.cc:181
- The new Shape start/end-attribute guard rejects any node that has an "end" attribute, even when end is the default full-range value. ORT’s Shape kernel treats end==std::numeric_limits<int64_t>::max() as the default (full shape), so this check can incorrectly block ReshapeFusion matching for models/exporters that explicitly set end to INT64_MAX.
// Opset 15+ added start/end attributes to Shape. Reject partial-shape queries.
if (shape.SinceVersion() >= 15) {
const ONNX_NAMESPACE::AttributeProto* start_attr = graph_utils::GetNodeAttribute(shape, "start");
const ONNX_NAMESPACE::AttributeProto* end_attr = graph_utils::GetNodeAttribute(shape, "end");
if (!((!start_attr || static_cast<int>(start_attr->i()) == 0) && (!end_attr))) {
return false;
}
This pull request expands support for additional ONNX opset versions in the attention fusion optimization code, making the optimizer compatible with newer and more diverse ONNX models. The changes primarily update the accepted opset versions for various operators such as
Transpose,Reshape,Squeeze,Unsqueeze,Shape, and others across multiple functions. This ensures broader model compatibility and improves the robustness of the fusion logic.Expanded opset version support for attention fusion:
Transpose,Reshape,Squeeze,Unsqueeze,Shape,Add,Mul,Sub,Div,Cast, etc.) in the main attention fusion logic (attention_fusion.cc), allowing matching and fusion of newer ONNX models using these operators at opsets up to 25. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]Helper and mask subgraph matching improvements:
These changes collectively future-proof the attention fusion optimizer for a wider range of ONNX models and operator versions, reducing the likelihood of unsupported patterns during optimization.