如何安装Tensorflow和CUDA驱动程序?



我已经安装了CUDA驱动程序和TensorFlow,但是我不能让TensorFlow使用我的CUDA驱动程序。

我的Windows 11 Pro版本是22H2。

我正在运行Anaconda Python 3.9.15.

这是我的CUDA驱动程序的信息(通过运行nvidia-smi):

Sat Apr  8 16:44:56 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 531.14                 Driver Version: 531.14       CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                      TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 2080 S...  WDDM | 00000000:01:00.0  On |                  N/A |
| N/A   48C    P8               10W /  N/A|   2049MiB /  8192MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

我安装的TensorFlow显示:

>pip install tensorflow
Requirement already satisfied: tensorflow in h:anaconda3libsite-packages (2.10.0)
Requirement already satisfied: wrapt>=1.11.0 in h:anaconda3libsite-packages (from tensorflow) (1.15.0)
Requirement already satisfied: keras<2.11,>=2.10.0 in h:anaconda3libsite-packages (from tensorflow) (2.10.0)
Requirement already satisfied: flatbuffers>=2.0 in h:anaconda3libsite-packages (from tensorflow) (23.1.21)
Requirement already satisfied: typing-extensions>=3.6.6 in h:anaconda3libsite-packages (from tensorflow) (4.5.0)
Requirement already satisfied: packaging in h:anaconda3libsite-packages (from tensorflow) (23.0)
Requirement already satisfied: absl-py>=1.0.0 in h:anaconda3libsite-packages (from tensorflow) (1.4.0)
Requirement already satisfied: opt-einsum>=2.3.2 in h:anaconda3libsite-packages (from tensorflow) (3.3.0)
Requirement already satisfied: numpy>=1.20 in h:anaconda3libsite-packages (from tensorflow) (1.21.6)
Requirement already satisfied: six>=1.12.0 in h:anaconda3libsite-packages (from tensorflow) (1.16.0)
Requirement already satisfied: libclang>=13.0.0 in h:anaconda3libsite-packages (from tensorflow) (14.0.6)
Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in h:anaconda3libsite-packages (from tensorflow) (0.27.0)
Requirement already satisfied: keras-preprocessing>=1.1.1 in h:anaconda3libsite-packages (from tensorflow) (1.1.2)
Requirement already satisfied: tensorflow-estimator<2.11,>=2.10.0 in h:anaconda3libsite-packages (from tensorflow) (2.10.0)
Requirement already satisfied: grpcio<2.0,>=1.24.3 in h:anaconda3libsite-packages (from tensorflow) (1.46.0)
Requirement already satisfied: setuptools in h:anaconda3libsite-packages (from tensorflow) (65.6.3)
Requirement already satisfied: astunparse>=1.6.0 in h:anaconda3libsite-packages (from tensorflow) (1.6.3)
Requirement already satisfied: termcolor>=1.1.0 in h:anaconda3libsite-packages (from tensorflow) (2.2.0)
Requirement already satisfied: tensorboard<2.11,>=2.10 in h:anaconda3libsite-packages (from tensorflow) (2.10.1)
Requirement already satisfied: protobuf<3.20,>=3.9.2 in h:anaconda3libsite-packages (from tensorflow) (3.19.6)
Requirement already satisfied: gast<=0.4.0,>=0.2.1 in h:anaconda3libsite-packages (from tensorflow) (0.4.0)
Requirement already satisfied: h5py>=2.9.0 in h:anaconda3libsite-packages (from tensorflow) (2.10.0)
Requirement already satisfied: google-pasta>=0.1.1 in h:anaconda3libsite-packages (from tensorflow) (0.2.0)
Requirement already satisfied: wheel<1.0,>=0.23.0 in h:anaconda3libsite-packages (from astunparse>=1.6.0->tensorflow) (0.40.0)
Requirement already satisfied: google-auth<3,>=1.6.3 in h:anaconda3libsite-packages (from tensorboard<2.11,>=2.10->tensorflow) (2.17.2)
Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in h:anaconda3libsite-packages (from tensorboard<2.11,>=2.10->tensorflow) (0.6.1)
Requirement already satisfied: werkzeug>=1.0.1 in h:anaconda3libsite-packages (from tensorboard<2.11,>=2.10->tensorflow) (2.2.3)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in h:anaconda3libsite-packages (from tensorboard<2.11,>=2.10->tensorflow) (0.4.6)
Requirement already satisfied: requests<3,>=2.21.0 in h:anaconda3libsite-packages (from tensorboard<2.11,>=2.10->tensorflow) (2.28.2)
Requirement already satisfied: markdown>=2.6.8 in h:anaconda3libsite-packages (from tensorboard<2.11,>=2.10->tensorflow) (3.4.3)
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in h:anaconda3libsite-packages (from tensorboard<2.11,>=2.10->tensorflow) (1.8.1)
Requirement already satisfied: rsa<5,>=3.1.4 in h:anaconda3libsite-packages (from google-auth<3,>=1.6.3->tensorboard<2.11,>=2.10->tensorflow) (4.9)
Requirement already satisfied: pyasn1-modules>=0.2.1 in h:anaconda3libsite-packages (from google-auth<3,>=1.6.3->tensorboard<2.11,>=2.10->tensorflow) (0.2.7)
Requirement already satisfied: cachetools<6.0,>=2.0.0 in h:anaconda3libsite-packages (from google-auth<3,>=1.6.3->tensorboard<2.11,>=2.10->tensorflow) (5.3.0)
Requirement already satisfied: requests-oauthlib>=0.7.0 in h:anaconda3libsite-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.11,>=2.10->tensorflow) (1.3.1)
Requirement already satisfied: importlib-metadata>=4.4 in h:anaconda3libsite-packages (from markdown>=2.6.8->tensorboard<2.11,>=2.10->tensorflow) (6.2.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in h:anaconda3libsite-packages (from requests<3,>=2.21.0->tensorboard<2.11,>=2.10->tensorflow) (1.26.15)
Requirement already satisfied: certifi>=2017.4.17 in h:anaconda3libsite-packages (from requests<3,>=2.21.0->tensorboard<2.11,>=2.10->tensorflow) (2022.12.7)
Requirement already satisfied: idna<4,>=2.5 in h:anaconda3libsite-packages (from requests<3,>=2.21.0->tensorboard<2.11,>=2.10->tensorflow) (3.4)
Requirement already satisfied: charset-normalizer<4,>=2 in h:anaconda3libsite-packages (from requests<3,>=2.21.0->tensorboard<2.11,>=2.10->tensorflow) (2.1.1)
Requirement already satisfied: MarkupSafe>=2.1.1 in h:anaconda3libsite-packages (from werkzeug>=1.0.1->tensorboard<2.11,>=2.10->tensorflow) (2.1.2)
Requirement already satisfied: zipp>=0.5 in h:anaconda3libsite-packages (from importlib-metadata>=4.4->markdown>=2.6.8->tensorboard<2.11,>=2.10->tensorflow) (3.15.0)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in h:anaconda3libsite-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard<2.11,>=2.10->tensorflow) (0.4.8)
Requirement already satisfied: oauthlib>=3.0.0 in h:anaconda3libsite-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.11,>=2.10->tensorflow) (3.2.2)

当我运行以下测试时,它显示TensorFlow找不到CUDA驱动程序

>python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
[]
  1. 检查您的CUDA安装是否有任何问题:

    nvcc - v

  2. 检查环境变量设置是否正确:CUDA_HOME:文件的路径CUDA安装目录。PATH: CUDA和cuDNN bin目录的路径。LD_LIBRARY_PATH: CUDA和cuDNN库目录的路径

  3. 如果TensorFlow正在检测你的GPU:

    导入tensorflow为tfprint (tf.config.list_physical_devices (GPU))

在TensorFlow原生Windows安装说明上有一个注释:

TensorFlow 2.10是最后一个在本机windows上支持GPU的TensorFlow版本。从TensorFlow 2.11开始,你需要在WSL2中安装TensorFlow,或者安装tensorflow-cpu,也可以选择尝试TensorFlow- directml - plugin。

所以如果你想继续使用Windows,你的选择如下:

  1. 使用旧版本的Tensorflow-GPU<= 2.10,并确保您正在使用来自测试构建配置的要求,用于具有GPU支持的Windows。例如,tensorflow-gpu版本2.8到2.10在Python 3.7-3.10, cuDNN 8.1和CUDA 11.2上进行了测试。

  2. 在运行Windows 10 19044或更高版本的Windows系统上安装Windows Subsystem for Linux (WSL2)。WSL允许用户运行Linux发行版(默认是Ubuntu,但也可以使用其他发行版),直接在Windows上使用Linux应用程序、实用工具等,而无需修改或虚拟机的开销。同样,还必须确保他们使用的是支持GPU的Linux的测试构建配置。例如,在撰写本文时,TensorFlow的最新版本是2.12,它需要Python版本3.8-3.11,cuDNN 8.6和CUDA 11.8。

如果你想认真对待开发,关心你的数据和隐私,并体验免费和开源软件社区的好处,那么更好的选择是迁移到Linux(假设你可以控制系统和它使用的操作系统)。

相关内容

  • 没有找到相关文章

最新更新