Thank you, this seems to return correct results. One question though: why did you put v.detach() in the expression for jvp_val? I.e., why would something like this not work correctly?
def get_loss_fast(f, x, v):
    x = x.detach().requires_grad_()
    v = v.detach().requires_grad_()

    vjp_val = autograd.grad(f(x), x, v, create_graph=True)[0]
    jvp_val = autograd.grad(vjp_val, v, v)[0]  # instead of vjp_val, v, v.detach()

    return (vjp_val - jvp_val).norm(1)


Because of the detach at the beginning, no gradient will flow back to the input x or v if you try to backward the result of that function. Is that something you want?

Yes, it is exactly as I intend.