I think it’s because you’re using the prior as the output. This works on 0.3.1:
prior = Variable(torch.zeros(24), requires_grad=True)
prior_param = nn.Parameter(prior.data)
h_test = torch.autograd.grad(outputs=prior_param.mean(), inputs=[prior_param])
h_test = torch.autograd.grad(outputs=prior.mean(), inputs=prior)

I’m not sure why the code you posted works for 0.4 and not 0.3.1, but it’s probably something to do with the tensor variable merge.