--- id: flax version: "0.12.8" license: unclear license_treatment: permissive maintenance: active --- # flax — Flax: A neural network library for JAX designed for flexibility License: permissive · Maintenance: active · Downloads: 4.6M/mo ## 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 above — 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 pip install flax uv add flax 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_current - Install friction: low - Maintenance: active - Downloads: 4.6M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags JAX neural network library, deep learning with JAX, neural network framework JAX, Flax NNX API, flexible neural networks, JAX model building, reference semantics neural nets, jax-ecosystem, deep-learning, research-framework [View on SkillFed](https://skillfed.io/packages/flax) · [View on PyPI](https://pypi.org/project/flax/)