与功能较弱的 GPU 相比,Tesla V100-SXM2-16GB GPU 上的 keras 启动时间 (_make_train_function()) 非常慢

2024-02-22

跟进:GPU 机器上的 keras 和 TensorFlow - 有些部分非常慢 https://stackoverflow.com/q/47296197/590335

从tensorflow 1.4运行mnist_cnn.py(稍微修改 - 主要添加日志记录)

运行是使用预构建的 docker 映像完成的:tensorflow/tensorflow:1.4.0-gpu-py3

在 p2.xlarge aws 机器(具有 Tesla K80 GPU)上性能良好,第一个批次(主要是对 _make_train_function 的调用)大约需要 2 秒:(请参阅开始批次和结束批次的时间戳)

2017-11-19 08:26:26,172 : INFO : fit

2017-11-19 08:26:26,637 : INFO : begin batch
2017-11-19 08:26:26.638409: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2017-11-19 08:26:26.760940: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:892] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2017-11-19 08:26:26.761478: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Found device 0 with properties:
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:00:1e.0
totalMemory: 11.17GiB freeMemory: 11.11GiB
2017-11-19 08:26:26.761506: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0, compute capability: 3.7)

2017-11-19 08:26:28,135 : INFO : end batch
x_train shape: (60000, 28, 28, 1)
60000 train samples
10000 test samples
Train on 60000 samples, validate on 10000 samples
Epoch 1/1
60000/60000 [==============================] - 12s - loss: 0.3526 - acc: 0.8920 - val_loss: 0.0818 - val_acc: 0.9755
Test loss: 0.081773182778
Test accuracy: 0.9755

在 p3.2xlarge 机器(配备 Tesla V100-SXM2-16GB GPU)上,相同的部分大约需要 10 分钟

2017-11-19 08:26:44,120 : INFO : fit

2017-11-19 08:26:44,715 : INFO : begin batch
2017-11-19 08:26:44.716680: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2017-11-19 08:26:46.108295: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:892] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2017-11-19 08:26:46.108775: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Found device 0 with properties:
name: Tesla V100-SXM2-16GB major: 7 minor: 0 memoryClockRate(GHz): 1.53
pciBusID: 0000:00:1e.0
totalMemory: 15.77GiB freeMemory: 15.36GiB
2017-11-19 08:26:46.108815: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: Tesla V100-SXM2-16GB, pci bus id: 0000:00:1e.0, compute capability: 7.0)

2017-11-19 08:36:16,552 : INFO : end batch
x_train shape: (60000, 28, 28, 1)
60000 train samples
10000 test samples
Train on 60000 samples, validate on 10000 samples
Epoch 1/1
60000/60000 [==============================] - 576s - loss: 0.3418 - acc: 0.8949 - val_loss: 0.0769 - val_acc: 0.9772
Test loss: 0.0769035610346
Test accuracy: 0.9772

使用的代码:

#!/usr/bin/env python
'''Trains a simple convnet on the MNIST dataset.

Gets to 99.25% test accuracy after 12 epochs
(there is still a lot of margin for parameter tuning).
16 seconds per epoch on a GRID K520 GPU.
'''

from __future__ import print_function
import cProfile
import os
from tensorflow.contrib import keras
from tensorflow.contrib.keras import backend as K
import logging


logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='\n%(asctime)s : %(levelname)s : %(message)s')

class callback(keras.callbacks.Callback):
    def on_batch_begin(self, batch, logs=None):
      if batch <= 1:
            logger.info('begin batch')

class callback(keras.callbacks.Callback):
    def on_batch_end(self, batch, logs=None):
        if batch <= 1:
            logger.info('end batch')

batch_size = 128
num_classes = 10
epochs = 1

# input image dimensions
img_rows, img_cols = 28, 28

# the data, shuffled and split between train and test sets
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()

if K.image_data_format() == 'channels_first':
    x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)
    x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)
    input_shape = (1, img_rows, img_cols)
else:
    x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
    x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
    input_shape = (img_rows, img_cols, 1)

x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train /= 255
x_test /= 255
print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')

# convert class vectors to binary class matrices
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

model = keras.models.Sequential()
model.add(keras.layers.Conv2D(32, kernel_size=(3, 3),
                 activation='relu',
                 input_shape=input_shape))
model.add(keras.layers.Conv2D(64, (3, 3), activation='relu'))
model.add(keras.layers.MaxPooling2D(pool_size=(2, 2)))
model.add(keras.layers.Dropout(0.25))
model.add(keras.layers.Flatten())
model.add(keras.layers.Dense(128, activation='relu'))
model.add(keras.layers.Dropout(0.5))
model.add(keras.layers.Dense(num_classes, activation='softmax'))

model.compile(loss=keras.losses.categorical_crossentropy,
              optimizer=keras.optimizers.Adadelta(),
              metrics=['accuracy'])
profiler = cProfile.Profile()
profiler.enable()
logger.info('fit')
model.fit(x_train, y_train,
          batch_size=batch_size,
          epochs=epochs,
          verbose=1,
          validation_data=(x_test, y_test), callbacks=[callback()])
profiler.dump_stats(os.path.expanduser('~/profiler.pstats'))
score = model.evaluate(x_test, y_test, verbose=0)

print('Test loss:', score[0])
print('Test accuracy:', score[1])

使用使用 CUDA 9 构建的张量流版本似乎几乎完全解决了这个问题:https://github.com/mind/wheels/releases/tag/tf1.4-gpu-cuda9 https://github.com/mind/wheels/releases/tag/tf1.4-gpu-cuda9

使用此版本还需要安装 MKL 库 - 说明如下:https://software.intel.com/en-us/articles/intel-mkl-dnn-part-1-library-overview-and-installation https://software.intel.com/en-us/articles/intel-mkl-dnn-part-1-library-overview-and-installation

解释为什么会发生这种情况,或者不涉及张量流修改版本的解决方案仍然是首选

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

与功能较弱的 GPU 相比,Tesla V100-SXM2-16GB GPU 上的 keras 启动时间 (_make_train_function()) 非常慢 的相关文章

  • 使用 pdfkit 和 FastAPI 下载 PDF 文件

    我将使用 FastAPI 创建一个 API 将HTML页面到 PDF 文件 使用pdfkit 但是 它将文件保存到我的本地磁盘 当我在线提供此API后 用户如何将该PDF文件下载到他们的计算机上 from typing import Opt
  • 配置 PIP 以在代理后面工作

    我已经安装了 python 3 4 3 附带pip 我想从代理后面使用 pip 所以我执行了以下操作 Created C Users foo pip pip ini并添加了代理配置部分 proxy export http proxy my
  • Native TF 与 Keras TF 性能比较

    我使用本机和后端张量流创建了完全相同的网络 但在使用多个不同参数进行了多个小时的测试后 仍然无法弄清楚为什么 keras 优于本机张量流并产生更好 稍微但更好 的结果 Keras 是否实现了不同的权重初始化方法 或者执行除 tf train
  • 来自多元 t 分布的样本 python

    我想知道Python中是否有一个从多元学生t分布中采样的函数 我有包含 14 个元素的均值向量 14x14 协方差矩阵和自由度 我想从这个 t 分布中采样一个向量 对于一维情况 我使用 stats t rvs df loc scale 并且
  • 以编程方式结束/退出粘合作业

    我正在使用 Glue 书签来处理数据 我的工作是每天安排的 但也可以 手动 启动 由于我使用书签 有时胶水作业可以在没有新数据要处理的情况下启动 然后读取的数据帧为空 在这种情况下 我想好好地结束我的工作 因为它没有什么关系 我试过 if
  • 如何使用 django Rest 框架保存多对多字段对象

    我有博客 发布 标签三个模型 在博客模型中 我将字段 postedin 作为发布模型的外键 将 标签 作为标签模型的许多字段 模型 py class Posted models Model name models CharField Pos
  • 在 Python 中倾斜数组

    我有一个 2D 数组 我将使用它保存为灰度图像scipy misc toimage 在此之前 我想将图像倾斜给定角度 像这样进行插值scipy ndimage interpolation rotate 上图只是为了说明倾斜过程 我知道我必须
  • ipython/jupyter 中的 tk 问题

    我正在尝试编写一个用于从 ipython jupyter 笔记本启动的 gui 但在笔记本中使用 tkinter 时遇到了麻烦 特别是在让 tk gui 窗口正常关闭方面 如何从 jupyter 制作 启动 tkinter gui 然后在不
  • “DATETIME_INPUT_FORMATS”在 Django Admin 中不起作用,而“DATE_INPUT_FORMATS”和“TIME_INPUT_FORMATS”则可以

    I use 日期时间字段 https docs djangoproject com en 4 2 ref models fields datetimefield 日期字段 https docs djangoproject com en 4
  • 将具有多个时区的 pandas 列转换为单个时区

    Problem 我在 pandas DataFrame 中有一个列 其中包含带有时区的时间戳 此列中有两个不同的时区 我需要确保只有一个 这是该列末尾的输出 260003 2019 05 21 12 00 00 06 00 260004 2
  • django-allauth:电子邮件确认

    我已经设置了 django allauth 并在新用户注册时使用电子邮件确认 效果很好 但在确认电子邮件中 我得到 Hello from example com You re receiving this e mail because us
  • __author__ 的起源是什么?

    使用私有元数据变量的约定在哪里 author 一个模块内部从何而来 This http mail python org pipermail python dev 2001 March 013328 htmlPython 邮件列表线程似乎暗示
  • 在解析器/子解析器的开头使用 argparse.REMAINDER

    我想实现一个 arg 解析器 它允许我将单元测试作为子命令之一运行 盲目地将参数传递给 unittest main 例如 foo py unittest args to pass to unittest main 以及其他子命令 foo p
  • 如何在 Python 中连接两个列表?

    这个问题的答案是社区努力 help privileges edit community wiki 编辑现有答案以改进这篇文章 目前不接受新的答案或互动 如何在 Python 中连接两个列表 Example listone 1 2 3 lis
  • Python:Factory Boy 生成对象创建时指定长度的列表

    我正在尝试使用 Factoryboy 在创建时指定长度的对象中创建一个列表 我可以创建列表 但由于提供的长度 大小的惰性性质 每次尝试创建具有指定长度的列表都会导致问题 这是我到目前为止所拥有的 class FooFactory facto
  • 如何动态选择要在flask中使用的模板目录?

    默认情况下 Flask 使用存储在 template 目录中的模板文件 flaskapp application py templates hello html 有没有办法根据登录的用户动态选择模板目录 这就是我想要的目录结构 flaska
  • 如何将动态数据传递给装饰器

    我正在尝试编写一个基本的 CRUD 控制器类来执行以下操作 下列的 class BaseCrudController model field validation template dir expose self template dir
  • Paramiko ValueError“p 的长度必须恰好为 1024、2048 或 3072 位”

    我正在尝试使用 Python 脚本连接 SFTP 由于 p 错误 我无法连接 import paramiko client paramiko SSHClient client load system host keys client con
  • 如何通过解析导入来组合并获取单个 Python 文件

    我正在尝试获取单个 Python 文件作为输出 我有一个 Python 脚本 其中有多个此类导入 from that import sub 导入来自所有本地模块 而不是来自系统或 Python 库 有什么方法可以解决这些问题并获得一个完整的
  • 收到 Python 错误“来自:无法读取 /var/mail/Bio”

    我正在运行一个 bio python 脚本 这会导致以下错误 from can t read var mail Bio 由于我的脚本与邮件没有任何关系 我不明白为什么我的脚本在 var mail 中查找 这里似乎有什么问题 我怀疑这会有帮助

随机推荐