How to check if pytorch is using the GPU?

后端 未结 10 1258
既然无缘
既然无缘 2020-12-04 05:01

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,

10条回答
  •  天命终不由人
    2020-12-04 05:20

    Simply from command prompt or Linux environment run the following command.

    python -c 'import torch; print(torch.cuda.is_available())'
    

    The above should print True

    python -c 'import torch; print(torch.rand(2,3).cuda())'
    

    This one should print the following:

    tensor([[0.7997, 0.6170, 0.7042], [0.4174, 0.1494, 0.0516]], device='cuda:0')
    

提交回复
热议问题