memory leakage problem when loss.backward()
See original GitHub issueHi.
How can i solve memory leakage problem on loss.backward? Actually my code is a bit complex, which makes it hard to provide whole.
The main memory burden comes from here. Exactly after the execution of loss.backward(). The memory increases for every iteration, which leads to OOM.
loss = bce_extended(logits, y).sum()
with backpack(BatchGrad()):
if real_sample:
loss.backward(inputs = list(model.parameters()))
I also tried with disable():
which prevent the memory leak problem. However, it cannot be implemented with with backpack(BatchGrad()):
when i want to get the per-sample gradient.
Issue Analytics
- State:
- Created a year ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
PyTorch memory leak on loss.backward on both gpu as well ...
First of all, I couldn't find you using .to(device) or .to(cuda) on your data. it should be in your training loop where you...
Read more >Memory leak under "full backward hook" with ... - GitHub
This minimal bug-reproducing example illustrates a memory leak in ... memory leakage problem when loss.backward() f-dangel/backpack#258.
Read more >Loss.backward() cause CPU memory leak - PyTorch Forums
when I run cifar10_tutorial.py in Deep Learning with PyTorch: A 60 minutes Blitz, I find memory leak in loss.backward().
Read more >PyTorch 101, Part 4: Memory Management and Using Multiple ...
How to diagnose and analyse memory issues should they arise. ... loss function loss.mean().backward() # Average GPU-losses + backward pass optimizer.step().
Read more >pytorch-memlab - PyPI
A lab to do simple and accurate memory experiments on pytorch. ... the CUDA tensors into CPU memory for courtesy, and of course...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
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
Hi,
just wanted to bring it up because I saw there is a
.backward(..., create_graph=True)
in your code: There’s a memory leak when usingfull_backward_hook
s withcreate_graph=True
in PyTorch (#82528). You could try installing PyTorch with the fix (#82788) to see if that’s causing the memory leak.Sadly I don’t have any data yet how BackPACK compares to
functorch
in terms of runtime, e.g. for computing individual gradients.But I think you will be able to port your existing code to
functorch
with relatively few changes to try if it works fast enough for your needs.