如何告诉 PyTorch 不使用 GPU? [英] How to tell PyTorch to not use the GPU?

查看:306
本文介绍了如何告诉 PyTorch 不使用 GPU?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一些 CPU 和 CPU 之间的时序比较GPU 以及一些分析,想知道是否有办法告诉 不使用 GPU 而只使用 CPU?我意识到我可以安装另一个仅限 CPU 的 ,但希望有更简单的方法.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆