Skip to content

Commit 28efc17

Browse files
sanrisepytorchmergebot
authored andcommitted
[pytorch/profiler] Honor escape quotes arg in a profiler metadata log formatter (pytorch#141527) (pytorch#141626)
Summary: We were ignoring the with_escaped_quotes param in format_list inline function iin utils.cpp in the case where we had to truncate a list of more than kTruncatelength items. In that case we would truncate a list into a string but always return it with an escaped quotes wrapping it. this will cause issues if this string is meant to be added to other lists which will also go through formatting. Leading to cases like `"["[a, b, c, ...]"]"`. now the above will be well formatted as `"[[a, b, c, ...]]"` as the escape quote requests will be honored. Differential Revision: D66521676 Pull Request resolved: pytorch#141626 Approved by: https://github.com/sraikund16
1 parent 78e53a9 commit 28efc17

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

torch/csrc/autograd/profiler_kineto.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ void onFunctionExit(
506506
auto& extra_meta = *(kineto_ctx_ptr->event_->extra_nccl_meta_);
507507
// Record only the outputs in this exit callback of the record function
508508
torch::profiler::impl::SaveNcclMetaConfig ncclMetaConfig{
509-
false, false, false, true};
509+
true, false, false, true};
510510
auto additonal_nccl_meta =
511511
torch::profiler::impl::saveNcclMeta(fn, ncclMetaConfig);
512512
extra_meta.insert(additonal_nccl_meta.begin(), additonal_nccl_meta.end());

torch/csrc/profiler/util.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,17 @@ static inline std::string format_list(
382382
bool truncate,
383383
bool with_escaped_quotes = true) {
384384
if (truncate && list.size() > kTruncatLength) {
385-
return fmt::format(
386-
"\"[{}, ...]\"",
387-
fmt::join(list.begin(), list.begin() + kTruncatLength, ", "));
385+
if (with_escaped_quotes == true) {
386+
auto x = fmt::format(
387+
"\"[{}, ...]\"",
388+
fmt::join(list.begin(), list.begin() + kTruncatLength, ", "));
389+
return x;
390+
} else {
391+
auto x = fmt::format(
392+
"[{}, ...]",
393+
fmt::join(list.begin(), list.begin() + kTruncatLength, ", "));
394+
return x;
395+
}
388396
}
389397
if (with_escaped_quotes == true) {
390398
auto x = fmt::format("\"[{}]\"", fmt::join(list.begin(), list.end(), ", "));
@@ -949,5 +957,4 @@ bool checkFunctionInputsForLogging(const at::RecordFunction& fn) {
949957
}
950958
return true;
951959
}
952-
953960
} // namespace torch::profiler::impl

0 commit comments

Comments
 (0)