Neural ODEs & FFJORD
Continuous-depth networks via neural ordinary differential equations: the adjoint method for memory-efficient training, FFJORD's trace estimator for free-form flows, and the connection between depth and continuous dynamics.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- From ResNets to Neural ODEs
- The Adjoint Method
- FFJORD: Free-Form Continuous Flows
- ODE Solvers for Neural ODEs
- Regularization of Neural ODEs
- Augmented Neural ODEs
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Derive neural ODEs as the continuous-depth limit of ResNets.
- Explain the adjoint method for memory-efficient backpropagation.
- Derive FFJORD's training objective with Hutchinson's trace estimator.
- Compare fixed-step vs adaptive ODE solvers for neural ODEs.
- Explain why augmented neural ODEs overcome topological limitations.
Notation
- — hidden state at continuous time
- — neural network defining dynamics
- — adjoint state
Core Intuition
A ResNet computes — a discrete Euler step. Taking the step size to zero: . This is a neural ODE: a network with "infinite depth" and continuous dynamics. Memory cost becomes independent of depth (via adjoint method), and the output is a diffeomorphism — making it a natural fit for normalizing flows.
Neural ODE Vector Field
From ResNets to Neural ODEs
ResNet (discrete): , for .
Neural ODE (continuous limit):
Output: .
Properties:
- Continuous depth: no fixed number of layers.
- Always invertible (ODE solutions with Lipschitz are diffeomorphisms).
- Adaptive computation: harder inputs use more solver steps.
The Adjoint Method
Problem: Backpropagation through layers needs memory (store all intermediate states). For neural ODEs with many solver steps, this is prohibitive.
Solution: Compute gradients by solving an adjoint ODE BACKWARD in time:
Parameter gradients:
Memory: in the number of solver steps (only store and , then integrate backward).
Tradeoff: Saves memory but doubles compute (forward + backward ODE solve). Also, numerical errors in backward solve can accumulate.
FFJORD: Free-Form Continuous Flows
FFJORD (Grathwohl et al., 2019): Combine neural ODE with the instantaneous change of variables:
Problem: Computing requires backprop passes (one per dimension).
Hutchinson's estimator:
The vector-Jacobian product costs ONE backward pass. Unbiased estimate with ONE random vector.
Training: Solve augmented ODE:
ODE Solvers for Neural ODEs
Fixed-step methods:
- Euler: . Error: .
- RK4: 4 function evaluations per step. Error: . Standard choice.
Adaptive methods (Dormand-Prince, dopri5):
- Adjust step size based on local error estimate.
- Fewer steps where dynamics are smooth; more where they're rapid.
- Default for neural ODE training.
Training consideration: Adaptive solvers make training non-deterministic (different samples may use different numbers of steps). This can cause issues with batch normalization and learning rate scheduling.
Regularization of Neural ODEs
Problem: Unregularized neural ODEs can learn extremely complex dynamics with many solver steps (expensive at inference).
Kinetic energy regularization:
Penalizes high-velocity dynamics → smoother trajectories → fewer solver steps.
Jacobian regularization: Penalize to encourage simple dynamics.
Effect: 2-3x reduction in NFE (number of function evaluations) with minimal quality loss.
Augmented Neural ODEs
Limitation: A neural ODE in defines a homeomorphism — it cannot change topology. For example, it cannot map a circle to two disconnected points.
Solution (Dupont et al., 2019): Augment the state with extra dimensions:
Intuition: By lifting to higher dimensions, trajectories can "pass around" each other. Project back to original dimensions at the end.
Analogy: Like a highway overpass — cars can cross paths without collision by using the vertical dimension.
Common Pitfalls
Pitfall 1. Using the adjoint method for short-horizon ODEs. For fewer than 20 solver steps, standard backpropagation is faster (adjoint has overhead from backward ODE solve).
Pitfall 2. Not regularizing dynamics complexity. Without regularization, the model may learn dynamics requiring 200+ solver evaluations — impractical for inference.
Pitfall 3. Expecting neural ODEs to scale to high-dimensional image generation. FFJORD works well for tabular/low-dim data but struggles beyond 64x64 images. Use flow matching instead for high-res.
Summary
- Neural ODE: Continuous-depth limit of ResNet; always invertible.
- Adjoint method: memory backpropagation through ODE (at 2x compute cost).
- FFJORD: Free-form continuous flow with Hutchinson trace estimator.
- Adaptive solvers: Automatically adjust compute based on dynamics complexity.
- Regularization: Penalize velocity to keep solver steps manageable.
- Augmented: Extra dimensions overcome topological limitations.
Exercises
Exercise 1. For a neural ODE with dimensions: compare the memory cost of standard backprop (100 solver steps) vs adjoint method.
Exercise 2. Derive the adjoint ODE (equation 2) using the Lagrangian/KKT approach.
Exercise 3. Show that a 2D neural ODE cannot separate two concentric circles (topological argument).
Exercise 4. Compute the variance of Hutchinson's trace estimator for a matrix with known trace. How many vectors needed for 10% relative error?
Exercise 5. Compare FFJORD vs RealNVP in BPD on 2D density estimation tasks (two moons, pinwheel). Explain which performs better and why.