From 3e5a389e79ff5e78fabb819e37c77214ad96d98b Mon Sep 17 00:00:00 2001 From: Aaron Orenstein Date: Fri, 31 Jan 2025 02:30:05 -0800 Subject: [PATCH] Fix dynamo use of `list[int]` in graph break (#145554) 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: https://github.com/pytorch/pytorch/pull/145554 Approved by: https://github.com/anijain2305 ghstack dependencies: #145551, #145552, #145553 Reviewed By: ZainRizvi Differential Revision: D68924393 fbshipit-source-id: 82fa9bd3f62df08df9ed80c08e98426f61d12f5e --- userbenchmark/dynamo/dynamobench/_dynamo/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/userbenchmark/dynamo/dynamobench/_dynamo/utils.py b/userbenchmark/dynamo/dynamobench/_dynamo/utils.py index cb1992987..e0a062f63 100644 --- a/userbenchmark/dynamo/dynamobench/_dynamo/utils.py +++ b/userbenchmark/dynamo/dynamobench/_dynamo/utils.py @@ -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}, )