Hugging Face adds native TPU support to Transformers and Diffusers
Transformers and Diffusers now support TPU through TorchTPU, which adds another backend to PyTorch. According to Hugging Face, Optimum TPU is no longer needed to run them on TPU. However, some tests are not yet passing.
Hugging Face has introduced native TPU support in Transformers and Diffusers through TorchTPU. This adds TPU as another backend in PyTorch. According to the company, Optimum TPU is no longer needed to run these libraries on TPU. TPU accelerators are available on Google Cloud.
On a TPU VM, TorchTPU can be installed with `pip install torch-tpu --extra-index-url https://download.pytorch.org/whl/cpu`. The additional package source ensures that the CPU build of PyTorch is installed instead of the larger CUDA build. In Transformers v5, a model is loaded using `device_map="tpu"`; in Diffusers, using `pipe.to("tpu")` is sufficient for eager mode. Compilation with torch.compile and splitting supported models across multiple chips are also supported.
For example, the company reports image generation with Qwen-Image-2.1 taking 3.5 seconds with compilation, compared with 8 seconds in eager mode. The measurement was taken on Cloud TPU v6e-4 with the model split across four chips, bf16 precision, a batch size of 1, a resolution of 1024 × 1024 and 40 steps. This is a measurement by the company, not an independently verified comparison.
Support is still being developed: the company says not all tests pass and is preparing nightly automated testing on TPU. Details are available in the source article.
Why it matters
Developers using PyTorch can consider TPU for text and image generation with minor code changes. The documented measurement also shows that the use of compilation matters when deciding how to deploy.
Two audiences, two different impacts
What this means
For individuals
When prototyping, you can load a model directly onto TPU or move an image pipeline to it using the parameters and calls shown.
For a business
Verifying the compatibility of the models in use remains important for enterprise deployment: Hugging Face says some TPU support tests are not yet passing.
DevelopmentCheck the original
Event sources
only one source so far · 1 publisher, 0 independent. We count feeds from the same owner only once.