RuntimeError: derivative for aten::linear_backward is not implemented on MPS

Dear all,

I’m currently using Pytorch 1.13.1 on my Macbook M1 Pro

Long story short, I wanted to reproduce this notebook:
https://github.com/nanditadoloi/PINN/blob/main/solve_PDE_NN.ipynb on my machine. But obviously, I have to change the device to "mps"

However, it returns RuntimeError: derivative for aten::linear_backward is not implemented if I set device = torch.device("mps")

But it runs fine if I set the device to "cpu". Does anyone have a similar problem?

Addition: Just found the culprit. In the training step in the given link, it combines two loss functions the mse_u and mse_f. I tried to use mse_u only and it works fine on MPS, but when I tried mse_f only, the error message appear.

But I still have no idea why.

Thank you in advance

I work with PINNs on MPS too. It seems not all gradient calculation functions have been implemented for Apple Silicon MPS backend.

So we can’t calculate the PDE loss in the domain using MPS.

u_x = torch.autograd.grad(u.sum(), x, create_graph=True)[0]
u_t = torch.autograd.grad(u.sum(), t, create_graph=True)[0]

would throw errors.

This is a known problem. It seems you can still make it work by using the nightly version (only for linear layers). Please check the following issue: