【问题标题】:Using a GPU with Tensorflow Eager Execution on Google Colaboratory在 Google Colaboratory 上使用带有 Tensorflow Eager Execution 的 GPU
【发布时间】:2018-04-03 07:31:20
【问题描述】:

我正在尝试在 Google Colaboratory 上的 Tensorflow Eager Execution 中将计算卸载到 GPU,但由于 Colab 处理 GPU 的方式,我遇到了麻烦。

通常,在使用 GPU 时,您将运行时更改为 GPU 加速的运行时,Tensorflow 会自动使用可用的 GPU 进行计算。如果您尝试手动设置 GPU,您会发现无法设置,因为连接的设备列表中没有。

但是,如果 GPU 可用,Eager 执行不会自动使用 GPU,并且由于您无法手动设置它,因此似乎无法使用。

请看附件:https://drive.google.com/file/d/1NeJQoO5Yi5V-m7Hmm85wmm1Cl5SrY33m/view?usp=sharing

尝试指定要使用的 GPU 会引发以下错误:RuntimeError: Error copying tensor to device: /job:localhost/replica:0/task:0/device:GPU:0. /job:localhost/replica:0/task:0/device:GPU:0 unknown device.

【问题讨论】:

    标签: python tensorflow google-colaboratory


    【解决方案1】:

    Eager execution 实际上允许您手动指定 GPU(例如,在 https://www.tensorflow.org/programmers_guide/eager 中搜索“GPU”)。

    您包含的特定错误消息表明 TensorFlow 找不到 GPU,因此请确保您已安装与 GPU 兼容的 TensorFlow 1.7 版本。完成此操作后,您需要对代码进行另一项更改。特别是,在相乘之前将张量 xy 复制到 GPU,如下所示:

    with tf.device('/gpu:0'):
         x = x.gpu()
         y = y.gpu()
         %timeit x * y
    

    【讨论】:

    • 抱歉,我的问题可能不是很清楚。我知道如何设置 gpu 设备(如您在 notebook 中所见),但未检测到 Google Colaboratory 上的设备(因此只能自动使用,不能手动设置)。
    • 有趣啊。你是对的 --- 这似乎是谷歌 Colaboratory 中的一个错误。甚至样本 GPU notebook 也无法检测到 GPU。 FAQs page 有报告错误的说明。
    猜你喜欢
    • 2019-02-13
    • 2019-01-11
    • 2018-07-21
    • 1970-01-01
    • 2019-04-07
    • 2019-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多