【问题标题】:How do I keep track of the time the CPU is used vs the GPUs for deep learning?如何跟踪使用 CPU 与 GPU 进行深度学习的时间?
【发布时间】:2018-04-16 13:00:21
【问题描述】:

我想知道我的脚本运行时在 CPU 和 GPU 上花费了多少时间 - 有没有办法跟踪这一点?

寻找一个通用的答案,但如果这对于这个玩具解决方案来说太抽象了(来自 keras 的 multi_gpu_model 示例)会很棒。

import tensorflow as tf
from keras.applications import Xception
from keras.utils import multi_gpu_model
import numpy as np
num_samples = 1000
height = 224
width = 224
num_classes = 1000
# Instantiate the base model (or "template" model).
# We recommend doing this with under a CPU device scope,
# so that the model's weights are hosted on CPU memory.
# Otherwise they may end up hosted on a GPU, which would
# complicate weight sharing.
with tf.device('/cpu:0'):
    model = Xception(weights=None,
                     input_shape=(height, width, 3),
                     classes=num_classes)
# Replicates the model on 8 GPUs.
# This assumes that your machine has 8 available GPUs.
parallel_model = multi_gpu_model(model, gpus=8)
parallel_model.compile(loss='categorical_crossentropy',
                       optimizer='rmsprop')
# Generate dummy data.
x = np.random.random((num_samples, height, width, 3))
y = np.random.random((num_samples, num_classes))
# This `fit` call will be distributed on 8 GPUs.
# Since the batch size is 256, each GPU will process 32 samples.
parallel_model.fit(x, y, epochs=20, batch_size=256)
# Save model via the template model (which shares the same weights):
model.save('my_model.h5')

【问题讨论】:

    标签: python tensorflow machine-learning deep-learning keras


    【解决方案1】:

    您只需添加基于 Chrome 的 timeline 分析,用于从 Tensorflow API 到您的 Keras 模型的 CPU/GPU!

    这是 Tensorflow 问题跟踪器中提供的示例:

    https://github.com/tensorflow/tensorflow/issues/9868#issuecomment-306188267

    这是 Keras 问题跟踪器中更复杂的示例:

    https://github.com/keras-team/keras/issues/6606#issuecomment-380196635

    最后,分析的输出如下所示:

    https://towardsdatascience.com/howto-profile-tensorflow-1a49fb18073d

    【讨论】:

      猜你喜欢
      • 2021-11-12
      • 1970-01-01
      • 2018-07-25
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 2018-10-25
      • 2017-11-08
      • 1970-01-01
      相关资源
      最近更新 更多