---
title: "Hugging Face ❤️ TorchTPU: TPUs, Natively"
description: "TorchTPU is a native PyTorch backend that makes TPU an ordinary device, replacing the lazy-tensor torch_xla path and making Optimum TPU unnecessary for running Hugging Face models."
url: "https://swe.quest/articles/hugging-face-torchtpu-tpus-natively-25e58a9bb63cbf24"
canonical: "https://huggingface.co/blog/hf-torchtpu"
source: "Hugging Face"
published: "2026-10-20"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 6
tags: ["inference","hardware","python","machine-learning"]
---

# Hugging Face ❤️ TorchTPU: TPUs, Natively

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2026-10-20, 6 min read, Announcement. Original: [https://huggingface.co/blog/hf-torchtpu](https://huggingface.co/blog/hf-torchtpu)

## Summary

TorchTPU is a native PyTorch backend that makes TPU an ordinary device, replacing the lazy-tensor torch\_xla path and making Optimum TPU unnecessary for running Hugging Face models. Transformers loads models with device\_map="tpu", and Diffusers pipelines run with pipe.to("tpu"), optionally with torch.compile and tensor parallelism across chips. Pallas kernels from the Kernels Hub, such as a Tokamax ragged-dot MoE kernel, speed up batch-64 decoding by 21.5× on Qwen3-30B-A3B and 12.8× on Gemma 4 26B-A4B. Of the Transformers tests that run on TPU, 96.5% pass, and 34 TorchTPU issues have been reported so far, 19 of them fixed.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)

## Prerequisites

- PyTorch basics
- Hugging Face Transformers

## Keywords

TorchTPU, TPU, PyTorch, Transformers, Diffusers, Pallas, torch\_xla, Tokamax

## Related posts

- [TorchNeuron: running HF models on AWS Trainium is easier than ever](https://swe.quest/articles/torchneuron-running-hf-models-on-aws-trainium-is-easier-than-ever-99ae731bb5ca0252.md): Hugging Face · 2026-10-19 · Medium · 7 min read · Hardware, Model training, Inference & serving, Python
  TorchNeuron is a PyTorch plugin that exposes AWS Trainium as a native \`neuron\` device with eager execution, \`torch.compile\`, and native distributed APIs (DTensor, FSDP2, TP), replacing the PyTorch XLA–based path that required lazy tensors and static graphs.
- [Learn the Hugging Face Kernel Hub in 5 Minutes](https://swe.quest/articles/learn-the-hugging-face-kernel-hub-in-5-minutes-049114b1e85677a7.md): Hugging Face · 2025-06-12 · Medium · 13 min read · Inference & serving, Performance engineering, Python, Hardware
  Hugging Face's Kernel Hub and \`kernels\` library let PyTorch code download pre-compiled, optimized GPU kernels such as FlashAttention, activations, RMSNorm and quantization kernels with a single \`get\_kernel\` call.
- [Custom Kernels for All from Codex and Claude](https://swe.quest/articles/custom-kernels-for-all-from-codex-and-claude-9d652cbc33fa9001.md): Hugging Face · 2026-02-13 · Medium · 9 min read · AI for coding, Performance engineering, Inference & serving, Hardware, Python
  Hugging Face packaged CUDA kernel expertise (GPU architecture guides for H100/A100/T4, diffusers and transformers integration patterns, vectorized kernel templates, benchmark scripts) into an agent skill that lets Claude and Codex generate complete kernel-builder projects with PyTorch bindings.
- [MPS in PyTorch 2.15](https://swe.quest/articles/mps-in-pytorch-2-15-b68893e8d3c0039f.md): Hugging Face · 2026-10-20 · Medium · 11 min read · Inference & serving, Performance engineering, Python, Hardware
  PyTorch 2.15 adds FP8 (float8\_e4m3fn) tensors and scaled\_mm on Apple's MPS backend and replaces many MPSGraph paths with dedicated Metal kernels.
- [Training a language model with 🤗 Transformers using TensorFlow and TPUs](https://swe.quest/articles/training-a-language-model-with-transformers-using-tensorflow-and-tpus-7d72fd7dce30644b.md): Hugging Face · 2023-04-27 · Medium · 8 min read · Model training, Hardware, Python, LLMs
  Training a RoBERTa-base masked language model from scratch on WikiText with TensorFlow on TPUs, end to end: training a Unigram tokenizer with 🤗 tokenizers, tokenizing and chunking text into fixed 128-token sequences, sharding into TFRecords stored in Google Cloud Storage, and training under TPUStrategy with XLA-compatible Transformers models.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
