Issue
I have a tensor
t = torch.zeros((4, 5, 6))
How to check if it is on gpu or not, and send it to gpu and back?
Solution
use t.is_cuda
, t.cuda()
, t.cpu()
t = torch.randn(2,2)
t.is_cuda # returns False
t = torch.randn(2,2).cuda()
t.is_cuda # returns True
t = t.cpu()
t.is_cuda # returns False
When passing to and from gpu and cpu, new arrays are allocated on the relevant device.
Answered By - Gulzar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.