TL;DR
Chen, Rubanova, Bettencourt and Duvenaud (2018) build a deep network whose hidden state is not produced by a fixed list of layers. A small neural network defines how fast the hidden state changes, and an off-the-shelf ODE solver computes where the state ends up. Gradients come from the Adjoint Sensitivity Method, which runs a second ODE backwards in time, so the memory cost does not grow with the number of solver steps. The paper tests this on MNIST digits, on density estimation with continuous normalizing flows, and on irregularly sampled time series.
Builds on: Neural Ordinary Differential Equation, Adjoint Sensitivity Method, Normalizing Flow · Leads to: Flow Matching, Flow Matching for Generative Modeling
Why it mattered
The paper made depth a continuous quantity. In its MNIST experiment, the six residual blocks of a small network were replaced by one call to a solver. The resulting ODE-Net reached 0.42 percent test error with 0.22 million parameters, while the residual network it was compared with reached 0.41 percent with 0.60 million parameters. The memory needed for training stayed constant as the solver took more steps, where the residual network's memory grew with its number of layers. A ResNet needs that memory to store every block's activations; the ODE-Net needs one state and one adjoint.
The paper also gave the community a usable tool. The authors released torchdiffeq, a PyTorch library with GPU implementations of standard solvers and the adjoint backward pass. Researchers building models in continuous time could then call a solver the way they call a layer.
Its generative part opened a line of work that continues today. A continuous normalizing flow moves samples from a simple distribution to a data distribution by following a learned flow, and it scores data by an exact formula. Flow Matching keeps the same picture of generation as an ODE from noise to data, but trains the velocity field directly. Much of the vocabulary of modern continuous-time generative models comes from this paper.
The problem
Before the paper, the standard deep networks were already a discrete approximation of an ODE. A residual block updates the state as , which is one Euler step of size 1 for the rule . Three problems followed from that.
The first is memory. Training a deep network means keeping the intermediate state of every layer, because backpropagation needs them. A network with layers stores states. An adaptive ODE solver may take many more steps than there are layers, and it chooses how many steps to take at run time, so the stored values are not even known in advance.
The second is that depth is fixed. A stack of layers spends the same computation on an easy input and on a hard one. An ODE solver can spend more steps where the dynamics change quickly and fewer where they change slowly, to hit a chosen error tolerance.
The third is irregular data. A recurrent network expects observations on a fixed grid of times, so measurements that arrive at uneven times have to be binned or padded. A differential equation has a state at every real-valued time, so it can be queried at each observation time directly.
For continuous normalizing flows there was a fourth obstacle. The change-of-variables formula needs the determinant of a Jacobian, whose cost grows with the cube of the dimension, which limits how wide each flow layer can be.
How it works
Take the smallest possible instance: a state with one number, dynamics with one parameter, a start value , an end time , and the loss . Here .
-
Input. The start state is and the parameter is . The network is a single multiplication by . No hidden layer is needed to show the idea.
Check: the rate of change at the start is , so the state should fall.
-
Forward solve. A solver follows the rate from to . The exact answer is , so . A crude Euler solver with two steps of size 0.5 gives and then . The solver's job is to choose steps so that the error stays inside a tolerance. The result of this step is the output .
Check: with the exact answer the loss is . The Euler answer 0.25 is off by about 0.12, which is why a serious solver adapts its step size.
-
Loss gradient at the output. The loss is , so its derivative with respect to the final state is . This is the only thing the backward pass starts from.
Check: increasing by 0.1 raises by 0.1, so the slope is 1.
-
Backward solve for the adjoint. Define , which starts at . Its rule is , since . Solving backwards from gives , so .
Check: the loss is for start value , so . The adjoint gives the same number.
-
Gradient with respect to the parameter. The parameter enters through . The gradient is . Here is constant, so the integral is .
Check: for , directly, so . The two agree.
The whole training step is therefore one forward solve and one backward solve. The backward solve needs at each time, and the method gets it by running backwards alongside from its final value, so no forward state has to be stored.
flowchart LR Z0[z of 0] --> FWD[forward solve with f] FWD --> ZT[z of t1] ZT --> LOSS[loss L] LOSS --> ADJ[backward solve for a and the parameter gradient] ADJ --> G[gradient with respect to z of 0 and theta]
The math
The model defines the output as the end point of an initial value problem.
Given a start state and a network , the output is
The right-hand side names the solver. Its internal steps are not part of the model.
Step 2 in symbols: the forward solve
The solver returns and the loss is . Nothing else from the solver's steps is kept for the backward pass, which is where the memory saving comes from.
Step 4 in symbols: the adjoint
The adjoint is the gradient of the loss with respect to the state at time :
To see where the second line comes from, take one small step of size . The state moves by , so the map from to is the identity plus . The chain rule then gives . Moving the term across and dividing by gives the equation above as goes to zero.
In the tiny example, , so , which is the rule used in step 4.
Step 5 in symbols: the parameter gradient
The gradient with respect to the parameters is an integral of the adjoint against the parameter's effect on the dynamics:
The integral runs backwards from to . The minus sign in front turns it into the ordinary forward integral from to of the same integrand.
In practice the paper solves all three quantities in a single backward call. It stacks them into one augmented state , where accumulates the parameter gradient, with . Solving this backwards from to leaves the parameter gradient in :
Each product is a vector-Jacobian product: a row vector times a matrix that is never written out. Automatic differentiation computes it at a cost close to one evaluation of (see Automatic Differentiation).
The instantaneous change of variables
For a continuous flow , the log density of the moving sample changes by
The trace is the sum of the diagonal entries of a square matrix. The discrete formula needed a determinant, and the trace is much cheaper. Integrating this rate from to gives the total change in log density along the trajectory, so the density at the end follows from the density at the start. The trace is also linear, so if is a sum of terms, the log-density rate is the sum of the traces. A continuous layer with hidden units therefore costs time that grows only linearly with .
Results
MNIST classification (Table 1). The paper compared a one-layer multilayer perceptron, a residual network, a Runge-Kutta network that backpropagates through the solver, and an ODE-Net.
| Model | Test error | Parameters | Memory | Time |
|---|---|---|---|---|
| 1-layer MLP (from LeCun et al., 1998) | 1.60% | 0.24 M | not reported | not reported |
| ResNet | 0.41% | 0.60 M | grows with layers L | grows with L |
| RK-Net | 0.47% | 0.22 M | grows with solver evaluations | grows with solver evaluations |
| ODE-Net | 0.42% | 0.22 M | constant, O(1) | grows with solver evaluations |
The ODE-Net matches the residual network's error within 0.01 points, with fewer parameters and constant training memory. The paper's claim is parity in accuracy with a different cost profile, not a gain in accuracy.
Error control. The forward cost grows roughly in proportion to the number of function evaluations, so tightening the tolerance trades speed for precision. The paper also suggests training at high accuracy and testing at lower accuracy, which is possible because the tolerance is a run-time setting.
Continuous normalizing flows. On density matching, a planar continuous flow with hidden units reached a lower loss than a planar normalizing flow with layers, which the paper reports as generally lower loss in its figure. The two flows were not trained under identical budgets, so the comparison is about the model form more than the exact numbers. On maximum-likelihood density estimation, the continuous flow with 64 hidden units fitted the two-circles and two-moons data, while the discrete flow with 64 one-unit layers had trouble with the moons.
Latent ODE time series (Table 2). On 1000 two-dimensional spirals sampled at 100 times and corrupted by noise, the predictive root-mean-squared error on 100 later time points was as follows, when only 30, 50 or 100 of the observed points were used.
| Observed points | RNN | Latent ODE |
|---|---|---|
| 30 of 100 | 0.3937 | 0.1642 |
| 50 of 100 | 0.3202 | 0.1502 |
| 100 of 100 | 0.1813 | 0.1346 |
The latent ODE is ahead at each sampling level, and its advantage is largest when the data are sparsest.
Limits. The experiments are small: MNIST, a handful of density datasets, and one synthetic spiral dataset. The paper's own section on scope lists three practical costs. Minibatching is less straightforward, because a batch shares one solver and may need more steps. Choosing tolerances is a user decision. And reversing the dynamics can add numerical error. The paper's results therefore show that the method works and has the right cost structure, not that it beats well-tuned discrete networks in general.
Tradeoffs and when to use it
A common mistake is to think that the adjoint method is always cheaper than backpropagating through the solver. It saves memory, but the backward solve recomputes the states, so each training step costs roughly one more solve. The paper reports that the adjoint method is memory efficient and, in its MNIST setting, comparable in time. Direct backpropagation through the solver is simpler and can be more exact when memory is not the bottleneck.
It is tempting to think a neural ODE has a fixed depth because the network is fixed. In fact the number of function evaluations depends on the input and on the tolerance, and the solver chooses it. Two inputs can use different amounts of computation through the same model. The paper treats this as a feature, but it makes timing harder to predict.
A second mistake is to think a small error tolerance is always better. Tight tolerances cost more evaluations. The authors chose 1e-3 for classification and 1e-5 for density estimation, and reported that these did not hurt performance. Sequence models used a much tighter tolerance.
A third mistake is to think that running the dynamics backwards recovers the forward trajectory exactly. It recovers it only up to numerical error, and the error can grow if the reconstruction drifts from the original. Checkpointing the forward states is one remedy, at the cost of some of the memory saving.
Use a neural ODE when the data arrives at irregular times, when you want an explicit accuracy-speed control, or when depth should adapt per input. Do not use it when a fixed, cheap stack of layers already works, because the solver adds overhead and tuning. Alternatives include residual networks with reversible blocks, which the paper cites as achieving constant memory with restricted architectures, and recurrent networks with time stamps concatenated to their inputs.
Reading guide
- Abstract and Section 1. Read with Residual Connection and Euler Method in mind. The residual update is one Euler step, and the paper's central move is to take the step size to zero.
- Section 2, reverse-mode differentiation. Needs Chain Rule, Backpropagation and Jacobian Matrix. The main technical content is the adjoint equation, derived in Adjoint Sensitivity Method. Figure 2 is about the observation times, which matter for the latent model.
- Section 3, supervised learning. Needs Convolutional Neural Network and Deep Residual Learning for Image Recognition (ResNet) for the baseline, and Stochastic Gradient Descent for training. Read Table 1 for the trade-off, not the exact error values.
- Section 4, continuous normalizing flows. Needs Normalizing Flow, Change of Variables Formula, Determinant, Trace of a Matrix and Probability Density Function. Read the instantaneous change of variables as the continuous form of the discrete determinant term.
- Section 5, latent ODE time series. Needs Variational Autoencoder, Kullback–Leibler Divergence and Recurrent Neural Network (the baseline). The Poisson process likelihood is a counting model for event times; the paper uses it only as an extra term.
- Section 6, scope and limitations. Needs Lipschitz Continuity, which is the condition under which a differential equation has one solution.
- Appendix A. Connects the instantaneous change of variables to Fokker–Planck Equation and continuity equations.
- Appendix B. Repeats the adjoint derivation in continuous backpropagation form, using the same notation as Section 2.
Check yourself
QuestionIn one sentence, what does the network f define in a neural ODE, and what is the output?Show answer
The network defines the rate of change of the hidden state, . The output is the state at the end time , which the ODE solver computes from the start state by following that rate.
QuestionIn the tiny example with , , and , what is to three decimal places?Show answer
The exact output is , so . The adjoint gives the same result: with gives . Also , so at every time, and the integral over is .
QuestionWhy does the adjoint method use less memory than backpropagating through every solver step?Show answer
Backpropagation through the solver would store every intermediate state the solver visits, and the number of those grows with the number of steps. The adjoint method stores only the final state and the adjoint, then recomputes the earlier states by running the dynamics backwards from the end. Its memory therefore does not grow with the number of solver steps.
QuestionA sensor reports values at irregular times 0.2, 0.9 and 3.7. A recurrent network needs a fixed time grid. Why does the neural ODE not need one, and what would it do at time 5.0?Show answer
The neural ODE defines a state at every real-valued time, so the solver can stop at 0.2, 0.9, 3.7, and 5.0 as requested, with no bins or padding. Predicting at 5.0 means continuing the same solve past 3.7 to 5.0, with no new model and no new bins.
Sources
- Chen, Rubanova, Bettencourt, Duvenaud (2018). Neural Ordinary Differential Equations. https://arxiv.org/abs/1806.07366
- torchdiffeq, the PyTorch implementation of ODE solvers and the adjoint method released by the authors. https://github.com/rtqichen/torchdiffeq