flax
Flax: A neural network library for JAX designed for flexibility
What it is and what it does
Flax is a neural network library built on top of JAX that provides a higher-level API for defining and training deep learning models. Unlike JAX's functional approach, Flax NNX (released in 2024) uses Python reference semantics, allowing you to write models as regular Python classes with mutable state and object references—making them easier to inspect, debug, and reason about. It comes with standard layers (Linear, Conv, BatchNorm, LayerNorm, GroupNorm, MultiHeadAttention, LSTMCell, GRUCell, Dropout) and utilities for checkpointing, metrics, and distributed training.
Flax is designed for research flexibility: you modify training loops and experiment with new ideas by forking examples and changing code, rather than extending a framework with new features. It depends on JAX for computation, optax for optimization, and several checkpoint and serialization libraries. The library is actively maintained by Google DeepMind and has been in development since 2020, with the NNX simplification representing a significant usability improvement over the earlier Linen API.
Use it for:
- Building and training transformer models, CNNs, and other neural architectures using Python class syntax instead of functional JAX code.
- Debugging and inspecting neural network state during training without the complexity of JAX's functional transformations.
- Research projects where you need to experiment with custom training loops and model architectures without framework constraints.
- Distributed training across multiple devices using Flax's replicated training patterns and checkpointing utilities.
- Inference with pretrained models like Gemma, leveraging JAX's performance on CPUs, GPUs, and TPUs.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Flax is a neural network library for JAX that lets you build, train, and debug deep learning models using Python objects with reference semantics instead of functional transformations.
Yes, if you are already committed to JAX and want a higher-level, more Pythonic API for neural networks. Flax NNX is actively maintained, has no known vulnerabilities, and offers genuine usability improvements over raw JAX. Install friction is low. The main condition is that JAX itself must be properly installed for your hardware, which is a separate step. Not recommended if you prefer a more batteries-included framework or are new to JAX.
Install
flax on PyPI
pip
pip install flaxuv
uv add flaxpoetry
poetry add flaxInstalling flax
Before you install
Low friction install as a pure Python wheel. Depends on JAX and several supporting libraries (numpy, msgpack, optax, orbax-checkpoint, tensorstore, rich, typing_extensions, PyYAML, treescope); JAX itself requires separate setup for CPU/GPU/TPU. Actively maintained with recent releases.
License in practice
Licensed under Apache Software License (permissive), allowing commercial and private use with minimal restrictions.
Quickstart
pip install flax
import flax.nnx as nnx
import jax
class MLP(nnx.Module):
def __init__(self, din, dout, rngs):
self.linear = nnx.Linear(din, dout, rngs=rngs)
def __call__(self, x):
return self.linear(x)
model = MLP(10, 2, rngs=nnx.Rngs(0))
Requires Python 3.11 or later and a working JAX installation (which itself requires separate setup for CPU, GPU, or TPU support).
Verify before relying
- Whether orbax-checkpoint, tensorstore, and treescope are always required or only for specific workflows.
- Performance characteristics compared to other JAX-based frameworks for large-scale training.
- Stability of the NNX API relative to the earlier Linen API for long-term projects.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 10 — numpy, jax, msgpack, optax, orbax-checkpoint, tensorstore, rich, typing_extensions, PyYAML, treescope |
| Maintenance | actively maintained — 25 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 4,616,508/month — #2,273 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: flax-0.12.8-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
cluCLU provides utilities and abstractions for…
permissive · top 15,000 on PyPI
dm-haikuHaiku is a neural network library for JAX that…
permissive · top 15,000 on PyPI
equinoxEquinox provides neural network and model…
permissive · top 5,000 on PyPI
jraphJraph provides data structures and utilities…
permissive · top 15,000 on PyPI
qwixQwix is a JAX quantization library that applies…
permissive · top 15,000 on PyPI
grainGrain is a Python library for reading,…
permissive · top 5,000 on PyPI
google-tunixTunix is a JAX-based library for post-training…
permissive · top 15,000 on PyPI
optaxOptax provides composable building blocks for…
permissive · top 5,000 on PyPI
jax-dataclassesProvides a JAX-compatible wrapper around Python…
permissive · top 15,000 on PyPI
orbax-exportOrbax Export serializes JAX models to…
permissive · top 15,000 on PyPI