Add routed affine and positive Exp scale folding - #1301
Add routed affine and positive Exp scale folding#1301Qiong Wu (qiowu) (DingmaomaoBJTU) merged 16 commits into
Conversation
|
could you add a anyone can understand example of exp-positive-scale-folding to prove its numeric correctness? |
|
Addressed in the latest commits by adding an explicit numeric example and by documenting the algebraic assumptions in the tests. For into the log-domain equivalent: The identity is elementwise, so broadcasting-safe constants work the same way: The new test The test verifies both sides with ONNX Runtime, and also checks that the optimizer actually removed the post- The implementation is guarded so the rewrite only happens when the scale is a finite floating-point constant, strictly positive, broadcast-compatible with the For the other algebraic rewrites in the same update:
Validation run on the branch: CI is also green on the latest push. |
xieofxie
left a comment
There was a problem hiding this comment.
Found one graph-corruption bug and two additional correctness/resource issues in the new Exp scale folding path.
xieofxie
left a comment
There was a problem hiding this comment.
The stale-node fix and overflow-semantics disclosure are resolved. Two issues remain in scale-shape handling.
xieofxie
left a comment
There was a problem hiding this comment.
The reshape mapping and orthogonal-broadcast initializer issues are resolved. Two additional edge cases remain.
xieofxie
left a comment
There was a problem hiding this comment.
The shape-product overflow issue is resolved. One opset edge case remains.
xieofxie
left a comment
There was a problem hiding this comment.
The strict default-opset resolution issue is resolved. Four additional compatibility/performance issues remain.
xieofxie
left a comment
There was a problem hiding this comment.
The four compatibility fixes are resolved and the batched rewrites are graph-safe. The quadratic-runtime fix remains incomplete in two paths.
xieofxie
left a comment
There was a problem hiding this comment.
Per-prefix name allocation is resolved. Three issues remain in serial scale handling and Conv parameter synthesis.
xieofxie
left a comment
There was a problem hiding this comment.
The three prior findings are resolved. Three new issues remain in generated provenance and external Constant handling.
xieofxie
left a comment
There was a problem hiding this comment.
The three prior findings are resolved. One analysis-reporting issue remains.
xieofxie
left a comment
There was a problem hiding this comment.
Quick incremental review found one analysis-state regression.
xieofxie
left a comment
There was a problem hiding this comment.
Reviewed the latest head. Previous findings are resolved and the focused final pass found no remaining blockers.
Summary
conv-channel-affine-foldingacross nested static channelSplitroutes and parallel non-overlapping channelSliceroutesexp-positive-scale-foldingfor finite, strictly positive constant scales afterExpThe implementation is generic ONNX graph rewriting. It contains no model-name, architecture, or execution-provider special cases.
CLI
The complete optimization now runs in one invocation:
ORTGraphPiperestores eligibleSplitnodes first.AlgebraicRewritePipethen folds routed Conv affine operations and positive post-Expscales.For
Exp(x) * C, the new capability requires floating-pointCto be immutable, finite, strictly positive, and statically broadcastable. It either combineslog(C)with an existing safe pre-Expconstant bias or replaces the post-ExpMulwith a pre-ExpAdd(log(C))while preserving element order through static shape-only views.Validation
93 passedintests/unit/optim/pipes/test_pipe_algebraic.py640 passed, 16 skipped, 1 xfailedintests/unit/optimGenerated-graph coverage includes CLI composition, nested
Split, parallelSlice, broadcast and dtype behavior, float32/float64 constants, idempotence, custom domains, overridable initializers, external data, shared/captured/output tensors, malformed definitions, cycles, and route-depth limits.Real-model evidence
A single CLI invocation on the motivating source model produced:
195 -> 181Splitnodes restoredExpscaleMulremovedThe graph-equivalent C1 candidate was previously confirmed on QNN NPU with 20 warmups and 200 measured iterations across four alternating AB/BA pairs:
27.167 ms21.786 ms5.381 ms/19.808%[5.261, 5.502] ms4/4at or below25 msQuality evidence for that candidate passed canonical tensor replay and 40/40 local-smoke renders (mean PSNR
89.340 dB, minimum83.508 dB). The final FFHQ quality gate remains pending.