I do think torchdiffeq is essential for reproducing the error. After a bit of print-debugging I’ve figured out that when I call odeint_adjoint, the state vector x is a leaf node that requires grad, while it is not a leaf node when I directly call forward() in a no_grad() context. Also, if I use the vanilla odeint function from torchdiffeq instead of odeint_adjoint, there is no error. So I think it’s potentially some bug in torchdiffeq— I’ll need to look into it some more.