TorchTPU makes Google TPUs a native PyTorch device on Hugging Face

A new native PyTorch backend called TorchTPU lets Transformers, Diffusers and Kernels run on Google TPUs by simply sending a model to "tpu", replacing the older torch_xla route.

Hardware2 min readBy
TorchTPU makes Google TPUs a native PyTorch device on Hugging Face
Image: Hugging Face

Hugging Face says running PyTorch on Google's TPUs no longer requires a detour. With TorchTPU, a native PyTorch backend, a TPU becomes one more device you can target, and the Hugging Face libraries Transformers, Diffusers and Kernels now support it directly.

What changed

TPUs are Google's in-house AI accelerators, built for the matrix math at the core of neural networks and used to train and serve Gemini. They are rented on Google Cloud, from a single chip up to pods of thousands. The problem for PyTorch users has always been software: the TPU stack grew up around TensorFlow and JAX, and the PyTorch path ran through PyTorch/XLA, whose lazy tensors, surprise graph recompilations and hard debugging put many developers off. Hugging Face had built Optimum TPU to smooth that over; the company says it is no longer needed for Transformers and Diffusers.

TorchTPU adds TPU as a regular PyTorch backend. It ships with Pallas kernels tuned for the hardware, distributed training support and a torch.compile integration, and installs on a TPU VM with a single pip command that pulls the CPU build of torch instead of the much larger CUDA build.

How it looks in code

In Transformers, loading a model onto a TPU means passing device_map="tpu". Models run in eager mode by default, with torch.compile available for more speed. In Diffusers, a pipeline moves to the chip with pipe.to("tpu"), and one compile call adds a compiled mode for deployment. Models too large for a single chip can be sharded across chips at load time with a tensor-parallel config.

The Kernels Hub also carries ready-made TPU kernels written in Pallas. Hugging Face reports that a ragged-dot kernel from Google's Tokamax library made decoding 21.5 times faster on Qwen3-30B-A3B and 12.8 times faster on Gemma 4 26B-A4B at batch size 64 on a TPU v6e-8.

Not finished yet

Hugging Face is candid that support is still maturing. Of the Transformers tests that run on TPU, 96.5% pass. The team has filed 34 issues against TorchTPU, 19 of which are already fixed, and is working on a nightly TPU CI with results published on the Transformers dashboard. The effort also surfaced bugs in Transformers itself, which were fixed upstream.

Why it matters for builders

Compute choice has been tied to CUDA for most PyTorch teams. If your training or serving code can move to TPUs with a one-line device change, Google Cloud TPU capacity becomes a realistic option for price or availability reasons, without rewriting in JAX. It is worth benchmarking your own models, starting with eager mode and adding compile and Hub kernels once results check out, and keeping an eye on the failing-test list before betting production on it.

Source: Hugging Face. This article is PickAI’s own summary and analysis based on the original reporting, prepared with AI assistance under our editorial policy.

Enjoyed this story? Get PickAI Weekly

Get the week’s best new AI tools and news — one email a week, free. No spam, unsubscribe anytime.

Related tools on PickAI

↗

Hugging Face

huggingface.co

Hub for open models, datasets and ML demos.

Related AI news

All news →
Hugging Face

PyTorch 2.15 makes Macs much faster for local models

Hugging Face's PyTorch team says 2.15 brings FP8 to Apple's MPS backend, 5-6.5x faster mixture-of-experts decoding, an 8x faster softmax and a Wan2.2 video VAE decode that peaks at 8 GiB instead of 270 GiB.

Hugging Face

TorchNeuron makes AWS Trainium a native PyTorch device

AWS's TorchNeuron backend brings eager mode, torch.compile and FSDP to Trainium, and Hugging Face Transformers, Diffusers, PEFT and TRL now run on it directly; the public beta starts October 20.

TechCrunch

Ricursive Intelligence bets on AI-designed chips

The startup is building AI that designs chips and improves with each iteration, aiming to speed up chip design.

Get the weekly AI tools drop

New tools and releases for builders, once a week. No spam, unsubscribe anytime.