I had updated the torch.dot() to requires_grad=True but it gives the error:
One of the differentiated Tensors appears to not have been used in the graph. Set allow_unused=True if this is the desired behavior.
I believe this is from the summation. Updated:
outputs = model(torch.tensor([1.,2.5,3.5]))[1]
grad = torch.autograd.grad(outputs, model.parameters(), grad_outputs=None, retain_graph=True, create_graph=True, only_inputs=True, allow_unused=False)
print(grad)
eta =  [torch.rand(x.shape, requires_grad=True) for x in grad]
print(eta)
mult = torch.sum(torch.tensor([torch.dot(torch.flatten(x),torch.flatten(y)).item() for x,y in zip(grad,eta)], requires_grad=True))
print(mult)
grad1 = torch.autograd.grad(mult, model.parameters(), grad_outputs=None, retain_graph=None, create_graph=True, only_inputs=True, allow_unused=False)
print(grad1)