Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytorch GPU memory keeps increasing with every batch

I'm training a CNN model on images. Initially, I was training on image patches of size (256, 256) and everything was fine. Then I changed my dataloader to load full HD images (1080, 1920) and I was cropping the images after some processing. In this case, the GPU memory keeps increasing with every batch. Why is this happening?

PS: While tracking losses, I'm doing loss.detach().item() so that loss is not retained in the graph.

like image 845
Nagabhushan S N Avatar asked Aug 05 '26 23:08

Nagabhushan S N


1 Answers

As suggested here, deleting the input, output and loss data helped.

Additionally, I had the data as a dictionary. Just deleting the dictionary isn't sufficient. I had to iterate over the dict elements and delete all of them.

like image 104
Nagabhushan S N Avatar answered Aug 07 '26 13:08

Nagabhushan S N



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!