Issue
How do I check if pytorch
is using the 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.
Solution
These functions should help:
>>> import torch
>>> torch.cuda.is_available()
True
>>> torch.cuda.device_count()
1
>>> torch.cuda.current_device()
0
>>> torch.cuda.device(0)
<torch.cuda.device at 0x7efce0b03be0>
>>> torch.cuda.get_device_name(0)
'GeForce GTX 950M'
This tells us:
- CUDA is available and can be used by one device.
Device 0
refers to the GPUGeForce GTX 950M
, and it is currently chosen by PyTorch.
Answered By - vinzee
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.