Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.
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