Hi,
I think you’re missing a optimizer.zero_grad() before the last .backward() that computes your gradient step.
Also a slight optimization to avoid computing all the gradients in the network in the when computing the force: force, = autograd.grad(energy, xi, create_graph=True).