From 5745a63f2a68f0c976ffab317f43c4454134fb31 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Thu, 25 May 2023 10:42:02 +0800 Subject: [PATCH] add log for memory stats (#54083) * add log for memory stats * fix string_split in einsum --- paddle/fluid/memory/stats.h | 17 +++++++++++++++-- paddle/phi/kernels/impl/einsum_grad_impl.h | 5 ++--- paddle/phi/kernels/impl/einsum_impl.h | 11 ++++------- paddle/utils/string/string_helper.h | 6 ++---- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/paddle/fluid/memory/stats.h b/paddle/fluid/memory/stats.h index d8cb7b812ad..bd4761f4111 100644 --- a/paddle/fluid/memory/stats.h +++ b/paddle/fluid/memory/stats.h @@ -22,6 +22,7 @@ limitations under the License. */ #include "paddle/fluid/platform/errors.h" #include "paddle/fluid/platform/macros.h" #include "paddle/phi/common/thread_data_registry.h" +#include "paddle/utils/string/string_helper.h" namespace paddle { namespace memory { @@ -74,6 +75,13 @@ class Stat : public StatBase { thread_data_registry.GetMutableCurrentThreadData(); thread_local_stat->current += increment; + VLOG(8) << string::split_string( + phi::enforce::demangle(typeid(*thread_local_stat).name()), + "::") + .back() + << ": Update current_value with " << increment + << ", after update, current value = " << GetCurrentValue(); + if (thread_local_stat->current > thread_local_stat->peak) { thread_local_stat->peak = thread_local_stat->current; int64_t current_value = GetCurrentValue(); @@ -81,8 +89,13 @@ class Stat : public StatBase { while (prev_value < current_value && !peak_value_.compare_exchange_weak(prev_value, current_value)) { } - VLOG(8) << "Update peak_value, after update, peak_value = " - << peak_value_.load() << " , current value = " << current_value; + VLOG(8) << string::split_string( + phi::enforce::demangle(typeid(*thread_local_stat).name()), + "::") + .back() + << ": Update current_value with " << increment + << ", after update, peak_value = " << peak_value_.load() + << " , current value = " << current_value; } } diff --git a/paddle/phi/kernels/impl/einsum_grad_impl.h b/paddle/phi/kernels/impl/einsum_grad_impl.h index 2b11e9eda66..ce33d08c1d8 100644 --- a/paddle/phi/kernels/impl/einsum_grad_impl.h +++ b/paddle/phi/kernels/impl/einsum_grad_impl.h @@ -152,7 +152,7 @@ void EinsumGradKernel(const Context& dev_ctx, if (x.size() == 1) { // Unary auto splits = paddle::string::split_string(equation, "->"); auto left = splits[0]; - right = splits[1].substr(1); + right = splits[1]; auto new_equation = right + "->" + gather_labels_except_reduction(left); auto new_operands = std::vector(); new_operands.push_back(&out_grad); @@ -171,8 +171,7 @@ void EinsumGradKernel(const Context& dev_ctx, auto splits = paddle::string::split_string(equation, "->"); auto left = splits[0]; auto ops = paddle::string::split_string(left, ","); - right = splits[1].substr(1); - + right = splits[1]; auto equation_for_A = ops[1] + "," + right + "->" + gather_labels_except_reduction(ops[0]); auto equation_for_B = diff --git a/paddle/phi/kernels/impl/einsum_impl.h b/paddle/phi/kernels/impl/einsum_impl.h index 92a4f99c6eb..d297e786845 100644 --- a/paddle/phi/kernels/impl/einsum_impl.h +++ b/paddle/phi/kernels/impl/einsum_impl.h @@ -326,19 +326,16 @@ inline static void ParseEinsumEquation( std::vector* output_dims, std::string* right, std::vector* input_strs) { - VLOG(5) << "Start ParseEinsumEquation"; + VLOG(5) << "Start ParseEinsumEquation " << equation; auto results = paddle::string::split_string(equation, "->"); auto left = results[0]; ReplaceEllipsis(left); - *right = results[1].substr(1); + *right = results[1]; ReplaceEllipsis(*right); auto op_labels = paddle::string::split_string(left, ","); - // split_string("i,") -> ["i"], we push back a "". + // split_string("i,") -> ["i", ""], we push back a "". // split_string("->") -> [], we push back a "". - if (op_labels.size() == 0) - op_labels.push_back(""); - else if (left[left.size() - 1] == ',') - op_labels.push_back(""); + if (op_labels.size() == 0) op_labels.push_back(""); std::for_each(op_labels.begin(), op_labels.end(), ReplaceEllipsis); GlobalInfo(op_labels, *right, labeltype, all_labels); InferLabelShape(op_labels, inputs, labelshape, ellipsis_dims, broadcast_dims); diff --git a/paddle/utils/string/string_helper.h b/paddle/utils/string/string_helper.h index 029eb9eb59d..004abfd9da2 100644 --- a/paddle/utils/string/string_helper.h +++ b/paddle/utils/string/string_helper.h @@ -127,12 +127,10 @@ std::vector split_string(const std::string& str, const std::string& delim) { while ((pos = str.find(delim, pre_pos)) != std::string::npos) { tmp_str.assign(str, pre_pos, pos - pre_pos); res_list.push_back(tmp_str); - pre_pos = pos + 1; + pre_pos = pos + delim.size(); } tmp_str.assign(str, pre_pos, str.length() - pre_pos); - if (!tmp_str.empty()) { - res_list.push_back(tmp_str); - } + res_list.push_back(tmp_str); return res_list; } -- GitLab