67
67
from torch .utils ._ordered_set import OrderedSet
68
68
from torch .utils ._python_dispatch import is_traceable_wrapper_subclass
69
69
70
- from . import config , exc , logging as torchdynamo_logging , variables
70
+ from . import config , exc , graph_break_hints , logging as torchdynamo_logging , variables
71
71
from .backends .registry import CompiledFn , CompilerFn
72
72
from .bytecode_transformation import (
73
73
create_call_function ,
@@ -1253,6 +1253,18 @@ def compile_subgraph(
1253
1253
1254
1254
log .debug ("COMPILING GRAPH due to %s" , reason )
1255
1255
1256
+ if not all (block .can_restore () for block in tx .block_stack ):
1257
+ unimplemented_v2 (
1258
+ gb_type = "Attempt to compile graph with unrecoverable block in the block stack" ,
1259
+ context = "" ,
1260
+ explanation = "Dynamo does not support graph breaking on context managers in "
1261
+ "nested function calls. For Python <= 3.10, this graph break may have instead been "
1262
+ "caused by attempting to graph break in a try block." ,
1263
+ hints = [
1264
+ * graph_break_hints .CAUSED_BY_EARLIER_GRAPH_BREAK ,
1265
+ ],
1266
+ )
1267
+
1256
1268
# prefix instructions (Python 3.11+)
1257
1269
prefix_insts : list [Instruction ] = []
1258
1270
if sys .version_info >= (3 , 11 ):
@@ -1295,8 +1307,6 @@ def compile_subgraph(
1295
1307
cur_tx : Optional [InstructionTranslatorBase ] = tx
1296
1308
while True :
1297
1309
assert cur_tx is not None
1298
- # this should have been checked by the caller
1299
- assert all (block .can_restore () for block in cur_tx .block_stack )
1300
1310
stack_values , restore_vars , meta = self ._get_stack_values_to_restore (
1301
1311
cur_tx , stack_pops
1302
1312
)
0 commit comments