GoogleGagik Amirkhanyan, Vaibhav SinghExplainer
TPU Model Design Considerations and Optimization Guide
Summary
Google’s TPU codesign guide provides hardware-grounded rules for maximizing performance on TPUs, which trade general-purpose scheduling for wide systolic arrays and custom interconnects. Shape rules require aligning every reduction and output dimension to 256 and using static shapes with bucketing and masking to avoid recompilation. Architecture choices include LatentMoE to compress routed token traffic, shared experts to reduce HBM reads, and block-scaled FP8 for memory-bound layers. Parallelism strategies map DP, TP, EP, CP, and PP axes directly to physical ICI links, with EP placed on a short 1D torus axis. Measured benchmarks show pure systems tuning lifted an open 30B MoE from 12% to 23% MFU before any model change, and 256-aligned MoEs run at roughly 2x the throughput of unaligned models.
Context
Google designed TPUs as custom ML ASICs with wide 256x256 systolic arrays, SparseCore engines, and custom interconnects. Achieving peak performance requires aligning model shapes, routing, and parallelism with these hardware characteristics. The guide targets teams building or adapting LLMs, MoE models, and other hardware-intensive workloads for TPUs, covering Ironwood (TPU v7x) and future generations including TPU 8t, TPU 8i, TPU 8tx, and TPU 8i Max.
Approach / What changed
The guide provides three groups of design rules: shape rules (align dimensions to 256, use static shapes with bucketing and masking), architecture choices (LatentMoE, shared experts, block-scaled FP8, multi-pass BF16, MTP), and parallelism strategies (map DP/TP/EP/CP/PP to physical ICI links, use 1D torus for EP, load-balanced CP, SparseCore offload).
Takeaways
Align every reduction and output dimension to 256, especially head_dim, to match the 256x256 MXU systolic array; reshaping from 32x128 to 16x256 sped up end-to-end training with gains widening at longer context.
LatentMoE compresses routed tokens from d_model to a smaller latent width (d/ℓ ≈ 2-4x) before dispatch, cutting all-to-all traffic and expert weight reads, and the saved bandwidth can be reinvested into more active experts.
Always evaluate architectural changes in wall-clock time on a tuned software stack rather than paper FLOPs; pure systems tuning lifted an open 30B MoE from 12% to 23% MFU before any model change.
FAQ
How should I align model dimensions for TPU efficiency?
Align every reduction and output dimension to 256, especially head_dim. For example, reshape attention from 32 heads x 128 dim to 16 heads x 256 dim, preserving total projection width and KV cache bytes. This matches the 256x256 MXU systolic array and avoids leaving the MXU 50% or more idle.
What is LatentMoE and why use it on TPUs?
LatentMoE projects routed tokens from full d_model down to a smaller latent width (d/ℓ ≈ 2-4x) before dispatch, cutting all-to-all traffic and expert weight reads. The saved bandwidth can be reinvested into more active experts, raising the nonlinearity budget at constant traffic. Keep ℓ a multiple of 256 and dispatch in FP8 while keeping projections in BF16.
How do I handle dynamic shapes like variable sequence lengths on TPUs?
Use bucketing and masking: pad requests to precompiled sequence-length and batch-slot buckets, replace data-dependent branches with masks, and pack training sequences. For dropless MoE routing and paged attention, use Scalar Prefetch with Pallas to keep buffers at fixed shapes and describe ragged structure with small integer arrays, avoiding recompilation.
Source and freshness
- Source
- developers.googleblog.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.