Skip to content

Commit

Permalink
fix the memory leak of offloading
Browse files Browse the repository at this point in the history
  • Loading branch information
yitongh committed Dec 12, 2024
1 parent 88cee13 commit 3eb1a89
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion torchacc/utils/cpu_offload.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,11 @@ def apply(tensor):
_applied_tensor = tensor
return tensor

return apply_to_tensors(apply, outputs)
outputs = apply_to_tensors(apply, outputs)
# delete the global variables to avoid memory leak
_apply_tensor = None
_applied_tensor = None
return outputs

return (
CpuOffloadHookWithOffloadHandler(offload_handler=cpu_offload_handler),
Expand Down

0 comments on commit 3eb1a89

Please sign in to comment.