The engineering behind inference.Contact ↗
Batch & Release/Inference

TorchTPU brings native PyTorch eager execution to Google TPUs

Google and Meta introduce TorchTPU, an open source PyTorch backend for TPUs with eager execution, torch.compile integration, and out-of-the-box model migration via a simple device change.

TorchTPU brings native PyTorch eager execution to Google TPUs
Image: PyTorch ↗

Google and Meta have introduced TorchTPU, an open source PyTorch backend for Google TPUs that runs models in eager mode by default and supports torch.compile integration. The project started at Google in mid 2025 and was built in collaboration with the PyTorch team at Meta. It replaces the earlier PyTorch/XLA approach, which relied on Lazy Tensors and required explicit compilable regions, suffered from compile-time latency, and lacked native eager execution support. TorchTPU is designed as a principled TPU backend, with no JAX dependencies in the runtime, and existing PyTorch workloads run out of the box with trivial code changes, such as changing model.to("cuda") to model.to("tpu").

The project is in active development and is used in production for inference and training workloads by some of the largest Google Cloud customers. It supports both eager and compiled modes, including a new DeferAndFuse eager mode, and covers about 450 Aten ops, including forward and backward passes for all Core ATen ops required for major deep learning architectures. Custom kernels can be authored via JAX/Pallas or via Helion DSL. TorchTPU has validated built-in compatibility with Hugging Face's Transformers v5, Diffusers, and Kernels libraries, with out-of-the-box execution on the 5,000 most downloaded Hugging Face models, including LLMs like Qwen, DeepSeek, Gemma, Llama, Mistral, GPT, OPT, BLOOM, Falcon, and StableML, audio models like Whisper and Wav2Vec2, vision models like DinoV2 and CLIP, and text encoders like BERT and T5. It also supports DTensor-based sharding, multi-host inference with vLLM and SGLang, and training workloads with TorchTitan, along with Ray-based orchestration.

Architecture and programming model

Google TPUs are specialized ASICs with TensorCores that include matrix-multiply units, vector units, and scalar units, plus SparseCores for sparse operations and collectives. TPUs are programmed through the XLA compiler stack using StableHLO for higher-level ML ops and Mosaic for custom kernels. A C++ program accesses a local TPU by instantiating a PjRT client, which compiles MLIR into a TPU executable and launches it. TPU execution is asynchronous, and the CPU can wait for results via PjRTBuffer.

A key difference from GPUs is that a TensorCore device acts as a single-threaded processor with massive matrix-multiply units, so reaching peak performance requires sufficiently wide shapes to exploit the MXU fully. TPUs can offload sparse and collective operations to SparseCore, either automatically or through user-supplied MLIR annotations. A TPU device can be accessed by only one user-space process, so TorchTPU adopts a one-process-per-device model for distributed workloads, in contrast with JAX's one-process-per-host model. StableHLO follows the SSA paradigm and does not allow in-place mutations, but TorchTPU provides familiar PyTorch view semantics, including mutations, through view decomposition and inversion. The XLA compiler assumes tensor shapes are known at compile time, so TorchTPU adds support for bounded dynamism, where maximum bounds are known at compile time but actual dimensions are known only at runtime. Collective ops are lowered to XLA as StableHLO ops rather than using a separate library like NCCL.

Precision modes and usability

TorchTPU adapts standard PyTorch precision APIs to TPU hardware. The native matrix multiplication format for TPUs is bfloat16, with FP32 accumulation on the MXU. For non-contracting operations like element-wise additions, activations, layernorm, and softmax, TorchTPU executes FP32 tensor operations on the TPU vector unit, which performs full IEEE-754 FP32 arithmetic. TorchTPU maps PyTorch precision modes to XLA configurations: medium uses lower precision for multiplication with FP32 accumulation and is the default, high uses a 3-pass algorithm that recovers most FP32 precision at roughly 3 times the compute cost, and highest uses a 6-pass algorithm that approximates full IEEE FP32 accuracy at roughly 6 times the compute overhead. Selecting high or highest triggers a performance warning.

For usability, TorchTPU leverages PyTorch's autoload mechanism. When a user imports PyTorch on a TPU machine with the TorchTPU wheel installed, running code on TPU requires only trivial changes, such as changing the device from cuda to tpu and the process group backend from nccl to tpu_dist. An alternative approach uses torch.accelerator.current_accelerator() and dist.init_process_group() without specifying a backend, which works on both TPU and GPU. The project aims to provide user-friendly and actionable messages for runtime and compiler errors, and integrates with tools like torch.profiler, DTensor, and Ray.

Sources & references

PyTorch: Introducing TorchTPU ↗Source consulted: 2026-10-22

Privacy choices

We remember your answer in this browser for 180 days. Come back here whenever you want to change it.

EssentialSaves your answer in this browser. No cookies, no third parties.Always active