通过 conda-forge 安装 tensorflow-gpu 会导致使用仅限 CPU 的 tensorflow

use*_*974 5 python conda tensorflow

我正在创建一个 conda 环境,仅用于使用频道中的tensorflow-gpuconda-forge

conda create -n tst -c conda-forge tensorflow-gpu
Run Code Online (Sandbox Code Playgroud)

这会导致安装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
    ...
Run Code Online (Sandbox Code Playgroud)

然后当我导入 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
Run Code Online (Sandbox Code Playgroud)

问题:

  • 为什么当只需要前者时,conda 会同时安装tensorflow-gputensorflow包?
  • 两个包可以和平共存,如果可以,如何在两者之间切换?
  • 加分项:为什么从主渠道安装时一切正常,即conda create -n tst tensorflow-gpu?(我未受过教育的猜测是,在 中conda-forgetensorflow-gpu包实际上来自主渠道,因此在导入期间具有较低的优先级)。

nwe*_*eir 2

从 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())
Run Code Online (Sandbox Code Playgroud)

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