torchdiffeq
ODE solvers and adjoint sensitivity analysis in PyTorch.
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 torchdiffequv
uv add torchdiffeqpoetry
poetry add torchdiffeqInstalling 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
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
torchcdeProvides differentiable GPU-capable solvers for…
permissive · top 15,000 on PyPI
torchsdeSolves stochastic differential equations (SDEs)…
permissive · top 5,000 on PyPI
diffraxDiffrax provides numerical solvers for…
permissive · top 15,000 on PyPI
pybammsolverspybammsolvers provides a Python interface to…
unclear · top 15,000 on PyPI
optimistixOptimistix provides nonlinear solvers for root…
permissive · top 15,000 on PyPI
autogradAutograd automatically computes derivatives of…
permissive · top 5,000 on PyPI
pytorch_revgradImplements a gradient reversal layer for…
permissive · top 15,000 on PyPI
torch-optimizerProvides a collection of alternative…
permissive · top 15,000 on PyPI
adam-atan2-pytorchProvides an Adam optimizer variant using atan2…
permissive · top 15,000 on PyPI
POTPOT provides solvers for optimal transport…
permissive · top 15,000 on PyPI