Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 40 ยท Getting Started

What Is JAX?

Meet JAX: NumPy-style arrays plus composable function transformations (grad, jit, vmap) that run on CPU, GPU and TPU through the XLA compiler.

JAX is a Python library for numerical computing and machine learning research. It gives you an array API that looks almost exactly like NumPy, and on top of it a small set of function transformations: tools that take a Python function and return a new, more powerful function. The three you will use every day are grad (differentiate), jit (compile) and vmap (vectorize).

What makes JAX special is that these transformations compose. You can differentiate a function, compile the result, then vectorize that over a batch, in any order, and it just works. This lesson explains the big picture before we write any real code.

Honest note about this course. JAX needs jaxlib, a large compiled extension, and there is no build of it for the in-browser Python runtime that powers this site's editors. So JAX itself cannot run in the live examples. Real JAX code in these lessons is shown in read-only blocks, and I only print an output when I am certain of it. Every runnable editor is clearly labelled as a stand-in: small NumPy-only code that demonstrates the same idea (for example, a few lines of forward-mode autodiff standing in for grad). To run the real thing, install JAX on your own machine as shown in the next lesson.

The one-sentence pitch

JAX = NumPy + autodiff + a compiler + automatic vectorization, designed around pure functions.

  • NumPy-like API. jax.numpy (usually imported as jnp) mirrors NumPy, so your existing knowledge transfers.
  • Autodiff. jax.grad computes derivatives of ordinary Python functions that use jnp, including loops and branches.
  • Compilation. jax.jit traces your function once and hands it to XLA (Accelerated Linear Algebra), which fuses operations and generates fast code for CPU, GPU or TPU.
  • Vectorization. jax.vmap turns a function written for one example into a function that handles a whole batch, with no manual batching code.
  • Parallelism. pmap and the newer sharding tools spread work over many devices.
flowchart LR
    F["your pure Python function f(x)"] --> G["grad(f)<br/>derivative"]
    F --> J["jit(f)<br/>compiled"]
    F --> V["vmap(f)<br/>batched"]
    G --> J2["jit(vmap(grad(f)))<br/>transformations compose"]
    V --> J2

Each transformation takes a function and returns a function, so you can stack them.

Where JAX fits

JAX in four ideas

NumPy API jnp looks like np
grad Exact derivatives
jit Compile with XLA
vmap Auto batching

Four tools, one idea: transform functions.

1 / 3

JAX compared with other tools

Tool Style Strength
NumPy Imperative, CPU only Universal, simple
PyTorch Imperative, tape-based autodiff, objects with state Huge ecosystem, easy debugging
TensorFlow Graphs and eager mode Production tooling
JAX Functional, transformation-based Composability, speed through XLA, research flexibility

JAX is not a neural-network framework by itself. It is a numerical engine. Neural network libraries such as Flax and Equinox, and optimizers such as Optax, are built on top; you will meet them in chapter 7 of this course. Large projects, including many modern research models, are written in this stack.

Function transformations, in plain Python

You do not need JAX to understand the key idea. A transformation is just a higher-order function: it accepts a function and returns another one. The stand-in below builds toy versions of all three. grad uses a tiny forward-mode "dual number" class, vmap loops over a batch, and jit caches results. These are not how JAX works inside (JAX traces to an intermediate representation and compiles it), but they show the shape of the API.

Python Stand-in: toy grad, vmap and jit

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that f is written once, for a single number. The derivative and the batching were added from the outside. That separation is the heart of JAX.

The real thing

Here is the same idea written with real JAX. This block is read-only; you will run code like it after installing JAX.

Python
import jax
import jax.numpy as jnp

def f(x):
    return 3 * x**2 + 2 * x + 1

df = jax.grad(f)
print(df(2.0))                           # 14.0
print(jax.vmap(df)(jnp.array([0.0, 1.0, 2.0])))   # [ 2.  8. 14.]
fast = jax.jit(jax.vmap(df))             # compose all three

Who should learn JAX?

JAX shines for research code, custom optimization, scientific simulation, probabilistic programming and anything where you need derivatives of unusual functions. If you only want to train a standard classifier quickly, higher-level tools may be simpler; but understanding JAX makes you a stronger practitioner either way.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. What is a JAX function transformation?

    grad, jit and vmap each accept a Python function and return a transformed function, which is why they can be stacked.
  2. 2. Which pair is correctly matched?

    jit hands the traced function to the XLA compiler; vmap does batching; grad differentiates; jnp is the NumPy-like array API.
  3. 3. Why are the runnable editors in this course labelled as stand-ins?

    The real library needs a compiled extension that is unavailable in the browser runtime, so examples are shown read-only or reproduced with small NumPy stand-ins.

Summary

  • JAX is a NumPy-like array library with composable transformations: grad, jit, vmap, and parallel tools.
  • Transformations take functions and return functions, so they stack.
  • Code runs on CPU, GPU and TPU through the XLA compiler.
  • JAX favors pure functions, immutable arrays and explicit randomness.
  • On this site JAX cannot run live: runnable editors are labelled NumPy stand-ins.

Next: Installing JAX and Choosing Devices