【发布时间】:2020-12-21 03:01:55
【问题描述】:
我正在尝试为卷积神经网络实现运行 tensorflow-gpu 版本 2.4.0-dev20200828(tf-nightly 构建)。其他一些细节:
- python的版本是Python 3.8.5。
- 运行 Windows 10
- 使用具有 8 GB VRAM 的 nVidia RTX 2080
- Cuda 版本 11.1
下面的sn-p是我运行的:
import tensorflow as tf
from tensorflow import keras
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
tf.config.experimental.set_virtual_device_configuration(
gpus[0],
[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024)])
logical_gpus = tf.config.experimental.list_logical_devices('GPU')
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
except RuntimeError as e:
# Virtual devices must be set before GPUs have been initialized
print(e)
vgg_16 = keras.applications.VGG16(include_top=False, input_shape=(600, 600, 3))
random_image = np.random.rand(1, 600, 600, 3)
output = vgg_16(random_image)
内存配置代码取自here的回答
我遇到的问题是我的 GPU 有 8GB 的 VRAM,我需要能够以相对较大的图像批量运行 CNN。该示例在单个图像上执行,但令人惊讶的是,我似乎只能将批量大小增加到大约 2-3 600 x 600 个图像。根据 cmets 获取的代码表明:
限制 TensorFlow 只在第一个 GPU 上分配 1GB 内存,这显然不理想。
一方面,如果我分配更多,比如 4000MB,我会收到如下错误:
E tensorflow/stream_executor/cuda/cuda_dnn.cc:325] Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED
如果我将其保留为 1024 MB,我会收到如下消息:
Allocator (GPU_0_bfc) ran out of memory trying to allocate 3.25GiB with freed_by_count=0. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
非常感谢任何有关如何理解此问题的见解/资源。如有必要,我愿意切换到另一个版本的 tensorflow/python/cuda,但最终我只是想更深入地了解这个问题是什么。
【问题讨论】:
-
你不需要在 tensorflow 中摆弄任何东西来使用你 GPU 中的所有 RAM,那么你为什么要这样做呢?您最初遇到的真正问题是什么?
-
@Dr.Snoopy 如果我没有添加内存摆弄代码,我会收到警告消息:创建 cublas 句柄失败:CUBLAS_STATUS_ALLOC_FAILED
-
你有没有考虑过这个网络对于这个 GPU 来说太大了?
-
@Dr.Snoopy 8GB Vram 真的不够用吗?我对这件事不是很有经验,所以我不知道。
-
是的,它可能是,VGG 需要大量 RAM 用于 224x224 图像,而增加到 600x60 将使用至少 4-6 倍的 RAM。对于较小的图像,它可能会起作用。
标签: tensorflow keras