Hi, I am trying to replicate the tensorflow hessian vector product 170 implementation.
This is the code :
criterion = nn.CrossEntropyLoss()
inputs, labels = Variable(inputs.cuda()),Variable(labels.cuda())
model.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, labels)

grads = torch.autograd.grad(loss,model.parameters(),create_graph=True) 

elem_prod =  [ grad * vi for grad,vi in zip(grads,v) ]

# Is grad_ouptuts correct here ?
Hvp = torch.autograd.grad(elem_prod, model.parameters(),grad_outputs=[torch.ones(i.size()).type(torch.cuda.FloatTensor) for i in grads],create_graph=True)

The second grad() here takes in a non-scalar input, is the above implementation right way to do it ?
Thanks.