If I’m understanding correctly, you want to compute the second-order gradients wrt w. So you’d like to have phi.grad itself to have an autograd graph accumulating into w (and thus have requires_grad=True).
You could do this by doing wp.backward(create_graph=True).