rtqichen / torchdiffeq

Differentiable ODE solvers with full GPU support and O(1)-memory backpropagation.
MIT License
5.61k stars 930 forks source link

underflow in dt nan #244

Closed huanranchen closed 6 months ago

huanranchen commented 1 year ago

Hi, when using dopri5 algorithm, it sometimes occurs "underflow in dt nan". Could we set a upper bound and a lower bound for dt to avoid such problems?

rtqichen commented 8 months ago

There is a min_step argument if you use any RK adaptive-step solver like the default dopri5. https://github.com/rtqichen/torchdiffeq/blob/master/torchdiffeq/_impl/rk_common.py#L146

odeint(..., method="dopri5", options={"min_step": 0.01})

Depending on your application, it might be worth thinking more about how to model a less stiff ODE though (if that is a possibility).

huanranchen commented 6 months ago

Thanks a lot!

This error occurs since dt is too small. By setting "min_step": 0.01, it works!

There is a min_step argument if you use any RK adaptive-step solver like the default dopri5. https://github.com/rtqichen/torchdiffeq/blob/master/torchdiffeq/_impl/rk_common.py#L146

odeint(..., method="dopri5", options={"min_step": 0.01})

Depending on your application, it might be worth thinking more about how to model a less stiff ODE though (if that is a possibility).

huanranchen commented 6 months ago

There is a min_step argument if you use any RK adaptive-step solver like the default dopri5. https://github.com/rtqichen/torchdiffeq/blob/master/torchdiffeq/_impl/rk_common.py#L146

odeint(..., method="dopri5", options={"min_step": 0.01})

Depending on your application, it might be worth thinking more about how to model a less stiff ODE though (if that is a possibility).

But this version (enabling setting min_step) hasn't been updated on pip. If we use pip to install torchdiffeq, we still cannot set min_step.

rtqichen commented 5 months ago

Thanks for letting me know. Latest version has been updated on pip.