Hugging Face ❤️ TorchTPU: TPUs, Natively
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.
Related posts
- TorchNeuron: running HF models on AWS Trainium is easier than ever
Hugging Face mediumAdeptTorchNeuron 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. As a result, Transformers, Diffusers, Accelerate, PEFT and TRL run directly on Trainium, and Hugging Face now recommends them over Optimum Neuron; 89% of the top 100 text-generation architectures work out of the box versus 46% before. Examples cover tensor-parallel generation with a static KV cache, TRL SFT with a TP×FSDP grid via `DistributedConfig`, and TP for Diffusers image pipelines. Practical caveats include keeping shapes static (padding to multiples of 128, disabling Dynamo automatic dynamic shapes) and disabling async weight loading; it enters public beta Oct. 20, 2026.
- Learn the Hugging Face Kernel Hub in 5 Minutes
Hugging Face mediumAdeptHugging 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. The library matches the binary to the installed Python, PyTorch and CUDA versions, which avoids source builds that for FlashAttention can need about 96 GB of RAM and hours of compilation. The walkthrough checks a fast GELU kernel against PyTorch and swaps a Triton LlamaRMSNorm into a simple model with the `use_kernel_forward_from_hub` decorator. It then benchmarks the kernel against a plain PyTorch RMSNorm using CUDA events.
- Custom Kernels for All from Codex and Claude
Hugging Face mediumAdeptHugging 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. Agent-written RMSNorm kernels averaged 1.88x over PyTorch for LTX-Video and 1.94x for Qwen3-8B on H100 in BF16, with Qwen3 speedups growing from 1.58x at 128 tokens to 2.47x at 8192. End to end, LTX-Video gained only 6% (1.43x with torch.compile), consistent with RMSNorm taking about 5% of compute. The post also walks through building all PyTorch/CUDA variants with Nix and publishing to the Kernel Hub for one-line loading via get_kernel.
- MPS in PyTorch 2.15
Hugging Face mediumAdeptPyTorch 2.15 adds FP8 (float8_e4m3fn) tensors and scaled_mm on Apple's MPS backend and replaces many MPSGraph paths with dedicated Metal kernels. A native GPU grouped matmul with a small-group decode kernel makes MoE decoding 5–6.5× faster than 2.14 (Qwen3.6-35B-A3B goes from 9.4 to 61.3 tokens/s on an M3 Ultra). GEMV-backed F.linear gives a 1.23× geomean speedup on decode shapes, and Metal softmax is about 8× faster over large vocabularies. Moving constant padding to Metal cuts Wan2.2 tiled VAE decode peak driver memory from 270 GiB to 8 GiB and fixes Qwen-Image VAE corruption. The release also adds complex LU and triangular solves, Python-level MPS streams, and requires macOS 15 and Python 3.11. Previewed 2.16 work includes all-Metal attention and periodic command-buffer commits that add up to 19% decode throughput.
- Training a language model with 🤗 Transformers using TensorFlow and TPUs
Hugging Face mediumAdeptTraining 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. Key details include initializing the model and optimizer inside the strategy scope, using a TF-native DataCollatorForLanguageModeling (return_tensors="tf"), and streaming data from GCS because TPU node host memory is small. The takeaway is that existing TF/Keras Transformers pipelines need little change to scale on TPU pods, offering an alternative to scarce GPUs.