Open cyx96 opened 2 years ago
Providing an update here based on our private chat, in case someone else is interested: this should be done using IFT at the fixed-point, implementing a custom backward for the implicit step.
@cyx96 graciously offered to help implement this
for future readers who spend a few minutes trying to figure out what IFT is...
IFT = Implicit Function Theorem
First of all, thank you for this amazing library!
For my own research, I want to test implicit integrators with adjoint sensitivity method to train a neural network. While implicit Euler method provided by the library can be used to integrate ODEs (no gradient required), it is incompatible with adjoint sensitivity method which requires gradient information. The code snippet to reproduce the error is provided as below.
I will get the RuntimeError by executing the above code snippet:
RuntimeError: Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved tensors after calling backward.
Changing
adjoint
toautograd
prevented RuntimeError from happening, but the loss will not decrease during training. And I tried to modify the implicit Euler method by changingretain_graph
fromFalse
toTrue
, it didn't solve the issue. I think this issue has something to do with the LBFGS optimizer used by the library to find roots for the implicit integrator, but I don't really know how to fix it.Any help on this issue is much appreciated! Thanks in advance!