翻篇收录说明
翻篇网页快照

TPU Model Design Considerations and Optimization Guide - Google Developers Blog

https://developers.googleblog.com/tpu-model-design-considerations-and-optimization-guide/

最近抓取:2026-12-04 18:26:18(北京时间)

最近内容变化:2026-12-02 05:37:48(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Learn essential TPU model design and optimization principles—covering 256-aligned shapes, LatentMoE compression, FP8 precision, and physical mesh parallelism—to maximize efficiency across LLM training and serving workloads.

正文摘录

TPU Model Design Considerations and Optimization Guide NOV. 16, 2026 Gagik Amirkhanyan Staff Software Engineer Vaibhav Singh Senior Staff Software Engineer Share Facebook Twitter LinkedIn Mail PurposeGoogle designed TPUs from the ground up to be exceptionally efficient for machine learning workloads, delivering top-tier performance per total cost of ownership (TCO). Because TPUs trade general-purpose hardware scheduling for wide systolic arrays, dedicated SparseCore engines, and custom interconnect fabrics, adhering to specific architectural best practices is essential to achieve maximum performance. To help developers get the most out of TPUs, we are launching the open-source AI-Hypercomputer/tpu-codesign guide. This post highlights its key principles—spanning shape alignment, architectural choices like LatentMoE, and parallelism strategies—to accelerate LLMs, Mixture-of-Experts (MoE) models, and other hardware-intensive workloads on TPUs.Codesign models for Ironwood (TPU v7x) and future TPU generations: training and inferencePerformance tuning starts with model definition. Architectural choices made before the first training step set permanent ceilings on MFU (Model FLOP Utilization), cost, and serving latency. This guide gives concrete, hardware-grounded design rules for teams building or adapting models for TPUs, organized into three groups:Shape rules (Principles 1–2): hardware-aligned dimensions and static shapes; near-zero model-quality risk. Adopt always.Architecture choices (Principles 3–7): structural design choices; most involve quality tradeoffs. Validate with ablations.Expressing parallelism (Principle 8): parallelism, kernel, and compiler tuning; no model changes required.How to use this guide. The shape rules apply to anyone designing a new model. If you are adapting an existing model rather than designing one, the Expressing Parallelism section applies without touching the checkpoint. The general rules hold for any large-matmul architecture (dense LLMs, multimodal, and world models), and the companion AI-Hypercomputer/tpu-codesign repository grows model- and workload-specific sections over time.Eighth-generation TPUs. These principles carry forward to TPU 8t and TPU 8i and to the newly announced TPU 8tx and TPU 8i Max. The reasoning stays the same and the thresholds move with the hardware. TPU 8t and TPU 8i both add native FP4. For training, TPU 8t also brings more balanced Vector Processing Unit (VPU) scaling. For serving, TPU 8i adds the Boardfly topology, a Collectives Acceleration Engine (CAE), and 3x more on-chip SRAM. We note the effects inline in Principles 5–8, and follow-up posts will cover eighth-generation designs in depth.Measured evidence. Alongside the published sources, notes marked Measured carry results from our own Ironwood profiling program: open 20–30B MoEs (a Qwen3-30B-derived LatentMoE variant; GPT-OSS-20B) plus dense controls, single slice (except for the 512-chip TPU v7x and 1,024-chip TPU v4 ablations in Principle 4), BF16, training shapes up to 32K sequence, all against tuned-systems baselines. Treat the trends and rankings as transferable, the exact percentages as config-specific.Foundational Performance Parameters (Ironwood / TPU v7x)TPUs are purpose-built custom ML ASICs designed from the ground up to deliver state-of-the-art performance per total cost of ownership (TCO). While their architectural choices—such as wide 256×256 systolic arrays, software-managed VMEM, dedicated SparseCore engines, and direct multi-dimensional ICI fabrics—enable exceptional efficiency, they inherently create specific structural constraints and programming patterns that must be carefully followed to unlock maximal performance. Reaching peak efficiency requires aligning model shapes, routing, and parallelism directly with these underlying hardware characteristics: Parallelism shorthand: DP = data, TP = tensor, EP = expert, CP = context, PP = pipeline parallelism; FSDP = fully sharded data parallel. Shape rules (adopt always)1. Align every reduction and output dimension to 256 (especially head_dim = 256)Make d_model, FFN and expert intermediate widths (d_ff), latent widths, attention projections, and padded vocabulary sizes (used as contracting or output dimensions) multiples of 256 to match the 256×256 MXU systolic array. Token/batch axes and counts such as heads, layers, and experts are exempt. The most frequently missed dimension is head_dim: at 64 or 128, flash-attention QK products leave the MXU ≥ 50% idle. Reshape to head_dim = 256 with proportionally fewer Q and KV heads, preserving total projection widths and logical KV cache bytes (iso-quality in our ablations).Measured: Reshaping Qwen3-30B MoE attention from 32 × 128 to 16 × 256 (identical parameters and FLOPs) sped up end-to-end training, with gains widening at longer context: These rules apply for non-quadratic attention as well, notably GDN ablations from Yang et al. 2025 also noted at par or better quality for head dimension 256 for their Gated DeltaNet Attention.2. Static and Dynamic ShapesXLA compiles each program for exact tensor shapes, so every buffer has a fixed address and every loop a known trip count, and a new shape means a recompilation and a host stall. What about dynamic shapes? Dynamic workloads fit this model: the trick is to separate the shape of a buffer from the extent of the data inside it.Bucketing and masking: At the program level, pad requests to a small set of precompiled sequence-length and batch-slot buckets (warmed up at server startup), replace data-dependent branches with masks, and pack training sequences (packing=True in MaxText) so padding never reaches the MXU.Scalar Prefetch: Another common pattern of dynamic shapes appears in dropless MoE layers, which route a different number of tokens to each expert every step, and in paged attention, which gives every sequence its own KV length, its own set of pages scattered through the cache, and in a mixed batch its own phase (prefill or decode). Instead of padding to the largest group or the longest sequence, we keep the buffers at fixed shapes (tokens sorted by expert and padded only at the tail, the KV cache as a fixed pool of pages) and describe the ragged structure with a few small integer arrays (group sizes and offsets; KV lengths, the page table, cumulative query lengths). Pallas copies these into the TensorCore's scalar memory before the grid starts (PrefetchScalarGridSpec), and the kernel reads them to choose the next tile and bound its loops, with a mask covering a tile that straddles a group boundary or a partly filled last page. The data dependence becomes an address and a trip count instead of a shape, so the compiled program is the same for every routing and every batch composition and the kernel runs at the unpadded FLOP count.Architecture choices (validate with ablations)3. Compress routed token traffic with LatentMoEStandard EP dispatches every routed token at full d_model width, making EP + FSDP slower than plain FSDP in our Ironwood benchmarks. LatentMoE projects routed tokens from d_model down to latent width ℓ (d/ℓ ≈ 2–4×) before dispatch, executes experts in latent space, and projects back up after combine (introduced by Nemotron 3 and adopted by 962B MAI-Base-1 and 2.8T Kimi K3):Shrink both MoE bottlenecks and reinvest: With expert width m = d_ff, latent compression cuts small-batch expert weight reads (∝ d × m) and throughput-bound all-to-all dispatch (∝ K × d) by d/ℓ. Reinvest the saved bandwidth into more active experts while keeping K_new × ℓ ≤ K_old × d_model, raising the nonlinearity budget K × m at constant traffic (for example, Nemotron 3's ℓ = 1024, N = 512, top-22 beat d = 4096, N = 128, top-6 at matched active and total parameters).TPU rules: Route on full d_model before compressing; keep ℓ a multiple of 256; dispatch in FP8 while keeping lightweight up/down projections in BF16; and place EP on one short 3D torus axis.Measured: On a 30B / 128-expert MoE, an ℓ = 768 (2.67×) LatentMoE cut on-device permute time 2.8×, lifted end-to-end training throughput +14% tokens/s (322 vs 270 TFLOP/s/chip, or +19%, since the latent projections add ~5% FLOPs per token; tokens stay ℓ-wide past the down-projection, so on-device permute and combine shrink alongside EP all-to-all), and freed ~25 GB/device of activation HBM when remat checkpoints were anchored on the compressed latent. While current MoE recipes in tpu-recipes run FSDP (+ TP), LatentMoE + FP8 dispatch makes EP roofline-viable when per-device batch is too small to hide FSDP weight all-gathers. Under both FSDP and EP, avoid over-fragmenting experts: small tokens × K / N group sizes starve MXU tiles.4. Prefer higher compute intensity when quality is neutralWhen candidate MoE layouts match on quality, pick the one with higher compute intensity at a similar active-parameter budget. A larger shared expert (wider d_shared) shifts work into dense, communication-free GEMMs that overlap EP dispatch/combine in training and amortize weight reads across the decode batch. Fewer, wider routed experts (halving N and K while doubling d_ff at fixed sparsity K/N) cut dispatch traffic in half and double per-expert GEMM fill. Optimal (N, K) grows with model size, and over-coarsening hurts routing diversity. Ablate expert granularity and the shared-to-routed split at your target scale rather than copying GPU co-designed models, since the TPU optimum is more shared-heavy.Measured: On a 63B LatentMoE (ℓ = 768, K/N = 1/32, 8K context, 512 TPU v7x chips at EP = 128), halving (N, K) from (512, 16) to (256, 8) while doubling d_ff and the shared expert lifted training throughput +57% tok/s and held lower loss across 120.8B tokens: 5. Overcome the decode bandwidth wall: topology scale-out (5.1), speculative decoding (5.2), and concurrency sizingLow-concurrency decode streams model weights every token (~300 concurrent tokens per weight shard are needed in dense FP8 to reach compute roofline). Combine tw