Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
ca2b27a
Update
guilhermeleobas Jan 8, 2025
452a062
Update
guilhermeleobas Jan 9, 2025
7828074
Update
guilhermeleobas Jan 9, 2025
f102f34
Update
guilhermeleobas Jan 9, 2025
718e9cb
Update
guilhermeleobas Jan 9, 2025
073e1b2
Update
guilhermeleobas Jan 9, 2025
16f54a2
Update
guilhermeleobas Jan 9, 2025
684b493
Update
guilhermeleobas Jan 9, 2025
8982ecd
Update
guilhermeleobas Jan 9, 2025
4f57701
Update
guilhermeleobas Jan 9, 2025
b8ac881
Update
guilhermeleobas Jan 9, 2025
4775444
Update
guilhermeleobas Jan 10, 2025
e1c3712
Update
guilhermeleobas Jan 10, 2025
75a5bfe
Update
guilhermeleobas Jan 10, 2025
1d56c39
Update
guilhermeleobas Jan 10, 2025
213c81c
Update
guilhermeleobas Jan 10, 2025
fd22f12
Update
guilhermeleobas Jan 10, 2025
6d4cad3
Update
guilhermeleobas Jan 10, 2025
d96c17b
Update
guilhermeleobas Jan 13, 2025
4c71295
Update
guilhermeleobas Jan 15, 2025
5eea205
Update
guilhermeleobas Jan 16, 2025
f2d934b
Update
guilhermeleobas Jan 16, 2025
e424a8d
Update
guilhermeleobas Jan 16, 2025
35e7462
Update
guilhermeleobas Jan 16, 2025
3485224
Update
guilhermeleobas Jan 16, 2025
431b233
Update
guilhermeleobas Jan 17, 2025
5aa6eb1
Update
guilhermeleobas Jan 17, 2025
1a04530
Update
guilhermeleobas Jan 17, 2025
6923d62
Update
guilhermeleobas Jan 17, 2025
f9c5add
Update
guilhermeleobas Jan 20, 2025
9a27433
Update
guilhermeleobas Jan 20, 2025
a43b155
Update
guilhermeleobas Jan 20, 2025
6b8438b
Update
guilhermeleobas Jan 21, 2025
bfd6583
Update
guilhermeleobas Jan 21, 2025
42277c3
Update
guilhermeleobas Jan 21, 2025
4830815
Update
guilhermeleobas Jan 22, 2025
d4f4121
Update
guilhermeleobas Jan 22, 2025
20e4d1e
Update
guilhermeleobas Jan 23, 2025
7eb4e80
Update
guilhermeleobas Jan 28, 2025
0b1de01
Update
guilhermeleobas Jan 28, 2025
d1ecd99
Update
guilhermeleobas Jan 28, 2025
00baf31
Update
guilhermeleobas Jan 28, 2025
f43b3d7
Update
guilhermeleobas Jan 29, 2025
c60313f
Update
guilhermeleobas Jan 31, 2025
65a7a9f
Update
guilhermeleobas Jan 31, 2025
a4e7f11
Update
guilhermeleobas Jan 31, 2025
68d3071
Update
guilhermeleobas Jan 31, 2025
e455ba3
Update
guilhermeleobas Jan 31, 2025
8251ef4
Update
guilhermeleobas Feb 3, 2025
69e155a
Update
guilhermeleobas Feb 3, 2025
e9199ec
Update
guilhermeleobas Feb 4, 2025
a4a7d9f
Update
guilhermeleobas Feb 4, 2025
7b4d1a7
Update
guilhermeleobas Feb 5, 2025
bd05940
Update
guilhermeleobas Feb 6, 2025
afe7844
Update
guilhermeleobas Feb 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions test/dynamo/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,38 @@ def fn(t):
self.assertEqual(i, 3)
self.assertEqual(y, [(0, t), (1, t + 1), (2, t + 2)])

@unittest.skipIf(sys.version_info < (3, 12), "Test CLEANUP_THROW")
@unittest.expectedFailure
def test_cleanup_throw(self):
def nested_generator():
try:
yield 1
yield 2
except StopIteration:
return 123 # noqa: B901

def outer_generator():
yield from nested_generator()
yield 3

@torch.compile(backend="eager", fullgraph=True)
def fn(t):
gen = outer_generator()
next(gen) # Start the outer generator and enter the nested generato

i = 0
try:
# Force an exception while the generator is running
i = gen.throw(StopIteration("stop"))
except RuntimeError:
pass
return (i, t.sin())

t = torch.randn(2)
i, y = self._compile_check(fn, args=(t,))
self.assertEqual(i, 3)
self.assertEqual(y, t.sin())

def test_iter(self):
def whoo():
i = 0
Expand Down Expand Up @@ -670,8 +702,6 @@ def fn(t):
y = fn(t)
self.assertEqual(y, t.sin())

@unittest.expectedFailure
@unittest.skipIf(sys.version_info < (3, 11), "Python 3.11+")
def test_close_subgen(self):
z = 0

Expand Down Expand Up @@ -844,8 +874,6 @@ def fn(t):
with self.assertRaises(exc):
fn(t)

@unittest.expectedFailure
@unittest.skipIf(sys.version_info < (3, 11), "Python 3.11+")
def test_close_with_subgen(self):
L = []
z = 0
Expand Down Expand Up @@ -1450,8 +1478,6 @@ def fn(t):

self._compile_check(fn)

@unittest.skipIf(sys.version_info < (3, 12), "Test CLEANUP_THROW")
@unittest.expectedFailure
def test_exception_context_with_yield_from_with_context_cycle(self):
# Check trying to create an exception context cycle:
# https://bugs.python.org/issue40696
Expand Down
9 changes: 9 additions & 0 deletions torch/_dynamo/symbolic_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,15 @@ def RAISE_VARARGS(self, inst):
self._raise_exception_variable(inst)
unimplemented("raise ... from ...")

def CLEANUP_THROW(self, inst):
# https://github.com/python/cpython/pull/96010
tos = self.stack[-1]
assert isinstance(tos, ExceptionVariable)
if tos.exc_type is StopIteration:
unimplemented("CLEANUP_THROW with StopIteration")
else:
self.RERAISE(inst)

def RERAISE(self, inst):
if sys.version_info >= (3, 11):
# RERAISE is currently supported in a narrow case of `raise ... from None`
Expand Down
Loading