Skip to content

Commit

Permalink
[Core] Update Exception.h (pytorch#64553)
Browse files Browse the repository at this point in the history
Summary:
Just a small thing that's a little annoying; currently `TORCH_INTERNAL_ASSERT` generates messages like this:

```
unknown file: Failure
C++ exception with description "g_outputs.count(out) > 0INTERNAL ASSERT FAILED at "../torch/csrc/jit/passes/memory_planning.cpp":481, please report a bug to PyTorch. 22
Exception raised from getManagedLiveRangesFromMemEvents at ../torch/csrc/jit/passes/memory_planning.cpp:481 (most recent call first):
```

i.e. with no space between the `#cond` checked and `INTERNAL ASSERT FAILED...`

Re the `STRIP_ERROR_MESSAGES` branch: I'm not sure whether the differences are intentional or accidental? I.e. we don't pass `__FILE__` and `__VA_ARGS__` to `torchCheckFail` whereas we do to `torchInternalAssertFail`. I can reconcile the two in this PR if it's simply an omission.

Pull Request resolved: pytorch#64553

Reviewed By: albanD

Differential Revision: D34482923

Pulled By: swolchok

fbshipit-source-id: 40b648dadb5ceea5d9038efd60771d98aa7f0b46
(cherry picked from commit 8d6f116)
  • Loading branch information
makslevental authored and pytorchmergebot committed Feb 28, 2022
1 parent a5dcc0c commit 20a037d
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions c10/util/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,30 +314,30 @@ C10_API std::string GetExceptionString(const std::exception& e);
// (unlike assert()).
//
#ifdef STRIP_ERROR_MESSAGES
#define TORCH_INTERNAL_ASSERT(cond, ...) \
if (C10_UNLIKELY_OR_CONST(!(cond))) { \
::c10::detail::torchCheckFail( \
__func__, \
__FILE__, \
static_cast<uint32_t>(__LINE__), \
#cond "INTERNAL ASSERT FAILED at" C10_STRINGIZE(__FILE__)); \
#define TORCH_INTERNAL_ASSERT(cond, ...) \
if (C10_UNLIKELY_OR_CONST(!(cond))) { \
::c10::detail::torchCheckFail( \
__func__, \
__FILE__, \
static_cast<uint32_t>(__LINE__), \
#cond " INTERNAL ASSERT FAILED at " C10_STRINGIZE(__FILE__)); \
}
#else
// It would be nice if we could build a combined string literal out of
// the TORCH_INTERNAL_ASSERT prefix and a user-provided string literal
// as the first argument, but there doesn't seem to be any good way to
// do that while still supporting having a first argument that isn't a
// string literal.
#define TORCH_INTERNAL_ASSERT(cond, ...) \
if (C10_UNLIKELY_OR_CONST(!(cond))) { \
::c10::detail::torchInternalAssertFail( \
__func__, \
__FILE__, \
static_cast<uint32_t>(__LINE__), \
#cond \
"INTERNAL ASSERT FAILED at " C10_STRINGIZE(__FILE__) ":" C10_STRINGIZE( \
__LINE__) ", please report a bug to PyTorch. ", \
c10::str(__VA_ARGS__)); \
#define TORCH_INTERNAL_ASSERT(cond, ...) \
if (C10_UNLIKELY_OR_CONST(!(cond))) { \
::c10::detail::torchInternalAssertFail( \
__func__, \
__FILE__, \
static_cast<uint32_t>(__LINE__), \
#cond \
" INTERNAL ASSERT FAILED at " C10_STRINGIZE(__FILE__) ":" C10_STRINGIZE( \
__LINE__) ", please report a bug to PyTorch. ", \
c10::str(__VA_ARGS__)); \
}
#endif

Expand Down

0 comments on commit 20a037d

Please sign in to comment.