█

AI/TLDR

TorchTPU

Run PyTorch on Cloud TPUs with a native "tpu" device instead of a compiler bridge

Efficient TrainingOpen source
Latest
0.2.0
Updated
19 Oct 2026
Language
C++
License
Apache-2.0
Coverage
2 stories

What's new

0.2.019 Oct 2026

Google published the TorchTPU repository on GitHub under Apache 2.0 and released version 0.2.0 on PyPI, making the native PyTorch-on-TPU backend installable with `pip install torch_tpu`. The release validates TPU v5e, v5p, v6e and v7, and supports DDP, FSDP2, SimpleFSDP and DTensor.

Latest news

Overview

TorchTPU is an open-source PyTorch backend for Google Cloud TPUs, built by Google together with the PyTorch team at Meta. It adds a real `tpu` device to PyTorch, so most of the work of porting a GPU script is changing `device="cuda"` to `device="tpu"` and the distributed backend from `"nccl"` to `"tpu_dist"`. There is no JAX runtime underneath, and PyTorch's tensor view and in-place mutation semantics are preserved, with one process per device.

Execution is eager by default: operators are dispatched one at a time and run asynchronously. A debug mode (`TORCH_TPU_LAUNCH_BLOCKING=1`) makes them synchronous and adds runtime bounds checking, and a DeferAndFuse mode (`TORCH_TPU_DEFER_AND_FUSE=1`) fuses sequences of operators up to a materialization point such as `.cpu()` or `.item()` to cut HBM traffic. For compiled execution, a `"tpu"` Dynamo backend lowers FX graphs to StableHLO and hands them to the OpenXLA compiler, with a three-tier compilation cache spanning process memory, host shared memory and persistent remote storage.

TorchTPU is the successor to PyTorch/XLA. Google announced the project in April 2026 and said it would replace PyTorch/XLA once the public repository shipped; the repository and release 0.2.0 on PyPI arrived in October 2026. The feature-set page lists TPU v5e, v5p, v6e and v7 as validated, with v8i and v8t as near-term work, and marks checkpointing, activation offloading and multi-slice training up to 8,000 chips as validated. Custom kernels can be written with Pallas through `torch.tpu.pallas.jax_op`, with the experimental Helion DSL, or taken pre-built from Tokamax.

What it does

  • Native `tpu` device registered with PyTorch — no JAX runtime dependency, one process per device
  • Three eager modes: strict (default, async), debug (synchronous with bounds checking), and DeferAndFuse (operator fusion)
  • `torch.compile` support via a `"tpu"` Dynamo backend that lowers FX graphs to StableHLO for OpenXLA
  • Distributed training at the `torch.distributed` process-group level: DDP, FSDP2, SimpleFSDP and DTensor
  • Three-tier compilation cache across process memory, host shared memory and remote storage
  • Custom kernels through Pallas, the experimental Helion DSL, or pre-built Tokamax kernels
  • Example models in the repo: Llama, Qwen, ResNet, DLRM, minGPT and UNet

Getting started

TorchTPU runs on a Cloud TPU VM. Install Python 3.12 and the wheel in that order so the PyTorch dispatcher and the TPU drivers line up, then switch your device string.

Set up Python on a TPU VM

The docs use a v6e Cloud TPU VM as the example. Newer TPU hardware is covered by the separate GKE guide.

bashbash
sudo apt update && sudo apt install -y python3.12 python3.12-venv
python3.12 -m venv env
source env/bin/activate

Install TorchTPU

Release 0.2.0 ships Linux x86-64 wheels for CPython 3.11 through 3.14, including a free-threaded 3.14 build.

bashbash
pip install torch_tpu

Initialize the device

The device string is `tpu`, in place of `cuda`.

pythonpython
import torch

device = torch.device("tpu")  # Change from cuda to tpu

print(f"TPU Initialization complete. Primary device: {device}")

Move tensors and read results back

Tensors can be moved with `.to(device)` or created directly on the TPU; `.cpu()` materializes the result.

pythonpython
tpu_tensor = torch.ones((5, 5)).to(device)
direct_tpu_tensor = torch.randn((5, 5), device="tpu")

result_on_cpu = (tpu_tensor + direct_tpu_tensor).cpu()
print(f"Result Checksum (Sum): {result_on_cpu.sum():.4f}")

Scale out

For distributed runs, set the process-group backend to `tpu_dist`; the docs at https://torchtpu.readthedocs.io cover FSDP2, DTensor, multi-slice training, Pallas kernels and XProf profiling.

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Move an existing PyTorch training script from NVIDIA GPUs to Cloud TPUs with small edits
  • Train large models on TPU pods with FSDP2, DTensor or multi-slice sharding
  • Compile a PyTorch model through OpenXLA for TPU execution with `torch.compile`
  • Write TPU kernels in Pallas or reuse Tokamax kernels from inside a PyTorch model

How TorchTPU compares

TorchTPU alongside other open-source efficient training tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
DeepSpeed★ 43.2kA deep learning optimization library whose ZeRO memory partitioning and offloading let you train very large models across many GPUs.
Megatron-LM★ 18.2kNVIDIA's library for training large transformer models at scale using tensor, pipeline, and sequence parallelism.
Accelerate★ 9.9kA library that runs the same PyTorch training code across CPUs, multiple GPUs, and TPUs while handling mixed precision, FSDP, and DeepSpeed.
DeepSpec★ 7.2kDeepSeek's codebase for training and evaluating draft models for speculative decoding, bundling data preparation, the DSpark, DFlash and Eagle3 drafters, training code and benchmarks.
TorchTitan★ 5.8kA PyTorch-native platform for pre-training large models that combines FSDP, tensor, pipeline, and context parallelism in one codebase.
LightlySSL★ 3.8kA modular PyTorch framework for self-supervised computer vision: losses, model heads and multi-view transforms for 20+ methods from MoCo and SimCLR to DINOv2, CAPI and LeJEPA.
Lingvo★ 2.9kGoogle's TensorFlow framework for building and training sequence models such as speech recognition, translation and GShard-scale language models.
TorchTPU—Run PyTorch on Cloud TPUs with a native "tpu" device instead of a compiler bridge