Skip to content

Commit 749738e

Browse files
committed
[dynamo] fix error_on_graph_break bug where non-empty checkpoint results in unwanted graph break resumption
ghstack-source-id: 9676e4f Pull Request resolved: #166586
1 parent 9ec0dd7 commit 749738e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

test/dynamo/test_decorators.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,23 @@ def f():
20642064

20652065
self.assertEqual(f(), 1)
20662066

2067+
def test_error_on_graph_break_nonempty_checkpoint(self):
2068+
cnts = torch._dynamo.testing.CompileCounter()
2069+
2070+
@torch.compile(backend=cnts)
2071+
def fn(x):
2072+
x = x + 1
2073+
x = x + 1
2074+
x = x + 1
2075+
with torch._dynamo.error_on_graph_break(True):
2076+
torch._dynamo.graph_break()
2077+
return x + 1
2078+
2079+
with self.assertRaises(Unsupported):
2080+
fn(torch.ones(3))
2081+
2082+
self.assertEqual(cnts.frame_count, 0)
2083+
20672084
def test_nested_compile_fullgraph(self):
20682085
# Test that fullgraph=True cannot be toggled back by fullgraph=False
20692086
inp = torch.ones(3)

torch/_dynamo/symbolic_convert.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,19 @@ def step(self) -> bool:
13761376
except (ReturnValueOp, YieldValueOp):
13771377
return False
13781378
except (Unsupported, StepUnsupported) as e:
1379+
# More restrictive condition than should_compile_partial_graph:
1380+
# if this condition is true, then we SHOULD NOT attempt to find
1381+
# a previous checkpoint to resume from and try to resume - we should
1382+
# immediately error out.
1383+
# The condition is more restrictive because, it may be possible to resume significantly earlier
1384+
# in the code (the most recent speculation point). This happens, for example, in the case
1385+
# of a graph break in a try block.
1386+
if (
1387+
self.one_graph
1388+
or self.error_on_graph_break
1389+
or self.is_tracing_resume_prologue
1390+
):
1391+
raise
13791392
if self.current_speculation is None:
13801393
log.debug("empty checkpoint")
13811394
if isinstance(e, StepUnsupported):

0 commit comments

Comments
 (0)