gpt4 book ai didi

python - 为什么在安装conda之后Tensorflow无法识别我的GPU?

转载 作者:行者123 更新时间:2023-12-03 09:46:48 59 4
gpt4 key购买 nike

我是深度学习的新手,最近两天我一直在徒劳地尝试在我的PC中安装tensorflow-gpu版本。我避免安装CUDA和cuDNN驱动程序,因为由于众多兼容性问题,一些在线论坛都不建议这样做。由于我之前已经使用过python的conda发行版,因此我按照在其官方网站https://anaconda.org/anaconda/tensorflow-gpu上编写的conda install -c anaconda tensorflow-gpu进行了购买。
但是,即使在全新的虚拟环境中安装了gpu版本(为避免与基本环境中pip安装的库可能发生冲突),出于某种神秘的原因,tensorflow甚至都无法识别我的GPU。
我运行了一些代码段(在anaconda提示符下)以了解它无法识别我的GPU:-
1。

>>>from tensorflow.python.client import device_lib
>>>print(device_lib.list_local_devices())
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 7692219132769779763
]
如您所见,它完全忽略了GPU。
2。
>>>tf.debugging.set_log_device_placement(True)
>>>a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
2020-12-13 10:11:30.902956: I tensorflow/core/platform/cpu_feature_guard.cc:142] This
TensorFlow
binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU
instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
>>>b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
>>>c = tf.matmul(a, b)
>>>print(c)
tf.Tensor(
[[22. 28.]
[49. 64.]], shape=(2, 2), dtype=float32)
在这里,应该通过显示 Executing op MatMul in device /job:localhost/replica:0/task:0/device:GPU:0(如此处所示: https://www.tensorflow.org/guide/gpu)来指示它与GPU一起运行,但是没有类似的东西存在。我也不知道第二行后面的消息是什么意思。
我也在网上搜索了几种解决方案,包括此处,但是几乎所有问题都与第一种手动安装方法有关,自从每个人都推荐这种方法以来,我还没有尝试过。
我不再使用cmd了,因为从基本环境中卸载tensorflow-cpu后,环境变量以某种方式弄乱了,并且在重新安装时,它与anaconda提示符完美配合,但与cmd完美配合。这是一个单独的问题(也是普遍存在的),但我提到它是为了在这里发挥作用。我将gpu版本安装在全新的虚拟环境中,以确保全新安装,并且据我了解,仅对于手动安装CUDA和cuDNN库需要设置路径变量。
我使用的卡:-(已启用CUDA)
C:\WINDOWS\system32>wmic path win32_VideoController get name
Name
NVIDIA GeForce 940MX
Intel(R) HD Graphics 620
我当前正在使用的Tensorflow和python版本:-
>>> import tensorflow as tf
>>> tf.__version__
'2.3.0'

Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
系统信息:Windows 10家庭版,64位操作系统,基于x64的处理器。
任何帮助将非常感激。提前致谢。

最佳答案

当前conda install tensorflow-gpu安装tensorflow v2.3.0,并且不安装conda cudnn或cudatoolkit软件包。手动安装它们(例如,使用conda install cudatoolkit=10.1)似乎也不能解决问题。
一种解决方案是安装tensorflow的早期版本,该版本的确会安装cudnn和cudatoolkit,然后使用pip进行升级

conda install tensorflow-gpu=2.1
pip install tensorflow-gpu==2.3.1
(2.4.0使用cuda 11.0和cudnn 8.0,但是截至2020年12月16日,cudnn 8.0不在anaconda中)
编辑:也请参阅@ GZ0的答案,该答案链接到具有单行解决方案的github讨论

关于python - 为什么在安装conda之后Tensorflow无法识别我的GPU?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65273118/

59 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com