JAX Core, From the Inside

JAX has one trick: run your Python once with stand-ins for the arrays and record what it did. Everything else, jit, grad, vmap, sharding, is a program that reads or rewrites that record. The track starts with a jaxpr you print in a notebook and ends at the lowering that turns it into StableHLO, with the cache, the transforms, and the pytree protocol read in between.

Phase 1 — Run it first

Print a jaxpr, lower it, compile it, and read each artefact before any article names the code behind it.

Phase 2 — Tracing

The wrapped function, the tracer, and the partial evaluator that turns a call into a jaxpr.

Phase 3 — jit and the cache

What a jit boundary is, what goes into the cache key, and where a recompile comes from.

Phase 4 — Transforms

grad and vmap are tables of rules, one per primitive; read the tables and the transforms stop being magic.

Phase 5 — Structure

Pytrees are how arbitrary Python data crosses a transform; control flow is a handful of primitives with their own rules.

Phase 6 — Devices

A mesh, a sharding, shard_map, and the lowering that produces the StableHLO XLA partitions.

Browse the full library