How to check if pytorch is using the GPU?

后端 未结 10 1263
既然无缘
既然无缘 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:30

    This is going to work :

    In [1]: import torch
    
    In [2]: torch.cuda.current_device()
    Out[2]: 0
    
    In [3]: torch.cuda.device(0)
    Out[3]: 
    
    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
    

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

提交回复
热议问题