diff --git a/orttraining/orttraining/core/framework/ortmodule_graph_builder.cc b/orttraining/orttraining/core/framework/ortmodule_graph_builder.cc index c5948e563fcf8..e01456ee3d769 100644 --- a/orttraining/orttraining/core/framework/ortmodule_graph_builder.cc +++ b/orttraining/orttraining/core/framework/ortmodule_graph_builder.cc @@ -183,7 +183,7 @@ Status OrtModuleGraphBuilder::OptimizeForwardGraph(const TrainingGraphTransforme } if (!config.optimized_pre_grad_filepath.empty()) { - ORT_RETURN_IF_ERROR(Model::Save(*forward_model_, config.optimized_pre_grad_filepath)); + ORT_RETURN_IF_ERROR(Model::Save(*forward_model_, ToPathString(config.optimized_pre_grad_filepath))); } return Status::OK(); diff --git a/orttraining/orttraining/core/optimizer/graph_transformer_config.h b/orttraining/orttraining/core/optimizer/graph_transformer_config.h index f72dbfa3fdfc3..c496e36689de1 100644 --- a/orttraining/orttraining/core/optimizer/graph_transformer_config.h +++ b/orttraining/orttraining/core/optimizer/graph_transformer_config.h @@ -28,6 +28,7 @@ struct TrainingGraphTransformerConfiguration : public GraphTransformerConfigurat bool print_input_density{false}; // Path for serialization of the transformed optimized model. If empty, serialization is disabled. + // A UTF-8 string. std::string optimized_pre_grad_filepath; }; diff --git a/orttraining/orttraining/python/orttraining_pybind_state.cc b/orttraining/orttraining/python/orttraining_pybind_state.cc index 5ea60102f3ef8..5697ce6f0c7a4 100644 --- a/orttraining/orttraining/python/orttraining_pybind_state.cc +++ b/orttraining/orttraining/python/orttraining_pybind_state.cc @@ -617,7 +617,7 @@ void addObjectMethodsForTraining(py::module& m) { ORT_THROW_IF_ERROR(gradient_graph_builder->builder_->Build()); }) .def("save", [](PyGradientGraphBuilderContext* gradient_graph_builder, const std::string& path) { - ORT_THROW_IF_ERROR(Model::Save(*(gradient_graph_builder->model_), path)); + ORT_THROW_IF_ERROR(Model::Save(*(gradient_graph_builder->model_), ToPathString(path))); }) .def("get_model", [](PyGradientGraphBuilderContext* gradient_graph_builder) { std::string model_str; diff --git a/orttraining/orttraining/test/gradient/allreduce_op_test.cc b/orttraining/orttraining/test/gradient/allreduce_op_test.cc index 82f01a3c43681..1b1bd680a1191 100644 --- a/orttraining/orttraining/test/gradient/allreduce_op_test.cc +++ b/orttraining/orttraining/test/gradient/allreduce_op_test.cc @@ -472,7 +472,7 @@ TEST(AllreduceTest, GPUHierarchicalAdasumAllreduceOptimizerTest) { build_allreduce_graph(graph, adasum_graph_configs, training::AdasumReductionType::GpuHierarchicalReduction, true /*build_optimizer*/, false /*half_precision*/); - std::string model_file_name = "GPUHierarchicalAdasumAllreduceOptimizerTest.onnx"; + PathString model_file_name = ORT_TSTR("GPUHierarchicalAdasumAllreduceOptimizerTest.onnx"); auto status = onnxruntime::Model::Save(model, model_file_name); SessionOptions so; @@ -649,7 +649,7 @@ TEST(AllreduceTest, GPUHierarchicalAdasumAllreduceOptimizerFP16Test) { build_allreduce_graph(graph, adasum_graph_configs, training::AdasumReductionType::GpuHierarchicalReduction, true /*build_optimizer*/, true /*half_precision*/); - std::string model_file_name = "GPUHierarchicalAdasumAllreduceOptimizerFP16Test.onnx"; + PathString model_file_name = ORT_TSTR("GPUHierarchicalAdasumAllreduceOptimizerFP16Test.onnx"); auto status = onnxruntime::Model::Save(model, model_file_name); SessionOptions so; @@ -791,7 +791,7 @@ TEST(AllreduceTest, GPUHierarchicalAdasumAllreduceTest) { adasum_graph_configs.push_back(adasum_graph_config); build_allreduce_graph(graph, adasum_graph_configs, training::AdasumReductionType::GpuHierarchicalReduction); - std::string model_file_name = "GPUHierarchicalAdasumAllreduceTest.onnx"; + PathString model_file_name = ORT_TSTR("GPUHierarchicalAdasumAllreduceTest.onnx"); auto status = onnxruntime::Model::Save(model, model_file_name); SessionOptions so; @@ -896,7 +896,7 @@ TEST(AllreduceTest, GPUHierarchicalAdasumFP16AllreduceTest) { false /*build_optimizer*/, true /*half_precision*/); - std::string model_file_name = "GPUHierarchicalAdasumFP16AllreduceTest.onnx"; + PathString model_file_name = ORT_TSTR("GPUHierarchicalAdasumFP16AllreduceTest.onnx"); auto status = onnxruntime::Model::Save(model, model_file_name); SessionOptions so; @@ -1003,7 +1003,7 @@ TEST(AllreduceTest, GPUAdasumAllreduceTest) { build_allreduce_graph(graph, adasum_graph_configs, training::AdasumReductionType::CpuReduction); - std::string model_file_name = "GPUAdasumAllreduceTest.onnx"; + PathString model_file_name = ORT_TSTR("GPUAdasumAllreduceTest.onnx"); auto status = onnxruntime::Model::Save(model, model_file_name); SessionOptions so; @@ -1110,7 +1110,7 @@ TEST(AllreduceTest, GPUAdasumFP16AllreduceTest) { build_allreduce_graph(graph, adasum_graph_configs, training::AdasumReductionType::CpuReduction, true /*half_precision*/); - std::string model_file_name = "GPUAdasumFP16AllreduceTest.onnx"; + PathString model_file_name = ORT_TSTR("GPUAdasumFP16AllreduceTest.onnx"); auto status = onnxruntime::Model::Save(model, model_file_name); SessionOptions so; diff --git a/orttraining/orttraining/test/optimizer/graph_transform_test.cc b/orttraining/orttraining/test/optimizer/graph_transform_test.cc index 4ab035a171430..b2ab4891f2e1e 100644 --- a/orttraining/orttraining/test/optimizer/graph_transform_test.cc +++ b/orttraining/orttraining/test/optimizer/graph_transform_test.cc @@ -627,7 +627,7 @@ TEST_F(GraphTransformationTests, MegatronMLPPartitionRank0) { TransformerLevel::Level1)); ASSERT_STATUS_OK(graph_transformation_mgr.ApplyTransformers(graph, TransformerLevel::Level1, *logger_)); - auto model_uri2 = "mlp_megatron_basic_test_partition_rank0.onnx"; + PathString model_uri2 = ORT_TSTR("mlp_megatron_basic_test_partition_rank0.onnx"); ASSERT_STATUS_OK(Model::Save(*p_model, model_uri2)); { @@ -705,7 +705,7 @@ TEST_F(GraphTransformationTests, MegatronMLPPartitionRank1) { TransformerLevel::Level1)); ASSERT_STATUS_OK(graph_transformation_mgr.ApplyTransformers(graph, TransformerLevel::Level1, *logger_)); - auto model_uri2 = "mlp_megatron_basic_test_partition_rank1.onnx"; + PathString model_uri2 = ORT_TSTR("mlp_megatron_basic_test_partition_rank1.onnx"); ASSERT_STATUS_OK(Model::Save(*p_model, model_uri2)); { @@ -765,7 +765,7 @@ TEST_F(GraphTransformationTests, MegatronMLPPartitionRank1) { } TEST_F(GraphTransformationTests, MegatronSelfAttentionPartitionRank0) { - auto model_uri = MODEL_FOLDER "model_parallel/self_attention_megatron_basic_test.onnx"; + PathString model_uri = MODEL_FOLDER "model_parallel/self_attention_megatron_basic_test.onnx"; std::shared_ptr p_model; ASSERT_STATUS_OK(Model::Load(model_uri, p_model, nullptr, *logger_)); Graph& graph = p_model->MainGraph(); @@ -781,7 +781,7 @@ TEST_F(GraphTransformationTests, MegatronSelfAttentionPartitionRank0) { TransformerLevel::Level1)); ASSERT_STATUS_OK(graph_transformation_mgr.ApplyTransformers(graph, TransformerLevel::Level1, *logger_)); - auto model_uri2 = "self_attention_megatron_basic_test_partition_rank0.onnx"; + PathString model_uri2 = ORT_TSTR("self_attention_megatron_basic_test_partition_rank0.onnx"); ASSERT_STATUS_OK(Model::Save(*p_model, model_uri2)); { @@ -838,7 +838,7 @@ TEST_F(GraphTransformationTests, MegatronSelfAttentionPartitionRank0) { } TEST_F(GraphTransformationTests, MegatronSelfAttentionPartitionRank1) { - auto model_uri = MODEL_FOLDER "model_parallel/self_attention_megatron_basic_test.onnx"; + PathString model_uri = MODEL_FOLDER "model_parallel/self_attention_megatron_basic_test.onnx"; std::shared_ptr p_model; ASSERT_STATUS_OK(Model::Load(model_uri, p_model, nullptr, *logger_)); Graph& graph = p_model->MainGraph(); @@ -856,7 +856,7 @@ TEST_F(GraphTransformationTests, MegatronSelfAttentionPartitionRank1) { TransformerLevel::Level1)); ASSERT_STATUS_OK(graph_transformation_mgr.ApplyTransformers(graph, TransformerLevel::Level1, *logger_)); - auto model_uri2 = "self_attention_megatron_basic_test_partition_rank1.onnx"; + PathString model_uri2 = ORT_TSTR("self_attention_megatron_basic_test_partition_rank1.onnx"); ASSERT_STATUS_OK(Model::Save(*p_model, model_uri2)); { @@ -913,7 +913,7 @@ TEST_F(GraphTransformationTests, MegatronSelfAttentionPartitionRank1) { } TEST_F(GraphTransformationTests, BiasGeluRecomputeTest) { - auto model_uri = MODEL_FOLDER "fusion/bias_gelu_fusion_recompute.onnx"; + PathString model_uri = MODEL_FOLDER "fusion/bias_gelu_fusion_recompute.onnx"; std::shared_ptr p_model; ASSERT_STATUS_OK(Model::Load(model_uri, p_model, nullptr, *logger_)); Graph& graph = p_model->MainGraph(); @@ -1397,7 +1397,7 @@ static void RunPartitionCorrectnessTest(std::string model_path, TransformerLevel::Level1)); ASSERT_STATUS_OK(graph_transformation_mgr.ApplyTransformers(graph, TransformerLevel::Level1, logger)); graphs.push_back(&graph); - auto model_uri2 = ToPathString(model_path) + ORT_TSTR("_partition_rank_") + ToPathString(std::to_string(i)) + ORT_TSTR(".onnx"); + PathString model_uri2 = ToPathString(model_path) + ORT_TSTR("_partition_rank_") + ToPathString(std::to_string(i)) + ORT_TSTR(".onnx"); ASSERT_STATUS_OK(Model::Save(*p_models[i], model_uri2)); } @@ -1405,7 +1405,7 @@ static void RunPartitionCorrectnessTest(std::string model_path, auto& combine_graph = combine_model.MainGraph(); auto ret = horizontal_parallel_test_utils::MergeGraphsOnAllWorkers(graphs, combine_graph); ORT_ENFORCE(ret.IsOK()); - auto model_uri2 = ToPathString(model_path) + ORT_TSTR("_partition_combine.onnx"); + PathString model_uri2 = ToPathString(model_path) + ORT_TSTR("_partition_combine.onnx"); ASSERT_STATUS_OK(Model::Save(combine_model, model_uri2)); float scale = 1.f; @@ -1790,7 +1790,7 @@ TEST_F(GraphTransformationTests, ScaledSumFusionTwoInputs) { #ifdef ENABLE_TRITON TEST_F(GraphTransformationTests, TritonFusion) { - auto model_uri = MODEL_FOLDER "bert_toy_opset14.onnx"; + PathString model_uri = MODEL_FOLDER "bert_toy_opset14.onnx"; std::shared_ptr model; ASSERT_STATUS_OK(Model::Load(model_uri, model, nullptr, *logger_)); Graph& graph = model->MainGraph(); @@ -1805,7 +1805,7 @@ TEST_F(GraphTransformationTests, TritonFusion) { ASSERT_TRUE(op_to_count["LayerNormalization"] == 4); { - auto model_uri = MODEL_FOLDER "bert_toy_opset14.onnx"; + PathString model_uri = MODEL_FOLDER "bert_toy_opset14.onnx"; std::shared_ptr model; ASSERT_STATUS_OK(Model::Load(model_uri, model, nullptr, *logger_)); Graph& graph = model->MainGraph(); @@ -1845,7 +1845,7 @@ TEST_F(GraphTransformationTests, TritonFusion) { // No Dropout. { - auto model_uri = MODEL_FOLDER "bert_toy_opset14.onnx"; + PathString model_uri = MODEL_FOLDER "bert_toy_opset14.onnx"; std::shared_ptr model; ASSERT_STATUS_OK(Model::Load(model_uri, model, nullptr, *logger_)); Graph& graph = model->MainGraph(); @@ -1884,7 +1884,7 @@ TEST_F(GraphTransformationTests, TritonFusion) { // Ignore min nodes. { - auto model_uri = MODEL_FOLDER "bert_toy_opset14.onnx"; + PathString model_uri = MODEL_FOLDER "bert_toy_opset14.onnx"; std::shared_ptr model; ASSERT_STATUS_OK(Model::Load(model_uri, model, nullptr, *logger_)); Graph& graph = model->MainGraph(); @@ -1924,7 +1924,7 @@ TEST_F(GraphTransformationTests, TritonFusion) { // Exclude Softmax using axis attribute. { - auto model_uri = MODEL_FOLDER "bert_toy_opset14.onnx"; + PathString model_uri = MODEL_FOLDER "bert_toy_opset14.onnx"; std::shared_ptr model; ASSERT_STATUS_OK(Model::Load(model_uri, model, nullptr, *logger_)); Graph& graph = model->MainGraph();