英文:
Tensorflow only showing (and using) cpu when gpu is available
问题
当我使用TensorFlow时,它只使用CPU。我正在运行Windows 11,并且我有NVIDIA GeForce RTX 3050笔记本GPU。
当我运行:
from tensorflow.python.client import device_lib
import tensorflow as tf
print(device_lib.list_local_devices())
print(tf.sysconfig.get_build_info())
输出是:
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 278769507336930520
xla_global_id
<details>
<summary>英文:</summary>
When I use tensorflow it only uses the cpu. I am running windows 11 and I have NVIDIA GeForce RTX 3050 Laptop GPU.
When I run:
from tensorflow.python.client import device_lib
import tensorflow as tf
print(device_lib.list_local_devices())
print(tf.sysconfig.get_build_info())
The output is:
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 278769507336930520
xla_global_id: -1
]
OrderedDict([('is_cuda_build', False), ('is_rocm_build', False), ('is_tensorrt_build', False), ('msvcp_dll_names', 'msvcp140.dll,msvcp140_1.dll')])
This shows that tensorflow only uses CPU. I have all the libraries (cuda and cudnn) and when I run `nvcc -V` inside the command line it outputs:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:41:10_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
I have cudnn 8.6 installed. Running `cudnn.h` `cudnn.lib` `cudnn64_8.dll` it opens the files normally. These are the tensor* python libraries I have installed:
tensorboard 2.13.0
tensorboard-data-server 0.7.0
tensorboard-plugin-wit 1.8.1
tensorflow 2.13.0
tensorflow-datasets 4.9.2
tensorflow-estimator 2.13.0
tensorflow-intel 2.13.0
tensorflow-io-gcs-filesystem 0.31.0
tensorflow-metadata 1.13.1
I had cuda 12.2 installed and tried installing cuda 11.8 but it didn't help. I searched the web and found similar problems but nothing helped. I found something about tensorflow_gpu but I also found that it is not used.
**EDIT**: if it is important I use GeForce Experience and have the latest drivers: GeForce Game Ready Driver 536.67
</details>
# 答案1
**得分**: 1
你已经安装了TensorFlow 2.13,但对于原生Windows安装,仅支持TensorFlow 2.10及更早版本的GPU加速([见此链接][1])。
从GPU支持链接中:
> 注意:在原生Windows上,仅支持2.10或更早版本的GPU,从TF 2.11开始,不再支持Windows上的CUDA构建。要在Windows上使用TensorFlow GPU,您需要在WSL2中构建/安装TensorFlow或使用TensorFlow-DirectML-Plugin的tensorflow-cpu。
尝试将安装降级到tf 2.10,或使用Linux(您可以双启动、使用虚拟机或wsl)。希望这有所帮助。
Derek
[1]: https://www.tensorflow.org/install/source_windows
<details>
<summary>英文:</summary>
You have tensorflow 2.13 installed, but for native windows installs, GPU acceleration is only supported up to tensorflow 2.10 ([see here][1]).
From the link under GPU Support:
> Note: GPU support on native-Windows is only available for 2.10 or earlier versions, starting in TF 2.11, CUDA build is not supported for Windows. For using TensorFlow GPU on Windows, you will need to build/install TensorFlow in WSL2 or use tensorflow-cpu with TensorFlow-DirectML-Plugin
Try downgrading the install to tf 2.10, or use linux (you can dual boot, use a VM or wsl). Hope this helps.
Derek
[1]: https://www.tensorflow.org/install/source_windows
</details>
# 答案2
**得分**: 1
你需要首先检查你的Tensorflow是否可以使用GPU:
```python
print("tf.config.list_physical_devices('GPU')")
如果你看到类似于"/GPU:0"
的输出,那么你的Tensorflow可以使用GPU。
其次,在Tensorflow版本大于2.9时,库会自动找到并用于训练。我建议查看这个链接和这个链接,并检查与CUDA和TensorFlow版本兼容的版本。
第三,我建议你安装稳定版本的TensorFlow,比如2.9或2.10。
第四,你可以使用Ubuntu来获得更好的硬件和资源管理。
第五,检查CUDA是否成功安装,如果你在Windows上成功安装了CUDA,nvidia-smi
命令应该在命令行中可以正常工作。
英文:
you have the first check if your GPU is available in your Tensorflow with:
print("tf.config.list_physical_devices('GPU')")
then if you see something like: "/GPU:0"
your GPU is available in Tensorflow
second:, in Tensorflow >> 2.9, the library automatically finds a GPU and uses it for training. so I recommend seeing this and this links and checking what version is compatible with the CUDA and TensorFlow versions.
third: I recommend you install stable versions of TensorFlow (like 2.9, 2.10)
fourth: you can use Ubuntu for Better hardware and resource management.
five: check the CUDA is successfully installed, if you completely successfully install the CUDA in Windows, the nvidia-smi
command is working on cmd
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论