Skip to content
quboliu
⚙

How to Think About GPUs如何理解 GPU

第 12 章 · How To Scale Your Model (结论与延伸阅读)

We love TPUs at Google, but GPUs are great too. This chapter takes a deep dive into the world of GPUs – how each chip works, how they're networked together, and what that means for LLMs, especially compared to TPUs. While there are a multitude of GPU architectures from NVIDIA, AMD, Intel, and others, here we will focus on NVIDIA GPUs. This section builds on Chapter 2 and Chapter 5, so you are encouraged to read them first.

我们在 Google 很喜欢 TPU,也同样欣赏 GPU。这一章探讨 GPU 的方方面面,包括单芯片的工作方式、芯片如何互连,以及这些硬件特性对大语言模型有什么影响,尤其是与 TPU 相比。NVIDIA、AMD、Intel 等厂商都有多种 GPU 架构,本章聚焦 NVIDIA GPU。阅读前建议先完成 第 2 章和第 5 章。

What Is a GPU?什么是 GPU?

A modern ML GPU (e.g. H100, B200) is basically a bunch of compute cores that specialize in matrix multiplication (called Streaming Multiprocessors or SMs) connected to a stick of fast memory (called HBM). Here’s a diagram:

现代机器学习 GPU (例如 H100,B200) 基本上是一堆专门用于矩阵乘法的计算核心 (称为流式多处理器或 SMs),连接到一块高速内存 (称为 HBM)。下图是一个示意图:

gpu diagram

Figure: a diagram showing the abstract layout of an H100 or B200 GPU. An H100 has 132 SMs while a B200 has 148. We use the term ‘Warp Scheduler’ somewhat broadly to describe a set of 32 CUDA SIMD cores and the scheduler that dispatches work to them. Note how much this looks like a TPU!

图: 展示 H100 或 B200 GPU 抽象布局的示意图。H100 有 132 个 SM,而 B200 有 148 个。我们宽泛地使用术语 ‘Warp 调度器’ 来描述一组 32 个 CUDA SIMD 核心以及向它们分派工作的调度器。注意这与 TPU 的相似之处!

Each SM, like a TPU’s Tensor Core, has a dedicated matrix multiplication core (unfortunately also called a Tensor Core1), a vector arithmetic unit (called a Warp Scheduler2), and a fast on-chip cache (called SMEM). Unlike a TPU, which has at most 2 independent “Tensor Cores”, a modern GPU has more than 100 SMs (132 on an H100). Each of these SMs is much less powerful than a TPU Tensor Core but the system overall is more flexible. Each SM is more or less totally independent, so a GPU can do hundreds of separate tasks at once.3

每个 SM,就像 TPU 的张量核心 (Tensor Core) 一样,拥有一个专用的矩阵乘法核心 (不幸的是也叫张量核心1),一个向量算术单元 (称为 Warp 调度器2),以及一个高速片上缓存 (称为 SMEM)。与 TPU 最多拥有 2 个独立的“张量核心”不同,现代 GPU 拥有超过 100 个 SM (H100 上有 132 个)。每个 SM 的功能远不如 TPU 张量核心强大,但整个系统更加灵活。每个 SM 或多或少是完全独立的,所以一个 GPU 可以同时执行数百个独立的任务。3

Let’s take a more detailed view of an H100 SM:

让我们更详细地看一下 H100 SM:

blackwell sm

Figure: a diagram of an H100 SM (source) showing the 4 subpartitions, each containing a Tensor Core, Warp Scheduler, Register File, and sets of CUDA Cores of different precisions. The ‘L1 Data Cache’ near the bottom is the 256kB SMEM unit. A B200 looks similar, but adds a substantial amount of Tensor Memory (TMEM) for feeding the bulky Tensor Cores.

图: H100 SM 的示意图 (来源),展示了 4 个子分区,每个子分区包含一个张量核心,Warp 调度器,寄存器文件,以及不同精度的 CUDA 核心集。底部附近的 ‘L1 数据缓存’ 是 256kB 的 SMEM 单元。B200 看起来类似,但增加了大量的张量内存 (TMEM) 来为庞大的张量核心提供数据。

Each SM is broken up into 4 identical quadrants, which NVIDIA calls SM subpartitions, each containing a Tensor Core, 16k 32-bit registers, and a SIMD/SIMT vector arithmetic unit called a Warp Scheduler, whose lanes (ALUs) NVIDIA calls CUDA Cores. The core component of each partition is arguably the Tensor Core, which performs matrix multiplications and makes up the vast majority of its FLOPs/s, but it’s not the only component worth noting.

每个 SM 被分成 4 个相同的象限,NVIDIA 称之为 SM 子分区,每个子分区包含一个张量核心,16k 个 32 位寄存器,以及一个称为 Warp 调度器的 SIMD/SIMT 向量算术单元,其通道 (ALU) NVIDIA 称之为 CUDA 核心。每个分区的核心组件可以说是执行矩阵乘法的张量核心,它构成了其绝大部分的 FLOPs/s,但它并非唯一值得注意的组件。

  • CUDA Cores: each subpartition contains a set of ALUs called CUDA Cores that do SIMD/SIMT vector arithmetic. Each ALU can generally do 1 arithmetic op each cycle, e.g. f32.add.4 Each subpartition contains 32 fp32 cores (and a smaller number of int32 and fp64 cores) that all execute the same instruction in each cycle. Like the TPU’s VPU, CUDA cores are responsible for ReLUs, pointwise vector operations, and reductions (sums).5
  • CUDA 核心: 每个子分区包含一组称为 CUDA 核心的 ALU,用于执行 SIMD/SIMT 向量运算。每个 ALU 通常每个周期可以执行 1 次算术运算,例如 f32.add。4 每个子分区包含 32 个 fp32 核心 (以及数量较少的 int32 和 fp64 核心),它们在每个周期都执行相同的指令。与 TPU 的 VPU 类似,CUDA 核心负责 ReLU,逐点向量运算和归约 (求和)。5
  • Tensor Core (TC): each subpartition has its own Tensor Core, which is a dedicated matrix multiplication unit like a TPU MXU. The Tensor Core represents the vast majority of the GPU’s FLOPs/s (e.g. on an H100, we have 990 bf16 TC TFLOP/s compared to just 66 TFLOPs/s from the CUDA cores).
    • 990 bf16 TFLOPs/s with 132 SM running at 1.76GHz means each H100 TC can do 7.5e12 / 1.76e9 / 4 ~ 1024 bf16 FLOPs/cycle, roughly an 8x8x8 matmul.6
    • Like TPUs, GPUs can do lower precision matmuls at higher throughput (e.g. H100 has 2x fp8 FLOPs/s vs. fp16). Low-precision training or serving can be significantly faster.
    • Each GPU generation since Volta has increased the TC size over the previous generation (good article on this). With B200 the TC has gotten so large it can no longer fit its inputs in SMEM, so B200s introduce a new memory space called TMEM.7
  • 张量核心 (TC): 每个子分区都有自己的张量核心,这是一个专用的矩阵乘法单元,类似于 TPU MXU。张量核心占了 GPU FLOPs/s 的绝大部分 (例如,在 H100 上,我们有 990 bf16 TC TFLOP/s,而 CUDA 核心只有 66 TFLOPs/s)。
    • 990 bf16 TFLOPs/s 意味着 132 个 SM 以 1.76GHz 运行时,每个 H100 TC 可以执行 7.5e12 / 1.76e9 / 4 ~ 1024 bf16 FLOPs/cycle,大约是一个 8x8x8 的矩阵乘法。6
    • 与 TPU 类似,GPU 可以用更低的精度执行矩阵乘法以获得更高的吞吐量 (例如 H100 的 fp8 FLOPs/s 是 fp16 的 2 倍)。低精度训练或服务可以显著加快速度。
    • 自 Volta 以来的每一代 GPU 都增加了 TC 的尺寸 (关于此内容的好文章)。到了 B200,TC 变得如此之大,以至于其输入不再能装入 SMEM,因此 B200 引入了一个名为 TMEM 的新内存空间。7

CUDA cores are more flexible than a TPU’s VPU: GPU CUDA cores (since V100) use what is called a SIMT (Single Instruction Multiple Threads) programming model, compared to the TPU’s SIMD (Single Instruction Multiple Data) model. Like ALUs in a TPU’s VPU, CUDA cores within a subpartition must execute the same operation in each cycle (e.g. if one core is adding two floats, then every other CUDA core in the subpartition must also do so). Unlike the VPU, however, each CUDA core (or “thread” in the CUDA programming model) has its own instruction pointer and can be programmed independently. When two threads in the same warp are instructed to perform different operations, you effectively do both operations, masking out the cores that don’t need to perform the divergent operation.

CUDA 核心比 TPU 的 VPU 更灵活: GPU CUDA 核心 (自 V100 起) 使用所谓的 SIMT (单指令多线程) 编程模型,而 TPU 使用 SIMD (单指令多数据) 模型。与 TPU VPU 中的 ALU 类似,一个子分区内的 CUDA 核心必须在每个周期执行相同的操作 (例如,如果一个核心正在对两个浮点数进行加法,那么该子分区中的所有其他 CUDA 核心也必须这样做)。然而,与 VPU 不同的是,每个 CUDA 核心 (或 CUDA 编程模型中的“线程”) 都有自己的指令指针,并且可以被独立编程。当同一 warp 中的两个线程被指示执行不同的操作时,你实际上会执行两种操作,屏蔽掉那些不需要执行发散操作的核心。

warp divergence

Figure: an example of warp divergence within a set of threads (source). White spaces indicate stalls of at least some fraction of the physical CUDA cores

图: 一组线程内 warp 发散的示例 (来源)。白色空间表示至少一部分物理 CUDA 核心的停顿。

This enables flexible programming at the thread level, but at the cost of silently degrading performance if warps diverge too often. Threads can also be more flexible in what memory they can access; while the VPU can only operate on contiguous blocks of memory, CUDA cores can access individual floats in shared registers and maintain per-thread state.

这使得在线程级别进行灵活编程成为可能,但代价是如果 warp 发散过于频繁,性能会悄无声息地下降。线程在访问内存方面也更灵活;VPU 只能操作连续的内存块,而 CUDA 核心可以访问共享寄存器中的单个浮点数并维护每个线程的状态。

CUDA core scheduling is also more flexible: SMs run a bit like multi-threaded CPUs, in the sense that they can “schedule” many programs (warps) concurrently (up to 64 per SM) but each Warp Scheduler only ever executes a single program in each clock cycle.8 The Warp Scheduler automatically switches between active warps to hide I/O operations like memory loads. TPUs are generally single threaded by comparison.

CUDA 核心调度也更灵活: SM 的运行方式有点像多线程 CPU,因为它们可以并发地“调度”许多程序 (warps) (每个 SM 最多 64 个),但每个 Warp 调度器 在每个时钟周期只执行一个程序。8 Warp 调度器会自动在活动 warp 之间切换,以隐藏 I/O 操作,如内存加载。相比之下,TPU 通常是单线程的。

Memory内存

Beyond the compute units, GPUs have a hierarchy of memories, the largest being HBM (the main GPU memory), and then a series of smaller caches (L2, L1/SMEM, TMEM, register memory).

除了计算单元,GPU 还有一个内存层次结构,最大的是 HBM (主 GPU 内存),然后是一系列较小的缓存 (L2,L1/SMEM,TMEM,寄存器内存)。

  • Registers: Each subpartition has its own register file containing 16,384 32-bit words on H100/B200 (4 * 16384 * 4 = 256kiB per SM) accessible by the CUDA cores.
    • Each CUDA core can only access up to 256 registers at a time, so although we can schedule up to 64 “resident warps” per SM, you can only fit 8 (256 * 1024 / (4 * 32 * 256)) at a time if each thread uses 256 registers.
  • 寄存器: 每个子分区都有自己的寄存器文件,在 H100/B200 上包含 16,384 个 32 位字 (4 * 16384 * 4 = 256kiB 每个 SM),可由 CUDA 核心访问。
    • 每个 CUDA 核心一次最多只能访问 256 个寄存器,所以虽然我们每个 SM 最多可以调度 64 个“常驻 warp”, 但如果每个线程使用 256 个寄存器,你一次只能容纳 8 个 (256 * 1024 / (4 * 32 * 256))。
  • SMEM (L1 Cache): each SM has its own 256kB on-chip cache called SMEM, which can either be programmer controlled as “shared memory” or used by the hardware as an on-chip cache. SMEM is used for storing activations and inputs to TC matmuls.
  • SMEM (L1 缓存): 每个 SM 都有自己的 256kB 片上缓存,称为 SMEM,它可以由程序员控制为“共享内存”, 也可以由硬件用作片上缓存。SMEM 用于存储激活值和 TC 矩阵乘法的输入。
  • L2 Cache: all SMs share9 a relatively large ~50MB L2 cache used to reduce main memory accesses.
    • This is similar in size to a TPU’s VMEM but it’s much slower and isn’t programmer controlled. This leads to a bit of “spooky action at a distance” where the programmer needs to modify memory access patterns to ensure the L2 cache is well used.10
    • NVIDIA does not publish the L2 bandwidth for their chips, but it’s been measured to be about 5.5TB/s. This is roughly 1.6x the HBM bandwidth but it’s full-duplex, so the effective bidirectional bandwidth is closer to 3x. By comparison, a TPU’s VMEM is 2x larger and has much more bandwidth (around 40TB/s).
  • L2 缓存: 所有 SM 共享9 一个相对较大的约 50MB 的 L2 缓存,用于减少主内存访问。
    • 这在大小上与 TPU 的 VMEM 相似,但它慢得多并且不受程序员控制。这导致了一些“远距离的诡异行为”, 程序员需要修改内存访问模式以确保 L2 缓存得到良好利用。10
    • NVIDIA 没有公布其芯片的 L2 带宽,但据测量约为 5.5TB/s。这大约是 HBM 带宽的 1.6 倍,但它是全双工的,所以有效的双向带宽接近 3 倍。相比之下,TPU 的 VMEM 大小是其 2 倍,并且 带宽要大得多 (约 40TB/s)。
  • HBM: the main GPU memory, used for storing model weights, gradients, activations, etc.
    • The HBM size has increased a lot from 32GB in Volta to 192GB in Blackwell (B200).
    • The bandwidth from HBM to the CUDA Tensor Core is called HBM bandwidth or memory bandwidth, and is about 3.35TB/s on H100 and 9TB/s on B200.
  • HBM: 主 GPU 内存,用于存储模型权重,梯度,激活值等。
    • HBM 的大小从 Volta 的 32GB 增加到 Blackwell (B200) 的 192GB。
    • 从 HBM 到 CUDA 张量核心的带宽称为 HBM 带宽或内存带宽,在 H100 上约为 3.35TB/s,在 B200 上约为 9TB/s。

Summary of GPU specsGPU 规格摘要

Here is a summary of GPU specs for recent models. The number of SMs, clock speed, and FLOPs differ somewhat between variants of a given GPU. Here are memory capacity numbers:

以下是近期型号的 GPU 规格摘要。SM 数量,时钟速度和 FLOPs 在给定 GPU 的不同变体之间略有不同。以下是内存容量数据:

GPUGeneration
世代
Clock Speed
时钟速度
SMs/chip
SMs/芯片
SMEM capacity/SM
SMEM 容量/SM
L2 capacity/chip
L2 容量/芯片
HBM capacity/chip
HBM 容量/芯片
V100Volta1.25GHz/1.38GHz8096kB6MB32GB
A100Ampere1.10GHz/1.41GHz108192kB40MB80GB
H100Hopper1.59GHz/1.98GHz132256kB50MB80GB
H200Hopper1.59GHz/1.98GHz132256kB50MB141GB
B200Blackwell?148256kB126MB192GB

All generations have 256kB of register memory per SM. Blackwell adds 256kB of TMEM per SM as well. Here are the FLOPs and bandwidth numbers for each chip:

所有世代每个 SM 都有 256kB 的寄存器内存。Blackwell 每个 SM 还增加了 256kB 的 TMEM。以下是每个芯片的 FLOPs 和带宽数据:

GPUGeneration
世代
HBM BW/chip
HBM BW/芯片
FLOPs/s/chip (bf16/fp16)
FLOPs/s/芯片 (bf16/fp16)
FLOPs/s/chip (fp8/int8)
FLOPs/s/芯片 (fp8/int8)
FLOPs/s/chip (fp4)
FLOPs/s/芯片 (fp4)
V100Volta9.0e11———
A100Ampere2.0e123.1e146.2e14—
H100Hopper3.4e129.9e142.0e15—
H200Hopper4.8e129.9e142.0e15—
B200Blackwell8.0e122.3e154.5e159.0e15

We exclude B100 since it wasn’t mass-produced.11 Some specs depend slightly on the precise version of the GPU, since NVIDIA GPUs aren’t as standard as TPUs.

我们排除了 B100,因为它没有大规模生产。11 一些规格略微取决于 GPU 的精确版本,因为 NVIDIA GPU 不像 TPU 那样标准化。

Here’s a helpful cheat sheet comparing GPU and TPU components:

这里有一个有用的备忘单,比较了 GPU 和 TPU 的组件:

GPUTPUWhat is it?
它是什么?
Streaming Multiprocessor (SM)
流式多处理器 (SM)
Tensor Core
张量核心
Core “cell” that contains other units
包含其他单元的核心“单元”
Warp Scheduler
Warp 调度器
VPUSIMD vector arithmetic unit
SIMD 向量算术单元
CUDA Core
CUDA 核心
VPU ALUSIMD ALU
SMEM (L1 Cache)
SMEM (L1 缓存)
VMEMFast on-chip cache memory
快速片上缓存
Tensor Core
张量核心
MXUMatrix multiplication unit
矩阵乘法单元
HBM (aka GMEM)
HBM (又名 GMEM)
HBMHigh bandwidth high capacity memory
高带宽大容量内存

GPUs vs. TPUs at the chip level芯片层面的 GPU 与 TPU 对比

GPUs started out rendering video games, but since deep learning took off in the 2010s, they’ve started acting more and more like dedicated matrix multiplication machines – in other words, more like TPUs.12 To an extent, this history explains why modern GPUs look the way they do. They weren’t designed purely for LLMs or ML models but as general-purpose accelerators, and the hardware aims for a level of “generality” that can be both a blessing and a curse. GPUs much more often “just work” when applied to new tasks and lean far less on a good compiler than TPUs do. But this also makes them much harder to reason about or get roofline performance out of, since so many compiler features can cause bottlenecks.

GPU 最初用于渲染视频游戏,但自 2010 年代深度学习兴起以来,它们越来越像专用的矩阵乘法机器——换句话说,越来越像 TPU。12 在某种程度上,这段历史解释了为什么现代 GPU 是现在这个样子。它们并非纯粹为 LLM 或 ML 模型设计,而是作为通用加速器,硬件追求的“通用性”水平既是福也是祸。GPU 在应用于新任务时更常“开箱即用”, 并且对优秀编译器的依赖远低于 TPU。但这也使得它们更难推理或从中获得 屋顶线 性能,因为太多的编译器特性可能导致瓶颈。

GPUs are more modular. TPUs have 1-2 big Tensor Cores, while GPUs have hundreds of small SMs. Likewise, each TC has a single big VPU composed of 4 independently programmable 8x128 units (for a total of 4096 ALUs); by comparison, an H100 has 132 * 4 = 528 independent SIMD units, each 32-wide (16k ALUs total). Here is a 1:1 comparison of GPUs to TPU that highlights this point:

GPU 的模块划分更细。 TPU 有 1–2 个大型张量核心,GPU 则有数百个较小的 SM。TPU 的每个张量核心有一个大型向量处理单元(VPU),由 4 个可独立编程的 8×128 单元组成(共 4096 个 ALU)。相比之下,H100 有 132 × 4 = 528 个独立的 SIMD 单元,每个单元的宽度为 32(共约 16,000 个 ALU)。下表逐项比较 GPU 与 TPU,说明这种差异:

GPUTPUH100 #TPU v5p #
SM (streaming multiprocessor)
SM (流式多处理器)
Tensor Core
张量核心
1322
Warp Scheduler
Warp 调度器
VPU slots5288
SMEM (L1 cache)
SMEM (L1 缓存)
VMEM32MB128MB
Registers
寄存器
Vector Registers (VRegs)
向量寄存器 (VRegs)
32MB256kB
Tensor Core
张量核心
MXU5288

This difference in modularity on the one hand makes TPUs much cheaper to build and simpler to understand, but it also puts more burden on the compiler to do the right thing. Because TPUs have a single thread of control and only support vectorized VPU-wide instructions, the compiler needs to manually pipeline all memory loads and MXU/VPU work to avoid stalls. A GPU programmer can just launch dozens of different kernels, each running on a totally independent SM. On the other hand, those kernels might get horrible performance because they are thrashing the L2 cache or failing to coalesce memory loads; because the hardware controls so much of the runtime, it becomes hard to reason about what’s going on behind the scenes. As a result, TPUs can often get closer to peak roofline performance with less work.

这种模块化上的差异一方面使得 TPU 的制造成本更低,理解起来更简单,但也给编译器带来了更大的负担,需要它做出正确的决策。因为 TPU 只有一个控制线程,并且只支持向量化的 VPU 范围指令,编译器需要手动流水线化所有内存加载和 MXU/VPU 工作以避免停顿。GPU 程序员可以启动数十个不同的内核,每个内核都在完全独立的 SM 上运行。另一方面,这些内核可能会因为 L2 缓存颠簸或未能合并内存加载而性能糟糕;因为硬件控制了如此多的运行时,很难推理幕后发生了什么。因此,TPU 通常可以用更少的工作量更接近峰值 屋顶线 性能。

Historically, individual GPUs are more powerful (and more expensive) than a comparable TPU: A single H200 has close to 2x the FLOPs/s of a TPU v5p and 1.5x the HBM. At the same time, the sticker price on Google Cloud is around \10/hourforanH200comparedto10/hour for an H200 compared to \\4/hour for a TPU v5p. TPUs generally rely more on networking multiple chips together than GPUs.

历史上,单个 GPU 比同类 TPU 更强大 (也更昂贵): 单个 H200 的 FLOPs/s 接近 TPU v5p 的 2 倍,HBM 是其 1.5 倍。同时,Google Cloud 上的标价约为 H200 每小时 10 美元,而 TPU v5p 每小时 4 美元。TPU 通常比 GPU 更依赖于将多个芯片联网在一起。

TPUs have a lot more fast cache memory. TPUs also have a lot more VMEM than GPUs have SMEM (+TMEM), and this memory can be used for storing weights and activations in a way that lets them be loaded and used extremely fast. This can make them faster for LLM inference if you can consistently store or prefetch model weights into VMEM.

TPU 拥有更多的高速缓存。 TPU 的 VMEM 也比 GPU 的 SMEM (+TMEM) 多得多,这种内存可以用来存储权重和激活值,使得它们可以被极快地加载和使用。如果你能持续地将模型权重存储或预取到 VMEM 中,这可以使它们在 LLM 推理中更快。

Quiz 1: GPU hardware测验 1:GPU 硬件

Here are some problems to work through that test some of the content above. Answers are provided, but it’s probably a good idea to try to answer the questions before looking, pen and paper in hand.

这里有一些问题可以测试上述内容。答案已提供,但最好在看答案之前,手持纸笔尝试回答问题。

Question 1 [CUDA cores]: How many fp32 CUDA cores (ALUs) does an H100 have? B200? How does this compare to the number of independent ALUs in a TPU v5p?

问题 1 [CUDA 核心]: 一个 H100 有多少个 fp32 CUDA 核心 (ALU)?B200 呢?这与 TPU v5p 中的独立 ALU 数量相比如何?

Click here for the answer. 点击这里查看答案

Answer: An H100 has 132 SMs with 4 subpartitions each containing 32 fp32 CUDA cores, so we 132 * 4 * 32 = 16896 CUDA cores. A B200 has 148 SMs, so a total of 18944. A TPU v5p has 2 TensorCores (usually connected via Megacore), each with a VPU with (8, 128) lanes and 4 independent ALUs per lane, so 2 * 4 * 8 * 128 = 8192 ALUs. This is roughly half the number of vector lanes of an H100, running at roughly the same frequency.

答案: 一个 H100 有 132 个 SM,每个 SM 有 4 个子分区,每个子分区包含 32 个 fp32 CUDA 核心,所以我们有 132 * 4 * 32 = 16896 个 CUDA 核心。一个 B200 有 148 个 SM,所以总共有 18944 个。一个 TPU v5p 有 2 个 TensorCore (通常通过 Megacore 连接),每个都有一个 VPU,VPU 有 (8,128) 个通道,每个通道有 4 个独立的 ALU,所以 2 * 4 * 8 * 128 = 8192 个 ALU。这大约是 H100 向量通道数量的一半,运行频率大致相同。

Question 2 [Vector FLOPs calculation]: A single H100 has 132 SMs and runs at a clock speed of 1.59GHz (up to 1.98GHz boost). Assume it can do one vector op per cycle per ALU. How many vector fp32 FLOPs can be done per second? With boost? How does this compare to matmul FLOPs?

问题 2 [向量 FLOPs 计算]:单个 H100 有 132 个 SM,时钟速度为 1.59GHz (最高可达 1.98GHz boost)。假设它每个 ALU 每个周期可以执行一次向量操作。每秒可以执行多少次向量 fp32 FLOPs?boost 模式下呢?这与矩阵乘法 FLOPs 相比如何?

Click here for the answer. 点击这里查看答案

Answer: 132 * 4 * 32 * 1.59e9 = 26.9TFLOPs/s. With boost its 33.5 TFLOPs/s. This is half what’s reported in the spec sheet because technically we can do an FMA (fused-multiply-add) in one cycle which counts as two FLOPs, but this isn’t useful in most cases. We can do 990 bfloat16 matmul TFLOPs/s, so ignoring FMAs, Tensor Cores do around 30x more FLOPs/s.

答案: 132 * 4 * 32 * 1.59e9 = 26.9TFLOPs/s. boost 模式下是 33.5 TFLOPs/s。这是规格表中报告的一半,因为严格来说我们可以在一个周期内完成一次 FMA (融合乘加),这算作两次 FLOPs,但在大多数情况下这并不实用。我们可以执行 990 bfloat16 矩阵乘法 TFLOPs/s,所以忽略 FMA,张量核心的 FLOPs/s 大约是其 30 倍。

Question 3 [GPU matmul intensity]: What is the peak fp16 matmul intensity on an H100? A B200? What about fp8? By intensity we mean the ratio of matmul FLOPs/s to memory bandwidth.

问题 3 [GPU 矩阵乘法强度]: H100 的峰值 fp16 矩阵乘法强度是多少?B200 呢?fp8 呢?强度我们指的是矩阵乘法 FLOPs/s 与内存带宽的比率。

Click here for the answer. 点击这里查看答案

Answer: For an H100, we have a peak 990e12 fp16 FLOPs and 3.35e12 bytes / s of bandwidth. So the critical intensity is 990e12 / 3.35e12 = 295, fairly similar to the 240 in a TPU. For B200 its 2250e12 / 8e12 = 281, very similar. This means, similar to TPUs, that we need a batch size of around 280 to be compute-bound in a matmul.

答案: 对于 H100,我们有峰值 990e12 fp16 FLOPs 和 3.35e12 字节/秒的带宽。所以临界强度是 990e12 / 3.35e12 = 295, 与 TPU 的 240 相当接近。对于 B200,它是 2250e12 / 8e12 = 281, 非常相似。这意味着,与 TPU 类似,我们需要大约 280 的批次大小才能在矩阵乘法中达到计算密集型。

For both H100 and B200 we have exactly 2x fp8 FLOPs, so the peak intensity also doubles to 590 and 562 respectively, although in some sense it stays constant if we take into account the fact that our weights will likely be loaded in fp8 as well.

对于 H100 和 B200,我们都有正好 2 倍的 fp8 FLOPs,所以峰值强度也翻倍到 590 和 562,尽管在某种意义上它保持不变,如果我们考虑到我们的权重也可能以 fp8 加载。

Question 4 [Matmul runtime]: Using the answer to Question 3, how long would you expect an fp16[64, 4096] * fp16[4096, 8192] matmul to take on a single B200? How about fp16[512, 4096] * fp16[4096, 8192]?

问题 4 [矩阵乘法运行时间]: 使用问题 3 的答案,你预计一个 fp16[64, 4096] * fp16[4096, 8192] 的矩阵乘法在单个 B200 上需要多长时间?fp16[512, 4096] * fp16[4096, 8192] 呢?

Click here for the answer. 点击这里查看答案

From the above, we know we’ll be communication-bound below a batch size of 281 tokens. Thus the first is purely bandwidth bound. We read or write 2BD+2DF+2BF2BD + 2DF + 2BF bytes (2*64*4096 + 2*4096*8192 + 2*64*8192=69e6) with 8e12 bytes/s of bandwidth, so it will take about 69e6 / 8e12 = 8.6us. In practice we likely get a fraction of the total bandwidth, so it may take closer to 10-12us. When we increase the batch size, we’re fully compute-bound, so we expect T=2*512*4096*8192/2.3e15=15us. We again only expect a fraction of the total FLOPs, so we may see closer to 20us.

从上面我们知道,当批次大小低于 281 个 token 时,我们将受通信限制。因此,第一个纯粹是带宽限制。我们读取或写入 2BD+2DF+2BF2BD + 2DF + 2BF 字节 (2*64*4096 + 2*4096*8192 + 2*64*8192=69e6),带宽为 8e12 字节/秒,所以大约需要 69e6 / 8e12 = 8.6us. 实际上,我们可能只能获得总带宽的一部分,所以可能需要接近 10-12us。当我们增加批次大小时,我们完全是计算密集型,所以我们预计 T=2*512*4096*8192/2.3e15=15us. 我们同样只期望总 FLOPs 的一部分,所以我们可能会看到接近 20us。

Question 5 [L1 cache capacity]: What is the total L1/SMEM capacity for an H100? What about register memory? How does this compare to TPU VMEM capacity?

问题 5 [L1 缓存容量]: H100 的总 L1/SMEM 容量是多少?寄存器内存呢?这与 TPU VMEM 容量相比如何?

Click here for the answer. 点击这里查看答案

Answer: We have 256kB SMEM and 256kB of register memory per SM, so about 33MB (132 * 256kB) of each. Together, this gives us a total of about 66MB. This is about half the 120MB of a modern TPU’s VMEM, although a TPU only has 256kB of register memory total! TPU VMEM latency is lower than SMEM latency, which is one reason why register memory on TPUs is not that crucial (spills and fills to VMEM are cheap).

答案: 我们每个 SM 有 256kB 的 SMEM 和 256kB 的寄存器内存,所以每种大约 33MB (132 * 256kB)。总共,这给了我们大约 66MB。这大约是现代 TPU 120MB VMEM 的一半,尽管一个 TPU 总共只有 256kB 的寄存器内存!TPU VMEM 的延迟低于 SMEM 的延迟,这也是为什么 TPU 上的寄存器内存不那么关键的原因之一 (溢出和填充到 VMEM 的成本很低)。

Question 6 [Calculating B200 clock frequency]: NVIDIA reports here that a B200 can perform 80TFLOPs/s of vector fp32 compute. Given that each CUDA core can perform 2 FLOPs/cycle in a FMA (fused multiply add) op, estimate the peak clock cycle.

问题 6 [计算 B200 时钟频率]: NVIDIA 在此 报告称,B200 可以执行 80TFLOPs/s 的向量 fp32 计算。鉴于每个 CUDA 核心可以在一个 FMA (融合乘加) 操作中执行 2 FLOPs/cycle,估算峰值时钟周期。

Click here for the answer. 点击这里查看答案

Answer: We know we have 148 * 4 * 32 = 18944 CUDA cores, so we can do 18944 * 2 = 37888 FLOPs / cycle. Therefore 80e12 / 37888 = 2.1GHz, a high but reasonable peak clock speed. B200s are generally liquid cooled, so the higher clock cycle is more reasonable.

答案: 我们知道我们有 148 * 4 * 32 = 18944 个 CUDA 核心,所以我们可以执行 18944 * 2 = 37888 FLOPs / cycle. 因此 80e12 / 37888 = 2.1GHz, 这是一个很高但合理的峰值时钟速度。B200 通常是液冷的,所以更高的时钟周期更合理。

Question 7 [Estimating H100 add runtime]: Using the figures above, calculate how long it ought to take to add two fp32[N] vectors together on a single H100. Calculate both TmathT_\text{math} and TcommsT_\text{comms}. What is the arithmetic intensity of this operation? If you can get access, try running this operation in PyTorch or JAX as well for N = 1024 and N=1024 * 1024 * 1024. How does this compare?

问题 7 [估算 H100 加法运行时间]: 使用上面的数字,计算在单个 H100 上将两个 fp32[N] 向量相加应该需要多长时间。计算 TmathT_\text{math} 和 TcommsT_\text{comms}. 这个操作的算术强度是多少?如果你可以访问,也尝试在 PyTorch 或 JAX 中运行这个操作,N = 1024 和 N=1024 * 1024 * 1024. 结果如何?

Click here for the answer. 点击这里查看答案

Answer: Firstly, adding two fp32[N] vectors performs N FLOPs and requires 4 * N * 2 bytes to be loaded and 4 * N bytes to be written back, for a total of 3 * 4 * N = 12N. Computing their ratio, we have total FLOPs / total bytes = N / 12N = 1 / 12, which is pretty abysmal.

答案: 首先,将两个 fp32[N] 向量相加执行 N 次 FLOPs,需要加载 4 * N * 2 字节并写回 4 * N 字节,总共 3 * 4 * N = 12N. 计算它们的比率,我们得到 total FLOPs / total bytes = N / 12N = 1 / 12, 这相当糟糕。

As we calculated above, we can do roughly 33.5 TFLOPs/s boost, ignoring FMA. This is only if all CUDA cores are used. For N = 1024, we can only use at most 1024 CUDA cores or 8 SMs, which will take longer (roughly 16x longer assuming we’re compute-bound). We also have a memory bandwidth of 3.35e12 bytes/s. Thus our peak hardware intensity is 33.5e12 / 3.35e12 = 10.13 So we’re going to be horribly comms bound. Thus our runtime is just

正如我们上面计算的,我们可以达到大约 33.5 TFLOPs/s 的 boost,忽略 FMA。这只有在所有 CUDA 核心都被使用的情况下才能实现。对于 N = 1024, 我们最多只能使用 1024 个 CUDA 核心或 8 个 SM,这将花费更长的时间 (假设我们是计算密集型,大约长 16 倍)。我们的内存带宽为 3.35e12 字节/秒。因此,我们的峰值硬件强度是 33.5e12 / 3.35e12 = 10.13 所以我们将严重受通信限制。因此我们的运行时间就是

T=max⁡(Tcomms,Tmath)=12⋅N3.35e12=N2.8e11T = \max(T_\text{comms}, T_\text{math}) = \frac{12 \cdot N}{\text{3.35e12}} = \frac{N}{\text{2.8e11}}

For N = 65,536, this is about 0.23us. In practice we see a runtime of about 1.5us in JAX, which is fine because we expect to be super latency bound here. For N = 1024 * 1024 * 1024, we have a roofline of about 3.84ms, and we see 4.1ms, which is good!

对于 N = 65,536, 这大约是 0.23us。实际上,我们在 JAX 中看到的运行时间约为 1.5us,这没关系,因为我们预计在这里会受到超延迟的限制。对于 N = 1024 * 1024 * 1024, 我们的 屋顶线 约为 3.84ms,我们看到的是 4.1ms,这很好!

Networking网络

Networking is one of the areas where GPUs and TPUs differ the most. As we’ve seen, TPUs are connected in 2D or 3D tori, where each TPU is only connected to its neighbors. This means sending a message between two TPUs must pass through every intervening TPU, and forces us to use only uniform communication patterns over the mesh. While inconvenient in some respects, this also means the number of links per TPU is constant and we can scale to arbitrarily large TPU “pods” without loss of bandwidth.

网络是 GPU 和 TPU 差异最大的领域之一。正如我们所见,TPU 以 2D 或 3D 环面连接,每个 TPU 只连接到其邻居。这意味着在两个 TPU 之间发送消息必须经过所有中间的 TPU,并迫使我们只能在网格上使用统一的通信模式。虽然在某些方面不方便,但这也意味着每个 TPU 的链接数量是恒定的,我们可以扩展到任意大的 TPU “pod” 而不损失带宽。

GPUs on the other hand use a more traditional hierarchical tree-based switching network. Sets of 8 GPUs called nodes (up to 72 for GB20014) are connected within 1 hop of each other using high-bandwidth interconnects called NVLinks, and these nodes are connected into larger units (called SUs or Scalable Units) with a lower bandwidth InfiniBand (IB) or Ethernet network using NICs attached to each GPU. These in turn can be connected into arbitrarily large units with higher level switches.

另一方面,GPU 使用更传统的分层树状交换网络。称为节点的 8 个 GPU 集合 (GB200 最多 72 个14) 使用称为 NVLink 的高带宽互连在 1 跳内连接,这些节点使用连接到每个 GPU 的 NIC,通过带宽较低的 InfiniBand (IB) 或以太网网络连接成更大的单元 (称为 SU 或可扩展单元)。这些单元又可以通过更高级别的交换机连接成任意大的单元。

superpod diagram

Figure: a diagram showing a typical H100 network. A set of 8 GPUs is connected into a node or NVLink domain with NVSwitches (also called NVLink switches), and these nodes are connected to each other with a switched InfiniBand fabric. H100s have about 450GB/s of egress bandwidth each in the NVLink domain, and each node has 400GB/s of egress bandwidth into the IB network.

图: 展示典型 H100 网络的示意图。一组 8 个 GPU 通过 NVSwitches (也称为 NVLink 交换机) 连接成一个节点或 NVLink 域,这些节点通过交换式 InfiniBand 结构相互连接。H100 在 NVLink 域中每个大约有 450GB/s 的出口带宽,每个节点有 400GB/s 的出口带宽进入 IB 网络。

At the node level节点层面

A GPU node is a small unit, typically of 8 GPUs (up to 72 for GB200), connected with all-to-all, full-bandwidth, low latency NVLink interconnects.15 Each node contains several high-bandwidth NVSwitches which switch packets between all the local GPUs. The actual node-level topology has changed quite a bit over time, including the number of switches per node, but for H100, we have 4 NVSwitches per node with GPUs connected to them in a 5 + 4 + 4 + 5 link pattern, as shown:

GPU 节点是一个小单元,通常由 8 个 GPU (GB200 最多 72 个) 组成,通过全对全,全带宽,低延迟的 NVLink 互连连接。15 每个节点包含几个高带宽的 NVSwitches,用于在所有本地 GPU 之间交换数据包。实际的节点级拓扑随时间变化很大,包括每个节点的交换机数量,但对于 H100,我们每个节点有 4 个 NVSwitches,GPU 以 5 + 4 + 4 + 5 的链接模式连接到它们,如下图所示:

nvlink nodes

Figure: node aka NVLink domain diagrams from Pascal (P100) onward. Since Volta (V100), we have had all-to-all connectivity within a node using a set of switches. The H100 node has 4 NVSwitches connected to all 8 GPUs with 25GB/s links.

图: 从 Pascal (P100) 开始的节点 (即 NVLink 域) 示意图。自 Volta (V100) 以来,我们通过一组交换机在节点内实现了全对全连接。H100 节点有 4 个 NVSwitches,通过 25GB/s 的链接连接到所有 8 个 GPU。

For the Hopper generation (NVLink 4.0), each NVLink link has 25GB/s of full-duplex16 bandwidth (50GB/s for B200), giving us 18 * 25=450GB/s of full-duplex bandwidth from each GPU into the network. The massive NVSwitches have up to 64 NVLink ports, meaning an 8xH100 node with 4 switches can handle up to 64 * 25e9 * 4=6.4TB/s of bandwidth. Here’s an overview of how these numbers have changed with GPU generation:

对于 Hopper 这一代 (NVLink 4.0),每个 NVLink 链接具有 25GB/s 的全双工16 带宽 (B200 为 50GB/s),这使得每个 GPU 进入网络的带宽为 18 * 25=450GB/s 全双工。庞大的 NVSwitches 最多有 64 个 NVLink 端口,这意味着一个拥有 4 个交换机的 8xH100 节点可以处理高达 64 * 25e9 * 4=6.4TB/s 的带宽。以下是这些数字随 GPU 世代变化的概览:

NVLink GenNVSwitch GenGPU Generation
GPU 世代
NVLink Bandwidth (GB/s, full-duplex)
NVLink 带宽 (GB/s, 全双工)
NVLink Ports / GPU
NVLink 端口 / GPU
Node GPU to GPU bandwidth (GB/s full-duplex)
节点 GPU 间带宽 (GB/s 全双工)
Node size (NVLink domain)
节点大小 (NVLink 域)
NVSwitches per node
NVSwitches / 节点
3.02.0Ampere251230086
4.03.0Hopper251845084
5.04.0Blackwell50189008/722/18

Blackwell (B200) has nodes of 8 GPUs. GB200NVL72 support larger NVLink domains of 72 GPUs. We show details for both the 8 and 72 GPUs systems.

Blackwell (B200) 的节点有 8 个 GPU。GB200NVL72 支持更大的 72 个 GPU 的 NVLink 域。我们展示了 8 GPU 和 72 GPU 系统的详细信息。

Quiz 2: GPU nodes测验 2:GPU 节点

Here are some more Q/A problems on networking. I find these particularly useful to do out, since they make you work through the actual communication patterns.

这里有更多关于网络的问题/解答。我发现做这些特别有用,因为它们让你实际思考通信模式。

Question 1 [Total bandwidth for H100 node]: How much total bandwidth do we have per node in an 8xH100 node with 4 switches? Hint: consider both the NVLink and NVSwitch bandwidth.

问题 1 [H100 节点的总带宽]: 在一个拥有 4 个交换机的 8xH100 节点中,我们每个节点有多少总带宽?提示:同时考虑 NVLink 和 NVSwitch 的带宽。

Click here for the answer. 点击这里查看答案

Answer: We have Gen4 4xNVSwitches, each with 64 * 25e9=1.6TB/s of unidirectional bandwidth. That would give us 4 * 1.6e12=6.4e12 bandwidth at the switch level. However, note that each GPU can only handle 450GB/s of unidirectional bandwidth, so that means we have at most 450e9 * 8 = 3.6TB/s bandwidth. Since this is smaller, the peak bandwidth is 3.6TB/s.

答案: 我们有 Gen4 4xNVSwitches,每个都有 64 * 25e9=1.6TB/s 的单向带宽。这将给我们 4 * 1.6e12=6.4e12 的交换机级别带宽。然而,请注意,每个 GPU 只能处理 450GB/s 的单向带宽,所以这意味着我们最多有 450e9 * 8 = 3.6TB/s 的带宽。由于这个数字更小,峰值带宽是 3.6TB/s。

Question 2 [Bisection bandwidth]: Bisection bandwidth is defined as the smallest bandwidth available between any even partition of a network. In other words, if we split a network into two equal halves, how much bandwidth crosses between the two halves? Can you calculate the bisection bandwidth of an 8x H100 node? Hint: bisection bandwidth typically includes flow in both directions.

问题 2 [对分带宽]:对分带宽定义为网络任意均分后可用的最小带宽。换句话说,如果将网络分成相等的两半,两半之间有多少带宽?你能计算一个 8x H100 节点的对分带宽吗?提示:对分带宽通常包括双向流量。

Click here for the answer. 点击这里查看答案

Answer: Any even partition will have 4 GPUs in each half, each of which can egress 4 * 450GB/s to the other half. Taking flow in both directions, this gives us 8 * 450GB/s of bytes cross the partition, or 3.6TB/s of bisection bandwidth. This is what NVIDIA reports e.g. here.

答案: 任何偶数分区都会在每一半有 4 个 GPU,每个 GPU 可以向另一半输出 4 * 450GB/s. 考虑到双向流量,这使得 8 * 450GB/s 的字节穿过分区,即 3.6TB/s 的对分带宽。这也是 NVIDIA 在例如这里报告的。

Question 3 [AllGather cost]: Given an array of B bytes, how long would a (throughput-bound) AllGather take on an 8xH100 node? Do the math for bf16[DX, F] where D=4096, F=65,536. It’s worth reading the TPU collectives section before answering this. Think this through here but we’ll talk much more about collectives next.

问题 3 [AllGather 成本]:给定一个 B 字节的数组,一个 (吞吐量受限的) AllGather 在一个 8xH100 节点上需要多长时间?对 bf16[DX, F] 进行计算,其中 D=4096, F=65,536. 在回答这个问题之前,值得阅读 TPU 集合通信的部分。在这里思考一下,但我们接下来会更详细地讨论集合通信。

Click here for the answer. 点击这里查看答案

Answer: Each GPU can egress 450GB/s, and each GPU has B/NB / N bytes (where N=8, the node size). We can imagine each node sending its bytes to each of the other N−1N - 1 nodes one after the other, leading to a total of (N - 1) turns each with Tcomms=(B/(N∗Wunidirectional))T_\text{comms} = (B / (N * W_\text{unidirectional})), or Tcomms=(N−1)∗B/(N∗Wunidirectional)T_\text{comms} = (N - 1) * B / (N * W_\text{unidirectional}). This is approximately B/WuniB / W_\text{uni} or B/450e9B / \text{450e9}.

**答案:**每个 GPU 的出口带宽为 450 GB/s,并持有 B/NB / N 字节,其中 N=8 是节点内的 GPU 数量。设想每个 GPU 依次向其余 N−1N - 1 个 GPU 发送自己的数据,共发送 N − 1 轮。每轮耗时 Tcomms=(B/(N∗Wunidirectional))T_\text{comms} = (B / (N * W_\text{unidirectional})),总耗时为 Tcomms=(N−1)∗B/(N∗Wunidirectional)T_\text{comms} = (N - 1) * B / (N * W_\text{unidirectional}),约等于 B/WuniB / W_\text{uni},即 B/450e9B / \text{450e9}。

For the given array, we have B = 4096 * 65536 * 2 = 536e6 bytes, so the total time is 536e6 * (8 - 1) / (8 * 450e9) = 1.04ms (or 536e6 / 450e9 = 1.19ms with the approximation). This could be latency-bound, so it may take longer than this in practice (in practice it takes about 1.5ms).

题目中的数组大小为 B = 4096 * 65536 * 2 = 536e6 字节,总耗时为 536e6 * (8 - 1) / (8 * 450e9) = 1.04ms(按近似公式为 536e6 / 450e9 = 1.19ms)。这个操作可能受延迟限制,实际耗时会更长,约为 1.5 毫秒。

Beyond the node level节点之外

Beyond the node level, the topology of a GPU network is less standardized. NVIDIA publishes a reference DGX SuperPod architecture that connects a larger set of GPUs than a single node using InfiniBand, but customers and datacenter providers are free to customize this to their needs.17

在节点级别之上,GPU 网络的拓扑结构不那么标准化。NVIDIA 发布了一个参考 DGX SuperPod 架构,该架构使用 InfiniBand 连接比单个节点更多的 GPU,但客户和数据中心提供商可以根据自己的需求进行定制。17

Here is a diagram for a reference 1024 GPU H100 system, where each box in the bottom row is a single 8xH100 node with 8 GPUs, 8 400Gbps CX7 NICs (one per GPU), and 4 NVSwitches.

这是一个参考的 1024 GPU H100 系统的示意图,其中底行的每个框都是一个包含 8 个 H100 GPU,8 个 400Gbps CX7 NIC (每个 GPU 一个) 和 4 个 NVSwitches 的单个 8xH100 节点。

h100 superpod

Figure: diagram of the reference 1024 H100 DGX SuperPod with 128 nodes (sometimes 127), each with 8 H100 GPUs, connected to an InfiniBand scale-out network. Sets of 32 nodes (256 GPUs) are called ‘Scalable Units’ or SUs. The leaf and spine IB switches provide enough bandwidth for full bisection bandwidth between nodes.

图: 1024 H100 DGX SuperPod 参考架构图,包含 128 个节点 (有时是 127 个),每个节点有 8 个 H100 GPU,连接到一个 InfiniBand 横向扩展网络。32 个节点 (256 个 GPU) 的集合称为 ‘可扩展单元’ 或 SU。叶交换机和主干 IB 交换机提供了足够的带宽,以实现节点间的完全对分带宽。

Scalable Units: Each set of 32 nodes is called a “Scalable Unit” (or SU), under a single set of 8 leaf InfiniBand switches. This SU has 256 GPUs with 4 NVSwitches per node and 8 Infiniband leaf switches. All the cabling shown is InfiniBand NDR (50GB/s full-duplex) with 64-port NDR IB switches (also 50GB/s per port). Note that the IB switches have 2x the bandwidth of the NVSwitches (64 ports with 400 Gbps links).

可扩展单元: 每 32 个节点组成一个“可扩展单元”(或 SU),隶属于一组 8 个叶 InfiniBand 交换机。这个 SU 有 256 个 GPU,每个节点有 4 个 NVSwitches,还有 8 个 Infiniband 叶交换机。图中显示的所有布线都是 InfiniBand NDR (50GB/s 全双工),配备 64 端口 NDR IB 交换机 (每个端口也是 50GB/s)。请注意,IB 交换机的带宽是 NVSwitches 的 2 倍 (64 个端口,400 Gbps 链接)。

SuperPod: The overall SuperPod then connects 4 of these SUs with 16 top level “spine” IB switches, giving us 1024 GPUs with 512 node-level NVSwitches, 32 leaf IB switches, and 16 spine IB switches, for a total of 512 + 32 + 16 = 560 switches. Leaf switches are connected to nodes in sets of 32 nodes, so each set of 256 GPUs has 8 leaf switches. All leaf switches are connected to all spine switches.

SuperPod: 整个 SuperPod 随后用 16 个顶层“主干”IB 交换机连接 4 个这样的 SU,得到 1024 个 GPU,512 个节点级 NVSwitches,32 个叶 IB 交换机和 16 个主干 IB 交换机,总共有 512 + 32 + 16 = 560 个交换机。叶交换机以 32 个节点为一组连接到节点,所以每组 256 个 GPU 有 8 个叶交换机。所有叶交换机都连接到所有主干交换机。

How much bandwidth do we have? The overall topology of the InfiniBand network (called the “scale out network”) is that of a fat tree, with the cables and switches guaranteeing full bisection bandwidth above the node level (here, 400GB/s). That means if we split the nodes in half, each node can egress 400GB/s to a node in the other partition at the same time. More to the point, this means we should have a roughly constant AllReduce bandwidth in the scale out network! While it may not be implemented this way, you can imagine doing a ring reduction over arbitrarily many nodes in the scale-out network, since you can construct a ring including every one.

我们有多少带宽? InfiniBand 网络 (称为“横向扩展网络”) 的整体拓扑结构是一个胖树,其电缆和交换机保证了节点级别以上的完全对分带宽 (这里是 400GB/s)。这意味着如果我们将节点分成两半,每个节点可以同时向另一分区的节点输出 400GB/s。更重要的是,这意味着我们在横向扩展网络中应该有大致恒定的 AllReduce 带宽!虽然可能不是这样实现的,但你可以想象在横向扩展网络中的任意多个节点上进行环形归约,因为你可以构建一个包含每个节点的环。

Level
级别
GPUsSwitches per Unit
每单元交换机数
Switch Type
交换机类型
Bandwidth per Unit (TB/s, full-duplex)
每单元带宽 (TB/s, 全双工)
GPU-to-GPU Bandwidth (GB/s, full-duplex)
GPU 间带宽 (GB/s, 全双工)
Fat Tree Bandwidth (GB/s, full-duplex)
胖树带宽 (GB/s, 全双工)
Node
节点
84NVL3.6450450
Leaf
叶
2568IB12.850400
Spine
主干
102416IB51.250400

By comparison, a TPU v5p has about 90GB/s egress bandwidth per link, or 540GB/s egress along all axes of the 3D torus. This is not point-to-point so it can only be used for restricted, uniform communication patterns, but it still gives us a much higher TPU to TPU bandwidth that can scale to arbitrarily large topologies (at least up to 8960 TPUs).

相比之下,一个 TPU v5p 每个链接大约有 90GB/s 的出口带宽,或者在 3D 环面的所有轴上总共有 540GB/s 的出口带宽。这不是点对点的,所以它只能用于受限的,统一的通信模式,但它仍然给了我们更高的 TPU 间带宽,可以扩展到任意大的拓扑 (至少高达 8960 个 TPU)。

The GPU switching fabric can in theory be extended to arbitrary sizes by adding additional switches or layers of indirection, at the cost of additional latency and costly network switches.

GPU 交换结构理论上可以通过增加额外的交换机或间接层来扩展到任意大小,但代价是增加延迟和昂贵的网络交换机。

GB200 NVL72s: NVIDIA has recently begun producing new GB200 NVL72 GPU clusters that combine 72 GPUs in a single NVLink domain with full 900GB/s of GPU to GPU bandwidth. These domains can then be linked into larger SuperPods with proportionally higher (9x) IB fat tree bandwidth. Here is a diagram of that topology:

GB200 NVL72s: NVIDIA 最近开始生产新的 GB200 NVL72 GPU 集群,将 72 个 GPU 组合在一个 NVLink 域中,具有完整的 900GB/s 的 GPU 间带宽。这些域可以连接成更大的 SuperPod,具有成比例更高 (9x) 的 IB 胖树带宽。以下是该拓扑的示意图:

gb200 superpod

Figure: a diagram showing a GB200 DGX SuperPod of 576 GPUs. Each rack at the bottom layer contains 72 GB200 GPUs.

图: 展示一个包含 576 个 GPU 的 GB200 DGX SuperPod 的示意图。底层的每个机架包含 72 个 GB200 GPU。

Counting the egress bandwidth from a single node (the orange lines above), we have 4 * 18 * 400 / 8 = 3.6TB/s of bandwidth to the leaf level, which is 9x more than an H100 (just as the node contains 9x more GPUs). That means the critical node egress bandwidth is much, much higher and our cross-node collective bandwidth can actually be lower than within the node. See Appendix A for more discussion.

计算单个节点的出口带宽 (上图中的橙色线),我们有 4 * 18 * 400 / 8 = 3.6TB/s 的带宽到叶级别,这比 H100 多 9 倍 (正如节点包含 9 倍多的 GPU)。这意味着关键的节点出口带宽要高得多,我们的跨节点集合带宽实际上可能低于节点内的带宽。 更多讨论请参见附录 A。

Node Type
节点类型
GPUs per node
每节点 GPU 数
GPU egress bandwidth
GPU 出口带宽
Node egress bandwidth
节点出口带宽
H1008450e9400e9
B2008900e9400e9
GB200 NVL7272900e93600e9

Quiz 3: Beyond the node level测验 3:节点之外

Question 1 [Fat tree topology]: Using the DGX H100 diagram above, calculate the bisection bandwidth of the entire 1024 GPU pod at the node level. Show that the bandwidth of each link is chosen to ensure full bisection bandwidth. Hint: make sure to calculate both the link bandwidth and switch bandwidth.

问题 1 [胖树拓扑]: 使用上面的 DGX H100 图,计算整个 1024 GPU pod 在节点级别的对分带宽。证明每个链接的带宽选择是为了确保完全的对分带宽。提示:确保计算链接带宽和交换机带宽。

Click here for the answer. 点击这里查看答案

Answer: Let’s do it component by component:

答案: 让我们逐个组件来分析:

  • First, each node has 8x400Gbps NDR IB cables connecting it to the leaf switches, giving each node 8 * 400 / 8 = 400 GB/s of bandwidth to the leaf. We have 8 leaf switches with 3.2TB/s each (64 400 GBps links), but we can only use 32 of the 64 ports to ingress from the SU, so that’s 32 * 400 / 8 = 12.8TB/s for 32 nodes, again exactly 400GB/s.
  • Then at the spine level we have 8 * 16 * 2 400Gbps NDR IB cables connecting each SU to the spine, giving each SU 8 * 16 * 2 * 400 / 8 = 12.8 TB/s of bandwidth to the leaf. Again, this is 400GB/s per node. We have 16 spine switches, each with 3.2TB/s, giving us 16 * 3.2 = 51.2 TB/s, which with 128 nodes is again 400GB/s.
  • 首先,每个节点有 8x400Gbps NDR IB 电缆连接到叶交换机,使得每个节点有 8 * 400 / 8 = 400 GB/s 的带宽到叶。我们有 8 个叶交换机,每个 3.2TB/s (64 个 400 GBps 链接),但我们只能使用 64 个端口中的 32 个从 SU 入口,所以是 32 * 400 / 8 = 12.8TB/s 用于 32 个节点,同样是每个节点 400GB/s。
  • 然后在主干级别,我们有 8 * 16 * 2 400Gbps NDR IB 电缆连接每个 SU 到主干,使得每个 SU 有 8 * 16 * 2 * 400 / 8 = 12.8 TB/s 的带宽到叶。同样,这是每个节点 400GB/s。我们有 16 个主干交换机,每个 3.2TB/s,得到 16 * 3.2 = 51.2 TB/s, 对于 128 个节点,同样是 400GB/s。

Thus if we bisect our nodes in any way, we will have 400GB/s per node between them. Every component has exactly the requisite bandwidth to ensure the fat tree.

因此,如果我们以任何方式对分我们的节点,我们将在它们之间有每个 GPU 400GB/s 的带宽。每个组件都恰好具有确保胖树所需的带宽。

Question 2 [Scaling to a larger DGX pod]: Say we wanted to train on 2048 GPUs instead of 1024. What would be the simplest/best way to modify the above DGX topology to handle this? What about 4096? Hint: there’s no single correct answer, but try to keep costs down. Keep link capacity in mind. This documentation may be helpful.

问题 2 [扩展到更大的 DGX pod]: 假设我们想在 2048 个 GPU 而不是 1024 个上进行训练。修改上述 DGX 拓扑以处理此问题的最简单/最佳方法是什么?4096 呢?提示:没有唯一的正确答案,但尽量降低成本。记住链接容量。这份 文档可能会有帮助。

Click here for the answer. 点击这里查看答案

Answer: One option would be to keep the SU structure intact (32 nodes under 8 switches) and just add more of them with more top-level switches. We’d need 2x more spine switches, so we’d have 8 SUs with 32 spine switches giving us enough bandwidth.

答案: 一种选择是保持 SU 结构不变 (32 个节点在 8 个交换机下),只需增加更多的 SU 和更多的顶层交换机。我们需要 2 倍的主干交换机,所以我们将有 8 个 SU 和 32 个主干交换机,这将给我们足够的带宽。

One issue with this is that we only have 64 ports per leaf switch, and we’re already using all of them in the above diagram. But instead it’s easy to do 1x 400 Gbps NDR cable per spine instead of 2x, which gives the same total bandwidth but saves us some ports.

这样做的一个问题是,每个叶交换机只有 64 个端口,而我们在上图中已经全部使用了。但相反,很容易做到每个主干使用 1x 400 Gbps NDR 电缆而不是 2x,这提供了相同的总带宽但为我们节省了一些端口。

For 4096 GPUs, we actually run out of ports, so we need to add another level of indirection, that is to say, another level in the hierarchy. NVIDIA calls these “core switches”, and builds a 4096 GPU cluster with 128 spine switches and 64 core switches. You can do the math to show that this gives enough bandwidth.

对于 4096 个 GPU,我们实际上用完了端口,所以我们需要增加另一层间接,也就是说,在层次结构中增加另一层。NVIDIA 称这些为“核心交换机”, 并用 128 个主干交换机和 64 个核心交换机构建了一个 4096 GPU 集群。你可以计算一下来证明这提供了足够的带宽。

How Do Collectives Work on GPUs?集合通信在 GPU 上如何工作?

GPUs can perform all the same collectives as TPUs: ReduceScatters, AllGathers, AllReduces, and AllToAlls. Unlike TPUs, the way these work changes depending on whether they’re performed at the node level (over NVLink) or above (over InfiniBand). These collectives are implemented by NVIDIA in the NVSHMEM and NCCL (pronounced “nickel”) libraries. NCCL is open-sourced here. While NCCL uses a variety of implementations depending on latency requirements/topology (details), from here on, we’ll discuss a theoretically optimal model over a switched tree fabric.

GPU 可以执行与 TPU 相同的所有集合通信:ReduceScatters,AllGathers,AllReduces,和 AllToAlls。与 TPU 不同,这些操作的工作方式取决于它们是在节点级别 (通过 NVLink) 还是在更高级别 (通过 InfiniBand) 执行。这些集合通信由 NVIDIA 在 NVSHMEM 和 NCCL (发音为“nickel”) 库中实现。NCCL 在这里开源。虽然 NCCL 根据延迟要求/拓扑使用多种实现 (细节),但从现在开始,我们将讨论一个在交换树状结构上的理论最优模型。

Intra-node collectives节点内集合通信

AllGather or ReduceScatter: For an AllGather or ReduceScatter at the node level, you can perform them around a ring just like a TPU, using the full GPU-to-GPU bandwidth at each hop. Order the GPUs arbitrarily and send a portion of the array around the ring using the full GPU-to-GPU bandwidth.18 The cost of each hop is Thop=bytes/(N∗GPU egress bandwidth)T_\text{hop} = \text{bytes} / (N * \text{GPU egress bandwidth}), so the overall cost is

AllGather 或 ReduceScatter: 对于节点级别的 AllGather 或 ReduceScatter,你可以像 TPU 一样围绕一个环执行它们,在每一跳都使用完整的 GPU 间带宽。任意排序 GPU,并使用完整的 GPU 间带宽将数组的一部分沿环发送。18 每一跳的成本是 Thop=bytes/(N∗GPU egress bandwidth)T_\text{hop} = \text{bytes} / (N * \text{GPU egress bandwidth}), 所以总成本是

TAG or RS comms=bytes⋅(N−1)N⋅GPU egress bandwidth→bytesGPU egress bandwidthT_\text{AG or RS comms} = \frac{\text{bytes} \cdot (N - 1)}{N \cdot \text{GPU egress bandwidth}} \rightarrow \frac{\text{bytes}}{\text{GPU egress bandwidth}}

You’ll note this is exactly the same as on a TPU. For an AllReduce, you can combine an RS + AG as usual for twice the cost.

你会注意到这和 TPU 上完全一样。对于 AllReduce,你可以像往常一样组合一个 RS + AG,成本是两倍。

all gather

Figure: bandwidth-optimal 1D ring AllGather algorithm. For B bytes, this sends B / X bytes over the top-level switches X - 1 times.

图: 带宽最优的一维环形 AllGather 算法。对于 B 字节,在顶层交换机上传输 B / X 字节,重复 X - 1 次。

If you’re concerned about latency (e.g. if your array is very small), you can do a tree reduction, where you AllReduce within pairs of 2, then 4, then 8 for a total of log⁡(N)\log(N) hops instead of N−1N - 1, although the total cost is still the same.

如果你关心延迟 (例如,如果你的数组非常小),你可以进行树状归约,即先在 2 个一组内 AllReduce,然后是 4 个,然后是 8 个,总共有 log⁡(N)\log(N) 跳而不是 N−1N - 1 跳,尽管总成本仍然相同。

Pop Quiz 1 [AllGather time]: Using an 8xH100 node with 450 GB/s full-duplex bandwidth, how long does AllGather(bf16[BX, F]) take? Let B=1024B=1024, F=16,384F=16,384.

小测验 1 [AllGather 时间]: 使用一个具有 450 GB/s 全双工带宽的 8xH100 节点,AllGather(bf16[BX, F]) 需要多长时间?设 B=1024B=1024, F=16,384F=16,384.

Click here for the answer. 点击这里查看答案

Answer: We have a total of 2⋅B⋅F2 \cdot B \cdot F bytes, with 450e9 unidirectional bandwidth. This would take roughly Tcomms=(2⋅B⋅F)/450e9T_\text{comms} = (2 \cdot B \cdot F) / \text{450e9}, or more precisely (2⋅B⋅F⋅(8−1))/(8⋅450e9)(2 \cdot B \cdot F \cdot (8 - 1)) / (8 \cdot \text{450e9}). Using the provided values, this gives us roughly (2⋅1024⋅16384)/450e9=75us(2 \cdot 1024 \cdot 16384) / \text{450e9} = \text{75us}, or more precisely, 65us\text{65us}.

答案: 我们总共有 2⋅B⋅F2 \cdot B \cdot F 字节,单向带宽为 450e9。这大约需要 Tcomms=(2⋅B⋅F)/450e9T_\text{comms} = (2 \cdot B \cdot F) / \text{450e9}, 或者更精确地,(2⋅B⋅F⋅(8−1))/(8⋅450e9)(2 \cdot B \cdot F \cdot (8 - 1)) / (8 \cdot \text{450e9}). 使用提供的值,这大约得到 (2⋅1024⋅16384)/450e9=75us(2 \cdot 1024 \cdot 16384) / \text{450e9} = \text{75us}, 或者更精确地,65us\text{65us}.

AllToAlls: GPUs within a node have all-to-all connectivity, which makes AllToAlls, well, quite easy. Each GPU just sends directly to the destination node. Within a node, for B bytes, each GPU has B/NB / N bytes and sends (B/N2)(B / N^2) bytes to N−1N - 1 target nodes for a total of

**AllToAll:**节点内各 GPU 可以直接互连,因此实现 AllToAll 很简单。每个 GPU 直接把数据发给目标 GPU。对于节点内总计 B 字节的数据,每个 GPU 持有 B/NB / N 字节,分别向 (B/N2)(B / N^2) 个目标发送 N−1N - 1 字节,因此总耗时为

TAllToAll comms=B⋅(N−1)W⋅N2≈BW⋅NT_\text{AllToAll comms} = \frac{B \cdot (N - 1)}{W \cdot N^2} \approx \frac{B}{W \cdot N}

Compare this to a TPU, where the cost is B/(4W)B / (4W). Thus, within a single node, we get a 2X theoretical speedup in runtime (B/4WB / 4W vs. B/8WB / 8W).

与 TPU 相比,其成本为 B/(4W)B / (4W). 因此,在单个节点内,我们的运行时间理论上可以提速 2 倍 (B/4WB / 4W vs。B/8WB / 8W)。

For Mixture of Expert (MoE) models, we frequently want to do a sparse or ragged AllToAll, where we guarantee at most kk of NN shards on the output dimension are non-zero, that is to say TAllToAll→K[B,N]T_\text{AllToAll} \rightarrow K[B, N] where at most kk of NN entries on each axis are non-zero. The cost of this is reduced by k/Nk/N, for a total of about min⁡(k/N,1)⋅B/(W⋅N)\min(k/N, 1) \cdot B / (W \cdot N). For an MoE, we often pick the non-zero values independently at random, so there’s some chance of having fewer than kk non-zero, giving us approximately (N−1)/N⋅min⁡(k/N,1)⋅B/(W⋅N)(N-1)/N \cdot \min(k/N, 1) \cdot B / (W \cdot N).19

在混合专家(MoE)模型中,经常需要稀疏或不规则的 AllToAll。我们保证输出维上 NN 个分片中最多有 kk 个非零,即 TAllToAll→K[B,N]T_\text{AllToAll} \rightarrow K[B, N],每个轴上的 NN 个条目中最多有 kk 个非零。通信成本因此缩减为原来的 k/Nk/N,约为 min⁡(k/N,1)⋅B/(W⋅N)\min(k/N, 1) \cdot B / (W \cdot N)。MoE 常独立随机选择非零值的位置,因此实际可能不到 kk 个非零,成本约为 (N−1)/N⋅min⁡(k/N,1)⋅B/(W⋅N)(N-1)/N \cdot \min(k/N, 1) \cdot B / (W \cdot N)。19

Pop Quiz 2 [AllToAll time]: Using an 8xH100 node with 450 GB/s unidirectional bandwidth, how long does AllToAllX->N(bf16[BX, N]) take? What if we know only 4 of 8 entries will be non-zero?

小测验 2 [AllToAll 时间]: 使用一个具有 450 GB/s 单向带宽的 8xH100 节点,AllToAllX->N(bf16[BX, N]) 需要多长时间?如果我们知道 8 个条目中只有 4 个是非零的呢?

Click here for the answer. 点击这里查看答案

Answer: Note that here BB is the batch dimension of the array, so the total array size is V=2⋅B⋅NV = 2 \cdot B \cdot N bytes. From the above, we know that in the dense case, the cost is V⋅(N−1)/(W⋅N2)V \cdot (N-1) / (W \cdot N^2), or roughly V/(W⋅N)V / (W \cdot N). If we know only 12\frac{1}{2} the entries will be non-padding, we can send V⋅k/N/(W⋅N)=V/(2⋅W⋅N)V \cdot k/N / (W \cdot N) = V / (2 \cdot W \cdot N), roughly half the overall cost.

**答案:**这里 BB 是数组的批次维度,因此整个数组占 V=2⋅B⋅NV = 2 \cdot B \cdot N 字节。在稠密情况下,由上文可知成本是 V⋅(N−1)/(W⋅N2)V \cdot (N-1) / (W \cdot N^2),约为 V/(W⋅N)V / (W \cdot N)。如果已知仅有 12\frac{1}{2} 的条目是有效数据,发送成本约为 V⋅k/N/(W⋅N)=V/(2⋅W⋅N)V \cdot k/N / (W \cdot N) = V / (2 \cdot W \cdot N),即总成本约减半。

Empirical measurements: here is an empirical measurement of AllReduce bandwidth over an 8xH100 node. The Algo BW is the measured bandwidth (bytes / runtime) and the Bus BW is calculated as 2⋅W⋅(8−1)/82 \cdot W \cdot (8 - 1) / 8, theoretically a measure of the actual link bandwidth. You’ll notice that we do achieve close to 370GB/s, less than 450GB/s but reasonably close, although only around 10GB/device. This means although these estimates are theoretically correct, it takes a large message to realize it.

实证测量: 这是在一个 8xH100 节点上 AllReduce 带宽的实证测量。Algo BW 是测量的带宽 (字节 / 运行时间),Bus BW 计算为 2⋅W⋅(8−1)/82 \cdot W \cdot (8 - 1) / 8, 理论上是实际链路带宽的度量。你会注意到我们确实达到了接近 370GB/s,低于 450GB/s 但相当接近,尽管每个设备只有大约 10GB。这意味着虽然这些估计在理论上是正确的,但需要一个大的消息才能实现它。

gpu all reduce bw

Figure: AllReduce throughput for an 8xH100 node with SHARP disabled. The blue curve is the empirical link bandwidth, calculated as 2∗bytes∗(N−1)/(N∗runtime)2 * \text{bytes} * (N - 1) / (N * \text{runtime}) from the empirical measurements. Note that we do not get particularly close to the claimed bandwidth of 450GB/s, even with massive 10GB arrays.

图: 禁用 SHARP 的 8xH100 节点的 AllReduce 吞吐量。蓝色曲线是根据实证测量计算出的经验链路带宽,计算公式为 2∗bytes∗(N−1)/(N∗runtime)2 * \text{bytes} * (N - 1) / (N * \text{runtime}). 注意,即使使用巨大的 10GB 数组,我们也没有特别接近声称的 450GB/s 带宽。

This is a real problem, since it meaningfully complicates any theoretical claims we can make, since e.g. even an AllReduce over a reasonable sized array, like LLaMA-3 70B’s MLPs (of size bf16[8192, 28672], or with 8-way model sharding, bf16[8192, 3584] = 58MB) can achieve only around 150GB/s compared to the peak 450GB/s. By comparison, TPUs achieve peak bandwidth at much lower message sizes (see Appendix B).

这是一个实际问题,因为它有意义地复杂化了我们可以做出的任何理论声明,因为例如,即使是在一个合理大小的数组上进行 AllReduce,比如 LLaMA-3 70B 的 MLP (大小为 bf16[8192, 28672], 或者 8 路模型分片后为 bf16[8192, 3584] = 58MB),也只能达到大约 150GB/s,而峰值是 450GB/s。相比之下,TPU 在小得多的消息大小下就能达到峰值带宽 (见附录 B)。

In network reductions: Since the Hopper generation, NVIDIA switches have supported “SHARP” (Scalable Hierarchical Aggregation and Reduction Protocol) which allows for “in-network reductions”. This means the network switches themselves can do reduction operations and multiplex or “MultiCast” the result to multiple target GPUs:

网络内归约: 自 Hopper 这一代以来,NVIDIA 交换机支持 “SHARP” (可扩展分层聚合和归约协议),允许“网络内归约”. 这意味着网络交换机本身可以执行归约操作,并将结果多路复用或“多播”到多个目标 GPU:

sharp algorithm

Figure: an AllReduce without SHARP has 2x the theoretical cost because it has to pass through each GPU twice. In practice, speedups are only about 30% (from NCCL 2.27.5).

图: 没有 SHARP 的 AllReduce 理论成本是 2 倍,因为它必须两次通过每个 GPU。实际上,速度提升只有大约 30% (来自 NCCL 2.27.5)。

Theoretically, this close to halves the cost of an AllReduce, since it means each GPU can send its data to a top-level switch which itself performs the reduction and broadcasts the result to each GPU without having to egress each GPU twice, while also reducing network latency.

理论上,这将 AllReduce 的成本减少了近一半,因为这意味着每个 GPU 可以将其数据发送到一个顶层交换机,该交换机本身执行归约并将结果广播到每个 GPU,而不必两次从每个 GPU 出口,同时也减少了网络延迟。

TSHARP AR comms=bytesGPU egress bandwidthT_\text{SHARP AR comms} = \frac{\text{bytes}}{\text{GPU egress bandwidth}}

Note that this is exact and not off by a factor of 1/N1/N, since each GPU egresses B⋅(N−1)/NB \cdot (N - 1) / N first, then receives the partially reduced version of its local shard (ingress of B/NB/N), finishes the reductions, then egresses B/NB/N again, then ingresses the fully reduced result (ingress of B⋅(N−1)/NB \cdot (N - 1) / N), resulting in exactly BB bytes ingressed.

请注意,这是精确的,而不是差一个 1/N1/N 的因子,因为每个 GPU 首先出口 B⋅(N−1)/NB \cdot (N - 1) / N, 然后接收其本地分片的局部归约版本 (入口 B/NB/N),完成归约,然后再次出口 B/NB/N, 然后入口完全归约的结果 (入口 B⋅(N−1)/NB \cdot (N - 1) / N),导致正好入口 BB 字节。

However, in practice we see about a 30% increase in bandwidth with SHARP enabled, compared to the predicted 75%. This gets us up merely to about 480GB/s effective collective bandwidth, not nearly 2x.

然而,在实践中,我们看到启用 SHARP 后带宽增加了约 30%, 而预测是 75%. 这仅仅使我们的有效集合带宽达到约 480GB/s,远非 2 倍。

sharp all reduce cost

Figure: empirical measurements of AllReduce algo bandwidth with and without NVIDIA SHARP enabled within a node. The gains amount to about 30% throughput improvement at peak, even though algorithmically it ought to be able to achieve closer to a 75% gain.

图: 在节点内启用和禁用 NVIDIA SHARP 的 AllReduce 算法带宽的实证测量。尽管算法上应该能实现接近 75% 的增益,但在峰值时,增益仅为约 30% 的吞吐量提升。

Cross-node collectives跨节点集合通信

When we go beyond the node-level, the cost is a bit more subtle. When doing a reduction over a tree, you can think of reducing from the bottom up, first within a node, then at the leaf level, and then at the spine level, using the normal algorithm at each level. For an AllReduce especially, you can see that this allows us to communicate less data overall, since after we AllReduce at the node level, we only have to egress BB bytes up to the leaf instead of B∗NB * N.

当我们超越节点级别时,成本就有点微妙了。当在树上进行归约时,你可以想象从下往上归约,首先在节点内,然后在叶级别,然后在主干级别,在每个级别都使用正常的算法。特别是对于 AllReduce,你可以看到这使我们能够总体上传输更少的数据,因为在节点级别进行 AllReduce 后,我们只需要向叶级别出口 BB 字节,而不是 B∗NB * N.

How costly is this? To a first approximation, because we have full bisection bandwidth, the cost of an AllGather or ReduceScatter is roughly the buffer size in bytes divided by the node egress bandwidth (400GB/s on H100) regardless of any of the details of the tree reduction.

这有多昂贵? 作为一阶近似,因为我们有完全的对分带宽,AllGather 或 ReduceScatter 的成本大约是缓冲区大小 (以字节为单位) 除以节点出口带宽 (H100 上为 400GB/s),而与树状归约的任何细节无关。

TAG or RS comms=bytesWnode egress=H100bytes400e9T_\text{AG or RS comms} = \frac{\text{bytes}}{W_\text{node egress}} \underset{H100}{=} \frac{\text{bytes}}{\text{400e9}}

where WnodeW_\text{node} egress is generally 400GB/s for the above H100 network (8x400Gbps IB links egressing each node). The cleanest way to picture this is to imagine doing a ring reduction over every node in the cluster. Because of the fat tree topology, we can always construct a ring with WnodeW_\text{node} egress between any two nodes and do a normal reduction. The node-level reduction will (almost) never be the bottleneck because it has a higher overall bandwidth and better latency, although in general the cost is

其中 WnodeW_\text{node} 出口通常是上述 H100 网络的 400GB/s (8x400Gbps IB 链路从每个节点出口)。想象这一点的最清晰方式是想象在集群中的每个节点上进行环形归约。由于胖树拓扑,我们总是可以在任意两个节点之间构建一个具有 WnodeW_\text{node} 出口的环,并进行正常的归约。节点级别的归约 (几乎) 永远不会成为瓶颈,因为它具有更高的总带宽和更好的延迟,尽管通常成本是

Ttotal=max⁡(Tcomms at node,Tcomms in scale-out network)=max⁡[bytesWGPU egress,bytesWnode egress]T_\text{total} = \max(T_\text{comms at node}, T_\text{comms in scale-out network}) = \max\left[\frac{\text{bytes}}{W_\text{GPU egress}}, \frac{\text{bytes}}{W_\text{node egress}}\right]
You can see a more precise derivation here. 查看更精确的推导

We can be more precise in noting that we are effectively doing a ring reduction at each layer in the network, which we can mostly overlap, so we have:

我们可以更精确地指出,我们实际上是在网络的每一层进行环形归约,我们可以大部分重叠它们,所以我们有:

TAG or RS comms=bytes⋅maxdepth i[Di−1Di⋅Wlink i]T_\text{AG or RS comms} = \text{bytes} \cdot max_\text{depth i}\left[\frac{D_i - 1}{D_i \cdot W_\text{link i}}\right]

where DiD_i is the degree at depth ii (the number of children at depth ii), Wlink iW_\text{link i} is the bandwidth of the link connecting each child to node ii.

其中 DiD_i 是深度 ii 的度 (深度 ii 的子节点数),Wlink iW_\text{link i} 是连接每个子节点到节点 ii 的链路带宽。

Using this, we can calculate the available AllGather/AllReduce bandwidth as mindepth i(Di∗Wlink i/(Di−1))min_\text{depth i}(D_i * W_\text{link i} / (D_i - 1)) for a given topology. In the case above, we have:

使用这个,我们可以计算可用的 AllGather/AllReduce 带宽为 mindepth i(Di∗Wlink i/(Di−1))min_\text{depth i}(D_i * W_\text{link i} / (D_i - 1)) 对于给定的拓扑。在上面的情况下,我们有:

  • Node: DnodeD_\text{node} = 8 since we have 8 GPUs in a node with Wlink i = 450GB/s. Thus we have an AG bandwidth of 450e9 * 8 / (8 - 1) = 514GB/s.
  • Leaf: DleafD_\text{leaf} = 32 since we have 32 nodes in an SU with Wlink i = 400GB/s (8x400Gbps IB links). Thus our bandwidth is 400e9 * 32 / (32 - 1) = 413GB/s.
  • Spine: DspineD_\text{spine} = 4 since we have 4 SUs with Wlink iW_\text{link i} = 12.8TB/s (from 8 * 16 * 2 * 400Gbps links above). Our bandwidth is 12.8e12 * 4 / (4 - 1) = 17.1TB/s.
  • 节点: DnodeD_\text{node} = 8,因为我们一个节点有 8 个 GPU,Wlink i = 450GB/s。因此我们的 AG 带宽是 450e9 * 8 / (8 - 1) = 514GB/s.
  • 叶: DleafD_\text{leaf} = 32,因为我们一个 SU 有 32 个节点,Wlink i = 400GB/s (8x400Gbps IB 链路)。因此我们的带宽是 400e9 * 32 / (32 - 1) = 413GB/s.
  • 主干: DspineD_\text{spine} = 4,因为我们有 4 个 SU,Wlink iW_\text{link i} = 12.8TB/s (来自上面的 8 * 16 * 2 * 400Gbps 链路)。我们的带宽是 12.8e12 * 4 / (4 - 1) = 17.1TB/s.

Hence our overall AG or RS bandwidth is min(514GB/s, 413GB/s, 17.1TB/s) = 413GB/s at the leaf level, so in practice TAG or RS comms=B/413GB/sT_\text{AG or RS comms} = B / \text{413GB/s}, i.e. we have about 413GB/s of AllReduce bandwidth even at the highest level. For an AllReduce with SHARP, it will be slightly lower than this (around 400GB/s) because we don’t have the (N−1)/N(N - 1) / N factor. Still, 450GB/s and 400GB/s are close enough to use as approximations.

因此,我们的整体 AG 或 RS 带宽是 min(514GB/s, 413GB/s, 17.1TB/s) = 413GB/s 在叶级别,所以实际上 TAG or RS comms=B/413GB/sT_\text{AG or RS comms} = B / \text{413GB/s}, 即即使在最高级别,我们也有大约 413GB/s 的 AllReduce 带宽。对于带 SHARP 的 AllReduce,它会略低于这个值 (约 400GB/s),因为我们没有 (N−1)/N(N - 1) / N 的因子。尽管如此,450GB/s 和 400GB/s 作为近似值已经足够接近了。

Other collectives: AllReduces are still 2x the above cost unless SHARP is enabled. NVIDIA sells SHARP-enabled IB switches as well, although not all providers have them. AllToAlls do change quite a bit cross-node, since they aren’t “hierarchical” in the way AllReduces are. If we want to send data from every GPU to every other GPU, we can’t use take advantage of the full bisection bandwidth at the node level. That means if we have an N-way AllToAll that spans M=N/8M = N / 8 nodes, the cost is

其他集合通信: 除非启用 SHARP,否则 AllReduce 的成本仍然是上述成本的 2 倍。NVIDIA 也销售支持 SHARP 的 IB 交换机,尽管并非所有提供商都有。AllToAlls 在跨节点时变化很大,因为它们不像 AllReduce 那样是“分层”的。如果我们想将数据从每个 GPU 发送到每个其他 GPU,我们无法利用节点级别的完全对分带宽。这意味着如果我们有一个跨越 M=N/8M = N / 8 个节点的 N 路 AllToAll,成本是

TAllToAll comms=B⋅(M−1)M2⋅Wnode egress≈BM⋅Wnode egressT_\text{AllToAll comms} = \frac{B \cdot (M - 1)}{M^2 \cdot W_\text{node egress}} \approx \frac{B}{M \cdot W_\text{node egress}}

which effectively has 50GB/s rather than 400GB/s of bandwidth. We go from B/(8∗450e9)B / (8 * \text{450e9}) within a single H100 node to B/(2⋅400e9)B / (2 \cdot \text{400e9}) when spanning 2 nodes, a more than 4x degradation.

这实际上具有 50GB/s 而不是 400GB/s 的带宽。我们从单个 H100 节点内的 B/(8∗450e9)B / (8 * \text{450e9}) 变为跨越 2 个节点时的 B/(2⋅400e9)B / (2 \cdot \text{400e9}), 性能下降超过 4 倍。

Here is a summary of the 1024-GPU DGX H100 SuperPod architecture:

以下是 1024-GPU DGX H100 SuperPod 架构的摘要:

Level
级别
Number of GPUs
GPU 数量
Degree (# Children)
度 (# 子节点)
Switch Bandwidth (full-duplex, TB/s)
交换机带宽 (全双工, TB/s)
Cable Bandwidth (full-duplex, TB/s)
电缆带宽 (全双工, TB/s)
Collective Bandwidth (GB/s)
集合带宽 (GB/s)
Node
节点
886.43.6450
Leaf (SU)
叶 (SU)
2563225.612.8400
Spine
主干
1024451.251.2400

We use the term “Collective Bandwidth” to describe the effective bandwidth at which we can egress either the GPU or the node. It’s also the bisection bandwidth∗2/N\text{bisection bandwidth} * 2 / N.

我们使用术语“集合带宽”来描述我们可以从 GPU 或节点出口的有效带宽。它也是 bisection bandwidth∗2/N\text{bisection bandwidth} * 2 / N.

Reductions when array is sharded over a separate axis: Consider the cost of a reduction like

当数组在单独的轴上分片时的归约: 考虑一个归约的成本,比如

AllReduceX(A[IY,J] {UX})\text{AllReduce}_X(A[I_Y, J]\ \{ U_X \})

where we are AllReducing over an array that is itself sharded along another axis YY. On TPUs, the overall cost of this operation is reduced by a factor of 1/Y1 / Y compared to the unsharded version since we’re sending 1/Y1 / Y as much data per axis. On GPUs, the cost depends on which axis is the “inner” one (intra-node vs. inter-node) and whether each shard spans more than a single node. Assuming YY is the inner axis, and the array has bytes\text{bytes} total bytes, the overall cost is reduced effectively by YY, but only if YY spans multiple nodes:

这里要对沿另一个轴 YY 分片的数组执行 AllReduce。在 TPU 上,每个轴传输的数据量是未分片时的 1/Y1 / Y,所以操作总成本也降至未分片时的 1/Y1 / Y。在 GPU 上,成本取决于内轴的范围(节点内或跨节点),以及每个分片是否跨越多个节点。假设 YY 是内轴、数组总大小为 bytes\text{bytes} 字节,那么只有当 YY 跨越多个节点时,总成本才会按 YY 缩减:

Tcomms at node=bytesWGPU egress⋅1min⁡(Y,Dnode)T_\text{comms at node} = \frac{\text{bytes}}{W_\text{GPU egress}} \cdot \frac{1}{\min(Y, D_\text{node})} Tcomms in scale-out network=bytesWnode egress⋅Dnodemax⁡(Dnode,Y)T_\text{comms in scale-out network} = \frac{\text{bytes}}{W_\text{node egress}} \cdot \frac{D_\text{node}}{\max(D_\text{node}, Y)} Ttotal=max⁡(Tcomms at node,Tcomms in scale-out network)T_\text{total} = \max(T_\text{comms at node}, T_\text{comms in scale-out network})

where N is the number of GPUs and again DnodeD_\text{node} is the number of GPUs in a node (the degree of the node). As you can see, if Y<DnodeY < D_\text{node}, we get a win at the node level but generally don’t see a reduction in overall runtime, while if Y>DnodeY > D_\text{node}, we get a speedup proportional to the number of nodes spanned.

其中 N 是 GPU 的总数,DnodeD_\text{node} 是每个节点的 GPU 数(即节点的度)。当 Y<DnodeY < D_\text{node} 时,节点内通信成本会降低,但总耗时通常不会减少。当 Y>DnodeY > D_\text{node} 时,加速比与跨越的节点数成正比。

If we want to be precise about the ring reduction, the general rule for a tree AllGatherX(AY { UX }) (assuming Y is the inner axis) is

如果我们想精确地进行环形归约,树状 AllGatherX(AY { UX }) 的一般规则 (假设 Y 是内轴) 是

TAR or RS comms=bytes⋅max⁡depth i[Di−1Di⋅max⁡(Y,Si−1)⋅Wlink i]T_\text{AR or RS comms} = \text{bytes} \cdot \max_{\text{depth } i}\left[\frac{D_i - 1}{D_i \cdot \max(Y, S_{i-1}) \cdot W_{\text{link } i}}\right]

where SiS_i is M * N * …, the size of the subnodes below level i in the tree. This is roughly saying that the more GPUs or nodes we span, the greater our available bandwidth is, but only within that node.

其中 SiS_i 是 M * N * …, 即树中 i 级以下子节点的大小。这大致是说,我们跨越的 GPU 或节点越多,我们可用的带宽就越大,但仅限于该节点内。

Pop Quiz 3 [Sharding along 2 axes]: Say we want to perform AllGatherX(bf16[DX,FY])\text{AllGather}_X(\text{bf16}[D_X, F_Y]) where YY is the inner axis over a single SU (256 chips). How long will this take as a function of DD, FF, and YY?

小测验 3 [沿 2 个轴分片]: 假设我们想在一个 SU (256 个芯片) 上执行 AllGatherX(bf16[DX,FY])\text{AllGather}_X(\text{bf16}[D_X, F_Y]), 其中 YY 是内轴。这将花费多长时间,作为 DD, FF 和 YY 的函数?

Click here for the answer. 点击这里查看答案

Answer: We can break this into two cases, where Y <= 8 and when Y > 8. When Y<=8Y <= 8, we remain bounded by the leaf switch, so the answer is, as usual, Tcomms=2∗D∗F∗(32−1)/(32∗400e9)T_\text{comms} = 2 * D * F * (32 - 1) / (32 * 400e9). When Y > 8, we have from above, roughly

答案: 我们可以将其分为两种情况,Y <= 8 和 Y > 8。当 Y<=8Y <= 8 时,我们仍然受叶交换机的限制,所以答案和往常一样,Tcomms=2∗D∗F∗(32−1)/(32∗400e9)T_\text{comms} = 2 * D * F * (32 - 1) / (32 * 400e9). 当 Y > 8 时,我们从上面得到,大约是

Tcomms=2⋅D⋅F⋅256Y⋅12.8e12=2DFY⋅50GB/sT_\text{comms} = \frac{2 \cdot D \cdot F \cdot 256}{Y \cdot \text{12.8e12}} = \frac{2DF}{Y \cdot \text{50GB/s}}

For D = 8192, F = 32,768, we have:

对于 D = 8192, F = 32,768, 我们有:

sharded all gather cost

Figure: theoretical cost of a sharded AllGather as the inner axis spans more nodes.

图: 随着内轴跨越更多节点,分片 AllGather 的理论成本。

Note how, if we do exactly 8-way model parallelism, we do in fact reduce the cost of the node-level reduction by 8 but leave the overall cost the same, so it’s free but not helpful in improving overall bandwidth.

注意,如果我们恰好进行 8 路模型并行,我们确实将节点级归约的成本降低了 8 倍,但总成本保持不变,所以这是免费的,但对提高总带宽没有帮助。

Quiz 4: Collectives测验 4:集合通信

Question 1 [SU AllGather]: Consider only a single SU with M nodes and N GPUs per node. Precisely how many bytes are ingressed and egressed by the node level switch during an AllGather? What about the top-level switch?

问题 1 [SU AllGather]: 只考虑一个 SU,它有 M 个节点,每个节点有 N 个 GPU。在 AllGather 期间,节点级交换机精确地入口和出口多少字节?顶层交换机呢?

Click here for the answer. 点击这里查看答案

Answer: Let’s do this step-by-step, working through the components of the reduction:

答案: 让我们一步一步来,逐个分析归约的组成部分:

  1. Each GPU sends B/MNB / MN bytes to the switch, for a total ingress of NB/MN=B/MNB / MN = B / M bytes ingress.
  2. We egress the full B/MB / M bytes up to the spine switch.
  3. We ingress B∗(M−1)/MB * (M - 1) / M bytes from the spine switch
  4. We egress B−B/MNB - B / MN bytes NN times, for a total of N∗(B−B/MN)=NB−B/MN * (B - B / MN) = NB - B / M.
  1. 每个 GPU 向交换机发送 B/MNB / MN 字节,总入口为 NB/MN=B/MNB / MN = B / M 字节。
  2. 我们将完整的 B/MB / M 字节出口到主干交换机。
  3. 我们从主干交换机入口 B∗(M−1)/MB * (M - 1) / M 字节。
  4. 我们出口 B−B/MNB - B / MN 字节 NN 次,总共 N∗(B−B/MN)=NB−B/MN * (B - B / MN) = NB - B / M.

The total is BB ingress and BNBN egress, so we should be bottlenecked by egress, and the total time would be TAllGather=BN/Wnode=B/450e9T_\text{AllGather} = BN / W_\text{node} = B / \text{450e9}.

总共是 BB 入口和 BNBN 出口,所以我们应该受出口的瓶颈限制,总时间将是 TAllGather=BN/Wnode=B/450e9T_\text{AllGather} = BN / W_\text{node} = B / \text{450e9}.

For the spine switch, the math is actually simpler. We must have B/MB / M bytes ingressed M times (for a total of BB bytes), and then B(M−1)/MB (M - 1) / M egressed MM times, for a total of B∗(M−1)B * (M - 1) out. Since this is significantly larger, the cost is TAllGather=B⋅(M−1)/(M⋅Wnode)=B⋅(M−1)/(M⋅400e9)T_\text{AllGather} = B \cdot (M - 1) / (M \cdot W_\text{node}) = B \cdot (M - 1) / (M \cdot \text{400e9}).

对于主干交换机,计算实际上更简单。我们必须有 B/MB / M 字节入口 M 次 (总共 BB 字节),然后 B(M−1)/MB (M - 1) / M 出口 MM 次,总共 B∗(M−1)B * (M - 1) 出口。由于这个数字明显更大,成本是 TAllGather=B⋅(M−1)/(M⋅Wnode)=B⋅(M−1)/(M⋅400e9)T_\text{AllGather} = B \cdot (M - 1) / (M \cdot W_\text{node}) = B \cdot (M - 1) / (M \cdot \text{400e9}).

Question 2 [Single-node SHARP AR]: Consider a single node with N GPUs per node. Precisely how many bytes are ingressed and egressed by the switch during an AllReduce using SHARP (in-network reductions)?

问题 2 [单节点 SHARP AR]: 考虑一个单节点,每个节点有 N 个 GPU。在使用 SHARP (网络内归约) 进行 AllReduce 期间,交换机精确地入口和出口多少字节?

Click here for the answer. 点击这里查看答案

Answer: As before, let’s do this step-by-step.

答案: 和之前一样,让我们一步一步来。

  1. Each GPU sends B∗(N−1)/NB * (N - 1) / N bytes, so we have N∗B∗(N−1)/N=B∗(N−1)N * B * (N - 1) / N = B * (N - 1) ingressed.
  2. We accumulate the partial sums, and we send back B/NB / N bytes to each GPU, so N∗B/N=BN * B / N = B bytes egressed.
  3. We do a partial sum on the residuals locally, then send this back to the switch. This is a total of N∗B/N=BN * B / N = B bytes ingressed.
  4. We capture all the shards and multicast them, sending B∗(N−1)/NB * (N - 1) / N to NN destinations, for a total of B∗(N−1)/N∗N=B∗(N−1)B * (N - 1) / N * N = B * (N - 1) egressed.
  1. 每个 GPU 发送 B∗(N−1)/NB * (N - 1) / N 字节,所以我们有 N∗B∗(N−1)/N=B∗(N−1)N * B * (N - 1) / N = B * (N - 1) 入口。
  2. 我们累加部分和,然后向每个 GPU 发回 B/NB / N 字节,所以 N∗B/N=BN * B / N = B 字节出口。
  3. 我们在本地对残差进行部分求和,然后将其发送回交换机。这总共是 N∗B/N=BN * B / N = B 字节入口。
  4. 我们捕获所有分片并进行多播,向 NN 个目标各发送 B∗(N−1)/NB * (N - 1) / N 字节,共发出 B∗(N−1)/N∗N=B∗(N−1)B * (N - 1) / N * N = B * (N - 1) 字节。

Therefore the total is B∗(N−1)+B=BNB * (N - 1) + B = BN bytes ingressed and egressed. This supports the overall throughput being exactly B/WegressB / W_\text{egress}.

因此,总共是 B∗(N−1)+B=BNB * (N - 1) + B = BN 字节入口和出口。这支持总吞吐量恰好是 B/WegressB / W_\text{egress}.

Question 3 [Cross-node SHARP AR]: Consider an array bf16[DX, FY] sharded over a single node of N GPUs. How long does AllReduce(bf16[D, FY] { UX }) take? You can assume we do in-network reductions. Explain how this differs if we have more than a single node?

问题 3 [跨节点 SHARP AR]: 考虑一个在单个 N GPU 节点上分片的数组 bf16[DX, FY]. AllReduce(bf16[D,FY] { UX }) 需要多长时间?你可以假设我们进行网络内归约。解释一下如果我们有多个节点,这会有什么不同?

Click here for the answer. 点击这里查看答案

Answer: We can try to modify the answer to the previous question above. Basically, we first egress B∗(X−1)/XYB * (X - 1) / XY bytes from each GPU, then send back B/XYB / XY to each GPU, then send that same amount back to the switch, then send B∗(X−1)/XYB * (X - 1) / XY back to each GPU. The total is NB/YNB / Y ingress and egress, so the total time is Tcomms=NB/(Y∗N∗Wlink)=N∗2DF/(Y∗N∗Wlink)=2∗D∗F/(Y∗Wlink)T_\text{comms} = NB / (Y * N * W_\text{link}) = N * 2DF / (Y * N * W_\text{link}) = 2 * D * F / (Y * W_\text{link}), so the total time does decrease with YY.

答案: 我们可以尝试修改上面问题的答案。基本上,我们首先从每个 GPU 出口 B∗(X−1)/XYB * (X - 1) / XY 字节,然后向每个 GPU 发回 B/XYB / XY, 然后将相同数量的字节发回交换机,然后向每个 GPU 发回 B∗(X−1)/XYB * (X - 1) / XY. 总共是 NB/YNB / Y 入口和出口,所以总时间是 Tcomms=NB/(Y∗N∗Wlink)=N∗2DF/(Y∗N∗Wlink)=2∗D∗F/(Y∗Wlink)T_\text{comms} = NB / (Y * N * W_\text{link}) = N * 2DF / (Y * N * W_\text{link}) = 2 * D * F / (Y * W_\text{link}), 所以总时间确实随着 YY 的增加而减少。

If we go beyond a single node, we can do roughly the same reduction as above, but when we egress the node-level switch, we need to send all B bytes, not just B/YB / Y. This is because we need to keep each shard separate.

如果我们超越单个节点,我们可以进行与上面大致相同的归约,但是当我们从节点级交换机出口时,我们需要发送所有 B 字节,而不仅仅是 B/YB / Y. 这是因为我们需要保持每个分片是独立的。

Question 4 [Spine level AR cost]: Consider the same setting as above, but with Y=256Y = 256 (so the AR happens at the spine level). How long does the AllReduce take? Again, feel free to assume in-network reductions.

问题 4 [主干级 AR 成本]: 考虑与上面相同的设置,但 Y=256Y = 256 (所以 AR 发生在主干级)。AllReduce 需要多长时间?同样,可以假设网络内归约。

Click here for the answer. 点击这里查看答案

Answer: This lets us take advantage of the rather ludicrous amount of bandwidth at the spine level. We have 51.2TB/s of bandwidth at the spine over 4 SUs, or 12.8TB/s per SU. Using SHARP, this could take as little as 2 * D * F / 12.8e12 seconds.

**答案:**这让我们可以充分利用主干层的大带宽。4 个 SU 在主干层共获得 51.2 TB/s 的带宽,每个 SU 对应 12.8 TB/s。使用 SHARP 时,操作最短可能只需 2 * D * F / 12.8e12 秒。

Question 5 [2-way AllGather cost]: Calculate the precise cost of an AllGather of BB bytes over exactly 2 nodes. Make sure to calculate the precise cost and not the approximation, and consider both the intra-node and cross-node cost.

问题 5 [2 路 AllGather 成本]: 计算在恰好 2 个节点上进行 BB 字节的 AllGather 的精确成本。确保计算精确成本而不是近似值,并考虑节点内和跨节点的成本。

Click here for the answer. 点击这里查看答案

Answer: At the node level, we have Tcomms=B∗7/(8∗450e9)=B/514e9T_\text{comms} = B * 7 / (8 * \text{450e9}) = B / \text{514e9} while beyond we actually have Tcomms=B∗(2−1)/(2∗400e9)=B/800e9T_\text{comms} = B * (2 - 1) / (2 * \text{400e9}) = B / \text{800e9}. Thus, we’re actually bounded by the node level reduction and not the leaf level! This motivates e.g. DeepSeek v3 which does 2-way Data Parallelism.

答案: 在节点级别,我们有 Tcomms=B∗7/(8∗450e9)=B/514e9T_\text{comms} = B * 7 / (8 * \text{450e9}) = B / \text{514e9}, 而在节点之外,我们实际上有 Tcomms=B∗(2−1)/(2∗400e9)=B/800e9T_\text{comms} = B * (2 - 1) / (2 * \text{400e9}) = B / \text{800e9}. 因此,我们实际上受节点级归约的限制,而不是叶级!这也解释了为什么 DeepSeek v3 等会进行 2 路数据并行。

Rooflines for LLM Scaling on GPUsGPU 上 LLM 扩展的屋顶线模型

Now let’s look at what this has all been building towards: understanding rooflines for LLM scaling on GPU. This is to complement the TPU training chapter here. As we did there, the goal here is to look at the total TmathT_\text{math} and TcommsT_\text{comms} for different parallelism strategies and understand at what point Tcomms>TmathT_\text{comms} > T_\text{math}. As before, we consider only the MLP block with operations

现在让我们来看看这一切都是为了什么:理解 GPU 上 LLM 扩展的屋顶线模型。这是对 TPU 训练章节这里的补充。和那里一样,这里的目标是查看不同并行策略的总 TmathT_\text{math} 和 TcommsT_\text{comms}, 并理解在什么点上 Tcomms>TmathT_\text{comms} > T_\text{math}. 和之前一样,我们只考虑 MLP 块,其操作为

MLP(x)≡x[B,D]∗DWin[D,F]⋅FWout[F,D]\text{MLP}(x) \equiv x[B, D] *_D W_\text{in}[D, F] \cdot_F W_\text{out}[F, D]

where BB is the global batch size in tokens (i.e. B=batch size⋅sequence lengthB = \text{batch size} \cdot \text{sequence length}).

其中 BB 是全局批次大小 (以 token 为单位) (即 B=batch size⋅sequence lengthB = \text{batch size} \cdot \text{sequence length})。

Here we’ll reproduce the table above showing effective bandwidths at both the GPU and node level:

这里我们将重现上面的表格,显示 GPU 和节点级别的有效带宽:

Node Type
节点类型
GPUs per node
每节点 GPU 数
GPU egress bandwidth
GPU 出口带宽
Node egress bandwidth
节点出口带宽
H1008450e9400e9
B2008900e9400e9
GB200 NVL7272900e93600e9

Note: Both the GPU and node egress bandwidths determine rooflines for our LLMs. We’ll use the term WcollectiveW_\text{collective} to describe either the GPU or node bandwidths depending on whether we are operating within or above the node level.

注意: GPU 和节点的出口带宽都决定了我们 LLM 的屋顶线。我们将使用术语 WcollectiveW_\text{collective} 来描述 GPU 或节点的带宽,具体取决于我们是在节点内还是节点之上操作。

Let’s look at the compute communication rooflines as we did for TPUs for data parallelism, tensor parallelism, pipeline parallelism, expert parallelism, and combinations thereof. For the rest of this section we’ll focus on H100 rooflines for specific calculations. GB200-NVL72 has the same general rooflines but because we have a larger node egress bandwidth, we can sometimes be bottlenecked at the node level instead.

让我们像对 TPU 那样,查看数据并行,张量并行,流水线并行,专家并行以及它们的组合的计算通信屋顶线。本节的其余部分,我们将专注于 H100 的 屋顶线 进行具体计算。GB200-NVL72 具有相同的一般 屋顶线,但由于我们有更大的节点出口带宽,我们有时可能会在节点级别遇到瓶颈。

Data Parallelism数据并行

As noted before, DP and ZeRO sharding involve either a weight AllReduce or a ReduceScatter + AllGather in the backward pass. Since these both have the same cost, to be compute-bound for pure data parallelism or FSDP without in-network reductions, we have, per layer, in the backward pass, with an axis of size X:

如前所述,DP 和 ZeRO 分片涉及在反向传播中进行权重 AllReduce 或 ReduceScatter + AllGather。由于这两者的成本相同,要想在纯数据并行或 FSDP 没有网络内归约的情况下达到计算密集型,我们在反向传播中,对于大小为 X 的轴,每层有:

Tmath=2⋅2⋅2⋅BDFX⋅CT_\text{math} = \frac{2 \cdot 2 \cdot 2 \cdot BDF}{X \cdot C} Tcomms=2⋅2⋅2⋅DFWcollectiveT_\text{comms} = \frac{2 \cdot 2 \cdot 2 \cdot DF}{W_\text{collective}}

Therefore, for Tmath>TcommsT_\text{math} > T_\text{comms}, we need B/(XC)>1/WcollectiveB / (XC) > 1 / W_\text{collective} or

因此,要使 Tmath>TcommsT_\text{math} > T_\text{comms}, 我们需要 B/(XC)>1/WcollectiveB / (XC) > 1 / W_\text{collective} 或

BX>CWcollective\frac{B}{X} > \frac{C}{W_\text{collective}}

where WcollectiveW_\text{collective} is either the GPU or node level egress bandwidth depending on whether we’re sharding within a node or across nodes. Thus:

其中 WcollectiveW_\text{collective} 是 GPU 或节点级别的出口带宽,具体取决于我们是在节点内还是跨节点分片。因此:

  • Within a node, we just need the per-GPU token batch size > 990e12/450e9=2200\text{990e12} / \text{450e9} = 2200.
  • Within an SU or at the spine level, BS > 990e12/400e9=2475\text{990e12} / \text{400e9} = 2475.
  • 在节点内,我们只需要每个 GPU 的 token 批次大小 > 990e12/450e9=2200\text{990e12} / \text{450e9} = 2200.
  • 在 SU 内或主干级别,BS > 990e12/400e9=2475\text{990e12} / \text{400e9} = 2475.

This is quite a bit higher than on a TPU, where the number is 850 with all three axes. For instance, LLaMA-3, which trained on 16000 H100s would need a batch size of at least 40M tokens (for reference, they used 16M). DeepSeek v3 trained on 2048 H800 GPUs with lower 300GB/s of bandwidth (instead of 450GB/s on H100) would need 990e12/300e9=3300\text{990e12} / \text{300e9} = 3300 tokens per GPU, or about 6.7M (in practice, they used 4M).

这比 TPU 上的数字要高得多,TPU 上所有三个轴的数字是 850。例如,在 16000 个 H100 上训练的 LLaMA-3,将需要至少 40M token 的批次大小 (作为参考,他们使用了 16M)。在 2048 个 H800 GPU 上训练的 DeepSeek v3,带宽较低,为 300GB/s (而不是 H100 上的 450GB/s),将需要每个 GPU 990e12/300e9=3300\text{990e12} / \text{300e9} = 3300 个 token,或约 6.7M (实际上,他们使用了 4M)。

With in-network reductions enabled and using pure data parallelism, theoretically we have 2x the AllReduce bandwidth, which would halve both of these numbers. However, in practice the benefit is closer to 30%, which only really makes up for the fact that we typically struggle to reach the reported numbers. Furthermore, because pure data parallelism is rarely useful, this basically doesn’t matter in practice.

启用网络内归约并使用纯数据并行,理论上我们的 AllReduce 带宽是 2 倍,这将使这两个数字减半。然而,实际上收益接近 30%, 这仅仅弥补了我们通常难以达到报告数字的事实。此外,因为纯数据并行很少有用,这在实践中基本上无关紧要。

MoE models: For a Mixture of Experts (MoE) model, where we have E experts and k experts per token, this increases to

MoE 模型: 对于专家混合 (MoE) 模型,其中我们有 E 个专家,每个 token 有 k 个专家,这增加到

Tmath=2⋅2⋅2⋅k⋅BDFX⋅CT_\text{math} = \frac{2 \cdot 2 \cdot 2 \cdot k \cdot BDF}{X \cdot C} Tcomms=2⋅2⋅2⋅EDFWcollectiveT_\text{comms} = \frac{2 \cdot 2 \cdot 2 \cdot EDF}{W_\text{collective}}

which inflates the per-GPU token batch size by a factor of E/kE/k, i.e.

这将每个 GPU 的 token 批次大小增加了 E/kE/k 的因子,即

BX>EkCWcollective\frac{B}{X} > \frac{E}{k} \frac{C}{W_\text{collective}}

For example, the new OpenAI OSS model with k=4k=4 and E=128E=128, this increases to 32 * 2475 = 79,200 across nodes, a kind of ridiculously high number.

例如,对于新的 OpenAI OSS 模型,k=4k=4 且 E=128E=128, 这在跨节点时增加到 32 * 2475 = 79,200, 这是一个相当高的数字。

What happens when X is small? When we do only e.g. 2-node data parallelism, we benefit from the (X−1)/X(X - 1) / X scaling, which gives us

当 X 很小时会发生什么? 当我们只进行例如 2 节点数据并行时,我们受益于 (X−1)/X(X - 1) / X 的缩放,这给了我们

Tmath=2⋅2⋅2⋅BDFN∗CT_\text{math} = \frac{2 \cdot 2 \cdot 2 \cdot BDF}{N * C} Tcomms=2⋅2⋅2⋅DF⋅(X−1)X⋅WcollectiveT_\text{comms} = \frac{2 \cdot 2 \cdot 2 \cdot DF \cdot (X-1)}{X \cdot W_\text{collective}}

where X is the number of nodes and N=8⋅XN = 8 \cdot X. Then for a dense model we have B/N>α⋅(X−1)/XB / N > \alpha \cdot (X - 1) / X, or e.g. B/N>1237B / N > \text{1237}, half the above value. You’ll notice 2-way data parallelism fairly often for this reason.

其中 X 是节点数,N=8⋅XN = 8 \cdot X. 那么对于密集模型,我们有 B/N>α⋅(X−1)/XB / N > \alpha \cdot (X - 1) / X, 或例如 B/N>1237B / N > \text{1237}, 是上述值的一半。出于这个原因,你会相当频繁地看到 2 路数据并行。

Tensor Parallelism张量并行

Tensor parallelism requires an AllGather and ReduceScatter over the activations, which we need to overlap with the MLP FLOPs. In other words, in the forward pass, we have

张量并行需要在激活值上进行 AllGather 和 ReduceScatter,我们需要将其与 MLP FLOPs 重叠。换句话说,在前向传播中,我们有

Tmath=2⋅2⋅BDFY⋅CT_\text{math} = \frac{2\cdot 2 \cdot BDF}{Y \cdot C} Tcomms=2⋅2⋅BDWcollectiveT_\text{comms} = \frac{2\cdot 2 \cdot BD}{W_\text{collective}}

which to be compute-bound gives us the rule

要达到计算密集型,这给了我们规则

Y<F⋅WcollectiveCY < \frac{F \cdot W_\text{collective}}{C}

Within a node, this gives us about F/2200F / 2200 or F/2475F / 2475 beyond a node. For F=28000F=\text{28000} like LLaMA-3, this is about 11-way TP (or rounding down, about 8-way, which is how large a node is). As with above, we get an extra 2X bandwidth when we span exactly 2 nodes, so we can generally do 16-way tensor parallelism (F>2475⋅(Y−8)F > 2475 \cdot (Y - 8)), which gives us up to 19-way model parallelism in theory.

在节点内,这给了我们大约 F/2200F / 2200, 在节点外是 F/2475F / 2475. 对于像 LLaMA-3 那样的 F=28000F=\text{28000}, 这大约是 11 路 TP (或者向下取整,大约 8 路,这是一个节点的大小)。和上面一样,当我们跨越正好 2 个节点时,我们获得了额外的 2 倍带宽,所以我们通常可以进行 16 路数据并行 (F>2475⋅(Y−8)F > 2475 \cdot (Y - 8)),这理论上给了我们高达 19 路的模型并行。

Expert Parallelism专家并行

As we’ve already noted above, Mixture of Expert (MoE) models come with E times more model weights with only k times more FLOPs, making data parallelism significantly harder. We can mitigate this somewhat by sharding our weights along the expert dimension, i.e. Win[EZ, D, F]. To do the MLP block, we need to introduce 2x AllToAll to send our activations to the corresponding experts.

正如我们上面已经指出的,专家混合 (MoE) 模型的模型权重是 E 倍,而 FLOPs 只有 k 倍,这使得数据并行明显更难。我们可以通过沿专家维度分片我们的权重来在一定程度上缓解这个问题,即 Win[EZ, D,F]. 要执行 MLP 块,我们需要引入 2 次 AllToAll 来将我们的激活值发送到相应的专家。

As noted above, the cost of this AllToAllZ->k([B, D, k]) if it spans multiple nodes is roughly TAllToAll=2⋅B⋅D⋅(Z−8)/Zmin⁡(8∗k/Z,1)T_\text{AllToAll} = 2 \cdot B \cdot D \cdot (Z-8)/Z \min(8 * k / Z, 1), so for pure expert parallelism we need

如上所述,如果这个 AllToAllZ->k([B,D,k]) 跨越多个节点,其成本大约是 TAllToAll=2⋅B⋅D⋅(Z−8)/Zmin⁡(8∗k/Z,1)T_\text{AllToAll} = 2 \cdot B \cdot D \cdot (Z-8)/Z \min(8 * k / Z, 1), 所以对于纯专家并行,我们需要

Tmath=4⋅B⋅k⋅D⋅FZ⋅CT_\text{math} = \frac{4 \cdot B \cdot k \cdot D \cdot F}{Z \cdot C} Tcomms=4⋅B⋅D⋅(Z−8)W⋅Z⋅min⁡(8⋅kZ,1)T_\text{comms} = \frac{4 \cdot B \cdot D \cdot (Z-8)}{W \cdot Z} \cdot \min\left(\frac{8 \cdot k}{Z}, 1\right)

We either need K>Z/8K > Z/8 with F>α⋅(Z−8)/kF > \alpha \cdot (Z - 8)/k or Z≫KZ \gg K and F>8⋅αF > 8 \cdot \alpha, where α=C/W\alpha = C/W. This gives you two domains in which expert parallelism is possible, one with a small amount of expert parallelism (roughly 2-node) and small FF, or one with large FF and ZZ arbitrarily large (up to E-way expert parallelism).

我们要么需要 K>Z/8K > Z/8 且 F>α⋅(Z−8)/kF > \alpha \cdot (Z - 8)/k, 要么 Z≫KZ \gg K 且 F>8⋅αF > 8 \cdot \alpha, 其中 α=C/W\alpha = C/W. 这给了你两个可以进行专家并行的领域,一个是少量专家并行 (大约 2 节点) 和小 FF, 另一个是大 FF 和任意大的 ZZ (高达 E 路专家并行)。

You’ll see both cases in practice, either a small amount of expert-parallelism (like DeepSeek v3 which has very small F and relatively small, restricted cross-node expert parallelism), or models with large F, in which case we can do significant cross-node EP alongside TP.

你在实践中会看到这两种情况,要么是少量的专家并行 (比如 DeepSeek v3,它的 F 非常小,跨节点专家并行相对较小且受限),要么是 F 很大的模型,在这种情况下我们可以进行显著的跨节点 EP 和 TP。

Pipeline Parallelism流水线并行

Pipeline parallelism splits layers across nodes with an extremely low communication cost, since we are just sending small microbatches of activations every couple layers. Historically pipelining has suffered from “pipeline bubbles”, but with new zero-bubble pipelining approaches, it is typically possible to do without.

流水线并行以极低的通信成本将层分布在节点之间,因为我们只是每隔几层发送小的微批次激活值。历史上,流水线一直受到“流水线气泡”的困扰,但随着新的零气泡流水线方法的出现,通常可以避免这种情况。

The overall communication cost of pipelining is tiny: with NMBN_\text{MB} microbatches and NstagesN_\text{stages}, we have Tcomms per hop=2⋅B⋅D/(W⋅NMB)T_\text{comms per hop} = 2 \cdot B \cdot D / (W \cdot N_\text{MB}) and NMB+Nstages−2N_\text{MB} + N_\text{stages} - 2 hops, so roughly

流水线的总通信成本很小:有 NMBN_\text{MB} 个微批次和 NstagesN_\text{stages} 个阶段,我们有 Tcomms per hop=2⋅B⋅D/(W⋅NMB)T_\text{comms per hop} = 2 \cdot B \cdot D / (W \cdot N_\text{MB}) 和 NMB+Nstages−2N_\text{MB} + N_\text{stages} - 2 跳,所以大约是

Ttotal PP comms=2BDW⋅NMB⋅(NMB+Nstages−2)T_\text{total PP comms} = \frac{2BD}{W \cdot N_\text{MB}} \cdot (N_\text{MB} + N_\text{stages} - 2) Tper-layer comms≈1.5⋅2BDW⋅NlayersT_\text{per-layer comms} \approx 1.5 \cdot \frac{2BD}{W \cdot N_\text{layers}}

Since we are dividing by NlayersN_\text{layers}, this is vastly smaller than any of the other costs. In other words, from a communication standpoint, pipelining is basically free. So why don’t we just do pipelining? There are a few reasons:

由于我们除以 NlayersN_\text{layers}, 这比任何其他成本都要小得多。换句话说,从通信的角度来看,流水线基本上是免费的。那么为什么我们不只做流水线呢?有几个原因:

(1) Code complexity: pipelining doesn’t fit as nicely into automatic parallelism frameworks (like XLA’s GSPMD) as other approaches. Because it introduces microbatching to hide pipeline bubbles, it changes the structure of the program, and custom zero-bubble pipeline schedules exacerbate this problem by requiring complicated interleaving of the forward and backward pass.

(1) 代码复杂性: 流水线不像其他方法那样能很好地融入自动并行框架 (如 XLA 的 GSPMD)。因为它引入了微批处理来隐藏流水线气泡,它改变了程序的结构,而定制的零气泡流水线调度通过要求前向和后向传播的复杂交错加剧了这个问题。

(2) Pipelining makes data parallelism and FSDP hard: probably the biggest reason not to do pipelining is that it plays badly with FSDP and data parallelism. ZeRO-3 sharding in particular works badly, since it requires us to AllGather the weights on every microbatch which doesn’t work when we have only B/NmicrobatchesB / N_\text{microbatches} tokens to amortize the AllGather cost. Furthermore, during the backward pass, we can’t AllReduce or ReduceScatter the gradients until the last microbatch has passed a given stage, which means we have significant non-overlapped communication time.

(2) 流水线使数据并行和 FSDP 变得困难: 可能不做流水线的最大原因是它与 FSDP 和数据并行的兼容性不好。特别是 ZeRO-3 分片效果很差,因为它要求我们在每个微批次上 AllGather 权重,当我们只有 B/NmicrobatchesB / N_\text{microbatches} 个 token 来摊销 AllGather 成本时,这是行不通的。此外,在反向传播期间,我们无法在最后一个微批次通过给定阶段之前对梯度进行 AllReduce 或 ReduceScatter,这意味着我们有显著的未重叠的通信时间。

pipeline bubble

Figure: an example 2 stage, 2 microbatch pipeline. F denotes a stage forward pass and B is a stage backward pass (2x the cost). G denotes the data-parallel AllReduces, which can be significantly longer than the time of a single microbatch.

图: 一个 2 阶段,2 微批次流水线的示例。F 表示阶段前向传播,B 是阶段后向传播 (成本是 2 倍)。G 表示数据并行 AllReduce,其时间可能明显长于单个微批次的时间。

(3) Pipeline bubbles and step imbalance: As you can see in the (bad) pipeline schedule above, it is easy to have significant bubbles (meaning wasted compute) during a naive pipeline schedule. Above, the second stage is idle on step 0, the first stage is idle from step 2 to 3, and the second stage is again idle on the last step. While we can avoid these somewhat with careful scheduling, we still often have some bubbles. We also have to pass activations from one stage to the next on the critical path, which can add overhead:

(3) 流水线气泡和步骤不平衡: 正如你在上面 (糟糕的) 流水线调度中看到的,在一个简单的流水线调度中很容易出现显著的气泡 (意味着浪费的计算)。上面,第二阶段在步骤 0 是空闲的,第一阶段从步骤 2 到 3 是空闲的,第二阶段在最后一步再次是空闲的。虽然我们可以通过仔细的调度在一定程度上避免这些,但我们仍然经常有一些气泡。我们还必须在关键路径上将激活值从一个阶段传递到下一个阶段,这会增加开销:

pipeline transfer

Figure: an example pipeline showing transfer cost in red. This shifts stages relative to each other and increases the pipeline bubble overhead.

图: 一个显示红色传输成本的流水线示例。这会使阶段相对移动,并增加流水线气泡开销。

There are workarounds for each of these issues, but they tend to be complicated to implement and difficult to maintain; pipelining remains a technique with low communication cost relative to other methods.

对于这些问题中的每一个都有变通方法,但它们往往实现起来复杂且难以维护,但流水线仍然是一种相对于其他方法通信成本较低的技术。

Caveat about latency: As noted before, GPUs struggle to achieve full AllReduce bandwidth even with fairly large messages. This means even if we in theory can scale e.g. expert-parallel AllToAlls across multiple nodes, we may struggle to achieve even 50% of the total bandwidth. This means we do try to keep TP or EP within a smaller number of nodes to minimize latency overhead.

关于延迟的警告: 如前所述,即使消息相当大,GPU 也难以实现完整的 AllReduce 带宽。这意味着即使我们理论上可以跨多个节点扩展例如专家并行的 AllToAlls,我们也可能难以达到总带宽的 50%. 这意味着我们确实尝试将 TP 或 EP 保持在较少数量的节点内,以最小化延迟开销。

Examples示例

What does DeepSeek do? For reference, DeepSeek V3 is trained with 2048 H800 GPUs with:

DeepSeek 是如何做的? 作为参考,DeepSeek V3 是用 2048 个 H800 GPU 训练的,配置如下:

  • 64-way Expert Parallelism (EP) spanning 8 nodes
  • 16-way Pipeline Parallelism (PP)
  • 2-way ZeRO-1 Data Parallelism (DP)
  • 64 路专家并行 (EP),跨越 8 个节点
  • 16 路流水线并行 (PP)
  • 2 路 ZeRO-1 数据并行 (DP)

They had a steady state batch size of 4096 * 15360 = 62,914,560 tokens, or 30k tokens per GPU. You can see that this is already quite large, but their model is also very sparse (k=8, E=256) so you need a fairly large batch size. You can see that with 64-way EP and 16-way PP, we end up with 1024-way model parallelism in total, which means the AllReduce is done at the spine level, and because it’s only 2-way, we end up with 2/(2−1)=22 / (2 - 1) = 2 times more bandwidth in practice. This also helps reduce the cost of the final data-parallel AllReduce overlapping with the final pipeline stages.

他们的稳态批次大小为 4096 * 15360 = 62,914,560 个 token,或每个 GPU 30k 个 token。你可以看到这已经相当大了,但他们的模型也非常稀疏 (k=8,E=256),所以你需要一个相当大的批次大小。你可以看到,通过 64 路 EP 和 16 路 PP,我们总共得到了 1024 路模型并行,这意味着 AllReduce 是在主干级别完成的,而且因为只有 2 路,我们实际上获得了 2/(2−1)=22 / (2 - 1) = 2 倍的带宽。这也有助于降低与最后流水线阶段重叠的最终数据并行 AllReduce 的成本。

What does LLaMA-3 do? LLaMA-3 trains with a BS of 16M tokens on 16k GPUs, or about 1k tokens per GPU. They do:

LLaMA-3 是如何做的? LLaMA-3 在 16k 个 GPU 上以 16M token 的 BS 进行训练,或每个 GPU 约 1k 个 token。他们采用:

  • 8-way Tensor Parallelism within a node (TP)
  • 16-way Pipeline Parallelism (PP)
  • 128-way ZeRO-1 Data Parallelism
  • 节点内 8 路张量并行 (TP)
  • 16 路流水线并行 (PP)
  • 128 路 ZeRO-1 数据并行

This is also a dense model so in general these things are pretty trivial. The 16-way PP reduces the cost of the data parallel AllReduce by 16x, which helps us reduce the critical batch size.

这也是一个密集模型,所以总的来说这些事情都相当简单。16 路 PP 将数据并行 AllReduce 的成本降低了 16 倍,这有助于我们降低临界批次大小。

TLDR of LLM Scaling on GPUsGPU 上 LLM 扩展的 TLDR

Let’s step back and come up with a general summary of what we’ve learned so far:

让我们退后一步,对我们到目前为止学到的东西做一个总结:

  • Data parallelism or FSDP (ZeRO-1/3) requires a local batch size of about 2500 tokens per GPU, although in theory in-network reductions + pure DP can reduce this somewhat.
  • Tensor parallelism is compute-bound up to about 8-ways but we lack the bandwidth to scale much beyond this before becoming comms-bound. This mostly limits us to a single NVLink domain (i.e. single-node or need to use GB200NVL72 with up to 72 GPUs).
  • Any form of model parallelism that spans multiple nodes can further reduce the cost of FSDP, so we often want to mix PP + EP + TP to cross many nodes and reduce the FSDP cost.
  • Pipeline parallelism works well if you can handle the code complexity of zero-bubble pipelining and keep batch sizes fairly large to avoid data-parallel bottlenecks. Pipelining usually makes ZeRO-3 impossible (since you would need to AllGather on each pipeline stage), but you can do ZeRO-1 instead.
  • 数据并行或 FSDP (ZeRO-1/3) 需要每个 GPU 约 2500 个 token 的本地批次大小,尽管理论上网络内归约 + 纯 DP 可以稍微降低这个数字。
  • 张量并行在最多约 8 路时是计算密集型的,但我们缺乏带宽来在此之上进行太多扩展,否则会变得受通信限制。这主要将我们限制在单个 NVLink 域 (即单节点或需要使用 GB200NVL72,最多 72 个 GPU)。
  • 任何跨越多个节点的模型并行形式都可以进一步降低 FSDP 的成本,所以我们经常希望混合 PP + EP + TP 来跨越许多节点并降低 FSDP 成本。
  • 如果你能处理零气泡流水线的代码复杂性,并保持相当大的批次大小以避免数据并行瓶颈,那么流水线并行效果很好。 流水线通常使 ZeRO-3 变得不可能 (因为你需要在每个流水线阶段进行 AllGather),但你可以改用 ZeRO-1。

At a high level, this gives us a recipe for sharding large models on GPUs:

从高层次来看,这给了我们在 GPU 上分片大型模型的秘诀:

  • For relatively small dense models, aggressive FSDP works great if you have the batch size, possibly with some amount of pipelining or tensor parallelism if needed.
  • For larger dense models, some combination of 1-2 node TP + many node PP + pure DP works well.
  • For MoEs, the above rule applies but we can also do expert parallelism, which we prefer to TP generally. If F>8∗C/WnodeF > 8 * C / W_\text{node}, we can do a ton of multi-node expert parallelism, but otherwise we’re limited to roughly 2-node EP.
  • 对于相对较小的密集模型,如果你有足够的批次大小,激进的 FSDP 效果很好,如果需要,可能带有一些流水线或张量并行。
  • 对于较大的密集模型,1-2 节点 TP + 多节点 PP + 纯 DP 的某种组合效果很好。
  • 对于 MoE,上述规则适用,但我们也可以进行专家并行,我们通常更喜欢它而不是 TP。如果 F>8∗C/WnodeF > 8 * C / W_\text{node}, 我们可以进行大量的多节点专家并行,否则我们受限于大约 2 节点 EP。

Quiz 5: LLM rooflines测验 5:LLM 屋顶线

Question 1 [B200 rooflines]: A B200 DGX SuperPod (not GB200 NVL72) has 2x the bandwidth within a node (900GB/s egress) but the same amount of bandwidth in the scale-out network (400GB/s) (source). The total FLOPs are reported above. How does this change the model and data parallel rooflines?

问题 1 [B200 屋顶线]: 一个 B200 DGX SuperPod (不是 GB200 NVL72) 在节点内有 2 倍的带宽 (900GB/s 出口),但在横向扩展网络中的带宽相同 (400GB/s) (来源)。总 FLOPs 如上所述。这如何改变模型和数据并行的 屋顶线?

Click here for the answer. 点击这里查看答案

Answer: Our FLOPs/s in bfloat16 increases from 990 to 2250 TFLOPs, a 2.25x increase. With 2x the bandwidth, within a node, our rooflines stay roughly the same. For TP, for example, the critical intensity goes up to 2250e12 / 900e9 = 2500, so we have a limit of Y<F/2500Y < F / 2500, only slightly higher (and this doesn’t help us unless the node size increases).

答案: 我们的 bfloat16 FLOPs/s 从 990 增加到 2250 TFLOPs,增加了 2.25 倍。带宽增加 2 倍,在节点内,我们的 屋顶线 大致保持不变。例如,对于 TP,临界强度上升到 2250e12 / 900e9 = 2500, 所以我们的限制是 Y<F/2500Y < F / 2500, 仅略高 (除非节点大小增加,否则这对我们没有帮助)。

Beyond a node, however, the lack of additional bandwidth actually makes it even harder for us to be compute-bound! For instance, for data parallelism, our critical batch size increases to 2250e12 / 400e9 = 5625, because our GPU can do significantly more FLOPs with the same bandwidth.

然而,在节点之外,缺乏额外的带宽实际上使我们更难达到计算密集型!例如,对于数据并行,我们的临界批次大小增加到 2250e12 / 400e9 = 5625, 因为我们的 GPU 可以用相同的带宽执行明显更多的 FLOPs。

GB200 SuperPods with 72-GPU nodes change this by adding more egress bandwidth (source).

具有 72-GPU 节点的 GB200 SuperPod 通过增加更多的出口带宽改变了这一点 (来源)。

Question 2 [How to shard LLaMA-3 70B]: Consider LLaMA-3 70B, training in bfloat16 with fp32 optimizer state with Adam.

问题 2 [如何分片 LLaMA-3 70B]: 考虑 LLaMA-3 70B,使用 bfloat16 训练,Adam 优化器状态为 fp32。

  1. At a minimum, how many H100s would we need simply to store the weights and optimizer?
  2. Say we want to train on 4096 H100 GPUs for 15T tokens. Say we achieved 45% MFU (Model FLOPs Utilization). How long would it take to train?
  3. LLaMA-3 70B has F = 28,672 and was trained with a batch size of about 4M tokens. What is the most model parallelism we could do without being comms-bound? With this plus pure DP, could we train LLaMA-3 while staying compute-bound on 4k chips? What about ZeRO-3? What about with 8-way pipelining? Note: consider both the communication cost and GPU memory usage.
  1. 仅仅为了存储权重和优化器,我们至少需要多少个 H100?
  2. 假设我们想在 4096 个 H100 GPU 上训练 15T token。假设我们达到了 45% 的 MFU (模型 FLOPs 利用率)。训练需要多长时间?
  3. LLaMA-3 70B 的 F = 28,672, 训练时批次大小约为 4M token。我们最多可以进行多少模型并行而不受通信限制?有了这个加上纯 DP,我们能否在保持计算密集型的情况下用 4,000 个芯片训练 LLaMA-3?ZeRO-3 呢?8 路流水线呢?
Click here for the answer. 点击这里查看答案
  1. We need 2 bytes for the weights and 8 for the optimizer state, so at least 700GB. With 80GB of DRAM, we’ll need at least 9 GPUs at a minimum, or (rounding up) at least 2 8xH100 nodes. This would take forever to train and wouldn’t hold the gradient checkpoints, but it’s a lower bound.
  2. This will require a total of 6 * 70e9 * 15e12 = 6.3e24 bf16 FLOPs. Each GPU can do 990e12 FLOPs, so at 45% MFU we can do 1.8e18 FLOPs/s. Thus the whole thing will take 3.5e6 seconds, or 40 days.
  3. Within a node, we have 450GB/s of bandwidth, so the limit is roughly F / 1995 = 28672 / 1995 = 14.372. Since this doesn’t span 2 nodes, it realistically means we’d go up to 8-way model parallelism.
    1. This would then require us to do 512 way DP. Firstly, we need to see if we have enough memory. Since our model is only sharded 8-ways, this would mean 700GB / 8 = 87.5GB / GPU, which won’t fit, so no!
    2. With ZeRO-3 and 8-way TP, we’ll be doing 512-way ZeRO-3. This won’t have any issue with memory because we’re sharding everything aggressively. We’ll have a per-GPU batch size of 4e6 / 4096 = 976. This is quite low, even below our pure DP limit, and this is twice that limit because we have to move our weights. So no.
    3. With 8-way pipelining, each model parallel shard now spans 8 nodes. As we’ve seen, this reduced the cost of our leaf-level AllGathers by 8, so the overall AllReduce/AllGather bandwidth there goes from 400GB/s to 8 * 400GB/s = 3200GB/s. The roofline then is 990e12 / 3200e9 = 309, so we should be good! We just need to implement pipelining efficiently.
  1. 我们需要 2 字节用于权重,8 字节用于优化器状态,所以至少需要 700GB。H100 有 80GB 的 DRAM,我们至少需要 9 个 GPU,或者 (向上取整) 至少 2 个 8xH100 节点。这将需要很长时间来训练,并且无法保存梯度检查点,但这是一个下限。
  2. 这将需要总共 6 * 70e9 * 15e12 = 6.3e24 bf16 FLOPs. 每个 GPU 可以执行 990e12 FLOPs,所以在 45% MFU 下,我们可以执行 1.8e18 FLOPs/s。因此,整个过程将需要 3.5e6 秒,约 40 天。
  3. 在节点内,我们有 450GB/s 的带宽,所以限制大约是 F / 1995 = 28672 / 1995 = 14.372. 由于这不跨越 2 个节点,实际上这意味着我们将进行最多 8 路模型并行。
    1. 这将要求我们进行 512 路 DP。首先,我们需要看看是否有足够的内存。由于我们的模型只分片了 8 路,这意味着 700GB / 8 = 87.5GB / GPU, 这装不下,所以不行!
    2. 使用 ZeRO-3 和 8 路 TP,我们将进行 512 路 ZeRO-3。这不会有任何内存问题,因为我们正在积极地分片所有东西。我们的每个 GPU 批次大小将是 4e6 / 4096 = 976. 这相当低,甚至低于我们的纯 DP 限制,而且这是该限制的两倍,因为我们必须移动我们的权重。所以不行。
    3. 使用 8 路流水线,每个模型并行分片现在跨越 8 个节点。正如我们所见,这将我们的叶级 AllGathers 的成本降低了 8 倍,所以那里的总 AllReduce/AllGather 带宽从 400GB/s 增加到 8 * 400GB/s = 3200GB/s. 那么 屋顶线 就是 990e12 / 3200e9 = 309, 所以我们应该没问题!我们只需要高效地实现流水线。

Question 3 [Megatron-LM hyperparams]: Consider this figure from the Megatron-LM repository highlighting their high MFU numbers.

问题 3 [Megatron-LM 超参数]: 考虑Megatron-LM 仓库中的这张图,突出了他们的高 MFU 数字。

megatron hparams

Note that their sequence length is 4096 everywhere. For the 16B, 70B, and 314B models, what is the per-GPU token batch size? Assuming data parallelism is the outermost axis and assuming bfloat16 reductions, determine whether each of these is theoretically compute-bound or communication-bound, and whether there is a more optimal configuration available?

注意,他们的序列长度到处都是 4096。对于 16B,70B 和 314B 模型,每个 GPU 的 token 批次大小是多少?假设数据并行是最外层的轴,并假设 bfloat16 归约,判断这些中的每一个在理论上是计算密集型还是通信密集型,以及是否有更优的配置可用?

Click here for the answer. 点击这里查看答案

Answer: Let’s start with batch sizes per GPU.

答案: 让我们从每个 GPU 的批次大小开始。

  • 16B: 192 * 4096 / 192 = 4096 tokens per GPU
  • 70B: 384 * 4096 / 768 = 2048 tokens per GPU
  • 314B: 1536 * 4096 / 3072 = 2048 tokens per GPU
  • 16B:192 * 4096 / 192 = 4096 tokens / GPU
  • 70B:384 * 4096 / 768 = 2048 tokens / GPU
  • 314B:1536 * 4096 / 3072 = 2048 tokens / GPU

This means with the exception of the first, these all hover around 2k tokens per batch, which is notably around the critical threshold we calculated for FSDP. We had calculated that bound to be 2,472 tokens / GPU based on the spine level reduction, which should roughly come into play here. For both the 70B and 314B though, because we have 16 and 64-way model (PP + TP) sharding respectively, we get 2x and 8x better throughput at the spine level, which means we should be compute-bound at roughly 1k and 300 tokens / step respectively.

这意味着除了第一个,这些都徘徊在 2k token / 批处理左右,这值得注意的是在我们为 FSDP 计算的临界阈值附近。我们计算出该界限是 2,472 token / GPU,基于主干级归约,这应该在这里大致发挥作用。然而,对于 70B 和 314B,因为我们分别有 16 路和 64 路模型分片,我们在主干级别获得了 2 倍和 8 倍的吞吐量提升,这意味着我们应该分别在约 1k 和 300 token / 步时达到计算密集型。

Acknowledgements and Further Reading致谢和延伸阅读

This chapter relied heavily on help from many knowledgeable GPU experts, including:

本章在很大程度上依赖于许多知识渊博的 GPU 专家的帮助,包括:

  • Adam Paszke, who helped explain the realities of kernel programming on GPUs.
  • Swapnil Patil, who first explained how GPU networking works.
  • Stas Bekman, who pointed out that the empirical realities of GPUs are often different from the purported specs.
  • Reiner Pope, who helped clarify how GPUs and TPUs compare at a hardware level.
  • Frédéric Bastien, who gave detailed feedback on the chip-level story.
  • Nouamane Tazi, whose experience with LLM training on GPUs helped improve the roofline section.
  • Sanford Miller, who helped me understand how GPUs are networked and how NVIDIA’s specifications compare to what’s often deployed in the field.
  • Adam Paszke,他帮助解释了 GPU 上内核编程的现实情况。
  • Swapnil Patil,他首先解释了 GPU 网络的工作原理。
  • Stas Bekman,他指出 GPU 的经验现实往往与声称的规格不同。
  • Reiner Pope,他帮助阐明了 GPU 和 TPU 在硬件层面的比较。
  • Frédéric Bastien,他对芯片级的故事给出了详细的反馈。
  • Nouamane Tazi,他在 GPU 上训练 LLM 的经验帮助改进了屋顶线部分。
  • Sanford Miller,他帮助我理解了 GPU 是如何联网的,以及 NVIDIA 的规格与现场经常部署的规格相比如何。

There’s a great deal of good reading on GPUs, but some of my favorites include:

关于 GPU 有大量的好读物,但我最喜欢的一些包括:

Appendix A: How does this change with GB200?附录 A:GB200 会带来哪些变化?

Blackwell introduces a bunch of major networking changes, including NVLink 5 with twice the overall NVLink bandwidth (900GB/s). B200 still has 8-GPU nodes, just like H100s, but GB200 systems (which combine B200 GPUs with Grace CPUs) introduce much larger NVLink domain (72 GPUs in NVL72 and in theory up to 576). This bigger NVLink domain also effectively increases the node egress bandwidth, which reduces collective costs above the node level.

Blackwell 引入了一系列重大的网络变化,包括 NVLink 5,其总 NVLink 带宽是原来的两倍 (900GB/s)。B200 仍然有 8-GPU 节点,就像 H100 一样,但 GB200 系统 (将 B200 GPU 与 Grace CPU 结合) 引入了更大的 NVLink 域 (NVL72 中有 72 个 GPU,理论上最多可达 576 个)。这个更大的 NVLink 域也有效地增加了节点出口带宽,从而降低了节点之上的集合通信成本。

b200 node

Figure: a diagram showing how a GB200 NVL72 unit is constructed, with 18 switches and 72 GPUs.

图: 展示 GB200 NVL72 单元如何构建的示意图,包含 18 个交换机和 72 个 GPU。

Within a node, this increased bandwidth (from 450GB/s to 900GB/s) doesn’t make much of a difference because we also double the total FLOPs/s of each GPU. Our rooflines mostly stay the same, although because NVLink has much better bandwidth, Expert Parallelism becomes easier.

在节点内,这种增加的带宽 (从 450GB/s 到 900GB/s) 并没有太大区别,因为我们也使每个 GPU 的总 FLOPs/s 翻了一番。我们的屋顶线模型基本保持不变,尽管因为 NVLink 有更好的带宽,专家并行变得更容易了。

Beyond a node, things change more. Here’s a SuperPod diagram from here.

在节点之外,情况变化更大。这是来自这里的 SuperPod 示意图。

gb200 superpod

Figure: a diagram showing a GB200 DGX SuperPod of 576 GPUs.

图: 展示一个包含 576 个 GPU 的 GB200 DGX SuperPod 的示意图。

As you can see, the per-node egress bandwidth increases to 4 * 18 * 400 / 8 = 3.6TB/s, up from 400GB/s in H100. This improves the effective cross-node rooflines by about 4x since our FLOPs/chip also double. Now we may start to worry about whether we’re bottlenecked at the node level rather than the scale-out level.

如你所见,每个节点的出口带宽增加到 4 * 18 * 400 / 8 = 3.6TB/s, 从 H100 的 400GB/s 增加。这将有效的跨节点 屋顶线 提高了约 4 倍,因为我们的 FLOPs/芯片也翻了一番。现在我们可能开始担心我们是否在节点级别而不是在横向扩展级别受到瓶颈限制。

Grace Hopper: NVIDIA also sells GH200 and GB200 systems which pair some number of GPUs with a Grace CPU. For instance, a GH200 has 1 H200 and 1 Grace CPU, while a GB200 system has 2 B200s and 1 Grace CPU. An advantage of this system is that the CPU is connected to the GPUs using a full bandwidth NVLink connection (called NVLink C2C), so you have very high CPU to GPU bandwidth, useful for offloading parameters to host RAM. In other words, for any given GPU, the bandwidth to reach host memory is identical to reaching another GPU’s HBM.

Grace Hopper: NVIDIA 还销售 GH200 和 GB200 系统,将一定数量的 GPU 与 Grace CPU 配对。例如,一个 GH200 有 1 个 H200 和 1 个 Grace CPU,而一个 GB200 系统有 2 个 B200 和 1 个 Grace CPU。这个系统的一个优点是 CPU 使用全带宽 NVLink 连接 (称为 NVLink C2C) 连接到 GPU,所以你有非常高的 CPU 到 GPU 带宽,这对于将参数卸载到主机 RAM 很有用。换句话说,对于任何给定的 GPU,到达主机内存的带宽与到达另一个 GPU 的 HBM 的带宽相同。

Appendix B: More networking details附录 B:更多网络细节

Here’s a diagram of an NVLink 4 switch. There are 64 overall NVLink4 ports (each uses 2 physical lanes), and a large crossbar that handles inter-lane switching. TPUs by contrast use optical switches with mirrors that can be dynamically reconfigured.

这是一个 NVLink 4 交换机的示意图。总共有 64 个 NVLink4 端口 (每个使用 2 个物理通道),以及一个处理通道间交换的大型交叉开关。相比之下,TPU 使用可以动态重新配置的带反射镜的光学交换机。

nvlink4

Figure: a lower level view of a single NVLink4 Switch.

图: 单个 NVLink4 交换机的更底层视图。

At each level we can be bottlenecked by the available link bandwidth or the total switch bandwidth.

在每个级别,我们都可能受到可用链路带宽或总交换机带宽的瓶颈限制。

  • Node level: at the node level, we have 4 * 1.6TB/s = 6.4TB/s of NVSwitch bandwidth, but each of our 8 GPUs can only egress 450GB/s into the switch, meaning we actually have a peak bandwidth of 450e9 * 8 = 3.6TB/s (full-duplex) within the node.
  • SU/leaf level: at the SU level, we have 8 switches connecting 32 nodes in an all-to-all fashion with 1x400 Gbps Infiniband. This gives us 8 * 32 * 400 / 8 = 12.8TB/s of egress bandwidth from the nodes, and we have 8 * 1.6TB/s = 12.8TB/s at the switch level, so both agree precisely.
  • Spine level: at the spine level, we have 16 switches connecting 32 leaf switches with 2x400 Gbps links, so we have 32 * 16 * 400 * 2 / 8 = 51.2TB/s of egress bandwidth. Unlike a leaf switch, all 64 ports of a spine switch face downward, so each switch can move 64 * 400 / 8 = 3.2TB/s of traffic, giving us 16 * 3.2TB/s = 51.2TB/s at the switch level, again agreeing precisely.
  • **节点层:**NVSwitch 带宽为 4 × 1.6 TB/s = 6.4 TB/s,但 8 个 GPU 各只有 450 GB/s 的带宽可用于向交换机发送数据,因此节点内实际峰值带宽为 450e9 × 8 = 3.6 TB/s(全双工)。
  • **SU/叶层:**8 台交换机用 1 × 400 Gbps 的 InfiniBand 链路连接 32 个节点,使它们能全互连。节点出口带宽为 8 × 32 × 400 / 8 = 12.8 TB/s,交换机侧带宽为 8 × 1.6 TB/s = 12.8 TB/s,两者恰好相等。
  • **主干层:**16 台交换机通过 2 × 400 Gbps 的链路连接 32 台叶交换机,出口带宽为 32 × 16 × 400 × 2 / 8 = 51.2 TB/s。与叶交换机不同,主干交换机的全部 64 个端口都连接下层,因此每台可以处理 64 × 400 / 8 = 3.2 TB/s;交换机侧总计 16 × 3.2 TB/s = 51.2 TB/s,两者也恰好相等。

Per GPU, this gives us 450GB/s of GPU to GPU bandwidth at the node level, and 50GB/s at both the SU and spine levels.

换算到每个 GPU,节点内的 GPU 间带宽为 450 GB/s,SU 层和主干层均为 50 GB/s。

GPU empirical AR bandwidth:

GPU 实证 AR 带宽:

gpu all reduce bw

Figure: AllReduce bandwidth on an 8xH100 cluster (intra-node, SHARP disabled).

图: 8xH100 集群上的 AllReduce 带宽 (节点内,禁用 SHARP)。

TPU v5p bandwidth (1 axis):

TPU v5p 带宽 (1 轴):

tpu all reduce bw

Figure: AllReduce bandwidth on a TPU v5p 4x4x4 cluster (along one axis).

图: TPU v5p 4x4x4 集群上的 AllReduce 带宽 (沿一个轴)。

Here’s AllGather bandwidth as well:

这里还有 AllGather 带宽:

gpu all gather bw

Figure: AllGather bandwidth on an 8xH100 cluster (intra-node).

图: 8xH100 集群上的 AllGather 带宽 (节点内)。

tpu all gather bw

Figure: AllGather bandwidth on a TPU v5e 8x16 cluster (along one axis).

图: TPU v5e 8x16 集群上的 AllGather 带宽 (沿一个轴)。

More on AllToAll costs:

更多关于 AllToAll 成本:

Here we can compare the approximation min⁡(K/Z)∗(Z−1)/Z\min(K / Z) * (Z - 1) / Z to the true value of (1−((Z−1)/Z)∗∗K)∗(Z−1)/Z(1 - ((Z - 1) / Z) ** K) * (Z - 1) / Z. They’re similar except for small values of ZZ.

在这里我们可以比较近似值 min⁡(K/Z)∗(Z−1)/Z\min(K / Z) * (Z - 1) / Z 与真实值 (1−((Z−1)/Z)∗∗K)∗(Z−1)/Z(1 - ((Z - 1) / Z) ** K) * (Z - 1) / Z. 除了 ZZ 值较小的情况外,它们是相似的。

all to all approx

Figure: a comparison of the approximate and true cost of a ragged AllToAll as the number of shards increases.

图: 随着分片数量增加,不规则 AllToAll 的近似成本与真实成本的比较。

Footnotes

  1. The GPU Tensor Core is the matrix multiplication sub-unit of the SM, while the TPU TensorCore is the umbrella unit that contains the MXU, VPU, and other components.

    GPU 的张量核心是 SM 的矩阵乘法子单元,而 TPU 的 TensorCore 是包含 MXU,VPU 和其他组件的总称单元。

    ↩
  2. NVIDIA doesn’t have a good name for this, so we use it only as the best of several bad options. The Warp Scheduler is primarily the unit that dispatches work to a set of CUDA cores, but we use it here to describe the control unit and the set of cores it controls.

    NVIDIA 对此没有一个好的命名,所以我们只是在几个不好的选项中选择了最好的一个。Warp 调度器主要是一个向一组 CUDA 核心分派工作的单元,但我们在这里用它来描述控制单元及其控制的核心集合。

    ↩
  3. Although SMs are independent, they are often forced to coordinate for peak performance because they all share a capacity-limited L2 cache.

    虽然 SM 是独立的,但为了达到峰值性能,它们通常被迫进行协调,因为它们都共享一个容量有限的 L2 缓存。

    ↩
  4. Newer GPUs support FMA (Fused-Multiply Add) instructions which technically do two FLOPs each cycle, a fact NVIDIA uses ruthlessly to double their reported specs.

    较新的 GPU 支持 FMA (融合乘加) 指令,严格来说每个周期执行两次 FLOP,NVIDIA 无情地利用这一事实将其报告的规格翻倍。

    ↩
  5. Historically, before the introduction of the Tensor Core, the CUDA cores were the main component of the GPU and were used for rendering, including ray-triangle intersections and shading. On today’s gaming GPUs, they still do a bulk of the rendering work, while TensorCores are used for up-sampling (DLSS), which allows the GPU to render at a lower resolution (fewer pixels = less work) and upsample using ML.

    历史上,在引入张量核心之前,CUDA 核心是 GPU 的主要组件,用于渲染,包括光线-三角形相交和着色。在今天的游戏 GPU 上,它们仍然承担着大量的渲染工作,而张量核心则用于上采样 (DLSS),这使得 GPU 能够以较低的分辨率进行渲染 (像素越少 = 工作量越少),并使用机器学习进行上采样。

    ↩
  6. NVIDIA doesn’t share many TC hardware details, so this is more a guess than definite fact – certainly, it doesn’t speak to how the TC is implemented. We know that a V100 can perform 256 FLOPs/TC/cycle. An A100 can do 512, H100 can do 1024, and while the B200 details aren’t published, it seems likely it’s about 2048 FLOPs/TC/cycle, since 2250e12 / (148 * 4 * 1.86e9) is about 2048. Some more details are confirmed here.

    NVIDIA 没有分享太多 TC 硬件细节,所以这更多是猜测而非确切事实——当然,这并没有说明 TC 是如何实现的。我们知道 V100 每 TC/周期可以执行 256 FLOPs。A100 可以执行 512,H100 可以执行 1024,虽然 B200 的细节尚未公布,但似乎可能是 2048 FLOPs/TC/周期,因为 2250e12 / (148 * 4 * 1.86e9) 大约是 2048。更多细节在这里得到确认。

    ↩
  7. In Ampere, the Tensor Core could be fed from a single warp, while in Hopper it requires a full SM (warpgroup) and in Blackwell it’s fed from 2 SMs. The matmuls have also become so large in Blackwell that the arguments (specifically, the accumulator) no longer fit into register memory/SMEM, so Blackwell adds TMEM to account for this.

    在 Ampere 中,张量核心可以由单个 warp 供给,而在 Hopper 中则需要一个完整的 SM (warpgroup),在 Blackwell 中则由 2 个 SM 供给。在 Blackwell 中,矩阵乘法也变得如此之大,以至于参数 (特别是累加器) 不再适合寄存器内存/SMEM,因此 Blackwell 增加了 TMEM 来解决这个问题。

    ↩
  8. Warps scheduled on a given SM are called “resident”.

    在给定 SM 上调度的 Warp 称为“常驻”.

    ↩
  9. Technically, the L2 cache is split in two, so half the SMs can access 25MB a piece on an H100. There is a link connecting the two halves, but at lower bandwidth.

    严格来说,L2 缓存被分成两部分,所以在 H100 上,每一半 SM 可以访问一块 25 MB 缓存。有一个连接两半的链接,但带宽较低。

    ↩
  10. The fact that the L2 cache is shared across all SMs effectively forces the programmer to run the SMs in a fairly coordinated way anyway, despite the fact that, in principle, they are independent units.

    L2 缓存由所有 SM 共享这一事实,实际上迫使程序员以一种相当协调的方式运行 SM,尽管原则上它们是独立的单元。

    ↩
  11. While NVIDIA made a B100 generation, they were only briefly sold and produced, allegedly due to design flaws that prevented them from running close to their claimed specifications. They struggled to achieve peak FLOPs without throttling due to heat and power concerns.

    虽然 NVIDIA 制造了 B100 这一代,但它们只是短暂销售和生产,据称是由于设计缺陷,导致它们无法接近其声称的规格运行。它们在不因热量和功率问题而降频的情况下难以达到峰值 FLOPs。

    ↩
  12. Before the deep learning boom, GPUs (“Graphics Processing Units”) did, well, graphics – mostly for video games. Video games represent objects with millions of little triangles, and the game renders (or “rasterizes”) these triangles into a 2D image that gets displayed on a screen 30-60 times a second (this frequency is called the framerate). Rasterization involves projecting these triangles into the coordinate frame of the camera and calculating which triangles overlap which pixels, billions of times a second. As you can imagine, this is very expensive, and it’s just the beginning. You then have to color each pixel by combining the colors of possibly several semi-opaque triangles that intersect the ray. GPUs were designed to do these operations extremely fast, with an eye towards versatility; you need to run many different GPU workloads (called “shaders”) at the same time, with no single operation dominating. As a result, consumer graphics-focused GPUs can do matrix multiplication, but it’s not their primary function.

    在深度学习热潮之前,GPU (“图形处理单元”) 做的是,嗯,图形处理——主要用于视频游戏。视频游戏用数百万个小三角形来表示物体,游戏每秒 30-60 次将这些三角形渲染 (或“光栅化”) 成显示在屏幕上的 2D 图像 (这个频率称为帧率)。光栅化涉及将这些三角形投影到相机的坐标系中,并计算哪些三角形与哪些像素重叠,每秒数十亿次。你可以想象,这非常昂贵,而且这仅仅是开始。然后你必须通过组合可能与光线相交的几个半透明三角形的颜色来为每个像素着色。GPU 被设计用来极快地执行这些操作,并着眼于通用性;你需要同时运行许多不同的 GPU 工作负载 (称为“着色器”),没有单一操作占主导地位。因此,消费级以图形为中心的 GPU 可以进行矩阵乘法,但这不是它们的主要功能。

    ↩
  13. It’s notable that this intensity stays constant across recent GPU generations. For H100s it’s 33.5 / 3.5 and for B200 it’s 80 / 8. Why this is isn’t clear, but it’s an interesting observation.

    值得注意的是,这种强度在最近几代 GPU 中保持不变。对于 H100,它是 33.5 / 3.5,对于 B200,它是 80 / 8。原因尚不清楚,但这是一个有趣的观察。

    ↩
  14. The term node is overloaded and can mean two things: the NVLink domain, aka the set of GPUs fully connected over NVLink interconnects, or the set of GPUs connected to a single CPU host. Before B200, these were usually the same, but in GB200 NVL72, we have an NVLink domain with 72 GPUs but still only 8 GPUs connected to each host. We use the term node here to refer to the NVLink domain, but this is controversial.

    术语“节点”是重载的,可以指两件事:NVLink 域,即通过 NVLink 互连完全连接的 GPU 集合,或连接到单个 CPU 主机的 GPU 集合。在 B200 之前,这两者通常是相同的,但在 GB200 NVL72 中,我们有一个包含 72 个 GPU 的 NVLink 域,但每个主机仍然只连接 8 个 GPU。我们在这里使用术语“节点”来指代 NVLink 域,但这有争议。

    ↩
  15. NVLink has been described to me as something like a souped-up PCIe connection, with low latency and protocol overhead but not designed for scalability/fault tolerance, while InfiniBand is more like Ethernet, designed for larger lossy networks.

    NVLink 被向我描述为一种增强版的 PCIe 连接,具有低延迟和协议开销,但不为可扩展性/容错性而设计,而 InfiniBand 更像以太网,专为更大的有损网络而设计。

    ↩
  16. Full-duplex here means 25GB/s each way, with both directions independent of each other. You can send a total of 50GB/s over the link, but at most 25GB/s in each direction.

    这里的全双工意味着每个方向 25GB/s,两个方向相互独立。你可以在链接上总共发送 50GB/s,但每个方向最多 25GB/s。

    ↩
  17. For instance, Meta trained LLaMA-3 on a datacenter network that differs significantly from this description, using Ethernet, a 3 layer switched fabric, and an oversubscribed switch at the top level.

    例如,Meta 在一个与此描述显著不同的数据中心网络上训练了 LLaMA-3,使用了以太网,一个 3 层交换结构,以及一个在顶层超额认购的交换机。

    ↩
  18. You can also think of each GPU sending its chunk of size bytes/N\text{bytes} / N to each of the other N−1N - 1 GPUs, for a total of (N−1)∗N∗bytes/N(N - 1) * N * bytes / N bytes communicated, which gives us the same answer.

    你也可以认为每个 GPU 将其大小为 bytes/N\text{bytes} / N 的块发送给其他 N−1N - 1 个 GPU,总共通信了 (N−1)∗N∗bytes/N(N - 1) * N * bytes / N 字节,算得的结果相同。

    ↩
  19. The true cost is actually (1−(Z−1Z)K)⋅Z−1Z(1 - \left(\frac{Z - 1}{Z}\right)^K) \cdot \frac{Z - 1}{Z} the expected number of distinct outcomes in KK dice rolls, but it is very close to the approximation given. See the Appendix for more details.

    实际成本为 (1−(Z−1Z)K)⋅Z−1Z(1 - \left(\frac{Z - 1}{Z}\right)^K) \cdot \frac{Z - 1}{Z},基于掷 KK 次骰子时不同结果数目的期望。这与上面的近似值非常接近。详见附录。

    ↩

补充说明

*Work done at Google DeepMind, now at MatX.

*这项工作完成于 Google DeepMind,现任职于 MatX。

引用

For attribution in academic contexts, please cite this work as:

学术写作中请按以下格式引用本书。

Austin et al., "How to Scale Your Model", Google DeepMind, online, 2025.

or as a BibTeX entry:

也可使用以下 BibTeX 条目。

@article{scaling-book,
  title = {How to Scale Your Model},
  author = {Austin, Jacob and Douglas, Sholto and Frostig, Roy and Levskaya, Anselm and Chen, Charlie and Vikram, Sharad
    and Lebron, Federico and Choy, Peter and Ramasesh, Vinay and Webson, Albert and Pope, Reiner},
  publisher = {Google DeepMind},
  howpublished = {Online},
  note = {Retrieved from https://jax-ml.github.io/scaling-book/},
  year = {2025}
}
原版章节与讨论