1#ifndef C10_UTIL_LOGGING_H_
2#define C10_UTIL_LOGGING_H_
18#ifndef CAFFE2_LOG_THRESHOLD
21#define CAFFE2_LOG_THRESHOLD INT_MIN
38#define C10_LOG_EVERY_MS(severity, ms) LOG_EVERY_MS(severity, ms)
40#define C10_LOG_EVERY_MS(severity, ms) LOG(severity)
45#define C10_LOG_FIRST_N(severity, n) LOG_FIRST_N(severity, n)
47#define C10_LOG_FIRST_N(severity, n) LOG(severity)
52#define C10_LOG_EVERY_N(severity, n) LOG_EVERY_N(severity, n)
54#define C10_LOG_EVERY_N(severity, n) LOG(severity)
69 const std::string& msg,
70 const void* caller =
nullptr);
76 const std::string& msg,
77 const void* caller =
nullptr);
101#define CAFFE_ENFORCE(condition, ...) \
103 if (C10_UNLIKELY(!(condition))) { \
104 ::c10::ThrowEnforceNotMet( \
105 __FILE__, __LINE__, #condition, ::c10::str(__VA_ARGS__)); \
109#define CAFFE_ENFORCE_FINITE(condition, ...) \
111 if (C10_UNLIKELY(!(condition))) { \
112 ::c10::ThrowEnforceFiniteNotMet( \
113 __FILE__, __LINE__, #condition, ::c10::str(__VA_ARGS__)); \
117#define CAFFE_ENFORCE_WITH_CALLER(condition, ...) \
119 if (C10_UNLIKELY(!(condition))) { \
120 ::c10::ThrowEnforceNotMet( \
121 __FILE__, __LINE__, #condition, ::c10::str(__VA_ARGS__), this); \
125#define CAFFE_THROW(...) \
126 ::c10::ThrowEnforceNotMet(__FILE__, __LINE__, "", ::c10::str(__VA_ARGS__))
155namespace enforce_detail {
173 template <
class...
Args>
179 "CAFFE_ENFORCE_THAT has to be used with one of special check functions "
180 "like `Equals`. Use CAFFE_ENFORCE for simple boolean checks.");
186 return msg_ !=
nullptr;
203#define BINARY_COMP_HELPER(name, op) \
204 template <typename T1, typename T2> \
205 inline EnforceFailMessage name(const T1& x, const T2& y) { \
207 return EnforceOK(); \
209 return c10::str(x, " vs ", y); \
217#undef BINARY_COMP_HELPER
219#define CAFFE_ENFORCE_THAT_IMPL(condition, expr, ...) \
221 using namespace ::c10::enforce_detail; \
222 const EnforceFailMessage& CAFFE_ENFORCE_THAT_IMPL_r_ = (condition); \
223 if (C10_UNLIKELY(CAFFE_ENFORCE_THAT_IMPL_r_.bad())) { \
224 ::c10::ThrowEnforceNotMet( \
228 CAFFE_ENFORCE_THAT_IMPL_r_.get_message_and_free( \
229 ::c10::str(__VA_ARGS__))); \
233#define CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER(condition, expr, ...) \
235 using namespace ::c10::enforce_detail; \
236 const EnforceFailMessage& CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER_r_ = \
238 if (C10_UNLIKELY(CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER_r_.bad())) { \
239 ::c10::ThrowEnforceNotMet( \
243 CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER_r_.get_message_and_free( \
244 ::c10::str(__VA_ARGS__)), \
250#define CAFFE_ENFORCE_THAT(condition, ...) \
251 CAFFE_ENFORCE_THAT_IMPL((condition), #condition, __VA_ARGS__)
253#define CAFFE_ENFORCE_EQ(x, y, ...) \
254 CAFFE_ENFORCE_THAT_IMPL(Equals((x), (y)), #x " == " #y, __VA_ARGS__)
255#define CAFFE_ENFORCE_NE(x, y, ...) \
256 CAFFE_ENFORCE_THAT_IMPL(NotEquals((x), (y)), #x " != " #y, __VA_ARGS__)
257#define CAFFE_ENFORCE_LE(x, y, ...) \
258 CAFFE_ENFORCE_THAT_IMPL(LessEquals((x), (y)), #x " <= " #y, __VA_ARGS__)
259#define CAFFE_ENFORCE_LT(x, y, ...) \
260 CAFFE_ENFORCE_THAT_IMPL(Less((x), (y)), #x " < " #y, __VA_ARGS__)
261#define CAFFE_ENFORCE_GE(x, y, ...) \
262 CAFFE_ENFORCE_THAT_IMPL(GreaterEquals((x), (y)), #x " >= " #y, __VA_ARGS__)
263#define CAFFE_ENFORCE_GT(x, y, ...) \
264 CAFFE_ENFORCE_THAT_IMPL(Greater((x), (y)), #x " > " #y, __VA_ARGS__)
265#define CAFFE_ENFORCE_EQ_WITH_CALLER(x, y, ...) \
266 CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER( \
267 Equals((x), (y)), #x " == " #y, __VA_ARGS__)
268#define CAFFE_ENFORCE_NE_WITH_CALLER(x, y, ...) \
269 CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER( \
270 NotEquals((x), (y)), #x " != " #y, __VA_ARGS__)
271#define CAFFE_ENFORCE_LE_WITH_CALLER(x, y, ...) \
272 CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER( \
273 LessEquals((x), (y)), #x " <= " #y, __VA_ARGS__)
274#define CAFFE_ENFORCE_LT_WITH_CALLER(x, y, ...) \
275 CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER(Less((x), (y)), #x " < " #y, __VA_ARGS__)
276#define CAFFE_ENFORCE_GE_WITH_CALLER(x, y, ...) \
277 CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER( \
278 GreaterEquals((x), (y)), #x " >= " #y, __VA_ARGS__)
279#define CAFFE_ENFORCE_GT_WITH_CALLER(x, y, ...) \
280 CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER( \
281 Greater((x), (y)), #x " > " #y, __VA_ARGS__)
295#define C10_LOG_API_USAGE_ONCE(...) \
296 C10_UNUSED static bool C10_ANONYMOUS_VARIABLE(logFlag) = \
297 ::c10::detail::LogAPIUsageFakeReturn(__VA_ARGS__);
C10_DECLARE_bool(caffe2_use_fatal_for_enforce)
#define BINARY_COMP_HELPER(name, op)
C10_DECLARE_int(caffe2_log_level)
Args({2<< 5}) -> Args({2<< 8}) ->Args({2<< 12}) ->Args({2<< 14})
The primary ATen error class.
std::string get_message_and_free(const std::string &extra) const
EnforceFailMessage(EnforceFailMessage &&)=default
EnforceFailMessage & operator=(const EnforceFailMessage &)=delete
EnforceFailMessage(Args...)
constexpr EnforceFailMessage(EnforceOK)
EnforceFailMessage & operator=(EnforceFailMessage &&)=delete
EnforceFailMessage(const EnforceFailMessage &)=delete
bool LogAPIUsageFakeReturn(const std::string &event)
EnforceFailMessage GreaterEquals(const T1 &x, const T2 &y)
EnforceFailMessage LessEquals(const T1 &x, const T2 &y)
EnforceFailMessage Greater(const T1 &x, const T2 &y)
EnforceFailMessage NotEquals(const T1 &x, const T2 &y)
EnforceFailMessage Equals(const T1 &x, const T2 &y)
EnforceFailMessage Less(const T1 &x, const T2 &y)
constexpr remove_reference_t< T > && move(T &&t) noexcept
This file contains functionality to take a C++ function and infer its c10::FunctionSchema.
void ShowLogInfoToStderr()
A utility to allow one to show log info to stderr after the program starts.
void SetStackTraceFetcher(std::function< string(void)> fetcher)
bool InitCaffeLogging(int *argc, char **argv)
void SetPyTorchDDPUsageLogger(std::function< void(const c10::DDPLoggingData &)> logger)
void LogAPIUsage(const std::string &event)
void SetAPIUsageLogger(std::function< void(const std::string &)> logger)
void LogPyTorchDDPUsage(const c10::DDPLoggingData &ddpData)
constexpr bool IsUsingGoogleLogging()
void ThrowEnforceNotMet(const char *file, const int line, const char *condition, const std::string &msg, const void *caller)
void UpdateLoggingLevelsFromFlags()
void ThrowEnforceFiniteNotMet(const char *file, const int line, const char *condition, const std::string &msg, const void *caller)
parameter efficient embedding termed TT which can be plugged in into any model and trained end to end The benefits of our compressed TT layer are twofold instead of storing huge embedding it stores a sequence of much smaller dimensional and dimensional necessary for reconstructing the required which allows compressing the model significantly at the cost of a negligible performance drop the overall number of parameters can be relatively which allows to use larger batches or train efficiently in a case of limited resources DOC vector< int >
$ where the softplus function
Module caffe2.python.context.
bool gradient_as_bucket_view
bool find_unused_parameters
std::vector< int > device_ids