Skip to content

Commit

Permalink
Revert "Optimize dict reconstruct to not codegen untouched values (py…
Browse files Browse the repository at this point in the history
…torch#134876)"

This reverts commit a1a57a4.

Reverted pytorch#134876 on behalf of https://github.com/jeanschmidt due to new introduced test test_reconstruct.py::ReconstructTest::test_functional_call_reconstruct is breaking internally. @zou3519 may you help get those changes merged back to main? ([comment](pytorch#134876 (comment)))
  • Loading branch information
pytorchmergebot committed Sep 17, 2024
1 parent e248c1d commit 3b5e268
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 314 deletions.
257 changes: 0 additions & 257 deletions test/dynamo/test_reconstruct.py

This file was deleted.

23 changes: 4 additions & 19 deletions torch/_dynamo/side_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,36 +590,21 @@ def codegen_update_mutated(self, cg: PyCodegen):
)

elif isinstance(var, variables.ConstDictVariable):
# Reconstruct works as follow:
# (1) codegen(...) each pair of key/value
# (2) create a new dictionary with the pairs of key/values above
# (3) clear the original dictionary
# + only if a key was removed from the input dict
# (4) update the original dictionary with the dict created in (2)

cg(var.mutable_local.source) # type: ignore[attr-defined]
cg.load_method("update")
cg(var, allow_cache=False)

if var.should_reconstruct_all:
cg(var.mutable_local.source) # type: ignore[attr-defined]
cg.load_method("clear")
cg(var.mutable_local.source) # type: ignore[attr-defined]
cg.load_method("clear")

suffixes.append(
[
*create_call_method(0), # clear
create_instruction("POP_TOP"),
*create_call_method(1), # update
create_instruction("POP_TOP"),
]
)

if var.should_reconstruct_all:
suffixes.append(
[
*create_call_method(0), # clear
create_instruction("POP_TOP"),
]
)

elif isinstance(
var, variables.torch_function.TorchFunctionModeStackVariable
):
Expand Down
4 changes: 1 addition & 3 deletions torch/_dynamo/variables/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,7 @@ def build_key_value(i, k, v):
source=self.source,
)
else:
result = ConstDictVariable(
result, user_cls=type(value), source=self.source
)
result = ConstDictVariable(result, type(value), source=self.source)

return self.set_source_and_track_mutable(value, result)
elif isinstance(value, torch.nn.Module):
Expand Down
Loading

0 comments on commit 3b5e268

Please sign in to comment.