如何告诉 PyTorch 不使用 GPU? [英] How to tell PyTorch to not use the GPU?
问题描述
我想做一些 CPU 和 CPU 之间的时序比较GPU 以及一些分析,想知道是否有办法告诉 pytorch 不使用 GPU 而只使用 CPU?我意识到我可以安装另一个仅限 CPU 的 pytorch,但希望有更简单的方法.
I want to do some timing comparisons between CPU & GPU as well as some profiling and would like to know if there's a way to tell pytorch to not use the GPU and instead use the CPU only? I realize I could install another CPU-only pytorch, but hoping there's an easier way.
推荐答案
您可以在运行您的 Torch 代码之前通过 shell 将 CUDA_VISIBLE_DEVICES
变量设置为空.
You can just set the CUDA_VISIBLE_DEVICES
variable to empty via shell before running your torch code.
导出 CUDA_VISIBLE_DEVICES="
应该告诉 torch 没有 GPU.
Should tell torch that there are no GPUs.
export CUDA_VISIBLE_DEVICES=0"
会告诉它只使用一个 GPU(id 为 0 的那个)等等.
export CUDA_VISIBLE_DEVICES="0"
will tell it to use only one GPU (the one with id 0) and so on.
这篇关于如何告诉 PyTorch 不使用 GPU?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!