Skip to content

Trainable neural-ODE flow (FFJORD / ContinuousNormalizingFlow) - #49

Merged
davidkhjo merged 1 commit into
mainfrom
cnf-ffjord
Aug 19, 2026
Merged

davidkhjo merged 1 commit into
mainfrom
cnf-ffjord

Conversation

@davidkhjo

Copy link
Copy Markdown
Owner

Trainable neural-ODE flow — FFJORD (0.15.0)

The second flagship: nets.ContinuousNormalizingFlow, the trainable generalization of the eval-only pf_ode_log_likelihood shipped earlier. A neural velocity field v_θ(x, t) defines an ODE from data (t=0) to a N(0, I) base (t=1); the exact log-density follows the instantaneous change of variables d log p/dt = -tr(∂v/∂x), with the divergence estimated by Hutchinson. Pure torch — fixed-step RK4 with direct backprop (no adjoint, no torchdiffeq). Trains by maximum likelihood, samples in one reverse pass, and doubles as a self-normalized energy (forward(x) = -log_prob(x), log Z = 0).

A new private ebm/_ode.py holds the augmented integrator + Hutchinson probe sampler; pf_ode_log_likelihood now reuses the shared probe sampler.

Validation:

  • Linear field v = xAᵀ: the flow maps x → e^A x with log|det| = tr(A), so log p(x) = log N(e^A x) + tr(A) — the mean matches (error 0.003, Hutchinson is unbiased).
  • Rotation (skew-symmetric field): tr = 0 exactly (εᵀSε = 0) and the base Gaussian is rotation-invariant, so log_prob(x) == log N(x; 0, I) to 1e-5.
  • Trainability: fits eight-gaussians / two-moons by ML; samples match the data (MMD² < 0.05).

Example train_cnf.py (two-moons, exact density by ODE). Lands under unreleased 0.15.0 (alongside the cleanup + VP diffusion).

Verification

ruff + format + mypy clean; 163 tests pass; example runs on CPU (~2.5 min).

🤖 Generated with Claude Code

A velocity field defines an ODE from data to a Gaussian base; the exact
log-density follows the instantaneous change of variables (Hutchinson trace),
torch-only via fixed-step RK4 with direct backprop. Trains by max likelihood,
samples in one reverse pass, doubles as a self-normalized energy. New private
ebm/_ode.py holds the augmented integrator; pf_ode_log_likelihood reuses its
probe sampler. Validated: linear-field closed form + exact rotation invariance.
@davidkhjo
davidkhjo merged commit 95dde62 into main Aug 19, 2026
5 checks passed
@davidkhjo davidkhjo mentioned this pull request Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant