为什么在 RTX 3070/cudnn8/CUDA11.1 上添加 convolution/pool 层会导致 Keras/Tensorflow 模型崩溃而 运行?
Why does adding convolution/pool layer crash Keras/Tensorflow model while running on RTX 3070/cudnn8/CUDA11.1?
系统信息
- OS: Windows 10,
- cudnn: 8.0,
- CUDA 工具包:11.1 安装在 10.2 之上,
- GPU:英伟达 RTX 3070,
- CPU:英特尔 I7 10700f,
- Tensorflow:
tf.__version__==2.4.0rc-0
(也曾于 2020 年 12 月 7 日尝试使用 tf-nightly-gpu
)
- CUDA、cudnn从源码手动编译
测试代码
下面的代码成功编译了一个模型,但在调用 model.fit(...)
时崩溃了。
from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt
(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()
train_images, test_images = train_images / 255.0, test_images / 255.0
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10))
model.compile(optimizer='Adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True))
history = model.fit(train_images, train_labels, batch_size=10, epochs=100)
通过删除 卷积 和 maxpooling 层并在输入后仅展平张量,模型能够很好地训练(显然输出这个模型没用,但它仍然可以训练。
程序崩溃时的错误代码是>Process finished with exit code -1073740791 (0xC0000409)
此外,在调用 tf.config.list_physical_devices('GPU')
时,tensorflow 能够打开库、查找 GPU 并将 GPU 记录为可用
更新
我在 tensorflow github 页面上打开了一个问题,你可以找到 here
无论出于何种原因,当 运行 在 IDE 终端中时,错误消息被抑制并且 Process finished with exit code -1073740791 (0xC0000409)
被记录为错误消息。
当 运行 从命令行显示以下错误消息而不是记录退出代码错误。
Could not load library cudnn_ops_infer64_8.dll. Error code 126
Please make sure cudnn_ops_infer64_8.dll is in your library path!
我认出这是包含在cudnn 库中的一个包,并将它从cudnn 中的bin 文件夹复制并粘贴到NVIDIA GPU 计算工具包> CUDA > V11.0 > bin。对以下包重复此过程,问题已解决。
cudnn_adv_infer64_8.dll
cudnn_adv_train64_8.dll
cudnn_cnn_infer64_8.dll
cudnn_cnn_train64_8.dll
cudnn_ops_infer64_8.dll
cudnn_ops_train64_8.dll
系统信息
- OS: Windows 10,
- cudnn: 8.0,
- CUDA 工具包:11.1 安装在 10.2 之上,
- GPU:英伟达 RTX 3070,
- CPU:英特尔 I7 10700f,
- Tensorflow:
tf.__version__==2.4.0rc-0
(也曾于 2020 年 12 月 7 日尝试使用tf-nightly-gpu
) - CUDA、cudnn从源码手动编译
测试代码
下面的代码成功编译了一个模型,但在调用 model.fit(...)
时崩溃了。
from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt
(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()
train_images, test_images = train_images / 255.0, test_images / 255.0
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10))
model.compile(optimizer='Adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True))
history = model.fit(train_images, train_labels, batch_size=10, epochs=100)
通过删除 卷积 和 maxpooling 层并在输入后仅展平张量,模型能够很好地训练(显然输出这个模型没用,但它仍然可以训练。
程序崩溃时的错误代码是>Process finished with exit code -1073740791 (0xC0000409)
此外,在调用 tf.config.list_physical_devices('GPU')
时,tensorflow 能够打开库、查找 GPU 并将 GPU 记录为可用
更新 我在 tensorflow github 页面上打开了一个问题,你可以找到 here
无论出于何种原因,当 运行 在 IDE 终端中时,错误消息被抑制并且 Process finished with exit code -1073740791 (0xC0000409)
被记录为错误消息。
当 运行 从命令行显示以下错误消息而不是记录退出代码错误。
Could not load library cudnn_ops_infer64_8.dll. Error code 126
Please make sure cudnn_ops_infer64_8.dll is in your library path!
我认出这是包含在cudnn 库中的一个包,并将它从cudnn 中的bin 文件夹复制并粘贴到NVIDIA GPU 计算工具包> CUDA > V11.0 > bin。对以下包重复此过程,问题已解决。
cudnn_adv_infer64_8.dll
cudnn_adv_train64_8.dll
cudnn_cnn_infer64_8.dll
cudnn_cnn_train64_8.dll
cudnn_ops_infer64_8.dll
cudnn_ops_train64_8.dll