【问题标题】:Google Colab GPU speed-up works with 2.x, but not with 1.xGoogle Colab GPU 加速适用于 2.x,但不适用于 1.x
【发布时间】:2019-12-25 14:39:31
【问题描述】:

在https://colab.research.google.com/notebooks/gpu.ipynb 中,我认为这是 Google 对 GPU 加速的官方演示,如果我按照这些步骤进行操作,使用 Tensorflow 2.x 的 GPU 加速(比 CPU 快大约 60 倍)有效。但是,如果我想像 https://colab.research.google.com/drive/12dduH7y0GPztxSM0AFlfpjj8FU5x8YSv 那样使用 1.15 版(与第一个链接中的笔记本相比,唯一的变化是两次都去掉了“%tensorflow_version 2.x”),tf.test.gpu_device_name() 返回字符串 /device:GPU:0但没有加速。不过,我真的很想使用 1.5 和 1.15 之间的 Tensorflow 版本,因为我要运行的代码使用了在 Tensorflow 2.x 中删除的函数。有谁知道如何使用 Tensorflow 1.x,同时还能获得 GPU 加速?

【问题讨论】:

    标签: tensorflow google-colaboratory


    【解决方案1】:

    在您的笔记本中,您的代码实际上并未执行,因为您没有调用 session.run() 或 tf.enable_eager_execution()。

    在代码顶部添加tf.enable_eager_execution(),您将看到cpu 和gpu 时间之间的真正区别。

    【讨论】:

    • 感谢您的回答。当我使用tf.enable_eager_execution() 时,我确认你说的是真的。你知道为什么 tf 2.x 不需要session.run() 或tf.enable_eager_execution() 来加速,但使用 1.x 就可以了吗?
    • @DeapSoup in tf2,eager execution 默认开启,不再有 session 概念。如果你没有在 tf v1.x 中启用 Eager Execution,你最终会在你的代码中调用session.run 来获取网络输出。
    • 我明白了!非常感谢
    猜你喜欢
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    • 2022-11-08
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多