如何使用TensorFlow GPU?

2024-04-28 04:25:25 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在Python 3.6x64中使用TensorFlow GPU版本而不是CPU版本?

import tensorflow as tf

Python正在使用my CPU进行计算。
我可以注意到,因为我有一个错误:

Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

我已经安装了tensorflow和tensorflow gpu。

如何切换到GPU版本?


Tags: import版本yourthatgpumytftensorflow
3条回答

首先需要安装tensorflow gpu,因为这个包负责gpu计算。还要记住使用环境变量CUDA_VISIBLE_DEVICES=0运行代码(或者如果有多个gpu,请将它们的索引用逗号表示)。可能有一些与使用gpu相关的问题。如果tensorflow不使用gpu,try this

遵循本教程Tensorflow GPU我做到了,它工作得很好。

注意!-安装9.0版!Tensorflow gpu不支持较新版本

步骤:

  1. 卸载旧的tensorflow
  2. 安装tensorflow gpupip install tensorflow-gpu
  3. 安装Nvidia显卡和驱动程序(您可能已经安装了)
  4. 下载并安装CUDA
  5. 下载并安装cuDNN
  6. 用简单程序验证

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

我试着遵循上面的教程。事情是tensorflow改变了很多,在GPU上运行所需的NVIDIA版本也改变了很多。下一个问题是,你的驱动程序版本决定了你的工具包版本等等。从今天起,关于软件需求的这些信息应该能帮助你了解它们是如何相互作用的:

NVIDIA® GPU drivers —CUDA 9.0 requires 384.x or higher.
CUDA® Toolkit —TensorFlow supports CUDA 9.0.
CUPTI ships with the CUDA Toolkit.
cuDNN SDK (>= 7.2) Note: Make sure your GPU has compute compatibility >3.0
(Optional) NCCL 2.2 for multiple GPU support.
(Optional) TensorRT 4.0 to improve latency and throughput for inference on some models.

并且here您将发现tensorflow所述的最新需求(希望它们定期更新)。

相关问题 更多 >