01 Hugging Face · Google InfraOpen source

Hugging Face × TorchTPU: run Transformers and Diffusers models on TPU with `device_map="tpu"`

Concept illustration (generated)

What is it?

Hugging Face published how to run Transformers, Diffusers and Kernels on TorchTPU, a PyTorch backend that treats a TPU as just another device. It replaces the older PyTorch/XLA route and Optimum TPU. Install it on a TPU VM:

pip install torch-tpu --extra-index-url https://download.pytorch.org/whl/cpu

Then load models with device_map="tpu" and move inputs with .to("tpu"). Eager mode is the default, and torch.compile is available for more speed.

Why does it matter?

Moving GPU code to TPUs used to mean writing XLA-specific code, and that barrier just got lower. In Hugging Face's own numbers, Qwen-Image-2.1 at 1024×1024 took 3.5 s compiled versus 8.0 s eagerVendor claim, and MoE decoding got up to 21.5x faster with a dedicated kernelVendor claim. Teams short on GPUs now have a cheaper path to evaluate TPUs.

Maturity

BetaBeta-level. 96.5% of the Transformers tests that run on TPU passVendor claim, and the post admits the nightly CI is not all green yet.

How to track it

  • Issues: watch how many of the 34 reported TorchTPU issues are still open and how fast they close.
  • CI: check whether Hugging Face announces a complete nightly TPU CI.
  • Your own test: run your model on a TPU v6e and a GPU under the same settings and compare cost per result.

More from the same day