skillfed

torchdiffeq

ODE solvers and adjoint sensitivity analysis in PyTorch.

torchdiffeq v0.2.5 1.1M downloads/30d#4,412 on PyPI6,472
Permissive license AGING released

What it is and what it does

torchdiffeq is a PyTorch library for solving ordinary differential equations (ODEs) with full support for automatic differentiation. It implements the main interface `odeint` which solves initial value problems of the form dy/dt = f(t, y) with y(t_0) = y_0, supporting multiple solver algorithms (Runge-Kutta variants, Adams methods, and others) and GPU execution.

The key capability is backpropagation through ODE solutions: you can compute gradients with respect to the initial condition, parameters, and time points. For deep learning applications, it provides an adjoint method that trades computation for memory, using O(1) memory during backprop by solving an adjoint ODE in the backward pass. The library also supports event-based termination (stopping when a condition is met) with differentiable event times and states, useful for physics-informed neural networks and other scientific computing tasks.

Use it for:

  • Training neural ODEs where the model is defined as a differential equation and gradients flow through the solver.
  • Physics-informed neural networks that need to differentiate through ODE solutions with memory efficiency.
  • Simulating and learning dynamics in continuous-time systems (e.g., bouncing ball, learned physics models).
  • Sensitivity analysis where you need gradients of ODE solutions with respect to parameters or initial conditions.
  • GPU-accelerated scientific computing requiring both forward ODE integration and backpropagation.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides PyTorch-based ODE solvers with backpropagation support through the adjoint method, enabling differentiable solutions to ordinary differential equations with constant memory cost.

Yes, if you need differentiable ODE solving in PyTorch. The library is well-established (6472 stars, top 5000 PyPI), has low install friction, permissive licensing, and no known vulnerabilities. The aging maintenance status (631 days since release) is a minor concern but the repo remains active. Install it when you're building neural ODEs, physics-informed models, or any system requiring gradients through ODE solutions.

Install

torchdiffeq on PyPI

pip

pip install torchdiffeq

uv

uv add torchdiffeq

poetry

poetry add torchdiffeq

Installing torchdiffeq

Before you install

Low friction install with only torch and scipy as runtime dependencies. Package is aging (631 days since last release) but repository remains active and unarchived with strong community adoption (6472 stars).

License in practice

MIT license (permissive) means you can use this freely in commercial and private projects with minimal restrictions.

Quickstart

pip install torchdiffeq

from torchdiffeq import odeint

# Solve dy/dt = f(t, y) with initial condition y0 at times t
result = odeint(func, y0, t)

# For memory-efficient backprop through adjoint method:
from torchdiffeq import odeint_adjoint as odeint
result = odeint(func, y0, t)  # func must be nn.Module

When using odeint_adjoint, func must be a torch.nn.Module to collect parameters; direct function callables will not work with the adjoint method.

Verify before relying

  • Whether the adjoint method's O(1) memory claim holds for all problem sizes and solver configurations in practice.
  • Performance characteristics on GPU versus CPU for typical problem scales.
  • Numerical stability guarantees for backpropagation through different solver methods beyond dopri5.

Package facts

License not declared (permissive)
Python support supports the current Python release (~=3.6)
Install friction low — pure-Python wheel
Runtime dependencies 2 — torch, scipy
Maintenance aging — 631 days since the last release
Last repo commit
First released
Downloads 1,067,062/month — #4,412 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: torchdiffeq-0.2.5-py3-none-any.whl

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3

Tags

pytorch ode solverdifferentiable ode solverneural odeadjoint sensitivity analysisbackprop through odeodeint pytorchgpu ode solver
neural-odeadjoint-methoddifferentiable-computing

More Artificial Intelligence packages

Further reading