RuntimeError: Gradients are not CUDA tensors

I am getting the following error.

File "/net/if5/wua4nw/wasi/academic/research_with_prof_chang/projects/question_answering/duplicate_question_detection/source/train.py", line 62, in train
    loss.backward()
  File "/if5/wua4nw/anaconda3/lib/python3.5/site-packages/torch/autograd/variable.py", line 145, in backward
    self._execution_engine.run_backward((self,), (gradient,), retain_variables)
  File "/if5/wua4nw/anaconda3/lib/python3.5/site-packages/torch/autograd/function.py", line 208, in _do_backward
    result = super(NestedIOFunction, self)._do_backward(gradients, retain_variables)
  File "/if5/wua4nw/anaconda3/lib/python3.5/site-packages/torch/autograd/function.py", line 216, in backward
    result = self.backward_extended(*nested_gradients)
  File "/if5/wua4nw/anaconda3/lib/python3.5/site-packages/torch/nn/_functions/rnn.py", line 210, in backward_extended
    grad_hx)
  File "/if5/wua4nw/anaconda3/lib/python3.5/site-packages/torch/backends/cudnn/rnn.py", line 360, in backward_grad
    raise RuntimeError('Gradients aren\'t CUDA tensors')
RuntimeError: Gradients aren't CUDA tensors

      

when run loss.backward()

in pytorch. The forward propagation works fine, but when the backpropagation step is executed, I get the error. Can anyone suggest me how to solve the problem?

PS: I am not posting the source code since it is too long!

+3


source to share





All Articles