0
votes

I'm trying to get this code running using FloydHub's GPU. When I run the train.py script under train_model folder, I'm getting the RuntimeError mentioned.

Here is the full traceback:

Traceback (most recent call last):
File "./train_model/train.py", line 79, in
answer = model(batch)
File "/usr/local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/floyd/home/train_model/model.py", line 29, in forward
vecs = self.embed(batch.text)
File "/usr/local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.6/site-packages/torch/nn/modules/sparse.py", line 110, in forward
self.norm_type, self.scale_grad_by_freq, self.sparse)
File "/usr/local/lib/python3.6/site-packages/torch/nn/functional.py", line 1110, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)

RuntimeError: Expected object of type torch.cuda.LongTensor but found type torch.LongTensor for argument #3 'index'

I understand that parts of code are using GPU and other parts aren't but not knowing how to identify these and get all of the code to run on GPU.

Please help!

1

1 Answers

0
votes

The error comes while forward function is being called. As the error says, the forward function "Expected object of type torch.cuda.LongTensor", I reckon that your input batch is still in the CPU, and needs to be transferred to the cuda device.

I feel that you already know how to do it, but if you don't, please read-up https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html#training-on-gpu.

Hope it helps, let me know if you need more help. :)