Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lint rule to recommend TORCH_CHECK(false) over throw std::runtime_error #59682

Open
rohan-varma opened this issue Jun 9, 2021 · 1 comment
Labels
better-engineering Relatively self-contained tasks for better engineering contributors triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@rohan-varma
Copy link
Member

馃殌 Feature

When throwing exceptions in the C++ codebase, we should prefer to use TORCH_CHECK(false, "foo") over throw std::runtime_error("foo") since the former can provide a detailed C++ stacktrace when TORCH_SHOW_CPP_STACKTRACES=1 is enabled, but the latter will not as it does not go through c10's exception handling logic here: https://github.com/pytorch/pytorch/blob/master/torch/csrc/Exceptions.h#L51. Thus we could have a lint rule that enforces this at code review time.

Motivation

Using TORCH_CHECK with TORCH_SHOW_CPP_STACKTRACES=1 helps investigate crashes with detailed logs, but this is quite easy to overlook in code review and it is natural for developers to instead use throw std::runtime_error especially if they are newer to the PyTorch codebase. Having a lint rule/recommendation would be helpful for encouraging this practice in the codebase.

@rohan-varma
Copy link
Member Author

cc @driazati

@driazati driazati self-assigned this Jun 9, 2021
@driazati driazati added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module better-engineering Relatively self-contained tasks for better engineering contributors labels Jun 9, 2021
@driazati driazati removed their assignment Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
better-engineering Relatively self-contained tasks for better engineering contributors triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

2 participants