dpernes:

create_graph=True)


Hi albanD, I hope to compute Hessian matrix, and I write the following codes:
class Net(torch.nn.Module):
  def __init__(self, iS):
    super(Net, self).__init__()
    self.layer = torch.nn.Linear(iS, 1)
  def forward(self, inputs):
    outputs = self.layer(inputs)
    return outputs.mean()
net = Net(10)
inputs = torch.rand(256, 10)
loss = net(inputs)
first_order_grads = torch.autograd.grad(loss, net.parameters(), retain_graph=True, create_graph=True)
# strange .... first_order_grads[0].requires_grad = False, should it be True?
second_order_grads = torch.autograd.grad(first_order_grads, net.parameters())
# the above line does not work

Do you have any suggestions? Thanks!