Shift from CPU to GPU

PyTorch Notes

Posted by viewsetting on May 25, 2019

Check CUDA status

if torch.cuda.is_available():
    print("CUDA is READY")

1558779896716

Model

model = Seq2Seq()
model.cuda(0)

Variable

hidden = Variable(torch.zeros(1, 1, n_hidden)) # Previous
hidden = Variable(torch.zeros(1, 1, n_hidden)).cuda()  # Now

Input & Output Tensor

input_batch, output_batch, target_batch = make_batch(seq_data)
input_batch=input_batch.cuda()
output_batch=output_batch.cuda()
target_batch=target_batch.cuda()