Neural ODEs, Adjoints, and Continuous Flows
Dive into Deep Learning · §38.3
Neural ODEs, Adjoint Sensitivity, and Continuous Flows
continuous-depth ResNets · Pontryagin adjoint ODE · Liouville trace rule · Hutchinson FFJORD
Why Discrete Normalizing Flows Hit an O(d³) Wall
Motivation
Training an invertible discrete layer \mathbf{g} : \mathbb{R}^d \to \mathbb{R}^d by maximum likelihood requires the Jacobian determinant:
\log p_{\text{out}}(\mathbf{g}(\mathbf{x})) = \log p_{\text{in}}(\mathbf{x}) - \log\left|\det \mathbf{J}_{\mathbf{g}}(\mathbf{x})\right|
- The O(d^3) determinant wall: For a 32 \times 32 RGB image (d = 3072), \det\mathbf{J}_{\mathbf{g}} costs \approx 2 \times 10^{10} FLOPs/layer, forcing triangular/coupling restrictions.
- Continuous-time escape: Replacing discrete layers with \dot{\mathbf{x}} = \mathbf{f}_{\boldsymbol{\theta}}(\mathbf{x}, t) converts \log|\det\mathbf{J}| into the trace integral -\int_0^T \operatorname{tr}(\mathbf{J})\,dt, estimated unbiasedly in 1 VJP.
Residual Networks as Forward Euler Discretizations
From ResNets to ODEs
Setting a residual block beside a forward-Euler step of an ODE reveals that a ResNet is a discretized dynamical system with unit step size h = 1:
- Discrete Residual Block (l = 0, \ldots, L-1): \mathbf{x}_{l+1} = \mathbf{x}_l + \mathbf{f}_{\boldsymbol{\theta}_l}(\mathbf{x}_l)
- Forward Euler Step (t_n = nh): \mathbf{x}_{n+1} = \mathbf{x}_n + h\,\mathbf{f}(\mathbf{x}_n, t_n)
- Qualitative Gap Between Steps and Flows: On \dot{x} = -x, the exact flow \Phi_t(x) = e^{-t}x is a smooth bijection for every t \in \mathbb{R}, whereas a single Euler step with h = 1 maps x \mapsto x - x = 0, collapsing all of \mathbb{R} onto the origin.
The Neural ODE Limit: Four Gains and Four Catches
The Continuous Model
Taking the continuous limit \mathbf{x}(T) = \mathbf{x}_0 + \int_0^T \mathbf{f}_{\boldsymbol{\theta}}(\mathbf{x}(t), t)\,dt trades four theoretical gains against four practical catches:
- 1. Bijective flow \Phi_T \leftrightarrow non-crossing paths preserve 1D order.
- 2. Adaptive test-time solver \leftrightarrow coarse Euler training fits a discrete program.
- 3. O(1)-memory adjoint ODE \leftrightarrow backward state integration amplifies rounding by e^{\lambda T}.
- 4. Trace likelihood -\operatorname{tr}(\mathbf{J}) \leftrightarrow Hutchinson probes add Monte Carlo variance.
Catch 1: Continuous Flows on the Line Preserve Order
Topological Expressivity
Because trajectories of a Lipschitz ODE cannot cross in space-time, a 1D Neural ODE is strictly less expressive than a 1-step residual block:
- Strict Monotonicity on \mathbb{R}: If x < y, their trajectories under \dot{z} = f(z, t) can never meet (by Picard–Lindelöf uniqueness applied backward from any crossing), so \Phi_T(x) < \Phi_T(y) for all T > 0.
- Why Reflection x \mapsto -x Fails in 1D: Swapping -1 and +1 reverses order. A discrete residual step x + f(x) with f(x) = -2x achieves x \mapsto -x because hL = 2 > 1 jumps over the crossing.
- 2D Augmentation Fix: Embedding x \mapsto (x, 0) \in \mathbb{R}^2 and rotating by \dot{\mathbf{x}} = \pi\mathbf{K}\mathbf{x} yields \Phi_1 = e^{\pi\mathbf{K}} = -\mathbf{I}, carrying (x, 0) \to (-x, 0) along non-crossing semicircles.
Discretize-Then-Optimize: Training Through a Solver
Training Setup
To map 64 points on the unit circle to an ellipse centered at (1.5, 0) with semi-axes (1.2, 0.4), we train a 32-unit tanh network by backpropagating directly through N = 10 unrolled steps (h = 0.1) of either Euler or RK4:
Euler-trained: loss 1.5e+00, 3.1e-06, 5.2e-07 at iterations 0, 200, 400
RK4-trained: loss 1.5e+00, 4.3e-06, 5.8e-07 at iterations 0, 200, 400
Judged on the 10-step objective they were trained on, both runs reduce the endpoint MSE from O(1) to below 10^{-5}.
Catch 2: Did We Learn a Continuous Flow or a Program?
Test-Time Refinement
What happens if we evaluate the trained vector fields at finer step counts (N = 100 and N = 1000, keeping Nh = 1) to approach their true continuous time-1 flows, or test forward-backward round-trip invertibility?
N Euler-trained RK4-trained Euler round trip
10 9.0e-04 9.8e-04 5.4e-02
100 1.7e-02 9.8e-04 5.5e-03
1000 1.9e-02 9.8e-04 5.5e-04
- Euler Trained a 10-Step Program: Refining the step size makes the Euler-trained network worse (error jumps from 9 \times 10^{-4} to 2 \times 10^{-2}), because its weights compensated for coarse h = 0.1 truncation error.
- RK4 Trained a True Flow: Because 10 RK4 steps were already exact to working precision, its endpoint error stays at 1.2 \times 10^{-3} across all step counts N \in \{10, 100, 1000\}.
- Discrete Round-Trip Error: Running N forward Euler steps followed by N backward Euler steps misses \mathbf{x}_0 by O(h) = O(1/N) (5.5 \times 10^{-2} \to 5.5 \times 10^{-4}).
Three Paradigms for Training Continuous Vector Fields
Computational Trade-Offs
- Unrolled Forward Euler (N = 10): Costs 10 fwd + 10 bwd evaluations and O(N) memory, but fits the coarse 10-step discretization (refining N at test time increases error).
- Unrolled Classical RK4 (N = 10): Costs 40 fwd + 40 bwd evaluations, matching the true continuous flow to O(h^4) across all test-time solvers.
- Score & Flow Matching (§§38.6–38.7): Regresses directly onto closed-form targets in 1 fwd + 1 bwd evaluation and O(1) memory with no ODE solver in the training loop.
Continuous Backpropagation: The Adjoint State a(t)
The Adjoint Method
In a discrete network, reverse-mode automatic differentiation propagates the sensitivity \mathbf{a}_l = \frac{\partial\mathcal{L}}{\partial\mathbf{x}_l} backward from layer l+1 to layer l. In continuous time, we track the adjoint state at every instant t \in [0, T]:
\mathbf{a}(t) = \frac{\partial\mathcal{L}}{\partial\mathbf{x}(t)} \in \mathbb{R}^d, \qquad \text{with terminal condition } \mathbf{a}(T) = \nabla_{\mathbf{x}}\ell(\mathbf{x}(T))
- Worked Scalar Case (\dot{x} = \theta x, x(0) = x_0, \mathcal{L} = \frac{1}{2}x(T)^2):
- Direct Differentiation: Since x(T) = e^{\theta T}x_0, \frac{\partial\mathcal{L}}{\partial\theta} = x(T)\frac{\partial x(T)}{\partial\theta} = T\,x(T)^2 (= e^2 \approx 7.389 at \theta = T = x_0 = 1).
- Adjoint Perspective: A state perturbation \delta x(t) at time t is magnified by the remaining flow e^{\theta(T-t)} at time T, so a(t) = e^{\theta(T-t)}x(T), which satisfies the backward ODE \dot{a}(t) = -\theta a(t).
Scalar Adjoint Geometry: Constant Product a(t)x(t)
Adjoint Geometry
A parameter perturbation \delta\theta nudges the velocity at instant t by \frac{\partial f}{\partial\theta}\delta\theta = x(t)\delta\theta, and the adjoint a(t) converts that nudge into its final impact on \mathcal{L}:
- Forward State Growth: x(t) = e^{\theta t}x_0 grows exponentially from t = 0 to T.
- Backward Adjoint Decay: a(t) = e^{\theta(T-t)}x(T) grows backward from T to 0 (shrinking when read left-to-right).
- Exact Cancellation in the Product: \frac{\partial\mathcal{L}}{\partial\theta} = \int_0^T a(t)\,\frac{\partial f}{\partial\theta}(x(t), \theta)\,dt = \int_0^T x(T)^2\,dt = T\,x(T)^2
Pontryagin’s Continuous Adjoint Equations
General Theorem
For \dot{\mathbf{x}} = \mathbf{f}(\mathbf{x}, \boldsymbol{\theta}, t) and terminal loss \mathcal{L} = \ell(\mathbf{x}(T)), the adjoint \mathbf{a}(t) = \frac{\partial\mathcal{L}}{\partial\mathbf{x}(t)} and parameter gradient solve backward in time from \mathbf{a}(T) = \nabla\ell(\mathbf{x}(T)):
\dot{\mathbf{a}}(t) = -\left(\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\right)^{\!\top}\mathbf{a}(t), \qquad \frac{\partial\mathcal{L}}{\partial\boldsymbol{\theta}} = \int_0^T \left(\frac{\partial\mathbf{f}}{\partial\boldsymbol{\theta}}\right)^{\!\top}\mathbf{a}(t)\,dt
- One VJP per step: Both products are standard reverse-mode vector–Jacobian products seeded with \mathbf{a}(t), never forming the d \times d Jacobian.
Variational Proof of the Continuous Adjoint Equations
Derivation
Why does the minus sign and transposed Jacobian -(\frac{\partial\mathbf{f}}{\partial\mathbf{x}})^\top appear in the backward adjoint ODE?
- Linearize a Parameter Perturbation (\delta\boldsymbol{\theta}): Differentiating \dot{\mathbf{x}} = \mathbf{f}(\mathbf{x}, \boldsymbol{\theta}, t) shows how the trajectory perturbation \delta\mathbf{x}(t) evolves from \delta\mathbf{x}(0) = \mathbf{0}: \delta\dot{\mathbf{x}}(t) = \frac{\partial\mathbf{f}}{\partial\mathbf{x}}\,\delta\mathbf{x}(t) + \frac{\partial\mathbf{f}}{\partial\boldsymbol{\theta}}\,\delta\boldsymbol{\theta}
- Differentiate the Pairing \mathbf{a}(t)^\top\delta\mathbf{x}(t): By the product rule, choosing \dot{\mathbf{a}} = -(\frac{\partial\mathbf{f}}{\partial\mathbf{x}})^\top\mathbf{a} makes the state-coupling terms cancel identically: \frac{d}{dt}\left(\mathbf{a}^\top\delta\mathbf{x}\right) = \dot{\mathbf{a}}^\top\delta\mathbf{x} + \mathbf{a}^\top\delta\dot{\mathbf{x}} = -\mathbf{a}^\top\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\delta\mathbf{x} + \mathbf{a}^\top\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\delta\mathbf{x} + \mathbf{a}^\top\frac{\partial\mathbf{f}}{\partial\boldsymbol{\theta}}\delta\boldsymbol{\theta} = \mathbf{a}^\top\frac{\partial\mathbf{f}}{\partial\boldsymbol{\theta}}\delta\boldsymbol{\theta}
- Integrate from 0 to T: Using \delta\mathbf{x}(0) = \mathbf{0} and \mathbf{a}(T)^\top\delta\mathbf{x}(T) = \delta\mathcal{L} yields \delta\mathcal{L} = \left(\int_0^T \mathbf{a}(t)^\top\frac{\partial\mathbf{f}}{\partial\boldsymbol{\theta}}\,dt\right)\delta\boldsymbol{\theta}.
Discretize-Then-Optimize vs. Optimize-Then-Discretize
Discrete vs. Continuous Adjoint
- Discretize-then-optimize (Backprop): Differentiates the N-step Euler program exactly via \mathbf{a}_n = (\mathbf{I} + h\mathbf{J}(\mathbf{x}_n))^\top\mathbf{a}_{n+1} (stored with 2\sqrt{N} activation checkpoints).
- Optimize-then-discretize (Continuous adjoint): Integrates \dot{\mathbf{a}} = -\mathbf{J}^\top\mathbf{a} backward; if \mathbf{x}(t) is re-integrated backward without checkpoints, a contracting mode \lambda = 50 amplifies
fp64 rounding by e^{50T} \approx 5 \times 10^{21}.
Measuring Discrete vs. Continuous Adjoints in 2D
Numerical Verification
On the planar spiral \dot{\mathbf{x}} = \mathbf{A}\mathbf{x} with loss \mathcal{L} = \frac{1}{2}\|\mathbf{x}(T)\|^2 at T = 2, the continuous adjoint integral is \frac{\partial\mathcal{L}}{\partial\mathbf{A}} = \int_0^T \mathbf{a}(t)\mathbf{x}(t)^\top\,dt:
N = 1000: |backward sweep - central differences| = 1.2e-10
N = 100: |discrete - continuous adjoint| = 2.9e-02
N = 1000: |discrete - continuous adjoint| = 2.8e-03
N = 10000: |discrete - continuous adjoint| = 2.8e-04
Catch 3: Backward Integration Amplifies Drift by e^(λT)
Memory vs. Numerical Drift
Evaluating the Jacobian \mathbf{J}(\mathbf{x}(t)) during the backward adjoint pass requires the forward states \mathbf{x}(t). What goes wrong if we discard the forward tape and re-integrate \dot{\mathbf{x}} = \mathbf{f}(\mathbf{x}, t) backward from \mathbf{x}(T) in O(1) memory?
- Contracting Forward = Exploding Backward: A stable forward mode \dot{x} = -\lambda x (\lambda > 0) becomes an unstable backward mode \dot{x} = +\lambda x when integrated from T down to 0.
- Catastrophic Amplification of Float64 Rounding: On a stiff mode \lambda = 50,
float64 rounding of magnitude \delta \approx 10^{-16} in the stored terminal state \mathbf{x}(T) grows to e^{50T}\delta:
- At T = 0.25: drift is e^{12.5} \cdot 10^{-16} \approx 2.7 \times 10^{-11}.
- At T = 1.00: drift is e^{50} \cdot 10^{-16} \approx 5 \times 10^{5} (completely destroying the trajectory and gradient).
Systems Best Practice: Use discretize-then-optimize (backprop through the solver) with activation checkpointing every \sqrt{N} steps—storing only 2\sqrt{N} \approx 63 states for N = 1000 and recomputing segments forward in time so no mode is ever integrated against its stable direction.
Liouville’s Equation: Instantaneous Change of Variables
Continuous Normalizing Flows
Over a short step h, the flow Jacobian \mathbf{I} + h\mathbf{J} + o(h) satisfies \det(\mathbf{I} + h\mathbf{J}) = 1 + h\operatorname{tr}(\mathbf{J}) + O(h^2). Taking h \to 0 yields Liouville’s trace rule:
\frac{d}{dt}\log p_t(\mathbf{x}(t)) = -\operatorname{tr}\!\left(\frac{\partial\mathbf{f}}{\partial\mathbf{x}}(\mathbf{x}(t), t)\right) = -\nabla \cdot \mathbf{f}(\mathbf{x}(t), t)
- Zero O(d^3) determinants: Integrates log-density along the trajectory using only the first-order trace.
Divergence as Volume Contraction and Density Change
Geometric Intuition
Integrating -\operatorname{tr}(\mathbf{J}) from 0 to T replaces the sum of O(d^3) layer log-determinants by a single path integral:
\log p_T(\mathbf{x}(T)) = \log p_0(\mathbf{x}(0)) - \int_0^T \operatorname{tr}\!\left(\frac{\partial\mathbf{f}}{\partial\mathbf{x}}(\mathbf{x}(t), t)\right)dt
![]()
- Linear Special Case (Jacobi’s Formula): For \dot{\mathbf{x}} = \mathbf{A}\mathbf{x}, \det(e^{\mathbf{A}t}) = e^{t\operatorname{tr}\mathbf{A}}. On the contracting spiral (\operatorname{tr}\mathbf{A} = -0.5 - 0.5 = -1), disc area shrinks by e^{-1.2} \approx 0.30 at t = 1.2 while density along each trajectory rises by e^{+1.2} \approx 3.32.
Verifying the Trace Integral Along a Nonlinear Flow
Numerical Verification
On a nonlinear 8-unit tanh vector field \mathbf{f}(\mathbf{x}) = \mathbf{W}_2\tanh(\mathbf{W}_1\mathbf{x} + \mathbf{b}_1), the divergence \operatorname{tr}\mathbf{J}(\mathbf{x}) varies continuously along the trajectory, yet its RK4 time integral matches the finite-difference log-determinant \log|\det D\Phi_1(\mathbf{x}_0)| to 8 digits:
tr J along the path: from +0.889 to +1.013
trace integral +0.970187 log|det D Phi| +0.970187 gap 8.3e-11
Hutchinson’s Trace Estimator and FFJORD
Stochastic Trace Estimation
For any isotropic probe \boldsymbol{\epsilon} with \mathbb{E}[\boldsymbol{\epsilon}\boldsymbol{\epsilon}^\top] = \mathbf{I}, Hutchinson’s estimator computes \operatorname{tr}(\mathbf{J}) in one reverse-mode VJP:
\mathbb{E}\!\left[\boldsymbol{\epsilon}^\top \mathbf{J} \boldsymbol{\epsilon}\right] = \operatorname{tr}\!\left(\mathbf{J}\,\mathbb{E}[\boldsymbol{\epsilon}\boldsymbol{\epsilon}^\top]\right) = \operatorname{tr}(\mathbf{J})
- Rademacher (\epsilon_i \in \{\pm 1\}) beats Gaussian: Because \epsilon_i^2 \equiv 1 deterministically, Rademacher probes have zero diagonal variance (2\sum_{i \neq j} S_{ij}^2 vs. Gaussian 2\sum_{i,j} S_{ij}^2).
Benchmarking Rademacher vs. Gaussian Probes in d = 50
Estimator Variance
On \mathbf{f}(\mathbf{x}) = \mathbf{W}_2\tanh(\mathbf{W}_1\mathbf{x} + \mathbf{b}_1) - \mathbf{x} in d = 50 dimensions, the -\mathbf{x} pull contributes -1 to every diagonal entry J_{ii} (\operatorname{tr}\mathbf{J} \approx -50). Because \boldsymbol{\epsilon}^\top\boldsymbol{\epsilon} = d = 50 deterministically for Rademacher probes, they avoid the 2\sum_i J_{ii}^2 \approx 100 diagonal variance penalty of Gaussian probes:
Rademacher: exact -51.30, mean of 1000 probes -51.23 +- 0.16, one probe sd 4.99
Gaussian : exact -51.30, mean of 1000 probes -51.16 +- 0.37, one probe sd 11.62
Catch 4: Held Probes vs. Fresh Probes on a Path
FFJORD Design Trade-Off
When integrating \int_0^T \boldsymbol{\epsilon}^\top\mathbf{J}(\mathbf{x}(t))\boldsymbol{\epsilon}\,dt across N solver steps, should we hold one probe \boldsymbol{\epsilon} fixed for the entire trajectory or draw a fresh \boldsymbol{\epsilon}_n at every step?
N = 10: exact -51.90 | held probe -52.11, sd 5.69 | fresh probes -51.73, sd 1.71
N = 100: exact -51.93 | held probe -51.35, sd 5.98 | fresh probes -51.94, sd 0.63
N = 1000: exact -51.93 | held probe -51.28, sd 5.88 | fresh probes -51.92, sd 0.19
- Fresh Probes (\text{SD} \propto 1/\sqrt{N}): Independent step errors average out (SD drops from 1.7 at N=10 to 0.17 at N=1000), but inject white noise into the ODE right-hand side, breaking adaptive step-size controllers.
- Held Probe (FFJORD Standard): Holding \boldsymbol{\epsilon} fixed keeps the augmented ODE deterministic and smooth for RK45 and adjoint backprop, while minibatch SGD averages out the O(1) probe variance across examples and training iterations.
Invertible Residual Blocks vs. Continuous Flows
Discrete Contraction Series
What if we keep discrete residual steps F(\mathbf{x}) = \mathbf{x} + \mathbf{g}(\mathbf{x}) instead of taking the h \to 0 continuous limit?
- Banach Contraction Invertibility (c < 1): If \mathbf{g} has Lipschitz constant c = \|\mathbf{J}_{\mathbf{g}}\|_2 < 1 (spectral normalization), then \mathbf{x} = \mathbf{y} - \mathbf{g}(\mathbf{x}) is a contraction mapping, making F a global bijection whose inverse is computed by fixed-point iteration at geometric rate c^k.
- Power-Series Log-Determinant (i-ResNet): When \|\mathbf{J}_{\mathbf{g}}\|_2 \le c < 1, expanding \log(1 + \lambda_i) in the eigenvalues of \mathbf{J}_{\mathbf{g}} expresses the discrete log-determinant as an infinite trace series: \log\det(\mathbf{I} + \mathbf{J}_{\mathbf{g}}) = \sum_{k=1}^\infty \frac{(-1)^{k+1}}{k}\operatorname{tr}\!\left(\mathbf{J}_{\mathbf{g}}^k\right)
- Why Continuous Flows Win: A discrete invertible ResNet must restrict \|\mathbf{J}_{\mathbf{g}}\|_2 < 1 and pay K sequential VJPs per layer to truncate the power series, whereas a Continuous Normalizing Flow needs only the k = 1 linear trace term h\operatorname{tr}(\mathbf{J}) with no Lipschitz cap.
Running-Cost Adjoints and Kinetic Energy Regularization
Extending the Adjoint ODE
In practice, Continuous Normalizing Flows often augment the terminal loss \ell_T(\mathbf{x}(T)) with a running integral penalty \mathcal{L} = \ell_T(\mathbf{x}(T)) + \int_0^T \ell(\mathbf{x}(t), \boldsymbol{\theta}, t)\,dt to encourage straight, non-stiff trajectories:
- Adjoint ODE with Running Source Term: Extending the variational proof adds -\nabla_{\mathbf{x}}\ell(\mathbf{x}(t), \boldsymbol{\theta}, t) as a continuous source injecting sensitivity along the backward pass: \dot{\mathbf{a}}(t) = -\left(\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\right)^{\!\top}\mathbf{a}(t) - \nabla_{\mathbf{x}}\ell(\mathbf{x}(t), \boldsymbol{\theta}, t), \qquad \mathbf{a}(T) = \nabla\ell_T(\mathbf{x}(T))
- Kinetic Energy & Jacobian Frobenius Regularization (RNODE): Penalizing \ell(\mathbf{x}, \boldsymbol{\theta}, t) = \|\mathbf{f}(\mathbf{x}, \boldsymbol{\theta}, t)\|^2 + \lambda\|\mathbf{J}(\mathbf{x}, t)\|_F^2 prevents curved, stiff trajectories and cuts adaptive solver evaluations by orders of magnitude.
Concept Check: Expressivity, Adjoints, and Densities
Concept Check
Test your grasp of Neural ODEs and Continuous Normalizing Flows:
- 1D Flow Obstruction: Why can a 1-layer residual block x \mapsto x - 3x = -2x flip the orientation of the real line, whereas no Lipschitz Neural ODE \dot{x} = f(x, t) on \mathbb{R} can ever map (-1, 1) \mapsto (2, -2)?
- Checkpointing vs. Backward Integration: On a system with a fast decaying mode \lambda = 50 over T = 1, why does activation checkpointing remain stable while backward state re-integration loses all 16 digits of
float64 precision?
- Trace Estimator Choice: For a diagonal Jacobian \mathbf{J} = \mathrm{diag}(c_1, \ldots, c_d), what is the variance of a single Rademacher Hutchinson probe \boldsymbol{\epsilon}^\top\mathbf{J}\boldsymbol{\epsilon}?
Answers:
- In 1D, continuous trajectories of -1 and +1 would have to cross at some intermediate time s \in (0, T) to reverse order, violating Picard–Lindelöf uniqueness. A discrete step with hL = 3 > 1 teleports across the origin in a single jump.
- Checkpointing saves states along the forward pass and only recomputes short segments forward in time (e^{-50\Delta t} contracts errors), never integrating backward where e^{+50T} \approx 5 \times 10^{21} explodes rounding errors.
- Zero. For a diagonal matrix, S_{ij} = 0 for all i \ne j, and \sum_i \epsilon_i^2 c_i = \sum_i (\pm 1)^2 c_i = \sum_i c_i = \operatorname{tr}(\mathbf{J}) is exact in a single Rademacher probe.
Summary: Neural ODEs, Adjoints, and Continuous Flows
Key Takeaways
| Neural ODE Forward Map |
\mathbf{x}(T) = \mathbf{x}_0 + \int_0^T \mathbf{f}_{\boldsymbol{\theta}}(\mathbf{x}(t), t)\,dt |
Bijective map \Phi_T; requires accurate solver (RK4) or direct regression to learn a true flow |
| Continuous Adjoint ODE |
\dot{\mathbf{a}}(t) = -\left(\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\right)^\top\mathbf{a}(t), \mathbf{a}(T) = \nabla\ell(\mathbf{x}(T)) |
Propagates sensitivity backward via 1 VJP/step; use forward checkpointing to avoid e^{\lambda T} drift |
| Parameter Gradient |
\frac{\partial\mathcal{L}}{\partial\boldsymbol{\theta}} = \int_0^T \left(\frac{\partial\mathbf{f}}{\partial\boldsymbol{\theta}}\right)^\top\mathbf{a}(t)\,dt |
Backprop through Euler is exact for the discrete program and within O(h) of the flow gradient |
| Instantaneous Log-Density |
\frac{d}{dt}\log p_t(\mathbf{x}(t)) = -\operatorname{tr}\!\left(\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\right) = -\nabla\cdot\mathbf{f} |
Replaces O(d^3) discrete Jacobian determinants with a 1D path integral of the trace |
| Hutchinson Trace (FFJORD) |
\operatorname{tr}(\mathbf{J}) = \mathbb{E}\!\left[\boldsymbol{\epsilon}^\top\mathbf{J}\boldsymbol{\epsilon}\right] (\epsilon_i \in \{\pm 1\}) |
Unbiased trace in 1 VJP per step; Rademacher probes eliminate diagonal variance |