TorchTPU: Google open-sources a native PyTorch backend for TPUs

TorchTPU (Apache 2.0, version 0.2.0) registers TPUs as a normal PyTorch device, offers three eager modes, and compiles through TorchDynamo, StableHLO and XLA. We explain the design, what changed from PyTorch/XLA, the reported scaling numbers, and the stated limitations.
In short
On 20 October 2026, Google open-sourced TorchTPU under the Apache 2.0 license, a PyTorch backend that runs ordinary PyTorch code on Google's Tensor Processing Units (TPUs). Version 0.2.0 is on PyPI. It replaces the older PyTorch/XLA approach with an "eager first" design: code runs operation by operation like on a GPU, and torch.compile is used for speed. One day earlier, Amazon released TorchNeuron for its Trainium chips. Together they matter because PyTorch code has been tied in practice to NVIDIA GPUs, and both companies now try to make switching hardware close to a configuration change.
How it works
Device integration. PyTorch has an official extension point for out-of-tree hardware called PrivateUse1. TorchTPU registers the TPU through this interface, so tensors on the TPU are ordinary torch.Tensor objects with the device "tpu". Google says there are no tensor subclasses or wrappers. In practice you move a model with .to("tpu"), or in Hugging Face Transformers v5 with device_map="tpu".
Three eager modes (from Google's April 2026 design post):
- Debug Eager runs one operation at a time and waits for the TPU after each one. It is slow but makes shape errors, NaNs and out-of-memory errors easy to locate.
- Strict Eager also runs one operation at a time, but asynchronously, like default PyTorch on a GPU: CPU and TPU work in parallel until the code needs a result.
- Fused Eager groups the stream of operations into larger chunks before sending them to the TPU. Google reports a 50% to over 100% speed increase over Strict Eager, without stating the workloads.
All three share a compilation cache, which can be local or shared across hosts.
Compiled mode. torch.compile captures the full graph with TorchDynamo as an FX graph. TorchTPU then skips TorchInductor (the default PyTorch compiler for GPUs) and translates the graph to StableHLO, the input format of Google's XLA compiler. Google chose XLA because it already knows how to overlap computation with communication over the TPU's chip-to-chip network (ICI).
Analogy: a GPU behaves like a kitchen that cooks each order as it arrives; a TPU is most efficient when it gets a whole menu in advance. The eager modes take orders one by one, and the compiled mode hands over the whole menu.
Under the hood
What changed compared with PyTorch/XLA. Google describes PyTorch/XLA as the predecessor. It traced operations lazily into XLA graphs and supported only pure SPMD programs (every device runs the same program). Code where one rank does extra work, such as logging on rank 0, had to be rewritten. TorchTPU is designed for divergent (MPMD) execution and isolates communication operations where needed. Google does not say whether PyTorch/XLA will be deprecated.
Distributed training. DDP, FSDPv2 and DTensor are supported out of the box according to the April post. The README lists data and tensor parallelism. Google's TorchTitan fork has recipes for Llama 3 70B/405B, Qwen 3 8B/32B/235B (MoE) and FLUX.1 12B, and Google reports up to 52% model FLOPs utilization (MFU) for Qwen 3 8B with near-linear scaling up to 8,192 TPU v7x (Ironwood) chips. Google does not give the sequence length, batch size or precision for that figure.
Custom kernels. Kernels can be written in Pallas (the JAX kernel language) and attached with the decorator @torch_tpu.pallas.custom_jax_kernel. Support for Helion, the PyTorch kernel language, is in progress.
Inference ecosystem. Separate backends exist for vLLM (vllm-torchtpu) and SGLang (sglang-torchtpu). Hugging Face runs the Transformers test suite nightly on TPUs.
Known limitations (stated by Google).
- Dynamic sequence lengths and batch sizes trigger recompilation; "bounded dynamism" in XLA is planned.
- The first iteration has high latency because of compilation; a precompiled kernel library is planned.
- Google notes that current TPUs reach peak matrix-multiply efficiency with attention head dimensions of 128 or 256, while many models use 64. Such models may run below peak.
- Wheels are for Linux x86-64 and CPython 3.11–3.14. Google names TPU v6e and v7x; a full list of supported generations is not published.
- No independent comparison with GPUs or with PyTorch/XLA was available when we wrote this.
TorchNeuron (Amazon). Released on 19 October 2026 for Trainium, with the same goal of running PyTorch code without rewrites. Amazon is also sending changes to upstream PyTorch that separate features from NVIDIA-specific code, according to TechCrunch. We did not find enough technical primary material to describe its design here.
Try it yourself
You need a Google Cloud TPU VM; Google suggests a v6e instance. These steps follow the README; we did not run them ourselves because we have no TPU access.
Step 1. Install (Python 3.11 or newer):
pip install torch_tpu==0.2.0 --extra-index-url https://download.pytorch.org/whl/cpu
Step 2. Compare eager and compiled execution on a small matrix multiplication:
import time, torch
import torch_tpu # registers the "tpu" device
x = torch.randn(4096, 4096, device="tpu")
w = torch.randn(4096, 4096, device="tpu")
def f(x, w):
return torch.relu(x @ w) @ w
for name, fn in (("eager", f), ("compiled", torch.compile(f))):
fn(x, w).cpu() # warm-up and compilation
t = time.perf_counter()
for _ in range(20):
y = fn(x, w)
y.cpu() # forces the TPU to finish
print(name, (time.perf_counter() - t) / 20 * 1e3, "ms per call")
Step 3. Repeat with head-dimension-like shapes of 64 and 128 in the inner dimension (for example x of shape 4096×64 and w of 64×4096) to test Google's note about matrix-multiply efficiency. Also change the batch size between calls and observe the recompilation cost of the compiled version.
The exact import name and the API for switching eager modes are documented at torchtpu.readthedocs.io; check there if the import above fails.
Sources
What should happen next with this?
One click per article, no account needed. “Go deeper” feeds the research queue.