EUROPA联盟在JUPITER超算上训练1T参数MoE模型的技术复盘
Training a 1T-Parameter MoE on EU public infrastructure with PyTorch and TorchTitan
针对超大MoE模型在受限硬件上的训练难题,提供了极具参考价值的工程优化方案,特别是FlexShard与CPU卸载策略,值得大模型开发者深入研读。
TL;DR
TL;DR(太长不看)
Scaling pretraining for a ~1-trillion-parameter Mixture-of-Experts (MoE) model on shared, public infrastructure was previously considered unfeasible due to unique architectural and interconnect bottlenecks. However, by leveraging the fine-grained flexibility of PyTorch and TorchTitan, the EUROPA consortium successfully unlocked frontier-scale training on JUPITER, boosting throughput from 90 to ~1,300 tokens/sec per GPU across 384 NVIDIA GH200 GPUs per DP replica (96 nodes) as part of the EuroHPC Frontier AI Grand Challenge.
由于独特的架构和互连瓶颈,此前在共享公共基础设施上对约 1 万亿参数的混合专家(MoE)模型进行预训练扩展被认为不可行。然而,通过利用 PyTorch 和 TorchTitan 的细粒度灵活性,EUROPA 联盟成功在 JUPITER 上实现了前沿规模的训练,将每个 DP 副本(96 个节点)中 384 块 NVIDIA GH200 GPU 上的吞吐量从每秒 90 个 token 提升至约 1,300 个 token,这是 EuroHPC 前沿 AI 大奖赛的一部分。
The EuroHPC Frontier AI Grand Challenge was designed to prove that sovereign, open-source AI could compete at frontier levels using shared public resources. As part of that process, we – as the EUROPA consortium, formed by Domyn and Fraunhofer IAIS and IIS – were selected to an open European Mixture-of-Experts (MoE) model of at least 400B parameters, support for all 24 official EU languages, and strict compliance with the EU AI Act.
EuroHPC 前沿 AI 大奖赛旨在证明主权开源 AI 能够利用共享公共资源竞争到前沿水平。在此过程中,我们——由 Domyn 和 Fraunhofer IAIS 及 IIS 组成的 EUROPA 联盟——被选中开发一个至少包含 400B 参数的开源欧洲混合专家(MoE)模型,支持所有 24 种官方欧盟语言,并严格遵守《欧盟人工智能法案》。
In this post, we describe how we scaled pretraining to 1T MoE on JUPITER, the EuroHPC exascale supercomputer hosted at Forschungszentrum Jülich, proving that public infrastructure can indeed sustain frontier scale.
在本文中,我们描述了如何在位于于利希研究中心(Forschungszentrum Jülich)的 EuroHPC 百亿亿次超级计算机 JUPITER 上将预训练扩展到 1T MoE,证明了公共基础设施确实能够支撑前沿规模。
| Total parameters | 951.9B (32.8B active per token) |
|---|---|
| Layers | 74 |
| Hidden size | 6,144 |
| Experts | 384 routed, top-8 |
| Expert hidden size | 1,792 |
| Vocabulary | 256,000 |
| Pretrain Sequence length | 65,536 tokens |
| Optimizer | Muon + AdamW |
| 总参数量 | 951.9B(每 token 32.8B 活跃参数) |
|---|---|
| 层数 | 74 |
| 隐藏层大小 | 6,144 |
| 专家数 | 384 路由,top-8 |
| 专家隐藏层大小 | 1,792 |
| 词汇表大小 | 256,000 |
| 预训练序列长度 | 65,536 tokens |
| 优化器 | Muon + AdamW |
The table lists the configuration used for the experiments in the post.
该表格列出了本文实验中使用的配置。
Models of this size are usually trained on clusters that their developers operate or rent for exclusive use. JUPITER is instead publicly funded research infrastructure shared by hundreds of projects. It was also designed to support scientific research at large, which led to architectural choices that are somewhat atypical in the AI space, as we’ll describe in detail later in the post. As such, reaching the 1T parameter scale while maintaining viable throughput requires careful optimizations that go beyond standard distributed techniques.
这种规模的模型通常在开发者运营或租用专有的集群上进行训练。而 JUPITER 是由数百个项目共享的公共资助研究基础设施。它还被设计用于支持广泛的科学研究,这导致其架构选择在 AI 领域 somewhat 不典型,正如我们在本文稍后部分详细描述的那样。因此,在保持可行吞吐量的同时达到 1T 参数规模,需要进行超越标准分布式技术的细致优化。
In order to have access to the necessary level of flexibility to perform fine-grained optimizations to the pre-training setup, we chose to go with PyTorch and TorchTitan. Under these conditions, we raised throughput from 90 to ~1,300 tokens/s per GPU on 384 GH200 GPUs (96 nodes). We want to share the main milestones that get us there, each of which builds on TorchTitan’s design and led to contributions back to TorchTitan and PyTorch:
为了获得执行预训练设置细粒度优化所需的灵活级别,我们选择使用 PyTorch 和 TorchTitan。在这些条件下,我们将 384 块 GH200 GPU(96 个节点)上每 GPU 的吞吐量从每秒 90 个 token 提升至约 1,300 个 token。我们希望分享达成这一目标的主要里程碑,每一个都建立在 TorchTitan 的设计之上,并促成了对 TorchTitan 和 PyTorch 的贡献:
- FlexShard placement for the Muon optimizer, which removes most of the optimizer’s communication.
- Activation-checkpoint offloading to the Grace CPU.
- Running FSDP’s all-gather setup on the compute stream (unshard_async_op), which frees ~14 GiB of HBM per GPU.
- Muon 优化器的 FlexShard 放置策略,该策略消除了优化器的大部分通信开销。
- 将激活检查点卸载至 Grace CPU。
- 在计算流上运行 FSDP 的全收集设置(unshard_async_op),从而为每个 GPU 释放约 14 GiB 的 HBM 空间。
The full write-up covers the remaining changes in detail, with interactive figures and profiler traces.
完整的文章详细说明了其余更改,并包含交互式图表和性能分析追踪数据。
The machine and its constraints
机器及其约束条件
Each JUPITER Booster node has four NVIDIA GH200 Grace Hopper Superchips. Each superchip pairs a Hopper GPU (96 GB HBM3) with a 72-core Grace CPU (120 GB LPDDR5X), connected by a 900 GB/s NVLink-C2C link. GPUs in a node are connected by NVLink 4 at 150 GB/s per direction, and each node has four InfiniBand NDR200 adapters, about 25 GB/s per GPU.
每个 JUPITER Booster 节点配备四块 NVIDIA GH200 Grace Hopper 超级芯片。每个超级芯片将一个 Hopper GPU(96 GB HBM3)与一个 72 核心的 Grace CPU(120 GB LPDDR5X)配对,两者通过 900 GB/s 的 NVLink-C2C 链路连接。节点内的 GPU 通过 NVLink 4 互联,每方向带宽为 150 GB/s;每个节点配备四个 InfiniBand NDR200 适配器,每个 GPU 对应约 25 GB/s 的带宽。
Figure 2. Bandwidths within a JUPITER node, drawn to scale. All inter-node traffic leaves through the thin InfiniBand links.
图 2. JUPITER 节点内部的带宽比例示意图。所有节点间流量均通过细线所示的 InfiniBand 链路传输。
In addition to the accelerators, two key parts of the system are also relevant for the design:
除了加速器之外,系统中还有两个关键部分对设计至关重要:
- Inter-node bandwidth. InfiniBand is 36 times slower than the link between a GPU and its own CPU, and distributing a 1T parameter model over hundreds of accelerators requires crossing that boundary continuously during training. Traffic over InfiniBand must therefore aggressively overlap with computation.
- Host memory capacity. GH200 is available with up to 480 GB of LPDDR5X per Grace, but JUPITER’s compute nodes actually use the 120 GB configuration (as opposed to login nodes which sport 480GB), which favors bandwidth over capacity. After the kernel’s share, about 108 GiB per GPU is usable, and we found that in practice some nodes start jobs with much less. This limits how much state can be moved out of the HBM.
- 节点间带宽。InfiniBand 的速度比 GPU 与其自身 CPU 之间的链路慢 36 倍,而在数百个加速器上分布 1T 参数模型需要在训练过程中不断跨越这一边界。因此,InfiniBand 上的流量必须与计算高度重叠。
- 主机内存容量。GH200 最多可为每个 Grace 提供 480 GB 的 LPDDR5X 内存,但 JUPITER 的计算节点实际使用的是 120 GB 配置(区别于配备 480GB 的登录节点),这种配置更侧重带宽而非容量。扣除内核占用后,每个 GPU 可用约 108 GiB,我们发现实践中某些节点启动作业时可用内存更少。这限制了可以从 HBM 中移出的状态数据的规模。
These constraints dictate the parallelism layout: 384-way FSDP with 4-way expert parallelism inside each node and no pipeline parallelism. The MoE token all-to-all is hard to overlap, so we kept it on NVLink. Without pipeline parallelism steps tend to be shorter, which has the advantage of providing fast feedback at scale, and fixed costs are amortized via a large batch of 384 sequences of 65,536 tokens (~25M tokens per step). FSDP already provides us with the overlap of the gather of layer n+1 with the compute of layer n, so most of the remaining work goes into making the overlap effective. We achieve this across three dimensions: moving to longer sequences to compute for longer, reducing the bytes transmitted over InfiniBand, and leveraging Grace memory to provide enough total capacity to hold the model, the gradients and the optimizer state.
这些约束决定了并行布局:在每个节点内采用 384-way FSDP(完全分片数据并行)和 4-way 专家并行,且无流水线并行。MoE token 的 all-to-all 通信难以重叠,因此我们将其保留在 NVLink 上。由于没有流水线并行,各步骤往往较短,这带来了大规模下快速反馈的优势,并通过包含 384 个序列、每个序列 65,536 个令牌的大批次(每步约 2500 万令牌)来分摊固定成本。FSDP 已经为我们提供了第 n+1 层的 gather 与第 n 层的计算之间的重叠,因此大部分剩余工作致力于使这种重叠更有效。我们通过三个维度实现这一目标:使用更长的序列以进行更长时间的计算、减少通过 InfiniBand 传输的字节数,以及利用 Grace 内存提供足够的总容量来容纳模型、梯度和优化器状态。
FlexShard: Muon without the communication
FlexShard:无需通信的 Muon
We use Muon for every weight matrix except the router and embeddings (about 99.5% of the parameters) and AdamW for the rest. Muon requires one fp32 state per parameter, while Adam requires two. Removing the second state is instrumental in making a 65,536-token sequence fit in memory.
除了路由器和嵌入层(约占参数的 99.5%)外,我们对所有权重矩阵使用 Muon,其余部分使用 AdamW。Muon 需要每个参数一个 fp32 状态,而 Adam 需要两个。移除第二个状态对于让 65,536 个令牌的序列适应内存至关重要。
Muon orthogonalizes each update with a few Newton-Schulz iterations, which operate on the whole matrix. Because FSDP splits every matrix into 384 shards, a simple implementation gathers each matrix on one rank, runs Newton-Schulz there and scatters the result back. On our interconnect, this communication is too expensive.
Muon 通过几次 Newton-Schulz 迭代对每次更新进行正交化,这些迭代作用于整个矩阵。由于 FSDP 将每个矩阵分割为 384 个分片,简单的实现方式会在一个 rank 上收集每个矩阵,在该 rank 上运行 Newton-Schulz 迭代,然后将结果散射回去。在我们的互连网络上,这种通信开销过大。
FlexShard, now part of TorchTitan, lets us control which rank owns which parameters. We shard the experts by whole expert, so every rank owns complete expert matrices and runs their Newton-Schulz iterations with no communication at all. The dense matrices, such as the attention projections, are still collected on an owning rank, and each rank processes its own experts while the dense matrices are in transit, so that communication is overlapped.
FlexShard(现已成为 TorchTitan 的一部分)使我们能够控制哪个 rank 拥有哪些参数。我们按完整专家进行分片,因此每个 rank 都拥有完整的专家矩阵,并运行其 Newton-Schulz 迭代,无需任何通信。密集矩阵(如注意力投影)仍然由拥有它们的 rank 收集,每个 rank 在处理自己的专家时,密集矩阵正在传输中,从而实现了通信的重叠。
With FSDP’s CPU offload, the optimizer runs on Grace, where the parameters are stored, and Newton-Schulz on 72 Arm cores takes ~35 s per step. We contributed support to TorchTitan for running Newton-Schulz on the GPU while parameters stay offloaded. The optimizer step went from 41.7 s to 2.2 s, and throughput rose from 441 to 597 tokens/s per GPU (+35%).
借助 FSDP 的 CPU offload(卸载),优化器在存储参数的 Grace 上运行,Newton-Schulz 在 72 个 Arm 核心上运行,每步耗时约 35 秒。我们为 TorchTitan 贡献了支持,使其能够在参数保持卸载的情况下在 GPU 上运行 Newton-Schulz。优化器步骤从 41.7 秒缩短至 2.2 秒,吞吐量从每 GPU 每秒 441 个令牌提升至 597 个令牌(+35%)。
Figure 3. Rank 0’s profiled step from 80 s onward. Top: Newton-Schulz on Grace, with the GPU idle for ~34 s after the backward pass while the CPU computes. Bottom: Newton-Schulz on Hopper, where the optimizer takes a small fraction of the step.
图 3. Rank 0 从 80 秒开始的剖析步骤。上方:在 Grace 上运行 Newton-Schulz,反向传播后 GPU 空闲约 34 秒,而 CPU 正在计算。下方:在 Hopper 上运行 Newton-Schulz,优化器仅占用该步骤的一小部分时间。
Activation offloading to Grace
激活值卸载至 Grace
The volume of weights gathered per layer does not depend on the number of tokens in our setup, so a longer sequence increases compute time while not impacting communication. We first stored activations only at layer boundaries and recomputed everything inside a layer during the backward pass. In TorchTitan this is named FullAC. Since GPU was idle for most of the baseline step, the extra compute did not lengthen it. As a result, throughput went from 90 to 370 tokens/s per GPU at 32,768 tokens.
在我们的设置中,每层收集的权重体积不依赖于令牌数量,因此更长的序列会增加计算时间,但不会影响通信。我们最初仅在层边界存储激活值,并在反向传播期间重新计算层内的所有内容。在 TorchTitan 中,这被称为 FullAC。由于 GPU 在基线步骤的大部分时间内处于空闲状态,额外的计算并未延长该步骤的时间。因此,吞吐量从每 GPU 每秒 90 个令牌提升至 370 个令牌(在 32,768 个令牌时)。
At 65,536 tokens, the boundary activations alone take 74 layers × 65,536 tokens × 6,144 × 2 bytes ≈ 55 GiB per GPU, which does not fit in HBM next to the weights. GH200 has a 900 GB/s link to 120 GB of CPU memory, so we decide to offload them. Each boundary activation is copied to Grace after the forward pass produces it, and copied back to Hopper one layer before the backward pass recomputes it. An offloading parameter sets the share of layers that offload, which trades HBM for Grace memory.
在 65,536 个令牌时,仅边界激活值就需要 74 层 × 65,536 个令牌 × 6,144 × 2 字节 ≈ 每 GPU 55 GiB,这无法与权重一起容纳在 HBM 中。GH200 拥有连接到 120 GB CPU 内存的 900 GB/s 链路,因此我们决定将其卸载。每个边界激活值在前向传播生成后被复制到 Grace,并在反向传播重新计算之前一层被复制回 Hopper。一个卸载参数设置了执行卸载的层比例,从而在 HBM 和 Grace 内存之间进行权衡。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力