PyTorch vs JAX, the short answer: pick PyTorch unless you have a clear reason to choose JAX. PyTorch runs your Python code line by line, which makes it easy to write and debug, and almost the entire open model ecosystem is built on it: Hugging Face Transformers, vLLM, Unsloth, Axolotl and most research code. JAX treats your model as pure functions that it compiles with XLA, which makes it fast once compiled, excellent on Google TPUs, and handy for research that needs transformations like per example gradients. In our own CPU test, a jitted JAX training step ran faster than eager PyTorch but paid about 0.2 seconds of compile time up front and again when the batch size changed. Learn JAX if you will train on TPUs, join a JAX first lab, or want its functional model of computation. For the rest of the Python ML stack, see best ML frameworks for Python, and for classical vs deep learning, see TensorFlow vs scikit-learn.
PyTorch vs JAX at a glance
| Item | PyTorch | JAX |
|---|---|---|
| Latest release (checked November 19, 2026) | 2.15.0 (October 28; needs Python 3.11 or newer) | 0.12.1 (November 18; needs Python 3.12 or newer) |
| Programming style | Object oriented modules, eager by default | Pure functions and transformations |
| Compilation | Optional, with torch.compile | Central, with jax.jit and XLA |
| Neural network library | Built in (torch.nn) | Separate: Flax NNX, Equinox, or Keras |
| Best hardware fit | NVIDIA, plus AMD, Apple, Intel and CPU | TPUs and NVIDIA GPUs |
| TPU route | TorchTPU (replaces PyTorch/XLA) | Native, through XLA |
| Governance | PyTorch Foundation, part of the Linux Foundation | Google led open source project |
| License | BSD style | Apache 2.0 |
Release numbers and Python requirements come from PyPI; check PyTorch and the JAX changelog for newer versions.
How they feel different
PyTorch: write Python, get a model
In PyTorch, a model is a class with a forward method. Tensors hold state, layers hold their own parameters, and every line runs as soon as you call it. You can drop in a print statement or a debugger anywhere. When you want more speed, wrapping a model in torch.compile, which arrived with PyTorch 2.0, captures it as a graph and generates faster kernels, but compiling is optional. One practical catch: on CPU, torch.compile needs a working C++ compiler, which is why it failed on our test box.
JAX: pure functions plus transformations
JAX describes itself as a library for accelerator oriented array computation and program transformation. You write NumPy style functions with no hidden state, and then transform them: jax.grad for derivatives, jax.jit to compile with XLA, jax.vmap to vectorize over a batch, and sharding tools to spread work across many chips. These compose, so one line can give you compiled, per example gradients. The JAX README is candid that it is a research project with "sharp edges," and the classic one is that random numbers and parameters must be passed around explicitly.
Because JAX itself has no layer library, you pick one. The Flax README presents NNX, released in 2024, as its simplified API; it uses regular Python objects and feels closer to PyTorch's style than the older Linen API. Equinox is a popular alternative, and Keras 3 can run on JAX, PyTorch or TensorFlow as its backend.
The same training step in both
Here is the core of the step we timed. PyTorch mutates the model and optimizer in place:
def step(x, y):
opt.zero_grad()
loss = loss_fn(model(x), y)
loss.backward()
opt.step()
return loss
In JAX with Flax NNX, you describe the loss as a function, ask for its gradient, and compile the whole step:
@nnx.jit
def step(model, opt, x, y):
def loss_fn(model):
return optax.softmax_cross_entropy_with_integer_labels(model(x), y).mean()
loss, grads = nnx.value_and_grad(loss_fn)(model)
opt.update(model, grads)
return loss
Our CPU test: eager PyTorch vs jitted JAX
On November 19, 2026 we ran the same three layer MLP (784 to 1,024 to 1,024 to 10, about 1.86 million parameters) with Adam and a batch of 256 random samples, 200 steps per run, four runs per framework, on an 8 vCPU shared Linux machine.
| Measurement | PyTorch 2.15.0, eager | JAX 0.12.1, nnx.jit |
|---|---|---|
| First step (includes compile for JAX) | 18 to 56 ms | 199 to 207 ms |
| Steady speed | 53 to 139 steps per second | 169 to 211 steps per second |
| First step after changing batch size to 200 | 4 to 8 ms | 236 to 255 ms |
JAX was faster per step once compiled and steadier from run to run, while eager PyTorch swung widely as other jobs shared the CPU. JAX recompiled when the batch shape changed, which is the cost our guide on the ML framework for varying batch size explains. We could not time torch.compile, so this is not a compiled vs compiled comparison, and a tiny CPU model says little about large GPU or TPU jobs. Treat it as a picture of where each framework spends time, not a benchmark.
Hardware support
PyTorch has the broadest reach: NVIDIA CUDA is first class, and AMD ROCm, Apple's Metal backend, Intel GPUs and CPUs are all supported.
The JAX installation guide lists CPUs on Linux, Mac and Windows; NVIDIA GPUs on Linux (x86_64 and aarch64); Google TPUs on Linux; AMD GPUs on Linux x86_64; and Apple and Intel GPUs as experimental. Native Windows has no GPU support, so Windows users run JAX under WSL2, where NVIDIA and AMD GPU support is marked experimental. JAX 0.12.1 also added pip extras such as jax[rocm7] that pull AMD's ROCm wheels without a system ROCm install, and on GPUs it now preallocates 75% of memory at startup but lets the pool grow beyond that when needed.
PyTorch on TPU: TorchTPU replaces PyTorch/XLA
TPUs are where JAX shines, because both sit on Google's XLA compiler. That is the area changing fastest. PyTorch on TPU used to go through PyTorch/XLA, which recorded lazy graphs and often needed code changes. Its README now marks it deprecated, replaced by TorchTPU, and says the repo will be archived on November 15, 2026 (on November 19 GitHub did not yet show it as archived).
Google open sourced TorchTPU on October 20, 2026, and version 0.3.0 reached PyPI on November 13 (pip install torch_tpu, Python 3.11 or newer). Google's PyTorch on Cloud TPU page says it was built with the PyTorch team at Meta, runs eagerly by default with one process per device, compiles through torch.compile, and has no JAX runtime dependency. The same page points to vLLM-TorchTPU and SGLang-TorchTPU for serving and TorchTitan for training. It is still young, so JAX remains the more proven TPU route, but "PyTorch on TPU" no longer means a separate lazy tensor library. If you want to try either, Kaggle offers free TPU time, and Google Colab has TPU runtimes too; our Google Colab vs Kaggle GPU guide compares their free limits.
On a Mac, neither is the most natural choice for local language models; Apple's MLX framework is, as we explain in MLX vs GGUF on Mac. For MLX as a training framework, see MLX vs PyTorch and MLX vs JAX.
The ecosystem for open weight models
This is the deciding factor for most readers. Hugging Face said with Transformers v5 that it was sunsetting Flax and TensorFlow support "in favor of focusing on PyTorch as the sole backend," while working with JAX projects such as MaxText on interoperability. The Transformers README now asks for Python 3.11 or newer and PyTorch 2.6 or newer. The fine tuning tools covered in our guides to fine tune an LLM locally and fine tune an LLM with reinforcement learning, and the serving engines compared in vLLM vs llama.cpp, are PyTorch based or independent C++ projects.
JAX has a strong but smaller LLM stack, led by Google. The MaxText README describes it as a pure Python and JAX library for training models such as Gemma, Llama, DeepSeek, Qwen and Mistral on TPUs and GPUs, including SFT and GRPO post training. Tunix is a newer JAX library for post training that its README says is under active development.
Performance: which is faster?
There is no single answer to PyTorch vs JAX performance, and benchmark posts often compare tuned code in one framework with naive code in the other. Speed depends on hardware, shapes and how much you lean on compilers. Some fair generalizations:
- On TPUs, JAX is usually the safer bet today, because the whole stack was built around XLA; TorchTPU is promising but early.
- On NVIDIA GPUs, both can be fast. PyTorch benefits from the largest pool of hand optimized kernels, such as FlashAttention, used by the LLM tools above; JAX relies more on the XLA compiler and kernels written in Pallas, which JAX 0.12.1 now exposes as
jax.pallas. - For small experiments, JAX's compile step adds startup time each time shapes change, as our test showed, while eager PyTorch starts immediately.
- At very large scale, JAX's sharding model is elegant (0.12.1 removed the old GSPMD partitioner, so Shardy is now the only one), while PyTorch has mature options such as FSDP and the torchtitan training platform.
Measure your own model before switching frameworks for speed. For a lighter challenger, see our tinygrad vs PyTorch performance comparison.
Pros and cons
PyTorch
- Pros: easiest to learn and debug; the default for open models, tutorials and research code; widest hardware support; the framework used by tools like nanochat if you want to train a small LLM from scratch.
- Cons: the TPU backend just changed and is early; peak performance often needs
torch.compileor custom kernels; the API surface is large.
JAX
- Pros: composable transformations; excellent compiled performance and TPU support; clean model for parallelism; great for scientific computing beyond deep learning.
- Cons: steeper learning curve; explicit state and random keys; recompiles on new shapes; smaller open model ecosystem now that Transformers has dropped Flax; no native Windows GPU support.
Which should you choose?
- You fine tune or run open weight LLMs: PyTorch.
- You will train on TPUs or join a team that uses JAX: JAX, with Flax NNX. PyTorch teams can now trial TorchTPU instead.
- You do research needing per example gradients, higher order derivatives or custom transformations: JAX is a joy here.
- You want to keep options open: Keras 3 lets the same model code run on either backend; see Keras alternatives if Keras itself is the question.
- You are a beginner: start with PyTorch; the concepts carry over if you pick up JAX later.
FAQ
Is JAX faster than PyTorch?
Sometimes. JAX is often faster on TPUs and for code that compiles well with XLA. In our CPU test, jitted JAX ran 169 to 211 steps per second against 53 to 139 for eager PyTorch, but spent about 0.2 seconds compiling first. On NVIDIA GPUs, well tuned PyTorch with torch.compile and optimized kernels is competitive, so benchmark your own model on your own shapes.
Should I learn PyTorch or JAX first?
PyTorch, for most people. It is easier to debug, and it is what almost all open model tools and tutorials use. Learn JAX later if you need TPUs or its functional transformations.
PyTorch vs JAX vs TensorFlow: which should I pick?
For open weight LLMs and most new research code, start with PyTorch. Choose JAX when TPUs or functional transformations matter. Keep or learn TensorFlow when you inherit a TensorFlow codebase or need Keras 3's multibackend path; see TensorFlow vs PyTorch vs Keras.
Can PyTorch run on TPUs?
Yes. TorchTPU is now the official route: Google open sourced it on October 20, 2026, and version 0.3.0 was on PyPI as of November 19, 2026. PyTorch/XLA, the older route, is deprecated and due to be archived. TorchTPU is still early, so test your model before relying on it.
What is Flax NNX?
Flax NNX is the current neural network API in Google's Flax library for JAX. Released in 2024, it uses regular Python objects for layers, which feels closer to PyTorch than the older Flax Linen API. Flax on PyPI was 0.12.12 when we rechecked on November 19, 2026, and it needs Python 3.12 or newer.
Does Hugging Face Transformers support JAX?
Not in current versions. Hugging Face announced with Transformers v5 that it was sunsetting Flax and TensorFlow support to focus on PyTorch, while working with JAX projects such as MaxText on compatibility.



