Hugging Face ❤️ TorchTPU: TPUs, Natively

2026年10月20日 00:00
站內 AI 整理稿

Back to Articles Hugging Face ❤️ TorchTPU: TPUs, Natively Published October 20, 2026 Update on GitHub Upvote 2 Alvaro Moran tengomucho Follow Jingya Huang Jingya Follow Simon Pagezy pagezyhf Follow Jeff Boudier jeffboudier Follow Régis Pierrard regisss Follow If you ever tried to run PyTorch on a TPU, you probably ported your code to torchxla, or you ended up having to learn JAX.

With TorchTPU, a native PyTorch backend, TPU is now just another device.It opens up native support of TPU in the Hugging Face ecosystem.Transformers, Diffusers and Kernels run natively on TPU.Pick a model from the Hub, send it to "tpu", and you're done.Wait, what's a TPU?

🤔 TPU stands for Tensor Processing Unit.TPUs are Google's own AI accelerators.They are chips built for one job: the matrix math that neural networks spend most of their time on.Google has been designing them for about ten years, and uses them to train and serve its own models, including Gemini.

TPUs are available on Google Cloud, from a single chip up to pods of thousands of chips.They shine when you need a lot of compute, for training or for serving at scale.The catch has always been software.The TPU stack grew up around TensorFlow and JAX, and PyTorch users had to work harder to get in.

The old way Until now, running PyTorch on TPUs meant going through PyTorch/XLA (torchxla).It worked, but it had its quirks.Tensors were lazy (the tensors, not you), so your code didn't always run when you thought it did.

Small changes could trigger graph recompilations, and debugging was hard to reason about.To make life easier, we built Optimum TPU.It gave Hugging Face models inference and training support on TPUs.

Now that TorchTPU brings native support, Optimum TPU is not required anymore to run Hugging Face models with Transformers and Diffusers.Enter TorchTPU 🚀 TorchTPU adds TPU as a new backend to PyTorch.You write regular PyTorch code.

It comes with Pallas kernels tuned for TPUs, support for distributed training, and a torch.compile integration for when you want more speed.Installing it on a TPU VM takes one command: pip install torch-tpu --extra-index-url https://download.pytorch.

org/whl/cpu The extra index gives you the CPU build of torch.Without it, pip pulls the much bigger CUDA build, which you don't need on a TPU.

Your favourite libraries, now on TPU Transformers Transformers v5 was built around one idea: be the source of truth for model definitions, so they can run anywhere."Anywhere" now includes TPUs.To load a model on a TPU, pass devicemap="tpu".That's it.

from transformers import AutoModelForCausalLM, AutoTokenizer modelid = "Qwen/Qwen3.5-9B" model = AutoModelForCausalLM.frompretrained( modelid, devicemap="tpu", # will load model directly on the TPU ) tokenizer = AutoTokenizer.

frompretrained(modelid) inputs = tokenizer("The future of AI is", returntensors="pt").to("tpu") out = model.generate(**inputs, maxnewtokens=64) print(tokenizer.decode(out[0], skipspecialtokens=True)) The model runs in eager mode by default.You can also use torch.

compile for better performance, or run it in a distributed setup.Images?Videos?Diffusers paints them on TPUs 🎨 TPU is now a first-class device in Diffusers.For prototyping or debugging, eager mode only needs pipe.to("tpu").For deployment, compiled mode adds one compile call.

Your pipelines and code stay the same, and there's no TPU fork to maintain.import torch from diffusers import StableDiffusion3Pipeline pipe = StableDiffusion3Pipeline.frompretrained( "stabilityai/stable-diffusion-3.5-medium", dtype=torch.bfloat16 ) pipe.

to("tpu") # eager mode: that's the whole change # optional: compiled mode pipe.transformer.compile(backend="tpu", fullgraph=True, dynamic=False) image = pipe("a corgi astronaut planting a flag on a pizza moon").

images[0] The first call compiles, and every call after that with the same image size reuses the graph.Models too big for one chip?Pass a TensorParallelConfig to frompretrained and the transformer is sharded across chips as it loads, so the full model never has to fit in one place.

Many popular pipelines support it out of the box, and the ones that don't are just a tpplan away.The Diffusers TPU guide has the full recipe.Here are some examples run on a Cloud TPU v6e-4: TP=4 (each model split across four chips) · bf16 · batch 1 MiniMax-H3 (video + audio) Qwen-Image-2.

1 "The fluffy plush Hugging Face mascot from the picture, a round yellow smiling face with rosy cheeks and two little open hands, stands at the prow of an ancient Greek trireme […] Sound of crashing waves, creaking timber, wind in the rigging, distant seagulls, and a low epic orchestral swell.

" · 1344×768, 5.2 s, 49 steps · 188 s compiled, 262 s eager "A capybara wearing a wizard hat, reading a book by candlelight, oil painting" · 1024×1024, 40 steps · 3.5 s compiled, 8.0 s eager "A neon shop sign that reads 'QWEN IMAGE 2.

1', rainy night, reflections on wet pavement" · 2048×2048, 40 steps Kernels The Kernels Hub has ready-to-use TPU kernels.Load one with the Kernels library and give your model a speed boost.TPU kernels are written in Pallas, which gives you low-level control over the hardware.

You can also bring in kernels from the Tokamax library.Here is a ragged-dot kernel from Tokamax plugged into a Mixture-of-Experts model: from kernels import getkernel from transformers import AutoModelForCausalLM from transformers.integrations.

moe import ALLEXPERTSFUNCTIONS repoid = "tengomucho/ragged-dot-tpu" kernel = getkernel(repoid, version=1, trustremotecode=[repoid]) ALLEXPERTSFUNCTIONS.register("tokamaxraggeddot", kernel.expertsforward) model = AutoModelForCausalLM.

frompretrained( "Qwen/Qwen3-30B-A3B-Instruct-2507", expertsimplementation="tokamaxragged_dot", ) The bigger the batch, the bigger the win.At batch size 64, decoding is 21.5× faster on Qwen3-30B-A3B and 12.8× faster on Gemma 4 26B-A4B.Decode throughput on a TPU v6e-8, Hub kernel vs.

the default implementation.We test it so you don't have to 🧪 We're continuously improving TPU support in transformers by running the library test suite.We are working to add a nightly CI on TPU and make the results available in the (transformers dashboard)[https://huggingface.

co/spaces/transformers-community/transformers-ci-dashboard].The Transformers CI dashboard, with TPU results next to other accelerators.Work in progress!It's not all green yet, and we're fine with that.Of the tests that run on TPU, 96.5% pass.

Every failure we find becomes a small repro script and an issue on the TorchTPU repo.So far we have reported 34 issues, and 19 are already fixed.Running on TPU also caught a few bugs in Transformers itself, like in StaticCache and the Qwen3 tensor-parallel plans.We fixed those upstream.

If something breaks on TPU, we want to find out before you do.Get started TPUs are no longer a side quest for PyTorch users.Install TorchTPU, grab a model from the Hub, and send it to "tpu".TorchTPU on GitHub TPU kernels on the Hub Cloud TPU documentation We can't wait to see what you build 🤗.

If you hit a problem, open an issue and tell us about it.

More Articles from our Blog partnershipsgcpspaces Google Cloud TPUs made available to Hugging Face users 24 July 9, 2024 partnershipsgcphardware Making thousands of open LLMs bloom in the Vertex AI Model Garden 22 April 10, 2024 Community EditPreview Upload images, audio, and videos by dragging in the text input, pasting, or clicking here.

Tap or paste here to upload images Comment · Sign up or log in to comment Upvote 2

Related

相關文章

搶跑雙11開門紅,這些品牌如何憑“好貨與好策略”率先突圍?

2026年抖音商城雙11好物節開門紅階段已經打響,各行業品牌穩紮穩打、實現生意增長。在流量與銷量的雙重角逐中,打動消費者的不再侷限於價格。將優質的商品供給、豐富的內容生態、有競爭力的價格與穩定的履約服務相結合,同時善用智能工具提效,是品牌在雙11 實現增長的重要路徑。本文將拆解7大品牌在開門紅階段的高光表現,詳細分析他們如何通過精細化運營搶佔生意先機,為更多商家沉澱可複用的實戰經驗。百雀羚:“廠區直播+現貨現發”打爆開門紅,首日GMV同比增長2.5倍在分秒必爭的雙11大促中,“看得見的現貨”正成為打動消費者的關鍵。

5 天前
何夕2077AI應用場景

外部專家開始核驗機器生成證明

Ad Skip to content OpenAI asks outside experts, including a Nobel laureate, to check proofs its AI produced in math, computer science, and physics Maximilian Schreiner View the LinkedIn Profile of Maximilian Schreiner Oct 27, 2026 Nano Banana Pro prompted by THE DECODER OpenAI says its internal models have disproved a central assumption in computer science and proved part of one of the Millennium Prize Problems, among other results.

5 天前

2.3萬元起!首款觸屏MacBook來了,蘋果Logo重新發光點亮

作者 | 陳駿達 編輯 | 李水青 觸屏Mac,真的來了! 10月29日報道,今天凌晨1點,蘋果推出了其歷史上首款觸屏版Mac——搭載PROLED XDR顯示屏的MacBook Pro。 除了首次支持觸控之外,這款旗艦新品一口氣帶來了Mac產品線的多項“第一次”:首次引入iPhone上的靈動島,承載Spotlight、實時活動與Siri AI等功能;首次搭載雙層串聯OLED的PROLED XDR屏幕,峰值亮度達2000尼特。

6 天前

10月28日見!華為暢享 100 系列三款新品蓄勢待發:滿分配置搶先看

距離10月28日華為雙十一煥新季·全場景新品發佈會越來越近,華為暢享系列的新一代產品也逐漸揭開面紗。10月27日,隨著華為暢享 100 系列三款單品海報陸續釋出,這一系列在外觀設計、核心配置與日常體驗方面的看點進一步明朗。據瞭解,華為暢享 100 系列已於10月23日開啟預訂,此次新品包括華為暢享 100、華為暢享 100 Pro及華為暢享 100 Pro Max三款機型,圍繞麒麟8系芯片、華為巨鯨大電池與鴻蒙星盾防詐等核心配置展開佈局,全方位滿足消費者的多元化需求。

1 週前

開門紅強勢爆發!抖音商城雙11熱賣品牌榜發佈

雙11開門紅階段,大促消費熱情全面釋放,消費券帶動成交額破億的商家數量同比增長200%,寵物、母嬰行業成交額過千萬商家數同比增長分別為200%、83%,快消行業成交額破億品牌數量同比增長167%。服飾、快消、耐消等賽道標杆品牌集中爆發,在開門紅階段迎來生意高峰。10月23日,開門紅階段“熱賣品牌榜”正式出爐,立即揭曉雙11開門紅哪些品牌迎來強勢爆發。服飾賽道熱賣品牌榜秋冬換季疊加戶外熱潮,服飾賽道競爭激烈。

1 週前