Loss.backward() error when using M1 GPU (mps device)

I want to train a Seq2Seq model with M1 GPU. The source code runs well with cpu. However, if I change the device from cpu to mps:

device = torch.device("mps")

RuntimeError occurs when training model:

RuntimeError: Expected a proper Tensor but got None (or an undefined Tensor in C++) for argument #0 'grad_y'


Hi, have you got the sulotion?

I am having this problem too, and cannot find any information on how to solve it.

same error, just can’t find a way to fix it.

  • loss on gpu and cpu
  • retain_grad
  • tried to push output and label to cpu before loss

Same issue here as well, it looks like it is due to the LSTM in my network. I tried a GRU too but to no avail. CPU is fine, cuda is fine on Linux.