I think (just hypothesising) this is due to the torch.empty tensors. You need to initialise the tensors in order for you to have grads for the .backward() method.
You could initialise the phis with random values and then check to see if the algorithm works and indeed is capable of autograd.