Sar*_*ose 17 python gpu path-variables anaconda tensorflow
我是深度学习的新手,过去 2 天我一直在尝试在我的电脑上安装 tensorflow-gpu 版本,但徒劳无功。我避免安装 CUDA 和 cuDNN 驱动程序,因为由于许多兼容性问题,几个在线论坛不推荐它。由于我之前已经在使用 python 的 conda 发行版,所以我conda install -c anaconda tensorflow-gpu按照他们的官方网站上写的那样去:https : //anaconda.org/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
]
Run Code Online (Sandbox Code Playgroud)
如您所见,它完全忽略了 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)
Run Code Online (Sandbox Code Playgroud)
在这里,它应该通过显示Executing op MatMul in device /job:localhost/replica:0/task:0/device:GPU:0(如此处所写:https : //www.tensorflow.org/guide/gpu)来表明它与 GPU 一起运行,但没有类似的东西存在。另外我不确定第二行之后的消息是什么意思。
我也在网上搜索了几个解决方案,包括这里,但几乎所有的问题都与第一种手动安装方法有关,因为每个人都推荐了这种方法,所以我还没有尝试过。
我不再使用 cmd 了,因为在从基础 env 卸载 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
Run Code Online (Sandbox Code Playgroud)
我目前使用的 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.
Run Code Online (Sandbox Code Playgroud)
系统信息:Windows 10 Home、64 位操作系统、基于 x64 的处理器。
任何帮助将非常感激。提前致谢。
geo*_*kal 40
August 2021 Conda install may be working now, as according to @ComputerScientist in the comments below, conda install tensorflow-gpu==2.4.1 will give cudatoolkit-10.1.243 and cudnn-7.6.5
The following was written in Jan 2021 and is out of date
Currently conda install tensorflow-gpu installs tensorflow v2.3.0 and does NOT install the conda cudnn or cudatoolkit packages. Installing them manually (e.g. with conda install cudatoolkit=10.1) does not seem to fix the problem either.
A solution is to install an earlier version of tensorflow, which does install cudnn and cudatoolkit, then upgrade with pip
conda install tensorflow-gpu=2.1
pip install tensorflow-gpu==2.3.1
Run Code Online (Sandbox Code Playgroud)
(2.4.0 uses cuda 11.0 and cudnn 8.0, however cudnn 8.0 is not in anaconda as of 16/12/2020)
Edit: please also see @GZ0's answer, which links to a github discussion with a one-line solution
@geometrikal 解决方案几乎对我有用。但在使用 conda 安装tensorflow-gpu 和使用 pip 安装tensorflow 2.3 之间,我需要卸载tensorflow-gpu 包的tensorflow 部分,以避免pip 发出一致性警告。Conda 会卸载整个软件包。我知道Conda 不建议将 pip 与 conda 混合使用,但这是有效的解决方案,我厌倦了再花一天时间来解决这个问题。
conda create -n tfgpu python=3.7
conda activate tfgpu
conda install tensorflow-gpu=2.1
pip uninstall tensorflow
pip uninstall tensorflow-estimator
pip uninstall tensorboard
pip uninstall tensorboard-plugin-wit
pip install tensorflow==2.3
pip check
Run Code Online (Sandbox Code Playgroud)
小智 5
我还无法让 TF 2.3.0 识别我的 Nvidia Quadro Pro 620 GPU。
注意:我在这台 PC(Windows Pro)上还有 2 个其他“环境”,全部通过 Anaconda 安装:
我的机器有 Cuda 11.1;cuDNN 8.0.5
我的下一个想法是考虑在第三个配置中将 Python 从 3.8.6 降级到 3.7.8,其中 TF = 2.3.0
史蒂夫
| 归档时间: |
|
| 查看次数: |
23431 次 |
| 最近记录: |