gradient computed through _select_initial_step
Author: LeonardoPascottoCreated Sep 13, 2026Updated Sep 13, 2026
Hello everyone,
First of all, thank you very much for your work on this phenomenal library.
Regarding the issue: to my understanding, when computing the gradient backpropagating through an adaptive ODE solver, the calculation of the optimal step size should be ignored.
This is indeed the case for _optimal_step_size, which is called with the @torch.no_grad() decorator. However, the first step is computed using another function, _select_initial_step, which lacks the @torch.no_grad() decorator and is therefore not detached from the computational graph.
While this is a minor issue, perhaps it would be possible to add @torch.no_grad() to _select_initial_step as well.
Best regards, Leonardo
Source: rtqichen/torchdiffeq