Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pytorch check if using gpu

import torch

torch.cuda.is_available()
>>> True

torch.cuda.current_device()
>>> 0

torch.cuda.device(0)
>>> <torch.cuda.device at 0x7efce0b03be0>

torch.cuda.device_count()
>>> 1

torch.cuda.get_device_name(0)
>>> 'GeForce GTX 950M'
Comment

pytorch check gpu

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
Comment

pytorch check GPU

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
#或device = torch.device("cuda:0")
device1 = torch.device("cuda:1")  
for batch_idx, (img, label) in enumerate(train_loader):
    img=img.to(device)
    label=label.to(device)
Comment

How do I check if PyTorch is using the GPU?

>>> 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'
Comment

PREVIOUS NEXT
Code Example
Python :: python get file size in mb 
Python :: matplotlib axis rotate xticks 
Python :: matplotlib install 
Python :: remove all pyc files 
Python :: open firefox python 
Python :: simple flask hello world 
Python :: python currnent time 
Python :: how to use headless browser in selenium python 
Python :: change figure size pandas 
Python :: string to date python 
Python :: python sort a dictionary by values 
Python :: python start simplehttpserver 
Python :: scipy version check 
Python :: python slow print 
Python :: conda create environment python 3.6 
Python :: get stats from array python 
Python :: python download image 
Python :: change tkinter window name 
Python :: validation split python 
Python :: how to check the django version on a mac 
Python :: txt to list python 
Python :: how to get image in jupyter notebook 
Python :: update numpy in python 
Python :: plot to image python 
Python :: df iterrows pandas 
Python :: unzip file python 
Python :: subtract one hour from datetime python 
Python :: python typing as int or float 
Python :: plus or minus symbol 
Python :: beuatiful soup find a href 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =