Skip to content

Commit

Permalink
Fix dynamo use of list[int] in graph break (#145554)
Browse files Browse the repository at this point in the history
Summary:
This reintroduces the change backed out by #145393 and fixes the underlying problem.

Although using a BuiltinVariable was better than nothing when we saw a GenericAlias it had problems if there was a graph break and we had to reconstruct the original python code which BuiltinVariable did as a simple `list` instead of a `list[int]`.

This changes it to use a TypingVariable instead and then teaches TypingVariable how to reconstruct.

Original commit changeset: 77b9193acb23

python test/dynamo/test_repros.py ReproTests.test_graph_break_on_jit_isinstance

X-link: pytorch/pytorch#145554
Approved by: https://github.com/anijain2305
ghstack dependencies: #145551, #145552, #145553

Reviewed By: ZainRizvi

Differential Revision: D68924393

fbshipit-source-id: 82fa9bd3f62df08df9ed80c08e98426f61d12f5e
  • Loading branch information
aorenste authored and facebook-github-bot committed Jan 31, 2025
1 parent 7b7276d commit 3e5a389
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion userbenchmark/dynamo/dynamobench/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2162,7 +2162,16 @@ def rot_n_helper(n):
def is_safe_constant(v):
if istype(v, (tuple, frozenset)):
return all(map(is_safe_constant, v))
return isinstance(v, (enum.Enum, type, torch.Size)) or istype(
return isinstance(
v,
(
enum.Enum,
type,
torch.Size,
typing._GenericAlias, # type: ignore[attr-defined]
types.GenericAlias,
),
) or istype(
v,
common_constant_types | {slice},
)
Expand Down

0 comments on commit 3e5a389

Please sign in to comment.