C.W.K.
Stream
Lesson 04 of 05 · published

The JAX AI Stack and Pallas Custom Kernels

~8 min · ecosystem, jax, tutorial

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

The JAX AI Stack is an official meta-package that bundles the most commonly used JAX libraries. It's the easiest way to get started with a complete deep learning setup.

# Install the whole stack at once
# pip install jax-ai-stack

# This gives you:
# - jax            (core)
# - flax           (neural networks)
# - optax          (optimizers)
# - orbax          (checkpointing)
# - ml_dtypes      (bfloat16, etc.)
# - grain          (data loading)
# - chex           (testing utilities)

import jax
from flax import nnx
import optax
import orbax.checkpoint as ocp

# Version check (early 2026):
# jax ~0.9.x, flax ~0.12.x, optax ~0.2.x

Pallas: Custom GPU/TPU Kernels

Pallas is JAX's kernel language for writing custom low-level operations that run directly on GPUs and TPUs. When XLA's automatic optimization isn't enough, Pallas lets you write hand-optimized kernels while staying in Python.

import jax
from jax.experimental import pallas as pl
import jax.numpy as jnp

# A simple Pallas kernel: vector addition
def add_kernel(x_ref, y_ref, o_ref):
    """Pallas kernel: reads from x and y, writes to o."""
    o_ref[...] = x_ref[...] + y_ref[...]

# Launch the kernel
def pallas_add(x, y):
    return pl.pallas_call(
        add_kernel,
        out_shape=jax.ShapeDtypeStruct(x.shape, x.dtype),
    )(x, y)

x = jnp.ones(1024)
y = jnp.ones(1024) * 2
result = pallas_add(x, y)
print(result[:5])  # [3. 3. 3. 3. 3.]

Pallas translates to Triton on GPUs and Mosaic on TPUs. The name is a reference: in Greek mythology, Pallas is the parent of Triton.

💡 Why This Matters

Pallas is how Google implements things like FlashAttention and other custom fused kernels for JAX. Most users will never need Pallas directly — XLA's compiler handles 99% of optimization automatically. But if you're implementing novel attention mechanisms, custom quantization kernels, or other operations where XLA's fusion doesn't produce optimal code, Pallas gives you the escape hatch to write hand-optimized kernels while staying in the JAX ecosystem.

Code

# Install the whole stack at once
# pip install jax-ai-stack

# This gives you:
# - jax            (core)
# - flax           (neural networks)
# - optax          (optimizers)
# - orbax          (checkpointing)
# - ml_dtypes      (bfloat16, etc.)
# - grain          (data loading)
# - chex           (testing utilities)

import jax
from flax import nnx
import optax
import orbax.checkpoint as ocp

# Version check (early 2026):
# jax ~0.9.x, flax ~0.12.x, optax ~0.2.x
import jax
from jax.experimental import pallas as pl
import jax.numpy as jnp

# A simple Pallas kernel: vector addition
def add_kernel(x_ref, y_ref, o_ref):
    """Pallas kernel: reads from x and y, writes to o."""
    o_ref[...] = x_ref[...] + y_ref[...]

# Launch the kernel
def pallas_add(x, y):
    return pl.pallas_call(
        add_kernel,
        out_shape=jax.ShapeDtypeStruct(x.shape, x.dtype),
    )(x, y)

x = jnp.ones(1024)
y = jnp.ones(1024) * 2
result = pallas_add(x, y)
print(result[:5])  # [3. 3. 3. 3. 3.]

External links

Exercise

Read the Pallas overview. Don't write a full kernel — just understand the abstraction (Triton-like for JAX). Find one kernel in DeepMind/Google research code that uses Pallas and write a 3-line note on what it does. Knowing it's there is enough until you need it.

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.