Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dynamo] Fix OrderedDict reconstruction bytecode #95800

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/dynamo/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4444,6 +4444,23 @@ def dummy_fn():
# TODO should also pass the code object back into dynamo again, but
# dynamo is not enabled for Python 3.11 yet.

def test_ordered_dict_alias_reconstruct(self):
od = collections.OrderedDict

def fn():
d1 = dict()
d1["a"] = 1
d2 = od(d1)
d2["b"] = 2
torch._dynamo.graph_break()
if isinstance(d2, od):
return d2["a"] + d2["b"]
else:
return 0

dis.dis(fn)
self.assertEqual(torch._dynamo.optimize("eager")(fn)(), 3)

@torch._dynamo.config.patch(dynamic_shapes=True)
def test_raise_guard_full_constraint(self):
y = torch.randn([3, 3, 3])
Expand Down
6 changes: 3 additions & 3 deletions torch/_dynamo/variables/dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def reconstruct(self, codegen):
if self.user_cls is collections.OrderedDict:
codegen.extend_output(
[
codegen.create_load_python_module(collections),
create_instruction("LOAD_METHOD", "OrderedDict"),
codegen.create_load_python_module(collections, True),
codegen.create_load_attr("OrderedDict"),
]
)
# instructions to build the dict keys and values
Expand All @@ -55,7 +55,7 @@ def reconstruct(self, codegen):
if self.user_cls is collections.OrderedDict:
return [
create_instruction("BUILD_MAP", len(self.items)),
create_instruction("CALL_METHOD", 1),
*create_call_function(1, False),
]
# BUILD_MAP only if user_cls is dict
else:
Expand Down