【问题标题】:Installing tensorflow-gpu via conda-forge results in using CPU-only tensorflow通过 conda-forge 安装 tensorflow-gpu 会导致使用 CPU-only tensorflow
【发布时间】:2018-09-20 13:37:31
【问题描述】:

我正在创建一个 conda 环境,仅用于使用来自 conda-forge 频道的 tensorflow-gpu 包

conda create -n tst -c conda-forge tensorflow-gpu

这导致tensorflow-gpu 和 tensorflow 软件包都被安装:

The following NEW packages will be INSTALLED:

    _tflow_1100_select: 0.0.1-gpu
    ...
    tensorboard:        1.10.0-py36_0         conda-forge
    tensorflow:         1.10.0-py36_0         conda-forge
    tensorflow-gpu:     1.10.0-hf154084_0
    ...

然后当我导入 tensorflow 时,它看不到 GPU:

>>> import tensorflow as tf
>>> tf.test.is_gpu_available()
2018-09-20 15:29:21.778708: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
False

问题:

  • 为什么 conda 只需要 tensorflow-gpu 和 tensorflow 软件包时同时安装前者?
  • 两个包能否和平共存,如果可以,如何在两者之间切换?
  • 加分项:为什么从主频道(即conda create -n tst tensorflow-gpu)安装时一切正常? (我没有根据的猜测是,在conda-forge 中,tensorflow-gpu 包实际上来自主通道,因此在导入期间具有较低的优先级。

【问题讨论】:

  • 我不能告诉你为什么,但我可以确认这发生在我身上,因为我也是从conda-forge 频道安装的。阅读这个问题帮助我解决了我的 tensorflow-gpu 问题,非常感谢 :) 并为你点赞!

标签: python tensorflow conda


【解决方案1】:

通过查看 conda-forge (https://conda-forge.org/feedstocks/) 上的软件包列表,那里似乎没有 tensorflow-gpu 软件包。 conda-forge 和默认 anaconda 软件包之间存在一些奇怪的兼容性问题 - 我通常会尽量避免将两者混用。

即使你安装为conda install -c anaconda tensorflow-gpu,它也会同时拉入非GPU的tensorflow包,但运行

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

找到 GPU。所以它似乎自动使用启用 GPU 的版本。如果我想避免使用 GPU,我可能会使用 with tf.device([CPU ID here]) 来结束我的训练。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-14
    • 2019-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 2021-06-05
    相关资源
    最近更新 更多