mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-30 20:18:08 +00:00
Fix MatmulTransposeFusion::ApplyImpl() setting of modified flag (#4775)
Update MatmulTransposeFusion::ApplyImpl() to set modified flag whenever a fusion is performed.
This commit is contained in:
parent
8fb743f767
commit
74b3b8448c
4 changed files with 59 additions and 4 deletions
|
|
@ -149,6 +149,8 @@ Status MatmulTransposeFusion::ApplyImpl(Graph& graph, bool& modified, int graph_
|
|||
matmul_node.SetExecutionProviderType(node.GetExecutionProviderType());
|
||||
|
||||
graph_utils::FinalizeNodeFusion(graph, matmul_node, node);
|
||||
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// Have to remove node in reversed order for now to walk around the issue in RemoveNode
|
||||
|
|
@ -156,10 +158,6 @@ Status MatmulTransposeFusion::ApplyImpl(Graph& graph, bool& modified, int graph_
|
|||
graph.RemoveNode(removed_node);
|
||||
}
|
||||
|
||||
if (!removed_nodes.empty()) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
} // namespace onnxruntime
|
||||
|
|
|
|||
|
|
@ -805,6 +805,25 @@ TEST_F(GraphTransformationTests, TransposeMatmulFusionFromTransposeScaleMatMul)
|
|||
ASSERT_EQ(transpose_scale_matmul_node.GetAttributes().at("alpha").f(), expected_alpha);
|
||||
}
|
||||
|
||||
TEST_F(GraphTransformationTests, TransposeMatmulFusionWithPreservedTranspose) {
|
||||
auto model_uri = MODEL_FOLDER "fusion/transpose_matmul_2d_fusion_with_preserved_transpose.onnx";
|
||||
std::shared_ptr<Model> p_model;
|
||||
ASSERT_STATUS_OK(Model::Load(model_uri, p_model, nullptr, *logger_));
|
||||
Graph& graph = p_model->MainGraph();
|
||||
|
||||
onnxruntime::GraphTransformerManager graph_transformation_mgr{5};
|
||||
ASSERT_STATUS_OK(graph_transformation_mgr.Register(
|
||||
onnxruntime::make_unique<MatmulTransposeFusion>(), TransformerLevel::Level1));
|
||||
ASSERT_STATUS_OK(graph_transformation_mgr.ApplyTransformers(graph, TransformerLevel::Level1, *logger_));
|
||||
|
||||
std::map<std::string, int> op_to_count = CountOpsInGraph(graph);
|
||||
ASSERT_EQ(op_to_count["Transpose"], 1);
|
||||
ASSERT_EQ(op_to_count["MatMul"], 0);
|
||||
ASSERT_EQ(op_to_count["TransposeScaleMatMul"], 1);
|
||||
|
||||
ASSERT_FALSE(graph.GraphResolveNeeded());
|
||||
}
|
||||
|
||||
TEST_F(GraphTransformationTests, Gemm_LeakyRelu_Fusion) {
|
||||
auto model_uri = MODEL_FOLDER "gemm_activation_fusion/gemm_activation_fusion.onnx";
|
||||
|
||||
|
|
|
|||
BIN
onnxruntime/test/testdata/transform/fusion/transpose_matmul_2d_fusion_with_preserved_transpose.onnx
vendored
Normal file
BIN
onnxruntime/test/testdata/transform/fusion/transpose_matmul_2d_fusion_with_preserved_transpose.onnx
vendored
Normal file
Binary file not shown.
|
|
@ -12,6 +12,7 @@ msdomain.version = 1
|
|||
msdomain.domain = "com.microsoft"
|
||||
opsets = [onnxdomain, msdomain]
|
||||
|
||||
|
||||
def save(model_path, nodes, inputs, outputs, initializers):
|
||||
graph = helper.make_graph(
|
||||
nodes,
|
||||
|
|
@ -88,3 +89,40 @@ def gen_invalid_default_perm(model_path):
|
|||
|
||||
gen_invalid_default_perm(
|
||||
"transpose_matmul_4d_fusion_invalid_default_perm.onnx")
|
||||
|
||||
|
||||
def gen_with_preserved_transpose(model_path):
|
||||
nodes = [
|
||||
helper.make_node(
|
||||
"Transpose",
|
||||
["input_0"],
|
||||
["transposed_input_0"]),
|
||||
helper.make_node(
|
||||
"MatMul",
|
||||
["transposed_input_0", "input_1"],
|
||||
["output_0"]),
|
||||
helper.make_node(
|
||||
"Identity",
|
||||
["transposed_input_0"],
|
||||
["output_1"])
|
||||
]
|
||||
|
||||
inputs = [
|
||||
helper.make_tensor_value_info(
|
||||
"input_0", TensorProto.FLOAT, ['K', 'M']),
|
||||
helper.make_tensor_value_info(
|
||||
"input_1", TensorProto.FLOAT, ['K', 'N'])
|
||||
]
|
||||
|
||||
outputs = [
|
||||
helper.make_tensor_value_info(
|
||||
"output_0", TensorProto.FLOAT, ['M', 'N']),
|
||||
helper.make_tensor_value_info(
|
||||
"output_1", TensorProto.FLOAT, ['M', 'K'])
|
||||
]
|
||||
|
||||
save(model_path, nodes, inputs, outputs, [])
|
||||
|
||||
|
||||
gen_with_preserved_transpose(
|
||||
"transpose_matmul_2d_fusion_with_preserved_transpose.onnx")
|
||||
|
|
|
|||
Loading…
Reference in a new issue