【问题标题】:Blas GEMM launch failed when using TensorFlow GPU with Keras将 TensorFlow GPU 与 Keras 结合使用时,Blas GEMM 启动失败
【发布时间】:2020-02-15 11:00:52
【问题描述】:

相当不言自明。就像我之前和之后的无数人一样,我在尝试调用 model.fit() 时收到了 Blas GEMM launch failed 错误消息。

这是nvidia-smi调用model.compile()之前的输出:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.50       Driver Version: 430.50       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           Off  | 00000000:00:1E.0 Off |                    0 |
| N/A   45C    P0    74W / 149W |      0MiB / 11441MiB |    100%      Default |   <<<--- 0% Memory usage
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |   <<<--- nothing running
+-----------------------------------------------------------------------------+

以及nvidia-smi 调用model.compile()(以及紧接在model.fit()之前)的输出:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.50       Driver Version: 430.50       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           Off  | 00000000:00:1E.0 Off |                    0 |
| N/A   45C    P0    72W / 149W |  10942MiB / 11441MiB |      0%      Default |   <<<--- 96% Memory usage
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1811      C   /usr/bin/python3                           10929MiB |   <<<--- TF model here
+-----------------------------------------------------------------------------+

看起来编译后的 TensorFlow 模型垄断了 96% 的 GPU 内存。我不知道这是否正常,是否可能是后来尝试训练模型时出错的原因。

错误信息本身如下:

tensorflow/stream_executor/stream.cc:2041] 尝试执行 BLAS 在不支持 BLAS 的情况下使用 StreamExecutor 进行操作

InternalError: Blas GEMM 启动失败:a.shape=(32, 116032), b.shape=(116032, 256), m=32, n=256, k=116032 [[节点dense_1/MatMul (定义在 /home/ubuntu/.local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:3009) ]] [操作:__inference_keras_scratch_graph_1645]

函数调用栈:keras_scratch_graph

tf.config.experimental.list_physical_devices() 的输出:

[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'),
 PhysicalDevice(name='/physical_device:XLA_CPU:0', device_type='XLA_CPU'),
 PhysicalDevice(name='/physical_device:XLA_GPU:0', device_type='XLA_GPU'),
 PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

使用以下内容构建模型:

  • Keras 2.3.1(使用keras.models.Sequential
  • TensorFlow-GPU 2.1.0
  • CUDA 10.1
  • cuDNN 7.6.4
  • Ubuntu 18.04
  • AWS p2.xlarge 实例(配备 Tesla K80 GPU)

我经历了无数的 GitHub 问题、博客文章、S.O.问题,所有建议确保在启动新进程时在 GPU 上没有任何先前运行的进程仍然处于活动状态,或者将 CUPTI 位置添加到 LD_LIBRARY_PATH,或者使用各种 TF 选项......它都没有解决问题。任何关于导致该问题的原因以及如何解决的想法将不胜感激。

【问题讨论】:

    标签: python tensorflow keras


    【解决方案1】:

    我遇到了同样的问题。我看到了很多答案并使用了很多建议的代码来解决这个问题,但任何东西都对我有帮助。

    对我来说,问题在于 GPU 的使用,因此我使用以下代码限制我的 GPU 使用的内存:

    gpus = tf.config.experimental.list_physical_devices('GPU')
    if gpus:
    # Restrict TensorFlow to only allocate 1GB of memory on the first GPU
        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)
    

    取自https://www.tensorflow.org/guide/gpu#limiting_gpu_memory_growth。这解决了我的问题。我希望这也能解决您的问题。

    【讨论】:

      猜你喜欢
      • 2018-01-12
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-19
      • 2020-03-18
      • 1970-01-01
      • 2018-02-12
      相关资源
      最近更新 更多