【问题标题】:Tensorflow not detecting GPU where as Pytorch doesTensorflow 没有像 Pytorch 那样检测 GPU
【发布时间】:2021-03-13 01:55:34
【问题描述】:

ubuntu 18.04, 英伟达MX150, CUDA 10.1, 使用$ pip install tensorflow$ pip install tensorflow-gpu 安装的张量流。 问题是它没有检测到 GPU,但是当使用 pytorch 进行尝试时它会检测到。似乎找不到问题。 提前致谢。 Jupyterlab output when tried to test GPU

edit 1 - 我已将 CUDA_VISIBLE_DEVICES 设置为 0,我可以手动检测 GPU,但 tensorflow 无法检测到,我还没有尝试源构建选项。

【问题讨论】:

    标签: python tensorflow pytorch gpu


    【解决方案1】:

    您可以通过多种方式检查 TensorFlow 是否检测到 GPU。请尝试以下方法并根据我进一步更新我的答案更新问题。

    with tf.Session() as sess:
      devices = sess.list_devices()
    

    还有,

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

    如果您能够检测到 GPU,但未设置 TensorFlow,则可能是您的环境变量存在问题。有很多线程在讨论如何在 SO 上为 TensorFlow 设置 GPU。

    来自this post -

    1. 使用 CUDA_VISIBLE_DEVICES 环境变量。通过设置环境变量 CUDA_VISIBLE_DEVICES="1" 使只有设备 1 可见,通过设置 CUDA_VISIBLE_DEVICES="0,1" 使设备 0 和 1 可见。您可以在 python 中通过在导入 os 包后添加一行 os.environ["CUDA_VISIBLE_DEVICES"]="0,1" 来做到这一点。

    2. 使用 tf.device('/gpu:2') 并创建图形。然后它将使用 GPU 设备 2 运行。

    3. 使用 config = tf.ConfigProto(device_count = {'GPU': 1}) 然后 sess = tf.Session(config=config)。这将使用 GPU 设备 1。

    最后,如果以上方法都不能解决,请查看官方 TensorFlow repo 上的this GitHub issue。有人在这里回答说从源代码构建 TensorFlow 后他们的问题得到了解决。 Here is a link 了解如何做到这一点。

    【讨论】:

      猜你喜欢
      • 2020-12-04
      • 2019-04-02
      • 2023-03-19
      • 1970-01-01
      • 2020-11-17
      • 2017-09-15
      • 1970-01-01
      • 2021-05-12
      • 2018-05-31
      相关资源
      最近更新 更多