首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >AI论文陪读·ZeRO:分布式训练的第一篇论文(中英双语)

AI论文陪读·ZeRO:分布式训练的第一篇论文(中英双语)

作者头像
heidsoft
发布2026-07-02 12:21:33
发布2026-07-02 12:21:33
1370
举报

01

问题:显存为什么不够用

中文:训练时,每份参数在显存里实际要存多份东西。论文 Section 3.1 给出了具体公式:fp16 参数 + fp16 梯度 + Adam 优化器状态(fp32 动量+方差+参数副本),合计约 16Ψ 字节(Ψ = 参数数量)。

ENG:During training, each model parameter ψ requires multiple memory copies: fp16 parameters, fp16 gradients, and Adam optimizer states (fp32 momentum, variance, and a copy of parameters). Total ≈ 16ψ bytes per parameter.

# Memory Breakdown (per parameter ψ)

fp16 parameters: 2Ψ bytes

fp16 gradients: 2Ψ bytes

Adam optimizer (K=12): KΨ bytes ← fp32 momentum + variance + fp32 param copy

Total: ~16Ψ bytes | GPT-2 1.5B → 24 GB (vs 3 GB for params alone)

中文:以 GPT-2(1.5B 参数)为例:fp16 参数本体只占 3 GB,但加上优化器状态等,显存跳到 24 GB——是前者的 8 倍。如果是 1 万亿参数(1T)模型,模型状态显存需求约 16 TB,32 GB V100 卡要 500 张才能装下。

ENG:For GPT-2 (1.5B params): fp16 weights alone = 3 GB, but with optimizer states the requirement jumps to 24 GB. A 1 Trillion (1T) parameter model needs ~16 TB for model states alone — requiring ~500 × 32 GB V100 GPUs.

02

原有方案的根本局限 / Limitations of Prior Art

🔵 Data Parallelism(数据并行)

优势 / Pros:扩展效率高,通信量小,实现简单 / High scalability, low communication overhead, easy to implement

问题 / Cons:每张卡复制完整模型,显存冗余严重 / Every GPU stores a full replica — memory inefficient

🔵 Model Parallelism(模型并行)/ Pipeline Parallelism(流水线并行)

优势 / Pros:把模型切分到多卡,显存够用 / Partition model across GPUs — fits large models

问题 / Cons:计算粒度降低,跨节点通信开销大;需改动模型代码 / Reduced compute granularity, high cross-node communication, requires model code changes

中文:原文 Section 4.1 的核心洞察:DP 计算效率高但显存冗余,MP 显存效率高但计算效率低——两者是 tradeoff,既往方案只能二选一。

ENG:Paper Section 4.1 insight: DP offers high compute efficiency but memory redundancy; MP offers memory efficiency but lower compute efficiency. Prior work forces a tradeoff — ZeRO aims to have both.

03

ZeRO 三阶段:递进式显存节省 / Three-Stage Memory Optimization

中文:ZeRO 把显存优化分为三个依次叠加的阶段。每一阶段比上一阶段多切分一部分模型状态(Section 5 原文定义)。

ENG:ZeRO partitions model states across data-parallel GPUs in three cumulative stages (Section 5). Each stage shards an additional component of model state.

三阶段对照 / Three-Stage Comparison

阶段 / Stage

分片内容 / Sharded

显存节省 / Mem. Saving

通信量 / Comm.

ZeRO-1(Pos)

Optimizer States(优化器状态)

最高 4×

= DP

ZeRO-2(Pos+g)

+ Gradients(梯度)

最高 8×

= DP(原文证明)

ZeRO-3(Pos+g+p)

+ Parameters(参数)

最高 64×(512 GPUs)

04

最重要的结论:通信量不变 / Zero Communication Overhead

"

中文:ZeRO-2 分片梯度后,通信量 = 2Φ,与原始数据并行完全相同。这是论文 Section 7.2.1 的核心证明。

ENG:With gradient partitioning (Pos+g), communication volume = 2Φ — exactly the same as standard DP. This is proven in Section 7.2.1 of the paper.

中文:这意味着 ZeRO-2 用和普通数据并行完全一样的通信量,换来了 8 倍的显存节省——不增加通信负担,这是 ZeRO 最重要的工程价值。

ENG:ZeRO-2 achieves 8× memory reduction with identical communication volume compared to naive DP. No communication overhead — this is ZeRO's core engineering contribution.

05

硬数字 / Key Numbers from the Paper

硬件 / Hardware:400 × V100 GPU(25 DGX-2 nodes),节点间带宽 800 Gbps。原文 Table 2、Table 5 数据:

模型 / Model

并行方式 / Config

GPU 数量

结果 / Result

60B 参数

ZeRO-100B

64–400

38 TFlops/GPU,聚合 15 Petaflops

170B 参数

ZeRO + MP=16

400

超线性加速(GPU 翻倍,性能超线性增长)

13B 参数

ZeRO-100B(无 MP)

128

40+ TFlops/GPU,无需模型并行

中文:原文 Section 10.4 特别指出:13B 参数模型不需要任何模型并行,直接用 ZeRO 训,平均单卡 40 TFlops。意味着普通研究者不需要懂模型并行,也能训练超大规模模型。

ENG:Section 10.4: 13B parameter models can be trained without any model parallelism using ZeRO alone, at 40+ TFlops/GPU average. This democratizes large model training — no need to understand MP/PP to train large models.

06

ZeRO 与 Megatron 的关系 / ZeRO + Megatron

中文:两者正交(orthogonal),可以叠加。原文 Section 4.1:"ZeRO powered DP is orthogonal and complimentary to pipeline model parallelism." 具体分工:

ENG:ZeRO and model parallelism are orthogonal and complementary. They can be stacked together.

  • Megatron(Tensor Parallelism):层内模型并行,把单层参数矩阵切开分布到多卡,解决单卡算不动的问题
  • Pipeline Parallelism:层间模型并行,把不同层放到不同卡
  • ZeRO(Data Parallelism):消除数据并行中的显存冗余,每卡只存 1/N

三者叠加 = 2019-2020 年万卡集群训练方案的完整拼图,也是今天训练 GPT-3(175B)、LLaMA(65B)等大模型的标准范式。

💡 核心洞察 / Core Insight

中文:ZeRO 的本质是用通信换显存——ZeRO-2 在通信量不变的情况下,把显存砍到 1/8,是论文最重要的工程结论。三个阶段按需开启(ZeRO-1 → ZeRO-2 → ZeRO-3),现已成为 DeepSpeed 框架的标准底座。

ENG:ZeRO trades communication for memory. ZeRO-2 achieves 8× memory reduction with zero communication overhead. Three stages (Pos → Pos+g → Pos+g+p) are additive — enable them progressively as memory runs out. Now standard in DeepSpeed, powering Turing-NLG (17B) and beyond.

本周把三个阶段(Pos / Pos+g / Pos+g+p)对应的显存节省数字记下来

本月对照 DeepSpeed 文档,用 ZeRO-2 配置跑通一个 7B 模型

永远所有「并行」概念(DP / MP / PP / TP / ZeRO)先区分「切存储」还是「切计算」,不会再混

· · ·

— END —

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2026-06-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题:显存为什么不够用
  • 原有方案的根本局限 / Limitations of Prior Art
  • ZeRO 三阶段:递进式显存节省 / Three-Stage Memory Optimization
  • 最重要的结论:通信量不变 / Zero Communication Overhead
  • 硬数字 / Key Numbers from the Paper
  • ZeRO 与 Megatron 的关系 / ZeRO + Megatron
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档