TPU becomes a native device for PyTorch
On October 20, 2026, Hugging Face blogged that its Transformers, Diffusers, and Kernels libraries now support TorchTPU, which adds TPU as a native backend to PyTorch. TorchTPU is not a product of Hugging Face; rather, Hugging Face has adapted its libraries to work with it. This allows PyTorch users to utilize TPUs without migrating code for PyTorch/XLA (torch_xla) or learning JAX. Previously, it was necessary to go through PyTorch/XLA (torch_xla), but with TorchTPU, models work simply by sending them to the "tpu" device while keeping standard PyTorch code intact.
TPUs are AI accelerators designed by Google over approximately 10 years, specifically optimized for neural network matrix operations. They are available on Google Cloud ranging from single chips to pods of thousands of chips. Previously, the software stack was maintained for TensorFlow and JAX, requiring additional work for PyTorch users.
Conventional methods and TorchTPU
Previously, using TPUs with PyTorch required PyTorch/XLA. With XLA, tensors are evaluated lazily, meaning code might not execute at the intended timing. Small changes could trigger recompilation of the graph, making debugging difficult. Hugging Face had previously provided TPU support for Transformers and Diffusers via its own library, Optimum TPU. However, with the advent of TorchTPU, Optimum TPU is no longer mandatory.
TorchTPU can be installed on TPU VMs with a single command. It includes TPU kernels written in Pallas, support for distributed training, and integration with torch.compile.
Usage with Transformers and Diffusers
With Transformers v5, models run on TPUs simply by specifying device_map="tpu" when loading the model. It operates in eager mode by default, and performance can be improved using torch.compile. It also supports execution in distributed environments.
TPU is now supported as a first-class device in Diffusers. For prototyping and debugging, one only needs to call pipe.to("tpu"). For deployment, add a single compilation call. Compilation occurs during the first call, and the graph is reused for subsequent calls as long as the image size remains the same. The pipeline code does not need to be modified, nor is it necessary to maintain a fork for TPU.
If the model does not fit on a single chip, passing TensorParallelConfig to from_pretrained splits the transformer across multiple chips during loading. Many common pipelines support this feature by default.
According to Hugging Face's measurements, Qwen-Image-2.1 (1024×1024, 40 steps) ran in 3.5 seconds with compilation and 8.0 seconds in eager mode on Cloud TPU v6e-4 (tensor parallelism 4, bf16, batch size 1). For MiniMax-H3, which generates videos with audio (1344×768, 5.2-second video, 49 steps), it took 188 seconds with compilation and 262 seconds in eager mode.
Kernels and Performance
Kernels Hub provides kernels for TPUs, which can be loaded via the Kernels library to improve model speed. TPU kernels are written in Pallas, allowing low-level control of the hardware. Kernels from the Tokamax library are also available, with examples showing the integration of Tokamax's ragged-dot kernel for Mixture-of-Experts models.
In Hugging Face's measurements, on TPU v6e-8, the Hub's kernels were 21.5 times faster than the default implementation for Qwen3-30B-A3B and 12.8 times faster for Gemma 4 26B-A4B during decoding with a batch size of 64. They state that the performance difference increases with larger batch sizes.
Testing and Quality Control
Hugging Face runs its test suite for Transformers on TPUs to continuously improve quality. Of the tests run on TPUs, 96.5% passed, though the company notes that not all tests pass. Failed tests are reported to the TorchTPU repository along with reproduction scripts. So far, 34 issues have been reported, 19 of which have been resolved. Additionally, running tests on TPUs revealed bugs in Transformers itself, such as issues with StaticCache and Qwen3's tensor parallel plan, which have since been fixed. Going forward, Hugging Face plans to add nightly CI on TPUs and publish the results on a dashboard.
Perspectives
Previously, using TPUs with PyTorch required passing through PyTorch/XLA, and Hugging Face had also prepared a dedicated layer called Optimum TPU. With TorchTPU, models simply need to be sent to the "tpu" device, just like GPUs, allowing existing Transformers and Diffusers code to be used as is. Hugging Face states that Optimum TPU is no longer required to run models with Transformers and Diffusers.
The performance figures shown are all examples tested by Hugging Face on Cloud TPU v6e. The 21.5x and 12.8x kernel speeds were compared against the default implementation during decoding with a batch size of 64. There are no figures comparing performance with other hardware such as GPUs. The 96.5% test pass rate is based only on tests run on TPUs; the number of tests not run on TPUs is not specified.