Performance#
This page compares padaquad with torchdiffeq [Chen, 2018], the
differentiable ODE solver of Chen et al. [2018], on integrals with known
answers. Every number below comes from the files
docs/performance/results_<device>.json, written by
examples/speed_test/torchdiffeq_comparison.py; one table per file is rendered
when this page is built.
What is compared#
To compute \(\int_0^1 f(t)\,dt\), torchdiffeq solves the ODE \(dy/dt = f(t)\) with \(y(0) = 0\). An ODE solver must take its steps one after another, because in general each step needs the state the previous one produced. padaquad uses the fact that the integrand does not depend on \(y\): it evaluates the nodes of many subintervals in one call of \(f\). The comparison measures what that buys on one machine:
torchdiffeq
dopri5, solving \(dy/dt = f(t)\);padaquad
dopri5, the same Runge-Kutta weights used as a quadrature method, so the difference is mostly the batching;padaquad
gk21, padaquad’s default method.
The integrands are the five entries of integrand_dict (all on \([0, 1]\)) and a
small neural network with fixed weights (two hidden layers of 64 tanh units;
reference value from scipy.integrate.quad at a tolerance of \(10^{-14}\)). Each
solver runs at atol = rtol of \(10^{-6}\) and \(10^{-9}\).
For each case the script records the median wall time of 7 runs after one
warm-up run (with torch.cuda.synchronize around each run on a GPU), the
smallest and largest time, the number of points at which \(f\) was evaluated,
and the absolute error against the exact answer. padaquad runs with a fixed
max_batch, so its one-time memory benchmark is not timed, and with
take_gradient=False, because no gradient is computed (torchdiffeq’s forward
solve is timed without one too).
Read the errors as well as the times. The two libraries apply the tolerance differently: torchdiffeq tests each step’s error against \(\text{atol} + \text{rtol}\,|y|\), padaquad each subinterval’s against \(\max(\text{atol}, \text{rtol}\,|I|)\) (Error control). Equal tolerances therefore do not give equal accuracy.
Results#
Apple M2 Max (cpu)#
Measured on Apple M2 Max (cpu, 8 torch threads), 2026-11-12T09:37:17+00:00, padaquad commit 2ec1d44; torch 2.15.0, torchdiffeq 0.2.5, Python 3.14.6. Times are medians of 7 runs after one warm-up run.
Integrand |
Tolerance |
Solver |
Median time (ms) |
Range (ms) |
Evaluations |
Abs. error |
Speedup vs torchdiffeq |
|---|---|---|---|---|---|---|---|
t |
1e-06 |
torchdiffeq dopri5 |
1.49 |
1.47-1.66 |
32 |
2.8e-16 |
1.0x |
t |
1e-06 |
padaquad dopri5 |
0.93 |
0.90-1.04 |
78 |
0.0e+00 |
1.6x |
t |
1e-06 |
padaquad gk21 |
0.89 |
0.89-0.90 |
254 |
0.0e+00 |
1.7x |
t |
1e-09 |
torchdiffeq dopri5 |
1.44 |
1.43-1.46 |
32 |
2.8e-16 |
1.0x |
t |
1e-09 |
padaquad dopri5 |
0.89 |
0.88-0.91 |
78 |
0.0e+00 |
1.6x |
t |
1e-09 |
padaquad gk21 |
0.88 |
0.88-0.90 |
254 |
0.0e+00 |
1.6x |
t_squared |
1e-06 |
torchdiffeq dopri5 |
1.53 |
1.52-1.54 |
32 |
1.1e-16 |
1.0x |
t_squared |
1e-06 |
padaquad dopri5 |
0.90 |
0.88-0.91 |
78 |
5.6e-17 |
1.7x |
t_squared |
1e-06 |
padaquad gk21 |
0.88 |
0.88-0.89 |
254 |
5.6e-17 |
1.7x |
t_squared |
1e-09 |
torchdiffeq dopri5 |
1.53 |
1.52-1.55 |
32 |
1.1e-16 |
1.0x |
t_squared |
1e-09 |
padaquad dopri5 |
0.89 |
0.88-0.92 |
78 |
5.6e-17 |
1.7x |
t_squared |
1e-09 |
padaquad gk21 |
0.89 |
0.88-0.90 |
254 |
5.6e-17 |
1.7x |
sine_squared |
1e-06 |
torchdiffeq dopri5 |
13.52 |
13.49-13.76 |
272 |
1.5e-06 |
1.0x |
sine_squared |
1e-06 |
padaquad dopri5 |
2.26 |
2.22-2.42 |
414 |
1.4e-06 |
6.0x |
sine_squared |
1e-06 |
padaquad gk21 |
0.86 |
0.86-0.87 |
254 |
5.6e-17 |
15.7x |
sine_squared |
1e-09 |
torchdiffeq dopri5 |
40.94 |
39.41-41.89 |
794 |
1.1e-10 |
1.0x |
sine_squared |
1e-09 |
padaquad dopri5 |
3.35 |
3.27-3.59 |
1828 |
3.1e-09 |
12.2x |
sine_squared |
1e-09 |
padaquad gk21 |
0.88 |
0.87-0.89 |
254 |
5.6e-17 |
46.3x |
exp |
1e-06 |
torchdiffeq dopri5 |
3.55 |
3.54-3.60 |
74 |
4.5e-04 |
1.0x |
exp |
1e-06 |
padaquad dopri5 |
1.32 |
1.31-1.36 |
92 |
2.8e-06 |
2.7x |
exp |
1e-06 |
padaquad gk21 |
0.90 |
0.90-0.91 |
254 |
3.6e-15 |
3.9x |
exp |
1e-09 |
torchdiffeq dopri5 |
9.69 |
9.62-9.85 |
200 |
9.8e-09 |
1.0x |
exp |
1e-09 |
padaquad dopri5 |
2.25 |
2.23-2.30 |
288 |
8.1e-09 |
4.3x |
exp |
1e-09 |
padaquad gk21 |
0.92 |
0.92-0.93 |
254 |
3.6e-15 |
10.5x |
damped_sine |
1e-06 |
torchdiffeq dopri5 |
5.70 |
5.69-5.73 |
104 |
4.9e-06 |
1.0x |
damped_sine |
1e-06 |
padaquad dopri5 |
1.84 |
1.83-1.88 |
204 |
3.8e-07 |
3.1x |
damped_sine |
1e-06 |
padaquad gk21 |
0.93 |
0.92-0.94 |
254 |
2.1e-17 |
6.1x |
damped_sine |
1e-09 |
torchdiffeq dopri5 |
19.16 |
19.14-19.22 |
362 |
4.4e-09 |
1.0x |
damped_sine |
1e-09 |
padaquad dopri5 |
2.80 |
2.77-2.86 |
820 |
5.6e-10 |
6.9x |
damped_sine |
1e-09 |
padaquad gk21 |
0.92 |
0.92-0.93 |
254 |
2.1e-17 |
20.8x |
neural_network |
1e-06 |
torchdiffeq dopri5 |
3.09 |
3.08-3.11 |
50 |
2.0e-06 |
1.0x |
neural_network |
1e-06 |
padaquad dopri5 |
1.07 |
1.03-1.23 |
78 |
5.1e-07 |
2.9x |
neural_network |
1e-06 |
padaquad gk21 |
1.14 |
1.08-1.39 |
254 |
0.0e+00 |
2.7x |
neural_network |
1e-09 |
torchdiffeq dopri5 |
8.24 |
8.17-8.44 |
140 |
4.8e-09 |
1.0x |
neural_network |
1e-09 |
padaquad dopri5 |
2.92 |
2.82-3.07 |
246 |
6.5e-10 |
2.8x |
neural_network |
1e-09 |
padaquad gk21 |
1.19 |
1.14-1.52 |
254 |
0.0e+00 |
6.9x |
padaquad dopri5 is 1.6 to 12.2 times faster than torchdiffeq at the same tolerance; its error is above torchdiffeq’s in sine_squared at 1e-09 (3.1e-09 against 1.1e-10).
padaquad gk21 is 1.6 to 46.3 times faster than torchdiffeq at the same tolerance; its error is at or below torchdiffeq’s in every case.
What the results show#
The lines under each table are generated from its results file, like the table
itself. The observations below are written by hand from the CPU results
(results_cpu.json); check them again whenever a results file changes.
The gain is smallest on the simplest integrands (
t,t_squared), where both solvers finish in about a millisecond and fixed per-call costs dominate, and largest where torchdiffeq needs many sequential steps (sine_squared,damped_sineat the tighter tolerance).On these smooth integrands
gk21meets both tolerances on the starting mesh, without splitting a subinterval: its number of evaluations is the same at both tolerances.GPU runs are claimed only where a CUDA table appears above. The batching is expected to matter more on a GPU, where one call on many points costs little more than a call on one point, but that is an expectation, not a measurement.
Reproduce#
pip install -e ".[dev]" # includes torchdiffeq
python examples/speed_test/torchdiffeq_comparison.py --device cpu \
--out docs/performance/results_cpu.json
For a GPU, use --device cuda --out docs/performance/results_cuda.json; the
page then shows both tables. Then revise “What the results show” for the new
numbers. Commit the results file only from a clean
working tree: the file records the git commit, and marks uncommitted changes.