Ah, sorry, I should have clarified that it’s the first line that creates an error.
I’ve gotten a bit closer by doing:
d1 = torch.autograd.grad(loss, model.linear.weight, create_graph=True)

Although currently giving me another error: “one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [13, 1]], which is output 0 of TBackward, is at version 151; expected version 150 instead.” (Trying to sort out what’s gone awry now)