Skip to content

Remove reference cycle #223

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

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions torchdynamo/convert_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def transform(instructions, code_options):
)
tracer.run()
output = tracer.output
output.cleanup()
assert output.output_instructions
instructions[:] = output.output_instructions
code_options.update(output.code_options)
Expand Down
9 changes: 9 additions & 0 deletions torchdynamo/output_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,12 @@ def add_output_instructions(self, prefix: List[Instruction]):

def install_global(self, name, value):
self.cleanups.append(CleanupHook.create(self.root_globals, name, value))

def cleanup(self):
# There is a reference cycle between tracer and OutputGraph, causing
# some of the tensor objects to be held alive for longer than necessary.
self.root_tx = None

# Cleanup graphargs
for graph_arg in self.graphargs:
graph_arg.erase()
3 changes: 3 additions & 0 deletions torchdynamo/variables/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def get_examples(self):
def __len__(self):
return 1

def erase(self):
self.example = None


class VariableBuilder:
"""Wrap a python value in a VariableTracker() instance"""
Expand Down