2026年11月30日
大型混合专家(MoE)模型对训练系统的每个环节都提出了极高要求:算力、内存和互连。为了评估 Ironwood(TPU7x)——即 Google Cloud 第七代 TPU——如何处理此类工作负载,我们对 DeepSeek-V3 671B 预训练进行了基准测试。DeepSeek-V3 是一款开放权重的行业标准模型,融合了多头隐注意力(MLA)、256 个细粒度路由专家和多 token 预测(MTP),代表了当今大规模 MoE 模型的架构需求。在固定模型、数据集、全局批大小和目标验证损失的前提下,我们测量了训练所需时间——即达到该目标所消耗的实际挂钟时间——分别在 2,048、4,096 和 8,192 颗芯片上。
每颗 Ironwood 芯片提供 4,614 TFLOP/s 的 FP8 算力和 192 GiB 的 HBM,带宽达 7.38 TB/s;单个 pod 通过片间互连(ICI)最多可连接 9,216 颗芯片。我们在 8,192 颗芯片上以 1.70 分钟完成 DeepSeek-V3 的训练,所有通信均在一个 ICI 域内完成。在 2,048 颗芯片上,最终结果达到了 56% 的有效模型 FLOPs 利用率(EMFU)。从 2,048 扩展到 4,096 颗芯片时的收敛扩展效率为 96%,从 2,048 扩展到 8,192 颗芯片时为 74%。在内部测试中,我们还测量到从 512 扩展到 2,048 颗芯片时效率接近 100%,通过梯度累积保持全局批大小不变。
我们将这项工作分为两条工作路线推进。本文介绍的是第一条,即 FSDP + EP 路线。该路线构建了一个与参考训练配置相匹配的 MaxText 训练方案,将其扩展至 8,192 个芯片,并开发了我们最终配置所依赖的诸多特性:FP8 量化方案、用于分组矩阵乘法和 token 排序的 Pallas 内核、注意力优化、带无丢弃回退机制的 MoE token 分块、重计算与 tile 大小调优,以及预运行预热。该路线无法隐藏所有集合通信。在 8,192 个芯片上,每个设备的小批量使得可用于与通信重叠的计算量十分有限,因此 EP reduce-scatter 仍然暴露在外。批量拆分调度几乎隐藏了所有这些集合通信,我们将在本系列第二篇(本月稍后发布)中分享其详细信息。
本文介绍我们如何在数周内在 Google Cloud TPU 上使用 MaxText 和 JAX 扩展并优化一个 671B 参数的 Mixture-of-Experts(MoE)模型。对于每一项优化,我们描述其所解决的瓶颈、工作原理及其收益,并在结尾分享可迁移至其他大型 MoE 模型的经验。
我们在所有规模下均以 16,384 条序列(每条 4,096 tokens)作为全局批量进行训练,每次运行在首次达到或低于 log perplexity 3.6 的评估时停止。在一周的优化期内(9 月 28 日至 10 月 5 日),FSDP + EP 路线在保持模型、数据集、全局批量大小和目标损失不变的前提下,将三个规模下的每芯片吞吐量分别提升了 1.56–1.82 倍。
- 2,048 个芯片:约 2,057 → 3,736 tokens/s/chip(+82%),EMFU 为 42.8%
- 4,096 个芯片:约 1,971 → 3,084 tokens/s/chip(+56%),EMFU 为 34.9%
- 8,192 个芯片:约 1,568 → 2,501 tokens/s/chip(+60%),EMFU 为 28.9%
图 1. FSDP + EP 赛道在 Ironwood 上 2,048、4,096 和 8,192 个芯片的每芯片吞吐量。这些结果来自仅运行 FSDP + EP 赛道,不包含第二部分中描述的批拆分调度。吞吐量包含训练期间运行的评估。
我们在每个规模下将全局批次保持在 16,384 个序列,因此增加芯片会将相同的工作划分得更细。两个配置共享该批次:每设备批大小(PBS),即每个 JAX 设备在每个微步中处理的序列数;以及梯度累积(GA),即每个优化器步中的微步数。每个 Ironwood 芯片由两个 chiplet 组成,每个 chiplet 包含一个 TensorCore、两个 SparseCore 和 96 GiB 的 HBM,通过 die-to-die(D2D)链路连接,其速度是 1D ICI 链路的六倍。JAX 将每个 TensorCore 作为一个设备暴露,因此 chips × 2 × PBS × GA = 16,384。我们从 512 到 8,192 个芯片,对 PBS 1、2 和 4 进行了扫描。
一个 Ironwood pod 通过 3D torus 连接最多 9,216 个芯片,每个芯片拥有 1.2 TB/s 的双向 ICI 带宽,因此单个 slice 可以将其所有通信保留在 ICI 上,而无需使用数据中心网络(DCN),后者每芯片仅提供 100 Gb/s。为了利用这一优势,我们的设备网格采用两个轴:重度完全分片数据并行(FSDP)和适度的专家并行(EP)。3D torus 使 FSDP 可以跨越整个 slice,但在 8,192 个芯片规模下,纯 FSDP 会在每一层将全部 256 个专家的权重 all-gather 到每个芯片上。同时,每个芯片的 token 会被分布得过于稀疏,导致专家矩阵乘法变为 HBM 瓶颈。此外,模型的大部分张量维度无法被 16,384 整除,因此将每个权重拆分到如此细的粒度需要代价高昂的填充或重排。加入 EP 解决了这两个问题:每个芯片只收集自己专家的权重,从而将权重流量和 HBM 占用按 EP 度数缩减;同时在 EP 组内池化 token,使专家矩阵乘法保持为计算瓶颈。我们排除了张量并行(TP),因为它会降低小专家维度上的算术强度(参见算术强度指南),也排除了流水线并行(PP),因为在这些规模下其气泡代价超过了通信节省。表 1 列出了在我们设置下各规模的最优配置。
这两个轴在不同层中扮演不同角色。具体细节因规模略有不同,但从宏观层面来看:
- 注意力机制。在注意力机制中,EP 轴承载批次,充当激活值的数据并行。注意力权重较小,因此在 4,096 和 8,192 芯片规模下使用的 1,024 大小的 FSDP 中,每个 FSDP 分片都会非常小,其 all-gather 将受限于延迟而非带宽。因此,我们沿低秩 query、低秩 key-value 和嵌入维度,仅在远小于 FSDP 的 EP 轴上对注意力权重进行分片,并在 FSDP 维度上进行 replicate。
- MoE 层。256 个路由专家分布在 EP 轴上(EP 8 时每个设备 32 个专家,EP 16 时每个设备 16 个),每个专家的权重进一步在 FSDP 轴上分片,并在使用前通过 all-gather 聚合。EP 使用 all-gather 和 reduce-scatter 替代 all-to-all。每个 EP 组内的 token 通过 all-gather 聚合,每个设备运行其本地专家,输出再通过 reduce-scatter 返回到各自的源设备。每个 token 作为单份副本传输,仅在接收设备上按该 token 托管在此处的每个 top-k 专家各复制一次。当 EP 组较小且映射到环(一维环面)时,此方法是高效的。由于集合通信的大小不随路由变化而改变,专家负载不均衡不会导致任何设备的传输出现掉队。
- 评估。评估集包含 1,024 条序列,少于设备数量,因此在评估期间,除 MoE 层外,EP 轴在每处都充当上下文并行,将每条序列在 EP 组内的设备之间进行分割。
图 2。在固定全局批次为 16,384 条序列的条件下,各 PBS 下端到端时间随芯片数的变化。虚线为最快的 512 芯片运行(PBS 4)的线性扩展。方框给出每次 PBS 在所有运行中端到端时间对 GA 的线性拟合。
在 2,048 个芯片以内,扩展性几乎呈线性。在图 2 中,每条 PBS 线与虚线线性扩展线平行:在固定 PBS 下将芯片数量翻倍会使 GA 减半,并将运行时间缩短 1.93–2.07 倍。图 2 中的线性拟合解释了原因。在固定 PBS 下,端到端时间随 GA 呈线性关系(R² > 0.999)。其中大部分是 micro-step 工作,其量随 GA 变化;此外每次运行还有 15–30 秒的固定开销,用于梯度归约和优化器更新等每步仅执行一次的操作。由于在这些规模下该固定部分相对于端到端时间很小,因此 GA 减半几乎使时间减半。如表 2 所示,从 512 到 2,048 个芯片的最快配置(PBS 4)相对于 512 个芯片达到 97–100% 的扩展效率,芯片时间基本恒定。
超过 2,048 个芯片后,已没有梯度累积可供消除。在 2,048 个芯片、PBS 4 的配置下,GA 已经为 1,因此每再翻倍一次芯片数量就必须将 PBS 减半:4,096 个芯片时降为 2,8,192 个芯片时降为 1。更小的 PBS 效率更低。在 512–2,048 个芯片的范围内(三个 PBS 值均可容纳),图 2 显示在相同芯片数量下,PBS 2 比 PBS 4 慢 6–9%,PBS 1 慢 33–35%。因此,最快配置的扩展效率在 4,096 个芯片时降至 81%,在 8,192 个芯片时降至 66%(表 2)。8,192 个芯片时的大部分损失来自更小的 PBS,而非额外的芯片:与 512 个芯片下 PBS 1 的运行相比,8,192 个芯片下 PBS 1 的运行仍达到线性扩展的 89%。要追回剩余差距,需要减少每个设备上的计算量,从而将通信隐藏在计算之后,这正是第二部分中 batch-split 调度方案的焦点。
我们分两个阶段进行。首先,通过 roofline 分析,在给定 Ironwood 的单芯片算力、HBM 带宽和 ICI 带宽的条件下,确定了 FSDP + EP 分片下 step 中每个部分所能达到的性能上限。然后我们对 step 进行 profiling,找到实测时间与可达时间之间最大的差距,对其进行优化,并再次测量。这些优化分为五个类别,详见下文。
GMM v2。每个路由专家只处理分配给它的 token,因此专家层是分组矩阵乘法(GMM),其中每个专家的行列数在每个 step 都会变化。从 Tokamax 的 ragged-dot kernel(v1)切换到基于 Tokamax GMM v2 构建的 MaxText GMM v2 kernel,使端到端吞吐量提升了约 10%。ragged-dot kernel 在固定网格上对行进行分块,因此每个跨越专家边界的 tile 都会为每个专家完整加载(DMA)并计算一次,然后再进行掩码处理。GMM v2 从每个专家的第一行开始分块,并将内存加载和 matmul 的尺寸调整为有效行的范围,从而消除了大部分浪费。
Splash attention。两项更改减少了浪费的 attention 计算:
- 对角线子 tile 跳过。因果掩码将对角线上每个 tile 的上半部分置零,因此部分已访问的 QK 计算被浪费:在使用 4,096 token 的序列和我们 8,192 芯片方案中 2,048 token 的前向传播 tile 时,其中约三分之一被浪费。将每个对角线 tile 分割为 4 × 4 的子 tile 网格并跳过空的子 tile(sa_qk_diag_skip, sa_qk_diag_grid: 4),可将该浪费降至 11%。
- 跳过 segment ID。在序列打包中,segment ID 用于阻止 token 跨文档进行注意力计算,但代价是每个计算 tile 都需要额外的向量单元运算。我们的 C4 数据管道则直接将文档拼接为一条以 EOS 分隔的流,不标记任何边界,因此每条序列都是单个 segment。由于此时 segment 掩码不起作用(no-op),我们将其跳过(sa_ignore_segment_ids)以避免该额外开销。
图 3. 前向传播不规则排序(上方,不规则收集)与逆排序(下方,不规则收集归约),展示 2 个 EP 分片和 4 个专家的情况:专家 0–1 位于分片 0,专家 2–3 位于分片 1。两个分片均看到相同的 6 个全收集后的 token(t0–t5),每个 token 被路由到其 top-2 专家。排序操作仅将属于该分片本地专家的行列入其填充后的 9 行缓冲区,并跳过填充行。逆排序将每个专家输出乘以其路由权重 w,然后按 token 求和得到部分输出,随后通过归约散列在各分片间合并这些部分输出。
不规则排序。在进入专家 GMM 之前,每个设备先对路由到其本地专家的 token 进行排序;完成后,再进行逆排序、应用路由权重,并求和其本地专家的 top-k 输出(EP 归约散列随后完成每个 token 的求和)。在全收集/归约散列 EP 路径中,每个设备首先在整个 EP 组内全收集 token,但只有动态确定的一个子集会被路由到某个给定秩上的专家,因此每个秩的活跃 token 切片是不规则的。若没有不规则内核,排序和逆排序将对完整的 EP 全收集缓冲区执行置换操作,移动比该秩实际所需多 8 倍或 16 倍(即 EP 度)的 token 数据。我们将不规则收集和不规则收集归约内核集成到了 MaxText 中以支持此路径:它们读取该秩的起始和结束偏移
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
NOV. 30, 2026
Large Mixture-of-Experts (MoE) models stress every part of a training system: compute, memory, and interconnect. To evaluate how Ironwood (TPU7x), Google Cloud's seventh-generation TPU, handles this class of workload, we benchmarked DeepSeek-V3 671B pre-training. As an open-weight, industry-standard model combining multi-head latent attention (MLA), 256 fine-grained routed experts, and multi-token prediction (MTP), DeepSeek-V3 reflects the architectural demands of today's large-scale MoEs. Holding the model, dataset, global batch size, and target validation loss fixed, we measured time to train—the wall-clock time to reach that target—at 2,048, 4,096, and 8,192 chips.
Each Ironwood chip delivers 4,614 TFLOP/s of FP8 compute and 192 GiB of HBM at 7.38 TB/s, and a single pod connects up to 9,216 chips over the inter-chip interconnect (ICI). We trained DeepSeek-V3 in 1.70 minutes on 8,192 chips, with all communication inside one ICI domain. At 2,048 chips, the final result reached an effective model FLOPs utilization (EMFU) of 56%. Convergence scaling efficiency was 96% from 2,048 to 4,096 chips and 74% from 2,048 to 8,192 chips. In internal runs, we also measured nearly 100% efficiency from 512 to 2,048 chips, using gradient accumulation to keep the global batch size the same.
We pursued this work in two workstreams. This post covers the first, the FSDP + EP track that built a MaxText recipe matching the reference training setup, scaled it to 8,192 chips, and developed many of the features our final configuration relies on: the FP8 quantization recipe, Pallas kernels for grouped matmuls and token sorting, attention optimizations, MoE token chunking with dropless fallback, rematerialization and tile size tuning, and pre-run warm-up. This track could not hide every collective. At 8,192 chips, the small per-device batch leaves little compute to overlap with communication, so the EP reduce-scatter remains exposed. The batch-split schedule hides nearly all of these collectives, and we will share details about it in Part 2 of this series later this month.
This post explains how we scaled and optimized a 671B-parameter Mixture-of-Experts (MoE) model with MaxText and JAX on Google Cloud TPUs in a matter of weeks. For each optimization, we describe the bottleneck it addressed, how it works, and what it gained, and we close with the lessons that carry over to other large MoE models.
We trained with a global batch of 16,384 sequences of 4,096 tokens at every scale, and each run stops at the first evaluation at or below a log perplexity of 3.6. In one week of optimization, from September 28 to October 5, the FSDP + EP track raised throughput per chip by 1.56–1.82× at all three scales while keeping the model, dataset, global batch size, and target loss unchanged.
- 2,048 chips: about 2,057 → 3,736 tokens/s/chip (+82%), with EMFU of 42.8%
- 4,096 chips: about 1,971 → 3,084 tokens/s/chip (+56%), with EMFU of 34.9%
- 8,192 chips: about 1,568 → 2,501 tokens/s/chip (+60%), with EMFU of 28.9%
Figure 1. Throughput per chip of the FSDP + EP track on Ironwood at 2,048, 4,096, and 8,192 chips. These results are from runs of the FSDP + EP track alone and don't include the batch-split schedule described in Part 2. Throughput includes the evaluation that runs during training.
We kept the global batch at 16,384 sequences at every scale, so adding chips divides the same work more finely. Two settings share the batch: the per-device batch size (PBS), the number of sequences each JAX device processes per micro-step, and gradient accumulation (GA), the number of micro-steps per optimizer step. Each Ironwood chip is built from two chiplets, each with one TensorCore, two SparseCores, and 96 GiB of HBM, joined by a die-to-die (D2D) link six times faster than a 1D ICI link. JAX exposes each TensorCore as a device, so chips × 2 × PBS × GA = 16,384. We swept PBS 1, 2, and 4 from 512 to 8,192 chips.
An Ironwood pod connects up to 9,216 chips in a 3D torus with 1.2 TB/s of bidirectional ICI bandwidth per chip, so a single slice can keep all of its communication on ICI rather than the data center network (DCN), which provides 100 Gb/s per chip. To take advantage of this, our device mesh uses two axes: heavy fully sharded data parallelism (FSDP) and modest expert parallelism (EP). The 3D torus lets FSDP span the whole slice, but pure FSDP at 8,192 chips would all-gather all 256 experts' weights onto every chip for every layer. Each chip's tokens would also be spread so thinly across the experts that the expert matmuls become HBM-bound. Also, most of the model's tensor dimensions don't divide evenly 16,384 ways, so splitting every weight that finely would require costly padding or relayouts. Adding EP fixes both problems. Each chip gathers only its own experts' weights, which cuts weight traffic and HBM footprint by the EP degree, and pooling tokens across the EP group keeps the expert matmuls compute-bound. We ruled out tensor parallelism (TP), which lowers arithmetic intensity on the small expert dimension (see the arithmetic intensity guide), and pipeline parallelism (PP), whose bubbles outweighed its communication savings at these scales. Table 1 lists the best configuration at each scale in our setting.
The two axes play different roles in different layers. The details vary slightly by scale, but at a high level:
- Attention. In attention, the EP axis carries the batch, acting as data parallelism for activations. Attention weights are small, so at the FSDP size of 1,024 used at 4,096 and 8,192 chips, each FSDP shard would be tiny and its all-gather would be bound by latency rather than bandwidth. We therefore shard the attention weights, along their low-rank query, low-rank key-value, and embedding dimensions, only across the much smaller EP axis, and replicate them across FSDP.
- MoE layers. The 256 routed experts are split across the EP axis (32 experts per device at EP 8, 16 at EP 16), and each expert's weights are further sharded across the FSDP axis and all-gathered before use. EP uses an all-gather and a reduce-scatter instead of all-to-all. Tokens are all-gathered within each EP group, each device runs its local experts, and the outputs are reduce-scattered back to their home devices. Each token is transferred as a single copy and replicated only on the receiving device, once for each of its top-k experts hosted there. This approach is efficient when the EP group is small and maps onto a ring (a 1D torus). Because the collective sizes are fixed regardless of routing, an imbalanced expert load cannot make any device's transfers a straggler.
- Evaluation. The evaluation set has 1,024 sequences, fewer than the number of devices, so during evaluation the EP axis acts as context parallelism everywhere except the MoE layer, splitting each sequence across the devices in an EP group.
Figure 2. End-to-end time vs. chip count at each PBS, with the global batch fixed at 16,384 sequences. The dashed line is linear scaling from the fastest 512-chip run (PBS 4). The box gives a linear fit of end-to-end time against GA for each PBS across all runs.
Up to 2,048 chips, scaling is nearly linear. In Figure 2, each PBS line runs parallel to the dashed linear-scaling line: doubling the chips at a fixed PBS halves GA and speeds up the run by 1.93–2.07×. The linear fits in Figure 2 show why. At a fixed PBS, end-to-end time is a straight line in GA (R² > 0.999). Most of it is micro-step work, which scales with GA, plus a fixed 15–30 seconds per run of once-per-step work such as gradient reduction and the optimizer update. Because that fixed part is small next to end-to-end times at these scales, halving GA nearly halves the time. As Table 2 shows, the fastest configuration from 512 to 2,048 chips (PBS 4) reaches 97–100% scaling efficiency relative to 512 chips, at essentially constant chip time.
Past 2,048 chips, there is no gradient accumulation left to remove. At 2,048 chips with PBS 4, GA is already 1, so each further doubling of chips must halve the PBS instead: to 2 at 4,096 chips and to 1 at 8,192. Smaller PBS are less efficient. At 512–2,048 chips, where all three PBS values fit, Figure 2 shows PBS 2 running 6–9% slower than PBS 4 at the same chip count, and PBS 1 running 33–35% slower. As a result, the fastest configuration drops to 81% scaling efficiency at 4,096 chips and 66% at 8,192 (Table 2). Most of the loss at 8,192 chips comes from the smaller PBS, not from the extra chips: compared with PBS 1 at 512 chips, the PBS 1 run at 8,192 chips still reaches 89% of linear scaling. Recovering the rest requires hiding communication behind less compute per device, which is the focus of the batch-split schedule in Part 2.
We worked in two phases. First, a roofline analysis bounded what each part of the step could achieve under the FSDP + EP sharding, given Ironwood's per-chip compute, HBM bandwidth, and ICI bandwidth. Then we profiled the step, picked the largest gap between measured and achievable time, optimized it, and measured again. The optimizations fall into five categories, described below.
GMM v2. Each routed expert processes only the tokens assigned to it, so the expert layers are grouped matrix multiplications (GMMs) whose per-expert row counts change at every step. Switching from Tokamax's ragged-dot kernel (v1) to MaxText's GMM v2 kernel, which is built on Tokamax GMM v2, improved end-to-end throughput by ~10%. The ragged-dot kernel tiles rows on a fixed grid, so each tile that straddles an expert boundary is loaded (DMA) and computed in full once per expert, then masked. GMM v2 starts tiles at each expert's first row and sizes both the memory loads and the matmul to the valid rows, which cuts most of that waste.
Splash attention. Two changes reduce wasted attention work:
- Diagonal sub-tile skipping. A causal mask zeroes the upper half of every tile on the diagonal, so part of the visited QK work is wasted: with 4,096-token sequences and the 2,048-token forward-pass tiles of our 8,192-chip recipe, a third of it. Splitting each diagonal tile into a 4 × 4 grid of sub-tiles and skipping the empty ones (sa_qk_diag_skip, sa_qk_diag_grid: 4) cuts that waste to 11%.
- Skipping segment IDs. With sequence packing, segment IDs stop tokens from attending across documents, at the cost of extra vector-unit work on every computed tile. Our C4 data pipeline instead joins documents into one EOS-separated stream with no boundaries marked, so every sequence is a single segment. Since the segment mask is then a no-op, we skip it (sa_ignore_segment_ids) to avoid that overhead.
Figure 3. Forward-pass ragged sort (top, ragged gather) and unsort (bottom, ragged gather-reduce), shown for 2 EP shards and 4 experts: experts 0–1 are on shard 0 and experts 2–3 on shard 1. Both shards see the same six all-gathered tokens (t0–t5), each routed to its top-2 experts. The sort copies only the rows for the shard's local experts into its padded 9-row buffer and skips the padding rows. The unsort weights each expert output by its routing weight w and sums them into a partial output per token, and a reduce-scatter later combines the partial outputs across shards.
Ragged sort. Before the expert GMMs, each device sorts the tokens routed to its local experts; afterward, it unsorts them, applies the routing weights, and sums the top-k outputs from its local experts (the EP reduce-scatter then completes each token's sum). In the all-gather/reduce-scatter EP path, each device first all-gathers tokens across the EP group, but only a dynamically determined subset of them is routed to the experts on any given rank, so each rank's active token slice is ragged. Without a ragged kernel, the sort and unsort permute the full EP-all-gathered buffer, moving 8× or 16× (the EP degree) more token data than the rank needs. We integrated ragged gather and ragged gather-reduce kernels into MaxText for this path: they read the rank's start and end offset
Auto-fetched and translated by AI Atlas. All rights belong to the original author.