为什么我的CUDA_错误_内存不足:Nvidia Quadro 8000内存不足,Tensorflow gpu 2.0上的可用内存不足
我们最近在实验室得到了一个Quadro 8000用于培训目的。但是,我无法运行最简单的代码,cuda_driver.cc抱怨未能分配内存(随后的消息表明cuda未能分配38.17G,然后是34.36G、30.92G、27.83G、25.05G、22.54G)即使GPU:0显示有39090MB内存。我使用的是基于miniconda的python,带有tensorflow gpu 2.0.0和cudnn(7.6.4)和cudatoolkit(10.0.130)的兼容版本,使用conda安装自动拉取。简单代码如下所示为什么我的CUDA_错误_内存不足:Nvidia Quadro 8000内存不足,Tensorflow gpu 2.0上的可用内存不足,tensorflow,out-of-memory,tensorflow2.0,Tensorflow,Out Of Memory,Tensorflow2.0,我们最近在实验室得到了一个Quadro 8000用于培训目的。但是,我无法运行最简单的代码,cuda_driver.cc抱怨未能分配内存(随后的消息表明cuda未能分配38.17G,然后是34.36G、30.92G、27.83G、25.05G、22.54G)即使GPU:0显示有39090MB内存。我使用的是基于miniconda的python,带有tensorflow gpu 2.0.0和cudnn(7.6.4)和cudatoolkit(10.0.130)的兼容版本,使用conda安装自动拉取。
from __future__ import absolute_import, division, print_function, unicode_literals
import MClib
import tensorflow as tf
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
# Currently, memory growth needs to be the same across GPUs
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
print('tf Memory growth : %r' % (tf.config.experimental.get_memory_growth(gpus[0])))
tf.config.experimental.set_virtual_device_configuration(
gpus[0],[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=512*38)])
logical_gpus = tf.config.experimental.list_logical_devices('GPU')
print("%d Physical GPUs, %d Logical GPUs" % (len(gpus), len(logical_gpus)))
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
c = tf.matmul(a, b)
print(c)
except RuntimeError as e:
# Memory growth must be set before GPUs have been initialized
print(e)
我尝试过的修复:
诸如重新启动电脑(duh)、减小批量大小等修复仍然会带来问题。当我使用一个小数据集进行训练时,有时训练会继续进行,尽管存在内存错误,这是其他人遇到的问题,但可以通过修改内存增长选项来解决(如果我记得正确的话)。这个解决方案对我没有帮助
我确实有一个临时的修复方法,通过取消对上面代码中try语句后的前两行的注释来设置内存限制。但我发现,即使gpu的可用内存增加了一倍左右,我也无法强制gpu分配超过大约20G的内存。
通过谷歌搜索可以设置GPU上的内存增长或内存限制。我甚至尝试设置这两行(同时取消第3行和第4行的注释),但都没有效果。
有没有人遇到过类似的问题?或者是有一个限制的GPU内存,一个人可以使用
System: Dell Precision 5820
Processor: Intel Xeon W-2123 CPU @ 3.60 GHz, 4 cores, 8 processors
RAM: 16G
感谢@OverLordGoldDragon的建议,如前所述,通过禁用“急切执行”解决了错误。我不知道“为什么”,但这可能是一个bug w/eager-请参阅解决方法!谢谢!很高兴听到-考虑投票赞成的答案