C.W.K.
Stream
Lesson 01 of 06 · published

Why JAX Doesn't Include a Neural Network Library

~8 min · neural-nets, jax, tutorial

Level 0Curious
0 XP0/73 lessons0/17 achievements
0/100 XP to next level100 XP to go0% complete

If you come from PyTorch, you're used to torch.nn being part of the core framework. TensorFlow has tf.keras. But JAX intentionally ships without a built-in neural network library. This is a deliberate design choice, not an oversight.

JAX's philosophy is separation of concerns: JAX provides the mathematical primitives (arrays, autodiff, compilation, parallelism) and lets the community build neural network abstractions on top. This has led to several excellent libraries, each with different design philosophies:

  • Flax (Google) — the "official" neural network library, now using the NNX API
  • Equinox (Patrick Kidger) — models as pytrees, PyTorch-like feel
  • Haiku (DeepMind) — now in maintenance mode, legacy codebases

This ecosystem approach has trade-offs:

# PyTorch: one way to define a model
# class Model(nn.Module):
#     def __init__(self):
#         super().__init__()
#         self.linear = nn.Linear(784, 10)
#     def forward(self, x):
#         return self.linear(x)

# JAX: you choose your library
# Flax NNX version:
from flax import nnx
class Model(nnx.Module):
    def __init__(self, rngs):
        self.linear = nnx.Linear(784, 10, rngs=rngs)
    def __call__(self, x):
        return self.linear(x)

# Equinox version:
import equinox as eqx
class Model(eqx.Module):
    linear: eqx.nn.Linear
    def __init__(self, key):
        self.linear = eqx.nn.Linear(784, 10, key=key)
    def __call__(self, x):
        return self.linear(x)

💡 Why This Matters

The JAX ecosystem's diversity is both its greatest strength and its biggest hurdle for newcomers. But the payoff is real: each library can innovate independently, and they all share the same JAX foundation. Flax NNX is the default choice for most projects (especially in the Google ecosystem), while Equinox is popular in scientific ML. You don't need to learn all of them — pick one and you can always switch later, since the underlying JAX concepts are the same.

The JAX AI Stack (pip install jax-ai-stack) bundles the most common libraries together: JAX + Flax + Optax + Orbax + ml_dtypes. This is the easiest way to get a complete deep learning setup with JAX.

Code

# PyTorch: one way to define a model
# class Model(nn.Module):
#     def __init__(self):
#         super().__init__()
#         self.linear = nn.Linear(784, 10)
#     def forward(self, x):
#         return self.linear(x)

# JAX: you choose your library
# Flax NNX version:
from flax import nnx
class Model(nnx.Module):
    def __init__(self, rngs):
        self.linear = nnx.Linear(784, 10, rngs=rngs)
    def __call__(self, x):
        return self.linear(x)

# Equinox version:
import equinox as eqx
class Model(eqx.Module):
    linear: eqx.nn.Linear
    def __init__(self, key):
        self.linear = eqx.nn.Linear(784, 10, key=key)
    def __call__(self, x):
        return self.linear(x)

External links

Exercise

Read three different opinions on 'why JAX core has no NN library' from official sources. Write a 100-word personal answer to a teammate asking 'why do I need to learn Flax/Equinox separately?' Knowing this story shapes what you'll pick later.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.