Skip to content

Commit

Permalink
[EASY] Rewrite test_anomaly_aot_autograd to more reliably trigger err…
Browse files Browse the repository at this point in the history
…or (pytorch#114122)

Signed-off-by: Edward Z. Yang <ezyang@meta.com>

Pull Request resolved: pytorch#114122
Approved by: https://github.com/albanD
  • Loading branch information
ezyang authored and pytorchmergebot committed Nov 20, 2023
1 parent 95eab50 commit 59bc98e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/dynamo/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6366,11 +6366,14 @@ def my_dyn_fn(x):
torch._dynamo.optimize("eager")(my_dyn_fn)(y)

def test_anomaly_aot_autograd(self):
def fail():
raise AssertionError("fail")

@allow_in_graph
def h(a):
r = a.sum()
# Trigger an exception in backwards
r.register_hook(lambda x: x + x.item())
r.register_hook(lambda x: fail())
return r

@torch.compile(backend="aot_eager")
Expand All @@ -6382,8 +6385,8 @@ def f(a):
):
f(torch.randn(2, 2, requires_grad=True))

self.assertEqual(len(w), 1)
self.assertIn("forward call that caused the error", str(w[0].message))
# Suppress unrelated pkg_resources warnings
self.assertIn("forward call that caused the error", str(w[-1].message))

def test_py_guards_mark_dynamic(self):
def my_dyn_fn(a):
Expand Down

0 comments on commit 59bc98e

Please sign in to comment.