New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get people to stop improperly using AT_ASSERT #20287
Comments
cc @gchanan |
Proposal was modified to use |
lgtm. |
I fully agree we should fix this and choose names that better describe what these do. Note that it's not always obvious if |
Matters will always be murky for the C++ API, because we publish the very same API we use internally and so you can't distinguish between user and internal code. However, one way to solve this problem is to distinguish between the internal API, and the public API (as @mike7ant has asked us to do). Then you can put proper checks in the public API. |
it would be nice if these macros all returned an ASSERT_AT(vec.size()) << "Vector size should never be equal to zero context ( node = " << *node << " ) some more useful information " ; EDIT: grammar |
@Krovatkin The
I plan to eliminate this inconsistency. (I'll have to construct two strings on error case because of variadic macro comma pasting shenanigans, but that's a small price to pay). |
For informational purposes: the way people are trained to do in fbcode is glog-style: I don't think we should have a crashing But having a macro vs. throw rule might be easier than remembering which of the macros you're supposed to use (or having an explicit-but-long name like |
@suo Are you OK with the |
This seems like a great improvement. It would be nice if the error messages knew what do with source range information, so, for instance, |
There's JIT_SCRIPT_ASSERT in error_report.h, but no one ever uses that |
I am just going to clean up SourceRange so it has an operator<<, that way it will work trivially with AT_CHECK and AT_ASSERT |
This patch makes SourceRange printable, so |
Summary: Pull Request resolved: #20321 First part of #20287 - Rename `AT_ASSERT` to `TORCH_INTERNAL_ASSERT` - Make `TORCH_INTERNAL_ASSERT` work with variadic inputs - Deprecated `AT_ASSERT` and `AT_ASSERTM` - Rename `AT_CHECK` to `TORCH_CHECK` - Make `TORCH_CHECK` give a better error message when no arguments are provided - Deprecate `AT_ERROR` in favor of `TORCH_CHECK(false, ...)` - Deprecate `AT_INDEX_ERROR` in favor of `TORCH_CHECK_INDEX(false, ...)` - Rename `AT_WARN` to `TORCH_WARN` No use sites are changed; I'll work on that in follow up patches (or disable the deprecation, if necessary.) Differential Revision: D15278439 fbshipit-source-id: 7e0ed489d4e89e5f56b8ad7eafa72cb9a06065ee
We fixed this! |
Just a note. All the docs for cpp extensions still use Also, is AT_CHECK also deprecated?
So all custom cpp extensions will have are deprecated now. |
@dashesy Thank you for the note. See pytorch/tutorials#711 |
nice advice, and thanks for you explanation of the utilities of these two states. I'm exactly struggling understanding the difference. |
Somehow, we have ended up in a situation where a lot of people in the PyTorch codebase are using
AT_ASSERT
when they should be usingAT_CHECK
(just do a grep forAT_ASSERT
inaten/src/ATen/native
, I audited the first five files and every occurrence ofAT_ASSERT
was wrong). Just to review the intended semantics:AT_ASSERT
means "internal error, someone on the PyTorch dev team fucked up." If anAT_ASSERT
triggers, that's a bug, and you should report a bug to PyTorch. In fact, the error message onAT_ASSERT
says exactly this.AT_CHECK
means "user error, report a message to the user." Users might triggerAT_CHECK
and that's fine, it just means they misused the API. Give them a nice, human-friendly message, and let them try something else in their Jupyter session, whatever,Use of
AT_ASSERT
when you meanAT_CHECK
is bad for a few reasons:AT_ASSERT
fails, we get spurious bug reports where users report a bug to PyTorch, because the error message told them to. Examples: C++ API, IValue toTensor() didn't work #13503, Tensor type mismatch, caller expects elements to be int, while tensor contains float #13052, isTensorList() ASSERT FAILED #17911Let's do some renaming to make the distinction clearer.
We propose the final state be just two macros (I'm lying; there's also an IndexError macro; I intend to preserve it but most people won't use it):
Translation guide:
AT_ASSERT(cond)
==>AT_INTERNAL_ASSERT(cond)
AT_ASSERTM(cond, msg)
==>AT_INTERNAL_ASSERT(cond, msg)
AT_CHECK(cond, msg)
==>AT_CHECK(cond, msg)
AT_ERROR(msg)
==>AT_CHECK(false, msg)
I'm OK with bikeshedding names.
For BC-reasons, we will need to retain the old macros with deprecation warnings. We'll use a similar strategy to
AT_DISPATCH_
here. The transition won't be done all in one go; at the same time we'll auditAT_ASSERT
sites to see if they really are internal errors or not.The text was updated successfully, but these errors were encountered: