skillfed

flax

Flax: A neural network library for JAX designed for flexibility

flax v0.12.8 4.6M downloads/30d#2,273 on PyPI7,296
Permissive license Active released

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 flax

uv

uv add flax

poetry

poetry add flax

Installing 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

Development Status :: 3 - AlphaIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: Apache Software LicenseProgramming Language :: Python :: 3.11Programming Language :: Python :: 3.12Topic :: Scientific/Engineering :: Artificial Intelligence

Tags

JAX neural network librarydeep learning with JAXneural network framework JAXFlax NNX APIflexible neural networksJAX model buildingreference semantics neural nets
jax-ecosystemdeep-learningresearch-framework

More Artificial Intelligence packages