Minimal normalizing flows in JAX
Project description
nflojax
A minimal, hackable normalizing flows library in JAX.
Overview
- RealNVP with affine coupling layers
- Spline flows with rational-quadratic splines [durkan2019]
- Conditional flows with context concatenation and optional feature extraction
- Identity gating for smooth boundary conditions on context-dependent flows
Installation
git clone <repo-url>
cd nflojax
pip install -e . # installs jax, jaxlib, flax
pip install -e ".[test]" # also installs pytest
Quick Start
import jax
from nflojax.builders import build_realnvp
key = jax.random.PRNGKey(0)
flow, params = build_realnvp(
key, dim=4, num_layers=4, hidden_dim=64, n_hidden_layers=2,
)
samples = flow.sample(params, key, shape=(1000,)) # (1000, 4)
log_prob = flow.log_prob(params, samples) # (1000,)
samples, log_prob = flow.sample_and_log_prob(params, key, shape=(1000,))
Features
- Affine flow (RealNVP) with affine coupling layers
- Spline flows for more expressive transforms
- Conditional flows with context variables
- Feature extractor for high-dimensional context
- Transform-only mode (bijection without base distribution)
- Identity gating for boundary conditions
- Custom architectures via assembly API
- Training recipes for forward KL (MLE) and reverse KL (VI)
Design
- Explicit parameters: no hidden state; params are always passed as PyTrees
- JAX-native: JIT-compatible, vmap-friendly, functional style
- Zero-init conditioners: flows start as identity for stable training
- LOFT stabilization: logarithmic tails prevent numerical issues in high dimensions
Documentation
| Document | Content |
|---|---|
| USAGE.md | How-to cookbook with copy-pasteable examples |
| REFERENCE.md | API reference: classes, builders, options, param structure |
| INTERNALS.md | Math foundations and design decisions |
| EXTENDING.md | Recipes for custom transforms, distributions, conditioners |
| AGENTS.md | Project context for coding agents |
References
- Dinh et al. (2017). "Density estimation using Real-NVP"
- Durkan et al. (2019). "Neural Spline Flows"
- Andrade (2021). "Stable Training of Normalizing Flows for High-dimensional Variational Inference"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nflojax-0.1.1.tar.gz
(63.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
nflojax-0.1.1-py3-none-any.whl
(39.0 kB
view details)
File details
Details for the file nflojax-0.1.1.tar.gz.
File metadata
- Download URL: nflojax-0.1.1.tar.gz
- Upload date:
- Size: 63.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a199b60e18c466f9ec61cd3ac0f2d0f4c1f47de6cc3e26d3e2f686a8a09de78
|
|
| MD5 |
da7d3c6bf6b5e788bf1858b55862e182
|
|
| BLAKE2b-256 |
bde38b4c5c336123ac507224e6afd734003ff1770267dfb9321013a287831aef
|
File details
Details for the file nflojax-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nflojax-0.1.1-py3-none-any.whl
- Upload date:
- Size: 39.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41a1a181d7d9f47c74186f4985d5f91142e3be481038fe2731031bf53a38b3b6
|
|
| MD5 |
e4f46535baa13c417c7e60178b33433a
|
|
| BLAKE2b-256 |
73422561c7bf3e6677cebdc2a3bf335ea0c5911c3fdbd6df70d1c9b84fca7c08
|