【问题标题】:Tensorflow GPU model.fit Crashes KernelTensorflow GPU model.fit 导致内核崩溃
【发布时间】:2022-03-08 16:34:53
【问题描述】:

我正在尝试在 GPU 上使用 tensorflow 训练一个非常基本的模型(Spyder 4.1.5、Python 3.8.5、tensorflow 2.7.0)。

它在 CPU 上运行良好,但如果我将设备设置为 GPU,则会崩溃。

这是代码:

import tensorflow as tf
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

class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',
               'dog', 'frog', 'horse', 'ship', 'truck']

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.summary()

model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])

with tf.device('gpu:0'):
    history = model.fit(train_images, train_labels, epochs=10, 
                    validation_data=(test_images, test_labels))

内核在 model.fit 崩溃,我得到的唯一输出是:

"2022???????? 01:11:35.629875: I tensorflow/core/platform/cpu_feature_guard.cc:151] 这个 TensorFlow 二进制文件使用 oneAPI 深度神经网络库 (oneDNN) 进行了优化,以在性能关键操作中使用以下 CPU 指令: AVX AVX2 要在其他操作中启用它们,请使用适当的编译器标志重建 TensorFlow。 2022?????????? 01:11:36.017910: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] 使用 3987 MB 内存创建设备 /job:localhost/replica:0/task:0/device:GPU:0:-> 设备: 0,名称:NVIDIA GeForce GTX 1660 Ti,pci总线id:0000:01:00.0,计算能力:7.5"

我认为应该正确安装 tensorflow + cuda,因为我有另一个在 GPU 上训练的模型可以正常工作。

有什么方法可以让我获得有关崩溃的更多信息?会不会是内存不够了?

GPU 执行期间来自 Spyder 控制台的图片:

在崩溃之前它会像这样等待几秒钟:

然后我得到了这个:

【问题讨论】:

  • 您能否澄清一下程序“崩溃”的原因以及您如何知道它已经崩溃?有错误信息吗?是否缺少预期的输出?
  • 崩溃在哪里?

标签: python tensorflow


【解决方案1】:

我直接从 anaconda 提示符运行脚本。这是cudnn的安装问题。这是引发的错误:

"I tensorflow/stream_executor/cuda/cuda_dnn.cc:366] 加载cuDNN版本8302 无法加载库 cudnn_cnn_infer64_8.dll。错误代码 126 请确保 cudnn_cnn_infer64_8.dll 在您的库路径中!”

解决方案是添加 zlibwapi.dll(https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html - 第 2.1.3 章)。 TensorFlow 现在可以在 GPU 上运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-21
    • 2021-07-09
    • 1970-01-01
    • 2018-09-02
    • 2014-05-25
    相关资源
    最近更新 更多