Tensorflow 2.4.0尽管使用兼容版本,但未检测到GPU

2024-04-25 05:19:34 发布

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

我最近从TensorFlow1.x-gpu迁移到TensorFlow2。但是TF不再识别GPU了。 我使用Spyder和非Python解释器。我使用pip来管理我的包。操作系统是Windows10。GPU是GTX 1660 Ti,因此它确实支持CUDA

  • Py版本——Python 3.7
  • 当前TF版本--2.4.0
  • 当前CUDA版本--11.1
  • 当前CUDNN版本--8.0.4.30

-我已按照此处指定的方式复制了提取后的所有CUDNN DLL--https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html

-还添加了所有必要的路径变量。我已经安装了Visual Studio 2019以及以前安装的Visual代码(当 我曾经在我的GPU上运行tensorflow)

NVIDIA SMI output :-
C:\WINDOWS\system32>nvidia-smi
Tue Feb  9 17:08:11 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.40       Driver Version: 461.40       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| 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  GeForce GTX 166... WDDM  | 00000000:01:00.0 Off |                  N/A |
| N/A   76C    P0    26W /  N/A |    273MiB /  6144MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A     15272    C+G   ...n64\EpicGamesLauncher.exe    N/A      |
|    0   N/A  N/A     16500      C   ...iles\Python37\pythonw.exe    N/A      |
+-----------------------------------------------------------------------------+


nvcc --version :-
C:\WINDOWS\system32>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Oct_12_20:54:10_Pacific_Daylight_Time_2020
Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.relgpu_drvr455TC455_06.29190527_0

tf.test.is_gpu_available(cuda_only=False, min_cuda_compute_capability=None)
Out[9]: False

根据https://www.tensorflow.org/install/source,我安装了CUDNN和CUDA的正确组合。然而,tf不认识我的gpu。 提前感谢您抽出时间:)

编辑1——添加在cmd中导入tensorflow后收到的日志 编辑2--添加了Tensorflow logging messages do not appear中指定的日志级别

>>> os.environ['TF_CPP_MIN_VLOG_LEVEL']='3'
>>> os.environ['TF_CPP_MIN_LOG_LEVEL']='0'
>>> import tensorflow as tf
2021-02-09 18:10:16.489113:Itensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll
    2021-02-09 18:10:16.558283: I tensorflow/core/platform/cloud/gcs_file_system.cc:804] GCS cache max size = 0 ; block size = 67108864 ; max staleness = 0
    2021-02-09 18:10:16.562188: I .\tensorflow/core/platform/cloud/ram_file_block_cache.h:64] GCS file block cache is disabled
    2021-02-09 18:10:16.565031: I tensorflow/core/platform/cloud/gcs_file_system.cc:844] GCS DNS cache is disabled, because GCS_RESOLVE_REFRESH_SECS = 0 (or is not set)
    2021-02-09 18:10:16.568337: I tensorflow/core/platform/cloud/gcs_file_system.cc:874] GCS additional header DISABLED. No environment variable set.

编辑2——添加PyTorch注册GPU的证据,如How to check if pytorch is using the GPU?

import torch

torch.cuda.current_device()
Out[2]: 0

torch.cuda.device(0)
Out[3]: <torch.cuda.device at 0x222be69a8c8>

torch.cuda.device_count()
Out[4]: 1

torch.cuda.get_device_name(0)
Out[5]: 'GeForce GTX 1660 Ti'

torch.cuda.is_available()
Out[6]: True

Tags: 版本gpuisdevicetftensorflowtorchout