Hi,
Yes you can take any degree of derivatives by calling backward() or autograd.grad() on the output of such function.
That being said, in your example, I don’t see any second derivative. You update t, then evaluate f with this new t, then update theta right?