Onnx optimizer is a C++ library with a python frontend to perform backend-agnostic optimizations of onnx graphs,.
To contribute an optimization pass we generally need to do the following:
Add a new file here
subclass the Pass class (or one of its subclasses) as defined here
PredicateBasedPass is a very common type of Pass to implement. Once this is subclassed, we need to implement patternMatchPredicate and runTransform
Register the new Pass here
Add a test here
Some of my contributions to this library are:
idempotent Sign op optimization: Since "Sign" op is idempotent (applying it more than one time has the same effect as applying it one time), we can add it to the EliminateConsecutiveIdempotentOps pass
where-not optimization: where(not(b), x, y) is equivalent to where(b, y, x). In such cases we can remove the not op.
The where-not optimization is illustrated in the pre and post graphs on the left
Note that the "Not" node has disappeared and the inputs have been swapped.