When running the onnxscript_bug.py multiple times on the attached input model, sometimes it will apply a rewrite rule, other times it won't.
In the below text, 6 out of 20 runs triggered a rewrite.
Non-deterministic behavior should be avoided at all cost, as it complicates matters.
$ cat onnxscript_bug.py
from onnxscript import ir
from onnxscript.optimizer import optimize_ir
ir_model = ir.load("input.onnx")
optimize_ir(ir_model, num_iterations = 1)
ir.save(ir_model, "output.onnx")
$ for i in {1..20}; do python onnxscript_bug.py; done
Applied 1 of general pattern rewrite rules.
Applied 1 of general pattern rewrite rules.
Applied 1 of general pattern rewrite rules.
Applied 1 of general pattern rewrite rules.
Applied 1 of general pattern rewrite rules.
Applied 1 of general pattern rewrite rules.
$ pip list | grep onnx
onnx 1.19.1
onnx-ir 0.2.0
onnxscript 0.6.2
sne4onnx 2.0.1
input.onnx.zip
the resulting graphs show the difference:

When running the onnxscript_bug.py multiple times on the attached input model, sometimes it will apply a rewrite rule, other times it won't.
In the below text, 6 out of 20 runs triggered a rewrite.
Non-deterministic behavior should be avoided at all cost, as it complicates matters.
input.onnx.zip
the resulting graphs show the difference: