@@ -5017,6 +5017,42 @@ def test_eliminate_common_subexression_with_attribute1(self): # type: () -> Non
50175017
50185018 assert len (optimized_model .graph .node ) == 6
50195019
5020+ def test_eliminate_common_subexpression_preserves_operator_domain (
5021+ self ,
5022+ ): # type: () -> None
5023+ X = helper .make_tensor_value_info ("X" , TensorProto .FLOAT , [1 ])
5024+ Y1 = helper .make_tensor_value_info ("Y1" , TensorProto .FLOAT , [1 ])
5025+ Y2 = helper .make_tensor_value_info ("Y2" , TensorProto .FLOAT , [1 ])
5026+ standard_add = helper .make_node ("Add" , ["X" , "X" ], ["Y1" ])
5027+ local_add = helper .make_node ("Add" , ["X" , "X" ], ["Y2" ], domain = "local" )
5028+ graph = helper .make_graph (
5029+ [standard_add , local_add ], "test" , [X ], [Y1 , Y2 ]
5030+ )
5031+ local_function = helper .make_function (
5032+ "local" ,
5033+ "Add" ,
5034+ ["A" , "B" ],
5035+ ["C" ],
5036+ [helper .make_node ("Sub" , ["A" , "B" ], ["C" ])],
5037+ [helper .make_opsetid ("" , LATEST_STABLE_OPSET_VERSION )],
5038+ )
5039+ model = helper .make_model (
5040+ graph ,
5041+ functions = [local_function ],
5042+ opset_imports = [
5043+ helper .make_opsetid ("" , LATEST_STABLE_OPSET_VERSION ),
5044+ helper .make_opsetid ("local" , 1 ),
5045+ ],
5046+ )
5047+
5048+ optimized_model = onnxoptimizer .optimize (
5049+ model , ["eliminate_common_subexpression" , "eliminate_deadend" ]
5050+ )
5051+
5052+ assert len (optimized_model .graph .node ) == 2
5053+ assert optimized_model .graph .node [0 ].domain == ""
5054+ assert optimized_model .graph .node [1 ].domain == "local"
5055+
50205056 def _test_fuse_qkv_with_opset (self , opset_version ): # type: (int) -> None
50215057 X = helper .make_tensor_value_info ("X" , TensorProto .FLOAT , [1 , 4096 , 320 ])
50225058 Y1 = helper .make_tensor_value_info ("Y1" , TensorProto .FLOAT , [1 , 4096 , 8 , 40 ])
0 commit comments