# JAX

> Composable function transformations (grad, jit, vmap) over NumPy-style code, popular for research and large-scale training on TPUs and GPUs. Free notes, key...

Canonical: https://www.internhack.in/roadmaps/tracks/machine-learning/jax
Last updated: 2026-11-28

Composable function transformations (grad, jit, vmap) over NumPy-style code, popular for research and large-scale training on TPUs and GPUs.

Advanced · about 18 hours · difficulty 4/5

Learn first: [Debugging and Running Training Experiments](https://www.internhack.in/roadmaps/tracks/machine-learning/training-debugging)

JAX looks like NumPy but lets you transform functions: take gradients, compile them with XLA, vectorize them and parallelize them across devices. It favours a functional style where model parameters are explicit data rather than hidden object state.

### Core transformations

- `jax.grad`: gradient of a scalar function.
- `jax.jit`: compile a function for big speedups.
- `jax.vmap`: automatic batching of a per-example function.
- `jax.pmap` / sharding APIs: multi-device parallelism.

### Things that surprise newcomers

- Arrays are **immutable**; use `x.at[i].set(v)` instead of in-place assignment.
- **Explicit random keys** (`jax.random.PRNGKey`, `split`) instead of global seeds.
- Python control flow inside jitted functions needs `jax.lax.cond` / `scan` when it depends on array values.

### Ecosystem

Flax (neural network layers), Optax (optimizers) and Orbax (checkpointing). Choose JAX if you work on TPUs, in research groups that use it, or need its transformations; otherwise PyTorch is the more common path.

**Good enough to move on** when you can train an MLP with Flax and Optax and explain what jit, grad and vmap each do.

## Key concepts

- **grad**
- **jit and XLA**
- **vmap**
- **PRNG keys**
- **Flax**
- **Optax**
- **Multi-device sharding**

## Other options for this step

- [PyTorch](https://www.internhack.in/roadmaps/tracks/machine-learning/pytorch): Tensors, autograd, nn.Module, Dataset/DataLoader and the explicit training loop, the most widely used framework in research and much of industry.
- [TensorFlow and Keras](https://www.internhack.in/roadmaps/tracks/machine-learning/tensorflow-keras): The Keras high-level API for fast model building with fit/evaluate, and the TensorFlow ecosystem for mobile and production deployment.

## Mini project

Implement logistic regression in pure JAX using grad, jit and vmap for per-example gradients, then rebuild a Fashion-MNIST MLP with Flax and Optax.

## Check yourself

Why does JAX require explicit random keys instead of a global random seed?

## Free resources

- [JAX documentation](https://docs.jax.dev/en/latest/) (JAX)
- [JAX on GitHub](https://github.com/jax-ml/jax) (GitHub)
- [Flax documentation](https://flax.readthedocs.io/en/latest/) (Flax)

Previous: [TensorFlow and Keras](https://www.internhack.in/roadmaps/tracks/machine-learning/tensorflow-keras) · Next: [GPUs and Efficient Training](https://www.internhack.in/roadmaps/tracks/machine-learning/gpu-training)

## More in Deep Learning Frameworks and Hardware

- [PyTorch](https://www.internhack.in/roadmaps/tracks/machine-learning/pytorch)
- [TensorFlow and Keras](https://www.internhack.in/roadmaps/tracks/machine-learning/tensorflow-keras)
- [JAX](https://www.internhack.in/roadmaps/tracks/machine-learning/jax)
- [GPUs and Efficient Training](https://www.internhack.in/roadmaps/tracks/machine-learning/gpu-training)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Machine Learning Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/machine-learning)
