TL;DR
A neural ODE replaces a stack of layers with a single function that describes how a hidden state changes over time, . The output is the state at the end time, found by an ODE solver. The solver decides how many steps to take, so the effective depth is set by the required accuracy rather than by a fixed count of layers. Gradients are computed by solving a second ODE backwards, which uses memory that does not grow with the number of steps.
Where you'll see it: in continuous-depth models for irregularly sampled time series, in continuous normalising flows that transform one distribution into another, and as a conceptual bridge between residual networks and differential equations.
Intuition
A residual network is a ladder of tiny steps
Look at a residual block from residual connections. It takes the state and produces . Now compare that with the simplest possible step of a numerical method. To move a point along a curve with slope , Euler's method takes . Set and , and the two formulas are identical.
So a residual network is an Euler solver for an ODE, where each layer is one step and the number of layers is the number of steps. The neural ODE takes this seriously. It asks: what if the layers were infinitely many, each infinitesimally small, so the stack became a continuous flow? The answer is a differential equation, and the depth of the network becomes the length of time you run the flow.
Why this is useful
A fixed stack of layers has two awkward properties. First, the depth is a hyperparameter you pick by hand and cannot change without retraining. Second, the network can only read its output at the fixed layer boundaries, so it cannot naturally answer a question like "what is the state at time 0.3?"
A neural ODE fixes both. The state is defined at every time, so you can read it wherever you need it. The solver can use fine steps where the dynamics change quickly and coarse steps where they are gentle. And the same learned function can be run for more or less time without new parameters.
flowchart LR A[Input state at time zero] --> B[ODE solver] B --> C[Evaluate f at current state and time] C --> D[Take a step] D --> B D --> E[Output state at end time]
The math
The model
A neural ODE takes an input , sets the initial state , and defines the output as the state at a final time , where the state follows
The output is . The function is a neural network with parameters .
Here is the hidden state at time , and is the learned function that sets its rate of change. The notation is the derivative of the state with respect to time. The network does not need to be a function of ; the time argument is optional and is included here for generality. The solution is the solution of an ordinary differential equation with initial condition .
Recovering a residual network
Apply Euler's method with step size to the model above, from to , using steps so that :
Here is the state after steps and . Rename as the residual branch , and this is a stack of residual blocks. A residual network is a neural ODE solved with Euler's method at a fixed step size. Chen and colleagues made this observation, and it is the starting point for the rest of the lesson.
Gradients by the adjoint method
To train the model we need , where is the loss on the output . Storing every intermediate state and backpropagating through the solver, as in Backpropagation, works but costs memory that grows with the number of steps. The adjoint method avoids this.
Define the adjoint state . It obeys its own ODE, run backwards in time from :
with starting value . The gradient with respect to the parameters is an integral over the same backward path:
In practice the backward solve runs a single augmented ODE that carries , and the parameter gradient together. Its memory cost does not depend on the number of steps the solver takes.
Here is where the adjoint equation comes from. Over a short time , . By the chain rule, . Rearranging gives , and letting yields the equation above. It is the same calculation as Backpropagation through one residual block, repeated over infinitely many infinitesimal blocks.
The price is accuracy. Solving the state backwards from does not reproduce the forward states exactly, because each solve has its own error. That error enters the gradient.
Worked examples
Take the simplest possible dynamics , with and end time . The exact solution is .
- Use a single Euler step, so .
- Evaluate the rate at the start: .
- Update: .
The update with and is exactly a residual block whose branch returns . Its output, , is far from the true . One block is a very coarse solver.
Same problem, now with more steps. The step size is .
- Two steps, : , then .
- Four steps, : the state is multiplied by each step, so .
- Errors against : one step gives , two steps give , and four steps give .
The error falls as the step shrinks, and for small steps it falls roughly in proportion to , because Euler's method is first order. A solver chooses to meet a tolerance. A residual network with four blocks would be fixed at four steps whatever accuracy the task needed.
The same dynamics, with , can describe a process observed at irregular times. Suppose measurements arrive at and .
- At , the exact state is .
- At , the exact state is .
- A solver can be asked to return the state at exactly those times, so the model reads off both values directly (a numerical solver gives close approximations of these exact values).
A fixed stack of layers has no state at , so it would need interpolation or a fixed grid. The neural ODE produces the state at each requested time without any change to its parameters. This is why the model suits time series with gaps.
Tradeoffs and failure modes
Neural ODEs trade fixed structure for adaptivity. That helps in some settings and costs in others.
| Situation | Problem | Better choice |
|---|---|---|
| Fixed-depth task on discrete tokens | Adaptive solving gives no benefit, and each solve is slower than a fixed stack | An ordinary residual or transformer network |
| Stiff dynamics | The solver needs very small steps, and training becomes slow | An implicit solver, or a different parameterisation of |
| Adjoint gradients with a loose tolerance | The backward solve drifts from the forward trajectory, so gradients are inaccurate | Tighter tolerances, or backpropagating through the solver |
| Batches with very different dynamics | The solver takes the smallest step any item needs, which wastes compute | Batching by similar dynamics, or a shared step schedule |
| Output needed at few times | The solver still steps through every interval | Fixed coarse steps when accuracy allows |
| Need for exact invertibility | Invertibility holds in theory, but numerical inversion adds error | A model that is invertible by construction |
The main practical cost is that every forward and backward pass runs a numerical solver, and the number of function evaluations varies with the input. This makes timing less predictable than for a fixed network.
History
The link between residual networks and ODEs was noticed before neural ODEs were named. In 2017, Eldad Haber and Lars Ruthotto analysed deep residual networks as discretised differential equations, and used that view to design stable architectures.
Ricky Chen, Yulia Rubanova, Jesse Bettencourt and David Duvenaud made the step explicit in 2018. They used the adjoint method to train continuous-depth models with constant memory and showed them on classification, time series and density modelling. The paper received a best paper award at NeurIPS that year. The adjoint method itself is much older. It comes from optimal control theory, where it was used decades earlier to compute gradients of costs for dynamical systems.
The idea spread quickly. Continuous normalising flows, such as FFJORD in 2019, used neural ODEs to transform one distribution into another with a tractable likelihood. Latent ODE models later applied the same approach to irregular time series. The main lasting contribution is the view that depth can be a continuous quantity.
Check yourself
QuestionA residual block computes . Which step of which numerical method does it match, and what would make the match exact?Show answer
It matches one step of Euler's method, , with and . The two formulas coincide when the residual branch is the rate function itself, , with unit step size. Stacking blocks is repeated Euler steps. A finer method needs smaller steps, which means more blocks and smaller branches.
QuestionTake with . Run one Euler step with . What is after that step?Show answer
The rate at the start is . The update is . The exact solution at is , so one step under-estimates the growth. Smaller steps would bring it closer.
QuestionWhy does the adjoint method use constant memory with respect to the number of solver steps, and what does it give up in return?Show answer
The backward pass solves the augmented ODE for the state, the adjoint, and the parameter gradient in one run. It does not store the intermediate states of the forward solve, because it can re-solve them backwards. The cost is accuracy: the backward solve may not retrace the forward path exactly, so the computed gradient carries numerical error that depends on the solver tolerance.
QuestionYou want to model patient heart-rate measurements recorded at uneven times. Why might a neural ODE be a better fit than a fixed-depth recurrent network?Show answer
A neural ODE has a state defined at every time, so it can be read at each measurement time without padding or interpolation, and the solver takes steps that match the gaps between observations. A standard recurrent network treats inputs as evenly spaced steps and must be adapted for irregular gaps. The neural ODE handles both the timing and the dynamics in one model.