TorchTPU: Open-Source PyTorch Backend for Google TPUs
TorchTPU is an open-source project developed by Google and Meta that provides a native PyTorch backend for Google TPUs, addressing limitations of earlier frameworks like PyTorch/XLA.
TorchTPU Overview and Development Context
TorchTPU is an open-source project developed by Google in collaboration with Meta that provides a native PyTorch backend for Google TPUs, as reported by InfoQ. This initiative builds on earlier efforts, such as PyTorch/XLA, which Google introduced in 2020 to enable PyTorch workloads on TPUs. However, PyTorch/XLA had limitations, including intrusive source-code modifications, compile-time latency, and limited support for PyTorch’s imperative execution mode. TorchTPU aims to address these issues by adhering to principles such as PyTorch Citizenship, which emphasizes no JAX dependencies, solid eager mode support, and compatibility with PyTorch distributed idioms. The project also integrates with existing PyTorch tools like torch.profiler and DTensor, ensuring a seamless experience for developers. According to the developers, TorchTPU allows models to run out of the box on TPUs, though achieving peak performance may require additional tuning.
TorchTPU Execution Modes and Performance Benefits
TorchTPU introduces three eager execution modes—strict, debug, and DeferAndFuse—to enable native PyTorch support on Google TPUs. The DeferAndFuse mode, a hybrid eager/compiled execution modality, is highlighted as a key innovation. According to Google, this mode can be 50% or more faster than Strict Eager while reducing peak HBM memory usage, as noted in the documentation. This improvement is attributed to op fusion, which minimizes temporary storage in HBM. Performance benchmarks show that on a single TPUv7 chip, inference throughput reaches 25.7k token/s at 5120 sequence length and 22.4k token/s at 10,240 sequence length. For training, using four TPUv7 chips, throughput reaches 5.6k token/s and 4.6k token/s at 5120 and 10,240 sequence lengths, respectively. These execution modes can be configured via environment variables or a context manager, offering flexibility for developers.
Integration with Ecosystem Tools and Frameworks
Integration with ecosystem tools and frameworks is a key focus of the TorchTPU initiative. Jana van Greunen, Director of PyTorch Engineering at Meta, highlights that the collaboration enables developers to deploy PyTorch workloads on Google TPUs, provide direct feedback, and build ecosystem flexibility. In partnership with Hugging Face, popular open-weight models across the Hugging Face Hub now run natively on TorchTPU. This includes Transformers v5, where models can be deployed by simply passing device_map="tpu", along with native support for Diffusers. Additionally, the vLLM backend, developed in partnership with Inferact, provides optimized, production-ready serving features and custom Pallas kernels for deploying open-weight models directly on TPUs. Native TorchTPU support has also been added to Ray, allowing orchestration of PyTorch workflows across CPUs, GPUs, and TPUs. As a CNCF Sandbox project, llm-d bridges the PyTorch and Kubernetes communities, enabling distributed systems to run and scale in production.
Performance Testing and Use Cases
Performance testing of TorchTPU on Google TPUs demonstrates notable throughput capabilities. On a single TPUv7 chip, inference throughput reached 25.7k token/s at 5120 sequence length and 22.4k token/s at 10,240 sequence length InfoQ. For training, using four TPUv7 chips, throughput reached 5.6k token/s and 4.6k token/s at 5120 and 10,240 sequence length, respectively InfoQ. TorchTPU maps PyTorch precision modes to underlying XLA/StableHLO configurations, with the medium mode using lower precision for multiplication while accumulation is performed in FP32 to maintain stability pytorch.org. This mode is the default, as it provides sufficient accuracy for nearly all deep learning workloads pytorch.org. Users are advised to switch to high or highest precision only if precision-related convergence issues are identified, as these modes trigger significant performance overhead pytorch.org. With the tpu-agent skill enabled, natural language prompts can be used to automate tasks like model onboarding and benchmarking discuss.google.dev.
TorchTPU Development Status and Future Directions
TorchTPU is in active development and is already being used in production for both inference and training workloads by some of Google Cloud’s largest customers, according to this GitHub repo. The project is now open source, as noted by Google Cloud in its AI Infrastructure blog, alongside the early preview of the TPU Agent Suite. The TPU Agent Suite aims to streamline onboarding and performance tuning by providing declarative bundles of multi-agent skills, routing protocols, and tools that compile and install natively across coding agent harnesses. With the tpu-agent skill enabled, users can leverage natural language prompts in their coding environments to automate tasks such as model onboarding, benchmarking, and inference server setup. These developments are part of an ongoing effort to expand PyTorch support on Google TPUs, including the addition of bounded dynamism for improved flexibility in workload execution.
Sources and reporting notes
Based on published source material. No independent hands-on testing is claimed.