# JAX (library)

> Canonical: https://skillalmanac.com/glossary/jax | Last verified: 2026-11-25 | Index status: index-eligible

JAX is a Python library for numerical array computation and composable transformations such as automatic differentiation, vectorization and compilation across supported CPU, GPU and TPU backends.

Also called: JAX.

## In plain language

JAX helps developers express numerical work with a NumPy-style array API and transform compatible functions. `grad` creates derivative functions, `vmap` maps a function across array axes and `jit` compiles compatible computations. JAX is used in machine-learning research, but it is neither a language model nor an LLM runtime. Its transformations favor functionally pure numerical code. JIT compilation has an upfront cost, is not guaranteed to make every function faster and may happen again when shapes, dtypes, static argument values, function identity or other compilation conditions change.

## Technical definition

JAX provides accelerator-oriented array operations and composable program transformations. `jax.grad` differentiates scalar-output numerical functions; `jax.vmap` vectorizes function application over array axes; and `jax.jit` traces and compiles JAX-compatible functions for XLA execution. Cached compiled code can be reused by later calls with a compatible compilation signature. Changes such as input shape or dtype, static argument values, or function identity can require another trace or compilation. Python side effects are not represented like JAX numerical primitives and can behave unexpectedly under transformations. CPU, GPU and TPU are supported backends, but backend availability and suitable code do not establish a performance improvement for a particular workload.

## How it shows up when you use agents

JAX appears when an agent reads or modifies Python for numerical computing or machine-learning research. It is an array-computing and program-transformation library, not a language model, chatbot or LLM-serving runtime. Its NumPy-style API supports array operations, while transformations such as `jax.grad`, `jax.vmap` and `jax.jit` can differentiate, vectorize and compile suitable functions.

Ask the agent to identify what transformation the code actually needs. `grad` is appropriate when a scalar-output numerical function needs derivatives. `vmap` is appropriate when one function should be applied across a batch axis without writing a manual loop. `jit` is appropriate when a JAX-compatible computation may benefit from compilation. These tools can be composed, but they are not an automatic recipe for optimizing every training loop or porting every PyTorch or TensorFlow program. State handling, control flow, library dependencies, sharding and surrounding architecture may require redesign.

When reviewing generated code, request small correctness checks before performance work. Compare the intended mathematics with the plain and transformed functions on tiny inputs. Check shapes, dtypes and static arguments. Also inspect Python side effects: JAX transformations trace numerical operations, and ordinary mutation or printing may not behave as a reader expects inside transformed code.

## Common confusions

JAX resembles NumPy, but a familiar interface does not mean every NumPy program transfers unchanged. JAX transformations are designed around compatible, functionally pure computations. A GPU or TPU is hardware; JAX is software that can target supported CPU, GPU and TPU backends.

JIT compilation is also not a universal speed switch. Compilation has an upfront cost, and later calls reuse cached code only when their compilation conditions are compatible. Changed shapes, dtypes, static argument values or function identities can trigger further tracing or compilation. Small computations may not benefit once overhead is considered.

For an agent-assisted change, the useful action is to define the expected numerical result, test representative shapes and dtypes, and then profile the real workload on its intended backend. Do not substitute local-LLM memory sizing or API-cost tools: those answer different questions and provide no evidence about a JAX program’s correctness, memory use or performance.

## Self-contained worked examples

### Differentiate and vectorize a square function

Status: illustrative example, not a measured performance result.

Scenario: This explicitly hypothetical, illustrative example shows how JAX transformations can be composed for tiny floating\-point inputs. The code is unexecuted and is not a hardware benchmark.

Demonstration: For f\(x\) = x × x, calculus gives f′\(x\) = 2x. Therefore the derivative at 3.0 is 6.0. Applying that gradient independently to \[1.0, 2.0, 3.0\] gives \[2.0, 4.0, 6.0\]. `jax.grad` constructs the derivative function, `jax.vmap` applies it across the vector and `jax.jit` may compile the vectorized computation.

```
import jax
import jax.numpy as jnp

def f(x):
    return x * x

grad_f = jax.grad(f)
vector_grad_f = jax.vmap(grad_f)
compiled_vector_grad_f = jax.jit(vector_grad_f)

x = jnp.array(3.0, dtype=jnp.float32)
xs = jnp.array([1.0, 2.0, 3.0], dtype=jnp.float32)

# Illustrative, unexecuted expectations:
# grad_f(x) -> 6.0
# compiled_vector_grad_f(xs) -> [2.0, 4.0, 6.0]
```

What it shows: Use `grad` for differentiation, add `vmap` when the same scalar calculation should run across a batch, and apply `jit` only where compilation suits the function and workload.

Limits: The expected values follow directly from the stated function; they are not reported execution results. This example does not measure speed, demonstrate every supported dtype or backend, or guarantee cache reuse or improvement from JIT.

## Related terms

- [Gradient descent](https://skillalmanac.com/glossary/gradient-descent.md)
- [Batch size](https://skillalmanac.com/glossary/batch-size.md)

## Sources

- [JAX: High performance array computing](https://docs.jax.dev/en/latest/), JAX project (accessed 2026-11-25)
- [Just-in-time compilation](https://docs.jax.dev/en/latest/jit-compilation.html), JAX project (accessed 2026-11-25)
- [Using JAX to accelerate our research](https://deepmind.google/discover/blog/using-jax-to-accelerate-our-research/), Google DeepMind (accessed 2026-11-25)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
