How can I solve 'ran out of gpu memory' in TensorFlow

Issue

I ran the MNIST demo in TensorFlow with 2 conv layers and a full-conect layer, I got an message that ‘ran out of memeory trying to allocate 2.59GiB’ , but it shows that total memory is 4.69GiB, and free memory is 3.22GiB, how can it stop with 2.59GiB? And with larger network, how can I manage gpu memory? I concern only how to make best use of the gpu memory and wanna know how it happened, not how to pre-allocating memory

Solution

It’s not about that. first of all you can see how much memory it gets when it runs by monitoring your gpu. for example if you have a nvidia gpu u can check that with watch -n 1 nvidia-smi command.
But in most cases if you didn’t set the maximum fraction of gpu memory, it allocates almost the whole free memory. your problem is lack of enough memory for your gpu. cnn networks are totally heavy. When you are trying to feed your network DO NOT do it with your whole data. DO this feeding procedure in low batch sizes.

Answered By – mrphoenix13

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published