Skip to content

Commit 790d459

Browse files
williamwen42pytorchmergebot
authored andcommitted
[dynamo] add error message for unsupported LOAD_BUILD_CLASS (pytorch#150323)
Improved error message for pytorch#128942 Pull Request resolved: pytorch#150323 Approved by: https://github.com/jansel, https://github.com/zou3519
1 parent ce52674 commit 790d459

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

test/dynamo/test_error_messages.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import torch._dynamo.test_case
1212
import torch.utils._pytree as python_pytree
1313
from torch._dynamo.exc import Unsupported
14+
from torch._dynamo.testing import skipIfNotPy312
1415
from torch._dynamo.utils import counters
1516
from torch.testing._internal.common_utils import (
1617
IS_FBCODE,
@@ -646,18 +647,42 @@ def fn():
646647
""",
647648
)
648649

649-
def test_unsupported_bytecode(self):
650+
def test_load_build_class(self):
650651
def fn():
651652
class Foo:
652653
pass
653654

654655
return Foo
655656

657+
self.assertExpectedInlineMunged(
658+
Unsupported,
659+
lambda: torch.compile(fn, backend="eager", fullgraph=True)(),
660+
"""\
661+
LOAD_BUILD_CLASS bytecode not supported
662+
Explanation: Dynamo does not support tracing classes that are defined in the compiled region.
663+
Hint: Move the class definition out of the compiled region.
664+
Hint: It may be possible to write Dynamo tracing rules for this code. Please report an issue to PyTorch if you encounter this graph break often and it is causing performance issues.
665+
666+
Developer debug context:
667+
668+
669+
from user code:
670+
File "test_error_messages.py", line N, in fn
671+
class Foo:""",
672+
)
673+
674+
@skipIfNotPy312
675+
def test_unsupported_bytecode(self):
676+
async def fn():
677+
async for i in range(3):
678+
print(i)
679+
return 1
680+
656681
def post_munge(s):
657682
s = re.sub(r"0x[0-9A-Fa-f]+", "0xmem_addr", s)
658683
s = re.sub(
659-
r"Instruction\(.*opname='LOAD_BUILD_CLASS'.*\)\n",
660-
"Instruction(LOAD_BUILD_CLASS)",
684+
r"Instruction\(.*opname='GET_AITER'.*\)\n",
685+
"Instruction(GET_AITER)",
661686
s,
662687
)
663688
return s
@@ -667,15 +692,15 @@ def post_munge(s):
667692
lambda: torch.compile(fn, backend="eager", fullgraph=True)(),
668693
"""\
669694
Missing bytecode handler
670-
Explanation: Dynamo does not know how to handle the bytecode instruction `LOAD_BUILD_CLASS`.
671-
Hint: Do not trace code that produces the `LOAD_BUILD_CLASS` bytecode instruction (see https:/docs.python.org/3/library/dis.html for bytecode semantics).
695+
Explanation: Dynamo does not know how to handle the bytecode instruction `GET_AITER`.
696+
Hint: Do not trace code that produces the `GET_AITER` bytecode instruction (see https:/docs.python.org/3/library/dis.html for bytecode semantics).
672697
Hint: It may be possible to write Dynamo tracing rules for this code. Please report an issue to PyTorch if you encounter this graph break often and it is causing performance issues.
673698
674-
Developer debug context: LOAD_BUILD_CLASS with args (<torch._dynamo.symbolic_convert.InstructionTranslator object at 0xmem_addr>, Instruction(LOAD_BUILD_CLASS)
699+
Developer debug context: GET_AITER with args (<torch._dynamo.symbolic_convert.InstructionTranslator object at 0xmem_addr>, Instruction(GET_AITER)
675700
676701
from user code:
677702
File "test_error_messages.py", line N, in fn
678-
class Foo:""",
703+
async for i in range(3):""",
679704
post_munge=post_munge,
680705
)
681706

torch/_dynamo/symbolic_convert.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,17 @@ def MATCH_KEYS(self, inst):
28242824
def LOAD_ASSERTION_ERROR(self, inst):
28252825
self.load_builtin_from_argval("AssertionError")
28262826

2827+
def LOAD_BUILD_CLASS(self, inst):
2828+
unimplemented_v2(
2829+
gb_type="LOAD_BUILD_CLASS bytecode not supported",
2830+
context="",
2831+
explanation="Dynamo does not support tracing classes that are defined in the compiled region.",
2832+
hints=[
2833+
"Move the class definition out of the compiled region.",
2834+
*graph_break_hints.SUPPORTABLE,
2835+
],
2836+
)
2837+
28272838
UNARY_POSITIVE = stack_op(operator.pos)
28282839
UNARY_NEGATIVE = stack_op(operator.neg)
28292840
UNARY_NOT = stack_op(operator.not_)

0 commit comments

Comments
 (0)