Memory leak when performing inner loop on a copy
See original GitHub issueWhen running the following script, memory usage seems to continually increase (not all iterations, but many of them in the beginning). Explicitly decrementing the reference counts for the functional model/differentiable optimizer seems to help, but not completely fix the issue. Script for reproducing attached. Monitoring GPU memory usage with watch -n 0.1 nvidia-smi
. Running PyTorch version 1.3.0, torchvision 0.4.1, higher version 0.1.3@59537fa. Let me know if any other information would be helpful.
Code to reproduce the issue:
import torch, torchvision
import higher
import time
from copy import deepcopy
print(torch.__version__, torchvision.__version__)
inner_loop_copy = True # Setting this to False gives no memory usage increase
device = torch.device('cuda:0')
model = torchvision.models.resnet18().to(device)
opt = torch.optim.SGD(model.parameters(), lr=1e-5)
for idx in range(100):
print(idx)
if inner_loop_copy:
model_ = deepcopy(model)
opt_ = torch.optim.SGD(model_.parameters(), lr=1e-5)
else:
model_ = model
opt_ = opt
with higher.innerloop_ctx(model_, opt_) as (fm, do):
pass
# del fm, do # Uncommenting this helps, but doesn't completely eliminate the memory usage increase
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Memory leak when cloning byte[] in a loop - Android
When I send the data using Arrays.copyOf(), System.arrayCopy() or data.clone(), OutOfMemory is occurs. When I send data directly, there is no ...
Read more >Memory Leak when looping over out-links of objects - Jazz.net
Memory leaks is DOORS is a complicated issue. Most of the time it is not obvious where the memory is leaked. When interating...
Read more >Do repeated Local and Global variable use in loops cause ...
The basic answer to "Do repeated Local and Global variable use in loops cause memory leaks?" is no. You can read / write...
Read more >4 Types of Memory Leaks in JavaScript and How to Get Rid Of ...
The main cause for leaks in garbage collected languages are unwanted references. To understand what unwanted references are, first we need to ...
Read more >Nested monadic loops may cause space leaks
It doesn't do much — except, as it turns out, eat a lot of memory! ... These nested loops happen often in server-side...
Read more >Top Related Medium Post
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Got it. Not sure I will be able to devote much time to it either. For the moment, though, it seems to be at least partially alleviated by explicitly deleting the functional model/differentiable optimizer.
Fixed in #15 (we believe). Please let us know if you have ongoing issues.