如何解决 TensorFlow 中的“gpu 内存不足"问题 [英] How can I solve 'ran out of gpu memory' in TensorFlow
问题描述
我在带有 2 个卷积层和一个完整连接层的 TensorFlow 中运行了 MNIST 演示,我收到一条消息内存不足,试图分配 2.59GiB",但它显示总内存为 4.69GiB,并且是免费的内存是3.22GiB,2.59GiB怎么能停?对于更大的网络,我如何管理 GPU 内存?我只关心如何最好地利用 gpu 内存并想知道它是如何发生的,而不是如何预分配内存
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
推荐答案
与此无关.首先,您可以通过监控您的 gpu 来查看它在运行时获得了多少内存.例如,如果您有 nvidia gpu,您可以使用 watch -n 1 nvidia-smi
命令进行检查.但是在大多数情况下,如果您没有设置 gpu 内存的最大部分,它会分配几乎整个空闲内存.你的问题是你的 GPU 内存不足.cnn 网络非常重.当您尝试为您的网络提供数据时,请勿使用您的全部数据.以小批量执行此喂料程序.
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.
这篇关于如何解决 TensorFlow 中的“gpu 内存不足"问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!