I have implemented a sequence-to-sequence model in PyTorch (v. 0.3.0post4) [Ubuntu 16.04] using Recurrent Neural Networks. I am trying to use pin_memory() to speed up the training as follows:
input_tensor = torch.LongTensor(...))
target_var = Variable(torch.LongTensor(...))
if USE_CUDA:
input_var = input_tensor.pin_memory()
target_var = target_var.cuda(async=True)
But during training, I get the following error:
File "xyz.py", line 224, in batch_pairs
target_var = target_var.cuda(async=True)
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/variable.py", line 298, in cuda
return CudaTransfer.apply(self, device, async)
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/_functions/tensor.py", line 201, in forward
return i.cuda(async=async)
File "/usr/local/lib/python3.5/dist-packages/torch/_utils.py", line 69, in _cuda
return new_type(self.size()).copy_(self, async)
RuntimeError: invalid argument 3: Source tensor must be contiguous at /pytorch/torch/lib/THC/generic/THCTensorCopy.c:114
I have no idea what could be causing this. Any tips would be appreciated. Thanks!