Ok, then you can just do:
# This is pseudo code, you can have a list of params from `model.parameters()` for example
# Also the autograd.grad return tuples so some massaging and for loops for gradients update may be needed
t = torch.rand(xxx, requires_grad=True)
theta = torch.rand(xxx, requires_grad=True)

out = f(t, theta)
loss = F.mse(out, target)

gradt = autograd.grad(loss, t, retain_graph=True, create_graph=True)

new_t = t - gradt

new_out = f(new_t, theta)
new_loss = F.mse(new_out, target)

gradtheta = autograd.grad(new_loss, theta)

new_theta = theta - gradtheta