Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions onnxruntime/core/framework/debug_node_inputs_outputs_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<float>(threshold);

opts.prepend_ep_to_file_name = ParseEnvironmentVariableWithDefault<bool>(env_vars::kPrependEpToFileName, false);

if (ParseEnvironmentVariableWithDefault<bool>(env_vars::kAppendRankToFileName, false)) {
std::string rank = Env::Default().GetEnvironmentVar("OMPI_COMM_WORLD_RANK");
if (rank.empty()) {
Expand Down Expand Up @@ -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);
Comment thread
yuhuchua-qti marked this conversation as resolved.

TensorStatisticsData tensor_statistics;
DumpTensor(dump_options, *tensor, tensor_metadata, tensor_statistics, session_state);
Expand Down Expand Up @@ -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);
Comment thread
yuslepukhin marked this conversation as resolved.

TensorStatisticsData tensor_statistics;
DumpTensor(dump_options, *tensor, tensor_metadata, tensor_statistics, session_state);
Expand Down
5 changes: 5 additions & 0 deletions onnxruntime/core/framework/debug_node_inputs_outputs_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Comment thread
yuslepukhin marked this conversation as resolved.
// the output directory for dumped data files
std::filesystem::path output_dir;
Expand Down
Loading