diff --git a/onnxruntime/core/framework/debug_node_inputs_outputs_utils.cc b/onnxruntime/core/framework/debug_node_inputs_outputs_utils.cc index 321884e887aee..38dd8de01147c 100644 --- a/onnxruntime/core/framework/debug_node_inputs_outputs_utils.cc +++ b/onnxruntime/core/framework/debug_node_inputs_outputs_utils.cc @@ -99,9 +99,23 @@ struct TensorMetadata { std::string producer; std::string consumer; std::string device_type; + std::string ep_type; size_t step; }; +std::string GetCleanedEpType(const Node& node) { + std::string ep_type = node.GetExecutionProviderType(); + + // Remove "ExecutionProvider" suffix from ep type to reduce length. + const std::string suffix_to_remove = "ExecutionProvider"; + size_t pos = ep_type.find(suffix_to_remove); + if (pos != std::string::npos) { + ep_type.erase(pos, suffix_to_remove.length()); + } + + return ep_type; +} + bool FilterNode(const NodeDumpOptions& dump_options, const Node& node) { auto match_pattern = [](const std::string& value, const std::string& delimited_patterns) { @@ -139,14 +153,18 @@ void DumpTensorToStdOut(const Tensor& tensor, const NodeDumpOptions& dump_option } } -PathString MakeTensorFileName(const std::string& tensor_name, const NodeDumpOptions& dump_options) { +PathString MakeTensorFileName(const TensorMetadata& tensor_metadata, const NodeDumpOptions& dump_options) { auto make_valid_name = [](std::string name) { std::replace_if( name.begin(), name.end(), [](char c) { return !std::isalnum(c); }, '_'); return name; }; - return path_utils::MakePathString(make_valid_name(tensor_name), dump_options.file_suffix, ".tensorproto"); + if (dump_options.prepend_ep_to_file_name) { + return path_utils::MakePathString(make_valid_name(tensor_metadata.ep_type + "_" + tensor_metadata.name), dump_options.file_suffix, ".tensorproto"); + } else { + return path_utils::MakePathString(make_valid_name(tensor_metadata.name), dump_options.file_suffix, ".tensorproto"); + } } void DumpTensorToFile(const Tensor& tensor, const std::string& tensor_name, const std::filesystem::path& file_path) { @@ -375,7 +393,7 @@ void DumpCpuTensor( break; } case NodeDumpOptions::DataDestination::TensorProtoFiles: { - const std::filesystem::path tensor_file = dump_options.output_dir / MakeTensorFileName(tensor_metadata.name, dump_options); + const std::filesystem::path tensor_file = dump_options.output_dir / MakeTensorFileName(tensor_metadata, dump_options); DumpTensorToFile(tensor, tensor_metadata.name, tensor_file); break; } @@ -485,6 +503,8 @@ const NodeDumpOptions& NodeDumpOptionsFromEnvironmentVariables() { debug_node_inputs_outputs_env_vars::kHalfOverflowThreshold, " shall be a positive integer <= ", kMaxHalfThreshold); opts.half_overflow_threshold = static_cast(threshold); + opts.prepend_ep_to_file_name = ParseEnvironmentVariableWithDefault(env_vars::kPrependEpToFileName, false); + if (ParseEnvironmentVariableWithDefault(env_vars::kAppendRankToFileName, false)) { std::string rank = Env::Default().GetEnvironmentVar("OMPI_COMM_WORLD_RANK"); if (rank.empty()) { @@ -582,6 +602,7 @@ void DumpNodeInputs( tensor_metadata.name = input_defs[i]->Name(); tensor_metadata.step = dump_context.iteration; tensor_metadata.consumer = node.Name() + ":" + std::to_string(i); + tensor_metadata.ep_type = GetCleanedEpType(node); TensorStatisticsData tensor_statistics; DumpTensor(dump_options, *tensor, tensor_metadata, tensor_statistics, session_state); @@ -678,6 +699,7 @@ void DumpNodeOutputs( tensor_metadata.name = output_defs[i]->Name(); tensor_metadata.step = dump_context.iteration; tensor_metadata.producer = node.Name() + ":" + std::to_string(i); + tensor_metadata.ep_type = GetCleanedEpType(node); TensorStatisticsData tensor_statistics; DumpTensor(dump_options, *tensor, tensor_metadata, tensor_statistics, session_state); diff --git a/onnxruntime/core/framework/debug_node_inputs_outputs_utils.h b/onnxruntime/core/framework/debug_node_inputs_outputs_utils.h index 2ea7d59ad620e..48915309e346e 100644 --- a/onnxruntime/core/framework/debug_node_inputs_outputs_utils.h +++ b/onnxruntime/core/framework/debug_node_inputs_outputs_utils.h @@ -54,6 +54,8 @@ constexpr const char* kOpTypeFilter = "ORT_DEBUG_NODE_IO_OP_TYPE_FILTER"; constexpr const char* kDumpDataDestination = "ORT_DEBUG_NODE_IO_DUMP_DATA_DESTINATION"; // set to non-zero to append OpenMPI world rank to filename constexpr const char* kAppendRankToFileName = "ORT_DEBUG_NODE_IO_APPEND_RANK_TO_FILE_NAME"; +// set to non-zero to prepend ep type to filename +constexpr const char* kPrependEpToFileName = "ORT_DEBUG_NODE_IO_PREPEND_EP_TO_FILE_NAME"; // specify the output directory for any data files produced constexpr const char* kOutputDir = "ORT_DEBUG_NODE_IO_OUTPUT_DIR"; // specify the file prefix for sqlite3 db (process id will be appended) @@ -117,6 +119,9 @@ struct NodeDumpOptions { SqliteDb } data_destination{DataDestination::StdOut}; + // Whether to prepend ep type to output file name. + bool prepend_ep_to_file_name{false}; + std::string file_suffix; // the output directory for dumped data files std::filesystem::path output_dir;