Skip to content

Commit 3858e16

Browse files
davidriazatifacebook-github-bot
authored andcommitted
Don't print backtrace for interpreter errors (#20925)
Summary: Eager Python errors don't include a backtrace so script shouldn't either Pull Request resolved: #20925 Pulled By: driazati Differential Revision: D15499952 fbshipit-source-id: 1169f13ba5578cd52948725eda73de8229146bb1
1 parent 371bd04 commit 3858e16

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

test/test_jit.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12983,6 +12983,16 @@ def split_two(tensor):
1298312983
y = torch.randn(3, 6)
1298412984
self.checkScript(split_two, [(x + y)])
1298512985

12986+
def test_conv_error(self):
12987+
@torch.jit.script
12988+
def fn(x, y):
12989+
return F.conv2d(x, y)
12990+
12991+
try:
12992+
fn(torch.ones(2, 2), torch.ones(4, 4))
12993+
except RuntimeError as e:
12994+
self.assertFalse('frame' in str(e))
12995+
1298612996
def test_python_op_name(self):
1298712997
import random
1298812998

torch/csrc/jit/source_range.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ struct CAFFE2_API SourceRange {
4747
const std::exception& e,
4848
const std::string& additional = "") {
4949
std::stringstream msg;
50-
msg << "\n" << e.what() << ":\n";
50+
std::string what;
51+
auto c10_error = dynamic_cast<const c10::Error*>(&e);
52+
if (c10_error) {
53+
what = c10_error->msg_without_backtrace();
54+
} else {
55+
what = e.what();
56+
}
57+
msg << "\n" << what << ":\n";
5158
if (!additional.empty()) {
5259
msg << additional << ":\n";
5360
}

0 commit comments

Comments
 (0)