From: Jerry Zhang Date: Wed, 3 Apr 2019 03:54:28 +0000 (-0700) Subject: Change ReinitializeTensor to use C10_LOG_FIRST_N (#18531) X-Git-Tag: accepted/tizen/6.5/unified/20211028.231830~463 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=40a54bf2f1b76f844b28c2fc084e0f58d6ebbc90;p=platform%2Fupstream%2Fpytorch.git Change ReinitializeTensor to use C10_LOG_FIRST_N (#18531) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/18531 Currently we use C10_LOG_EVERY_MS to log the data type change, but it pollutes the log of some service, we would like to change it to C10_LOG_FIRST_N to prevent that. Reviewed By: dzhulgakov Differential Revision: D14647704 fbshipit-source-id: b84e4002bd4aa94d616133cd1049c3d4ab05386e --- diff --git a/c10/util/Logging.h b/c10/util/Logging.h index 2d39d21..5833f35 100644 --- a/c10/util/Logging.h +++ b/c10/util/Logging.h @@ -40,6 +40,13 @@ C10_DECLARE_bool(caffe2_use_fatal_for_enforce); #define C10_LOG_EVERY_MS(severity, ms) LOG(severity) #endif +// Same for LOG_FIRST_N +#ifdef LOG_FIRST_N +#define C10_LOG_FIRST_N(severity, n) LOG_FIRST_N(severity, n) +#else +#define C10_LOG_FIRST_N(severity, n) LOG(severity) +#endif + namespace c10 { using std::string; diff --git a/caffe2/core/tensor.cc b/caffe2/core/tensor.cc index e4278b6..182b156 100644 --- a/caffe2/core/tensor.cc +++ b/caffe2/core/tensor.cc @@ -156,7 +156,7 @@ void ReinitializeTensor( if (tensor->dtype() == options.dtype()) { tensor->raw_mutable_data(); } else { - C10_LOG_EVERY_MS(WARNING, 1000) + C10_LOG_FIRST_N(WARNING, 1) << "Changing the data type of Tensor is discouraged." << " Attempt to change data type from: " << tensor->dtype() << " to: " << options.dtype();