Repository navigation
Use optimized reference ops in constant folding evaluator - #3162
Open
Santosh Todkar (todkarsant) wants to merge 5 commits into
Open
Santosh Todkar (todkarsant) wants to merge 5 commits into
Santosh Todkar (todkarsant) wants to merge 5 commits into
Conversation
The constant folding ReferenceEvaluator always used onnx.reference.ops.load_op() which only returns plain reference implementations. ONNX's own ReferenceEvaluator defaults to optimized=True and prefers ops from onnx.reference.ops_optimized (e.g., Conv uses im2col+GEMM instead of a slow Python loop nest). This change makes constant folding try onnx.reference.ops_optimized.optimized_operators first, falling back to the plain ops. The import is guarded with a try/except so older onnx versions without the module still work. Fixes microsoft#3003 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
|
@microsoft-github-policy-service agree |
…use-optimized-ops
Index ONNX's operator-class list by domain/name and preserve plain evaluation when optimized kernels reject inputs. Cover Conv parity and constant-folding integration across supported ONNX versions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3162 +/- ##
==========================================
+ Coverage 73.77% 73.83% +0.05%
==========================================
Files 270 270
Lines 33876 34000 +124
Branches 3243 3259 +16
==========================================
+ Hits 24993 25104 +111
- Misses 7829 7839 +10
- Partials 1054 1057 +3 ☔ View full report in Codecov by Harness. |
Decline automatic-padding Conv evaluation when legacy ONNX reference kernels are present: both plain and optimized implementations can return incorrect values without raising. Preserve the Conv node and optimized default/explicit-padding paths. Replace circular parity coverage with independent numerical and shape regressions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
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.
Fixes #3003.
SAME_UPPER,SAME_LOWER, andVALIDConv nodes unfolded on legacy ONNX: both reference kernels can silently compute incorrect automatic padding. Default/NOTSETand explicit-padding Conv retain the optimized path.Independent NumPy numerical/shape regressions cover all three automatic-padding modes across opsets 1/11/21, including unchanged-graph checks on legacy ONNX. Other coverage includes 1D/2D/3D/grouped Conv, explicit pads/strides/dilations, bias, float16/32/64, and graph folding.
Optimizer suite: 106 passed on ONNX 1.22; 105 passed, 1 intentional skip on development 1.24; 105 passed on ONNX 1.17 excluding one confirmed pre-existing IR-version checker incompatibility.
lintrunner -apasses.Windows AMD64, Python 3.11.18, ONNX 1.22, NumPy 2.4.6; reporter's
NOTSETConv, X=(1,2,192,192), W=(32,2,1,1): median 10.469 s → 6.253 ms (1,674×) over 3 plain / 7 guarded optimized runs, with identical float32 values.