liveBook · Manning

JAX

As explained in Deep Learning with JAX

A functional-first numerical computing library for machine learning and scientific computing in which state is made explicit and transformations like autodiff and compilation are central.

Need NumPy-style numerical code that can differentiate, compile, batch, and run across accelerators? JAX provides a functional-first Python library for high-performance array computing in machine learning, scientific computing, optimization, and simulation. section 1.0 section 1.2

JAX is useful when you need to:

  • Compute with a NumPy-compatible multidimensional Array API while targeting CPUs, GPUs, or TPUs. section 1.1.1 section 1.2.1
  • Compose automatic differentiation, just-in-time compilation, auto-vectorization, and parallel execution as function transformations. section 1.2.2
  • Keep model parameters, random-number state, gradients, and optimizer state explicit rather than hidden inside objects. section 1.1.2
  • Assemble a custom stack from separate neural-network, optimizer, data-loading, reinforcement-learning, or meta-learning modules. section 1.1.3

A functional array update

NumPy-style in-place updates do not fit JAX's immutable arrays. Instead of arr[i] += 10, write arr = arr.at[i].add(10). The same functional style applies to larger computations: define a pure function, then transform it with grad(), jit(), or vmap(). section 1.2.1 section 1.2.2

Figure 1.1 A simple (and pretty useless) function with some amount of computations that we will evaluate with pure NumPy, with JAX using a CPU and GPU, and with JAX-compiled versions of the same function for CPU and GPU backends. We will evaluate the time to calculate f(x).

Compare pure NumPy, JAX on CPU or GPU, and JIT-compiled JAX versions of the same computation to see where hardware and XLA compilation affect execution time. section 1.1.1

Figure 1.3 JAX (right) is much more than NumPy (left). It provides a set of composable function transformations for Python + NumPy code for compilation, vectorization, parallelization, and automatic differentiation.

Use the transformation overview to see how JAX extends NumPy with compilation, vectorization, parallelization, and automatic differentiation. section 1.2.2

The tradeoff is a change in habits: side effects, hidden state, mutable arrays, and some ordinary if statements or loops can conflict with JIT-oriented code. JAX is deliberately minimal compared with PyTorch and TensorFlow, so its ecosystem supplies many separate components. Existing embedded deployments or large established codebases may be better left in their current frameworks. section 1.1.2 section 1.3 section 1.1

How Deep Learning with JAX covers it

How deep it goes
Explains arrays, functional state, four core transformations, hardware, and ecosystem tradeoffs, while deferring detailed chapters on each feature.
Examples
Uses immutable indexed updates, performance comparisons, and an MNIST neural network combining gradients, compilation, and auto-vectorization.
What it assumes
Assumes Python and NumPy-style array familiarity while introducing functional state and transformations for newcomers.
What you can do after
Build a simple MNIST neural network using explicit state and grad(), jit(), and vmap().
How it connects
Connects NumPy, automatic differentiation, XLA, JIT compilation, vectorization, parallelization, functional programming, PyTorch, TensorFlow, and pytrees.

Also explained in

Compare how 3 books explain JAX →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with JAX. The section links point to the parts of the book it draws on.