From c14fae9461a18184f5e6b8d559914ff4041b947e Mon Sep 17 00:00:00 2001 From: rui-ren Date: Tue, 5 Dec 2023 07:46:08 -0800 Subject: [PATCH] add SAVE_TEST_GRAPH macro (#18696) ### Description Add a macro `SAVE_TEST_GRAPH ` in `graph_transform_test_builder.cc`. ### Motivation and Context This will help us debug the graph and Unitest. Co-authored-by: ruiren --- .../test/optimizer/graph_transform_test_builder.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/onnxruntime/test/optimizer/graph_transform_test_builder.cc b/onnxruntime/test/optimizer/graph_transform_test_builder.cc index c98dc78998..a5024f510b 100644 --- a/onnxruntime/test/optimizer/graph_transform_test_builder.cc +++ b/onnxruntime/test/optimizer/graph_transform_test_builder.cc @@ -14,6 +14,9 @@ #include "test/util/include/asserts.h" #include "test/util/include/inference_session_wrapper.h" +// enable to dump model for debugging +#define SAVE_TEST_GRAPH 0 + namespace onnxruntime { namespace test { @@ -73,7 +76,7 @@ void TransformerTester(const std::function& buil std::unique_ptr transformer = nullptr) { SessionOptions session_options; session_options.graph_optimization_level = transformer ? baseline_level : level; -#if 0 // enable to dump model for debugging +#if SAVE_TEST_GRAPH session_options.optimized_model_filepath = ToPathString("model" + std::to_string(static_cast(level)) + ".onnx"); #endif @@ -156,11 +159,17 @@ Status TestGraphTransformer(const std::function& if (pre_graph_checker) { ORT_RETURN_IF_ERROR(pre_graph_checker(graph)); } +#if SAVE_TEST_GRAPH + ORT_RETURN_IF_ERROR(Model::Save(model, "model_original.onnx")); +#endif ORT_RETURN_IF_ERROR(graph_transformation_mgr.ApplyTransformers(graph, level, logger)); if (post_graph_checker) { ORT_RETURN_IF_ERROR(post_graph_checker(graph)); } - } +#if SAVE_TEST_GRAPH + ORT_RETURN_IF_ERROR(Model::Save(model, "model_optimized.onnx")); +#endif + }; return Status::OK(); }