如何检查pytorch是否正在使用GPU? [英] How to check if pytorch is using the GPU?

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

问题描述

我想知道pytorch是否正在使用我的GPU.使用nvidia-smi可以检测在此过程中GPU是否有任何活动,但是我想要用python脚本编写的内容.

I would like to know if pytorch is using my GPU. It's possible to detect with nvidia-smi if there is any activity from the GPU during the process, but I want something written in a python script.

有办法吗?

推荐答案

这将起作用:

In [1]: import torch

In [2]: torch.cuda.current_device()
Out[2]: 0

In [3]: torch.cuda.device(0)
Out[3]: <torch.cuda.device at 0x7efce0b03be0>

In [4]: torch.cuda.device_count()
Out[4]: 1

In [5]: torch.cuda.get_device_name(0)
Out[5]: 'GeForce GTX 950M'

In [6]: torch.cuda.is_available()
Out[6]: True

这告诉我PyTorch正在使用GPU GeForce GTX 950M.

This tells me the GPU GeForce GTX 950M is being used by PyTorch.

这篇关于如何检查pytorch是否正在使用GPU?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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