如何扩展你的模型(12):认识 GPU
中英对照第 12 篇(Bonus):GPU 怎么工作、怎么组网、roofline 与 TPU 有何不同——SM、Tensor Core、NVLink、SuperPod 与流水线并行。左栏原文,右栏译文,配图保留。
本篇属于系列 如何扩展你的模型(How To Scale Your Model) · 第 12 篇
原文:How To Scale Your Model(Google DeepMind,作者 Jacob Austin、Sholto Douglas、Roy Frostig、Anselm Levskaya、Charlie Chen、Sharad Vikram、Federico Lebron、Peter Choy、Vinay Ramasesh、Albert Webson、Reiner Pope)。
本站是中英对照排版:左栏是英文原文,右栏是对应的中文译文。不好直译的术语(roofline、strong scaling、ICI、MXU、KV cache、FSDP、TP 等)保留英文写法;原文配图全部保留。
本文是系列《如何扩展你的模型(How To Scale Your Model)》的第 12 篇,共 13 篇。系列目录。
原文以 MIT 许可证发布,版权归 Google LLC;本译文仅作学习交流之用,如有错漏以原文为准。
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:
现代 ML GPU(例如 H100、B200)基本上就是一堆专精矩阵乘法的计算核心(称为 Streaming Multiprocessors,即流多处理器,简称 SM),连接到一根高速内存条(称为 HBM)。示意图如下:
Each SM, like a TPU’s Tensor Core, has a dedicated matrix multiplication core (unfortunately also called a Tensor Core (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.)), a vector arithmetic unit (called a Warp Scheduler (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.)), 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. (Although SMs are independent, they are often forced to coordinate for peak performance because they all share a capacity-limited L2 cache.)
每个 SM 和 TPU 的 Tensor Core 类似,都有一个专用的矩阵乘法核心(可惜也叫 Tensor Core(GPU 的 Tensor Core 是 SM 内做矩阵乘法的子单元,而 TPU 的 TensorCore 是包含 MXU、VPU 等组件的总称单元。))、一个向量运算单元(称为 Warp Scheduler(NVIDIA 没有给它起个好名字,所以我们只能从几个糟糕选项里挑最好的一个。Warp Scheduler 主要负责把工作分派给一组 CUDA core,但我们在这里用它指代控制单元及其控制的那组 core。)),以及一个快速的片上缓存(称为 SMEM)。不同于最多只有 2 个独立「Tensor Core」的 TPU,现代 GPU 有 100 多个 SM(H100 上是 132 个)。每个 SM 都远不如一个 TPU Tensor Core 强大,但整个系统更灵活。每个 SM 大体上完全独立,所以一块 GPU 可以同时做几百件不同的事。(虽然 SM 相互独立,但由于它们共享一个容量有限的 L2 缓存,为了达到峰值性能往往又被迫协调。)
Let’s take a more detailed view of an H100 SM:
我们更仔细地看一下一个 H100 的 SM:
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 subpartition(SM 子分区),每个子分区包含一个 Tensor Core、16k 个 32 位寄存器,以及一个叫 Warp Scheduler 的 SIMD/SIMT 向量运算单元,它的各条 lane(ALU)被 NVIDIA 称为 CUDA Core。每个分区的核心组件可以说是 Tensor Core,它执行矩阵乘法、贡献了绝大部分 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. (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.) 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). (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 Core: 每个子分区包含一组叫 CUDA Core 的 ALU,做 SIMD/SIMT 向量运算。每个 ALU 一般每周期能做 1 次算术运算,例如 f32.add。(较新的 GPU 支持 FMA(Fused-Multiply Add,融合乘加)指令,严格说每周期做两次 FLOPs,NVIDIA 无情地利用了这一点把公布的规格翻倍。)每个子分区包含 32 个 fp32 core(以及数量较少的 int32 和 fp64 core),它们每周期都执行同一条指令。和 TPU 的 VPU 一样,CUDA core 负责 ReLU、逐点向量运算和归约(求和)。(历史上,在 Tensor Core 出现之前,CUDA core 是 GPU 的主要组件,用于渲染,包括射线-三角形求交和着色。在今天的游戏 GPU 上,它们仍承担大部分渲染工作,而 TensorCore 用于超分(DLSS),让 GPU 能以更低分辨率渲染(像素更少 = 工作量更少)再用 ML 上采样。)
- 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 ~ 1024bf16 FLOPs/cycle, roughly an 8x8x8 matmul. (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, since2250e12 / (148 * 4 * 1.86e9)is about 2048. Some more details are confirmed here.) - 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. (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.)
- 990 bf16 TFLOPs/s with 132 SM running at 1.76GHz means each H100 TC can do
- Tensor Core(TC): 每个子分区都有自己的 Tensor Core,它是一个类似 TPU MXU 的专用矩阵乘法单元。Tensor Core 贡献了 GPU 绝大部分的 FLOPs/s(例如 H100 上 Tensor Core 有 990 bf16 TFLOP/s,而 CUDA core 只有 66 TFLOPs/s)。
- 990 bf16 TFLOPs/s、132 个 SM 跑在 1.76GHz,意味着每个 H100 TC 每周期能做
7.5e12 / 1.76e9 / 4 ~ 1024次 bf16 FLOPs,大致是一个 8x8x8 的矩阵乘法。(NVIDIA 不怎么公开 TC 的硬件细节,所以这更多是猜测而非定论——当然,它也不能说明 TC 是如何实现的。我们知道 V100 每个 TC 每周期能做 256 FLOPs,A100 是 512,H100 是 1024,而 B200 的细节没公布,但看起来很可能约 2048 FLOPs/TC/周期,因为2250e12 / (148 * 4 * 1.86e9)约为 2048。更多细节在这里得到确认。)Blackwell 还引入了一个叫 TMEM 的新显存空间。(在 Ampere 中,Tensor Core 可以由单个 warp 喂入,而在 Hopper 中需要一个完整的 SM(warpgroup),在 Blackwell 里则由 2 个 SM 喂入。Blackwell 的矩阵乘法也大到参数(具体说是累加器)不再能放进寄存器/SMEM,所以 Blackwell 增加了 TMEM 来应对。)
- 990 bf16 TFLOPs/s、132 个 SM 跑在 1.76GHz,意味着每个 H100 TC 每周期能做
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 core 比 TPU 的 VPU 更灵活: GPU 的 CUDA core(自 V100 起)使用所谓的 SIMT(Single Instruction Multiple Threads,单指令多线程)编程模型,而 TPU 是 SIMD(Single Instruction Multiple Data,单指令多数据)模型。和 TPU VPU 里的 ALU 一样,子分区内的 CUDA core 每周期必须执行相同的操作(例如一个 core 在加两个浮点数,那么子分区里其他每个 CUDA core 也必须这么做)。但与 VPU 不同的是,每个 CUDA core(在 CUDA 编程模型里就是「线程」)有自己的指令指针,可以被独立地编程。当同一个 warp 里的两个线程被指示执行不同的操作时,你实际上会两个操作都做,把不需要执行分歧操作的 core 用 mask 屏蔽掉。
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 core 可以访问共享寄存器里的单个浮点数,并维护每线程状态。
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. (Warps scheduled on a given SM are called “resident”.) The Warp Scheduler automatically switches between active warps to hide I/O operations like memory loads. TPUs are generally single threaded by comparison.
CUDA core 的调度也更灵活: SM 的运行有点像一个多线程 CPU,因为它们可以并发「调度」很多程序(warp,每个 SM 最多 64 个),但每个 Warp Scheduler 在每个时钟周期内只会执行一个程序。(调度到某个 SM 上的 warp 称为「常驻」(resident)。)Warp Scheduler 会在活跃 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 = 256kiBper 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.
- 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 (
- 寄存器: 每个子分区有自己的寄存器堆,在 H100/B200 上有 16,384 个 32 位字(每个 SM
4 * 16384 * 4 = 256kiB),可由 CUDA core 访问。- 每个 CUDA core 一次最多只能访问 256 个寄存器,所以虽然每个 SM 最多可以调度 64 个「常驻 warp」,如果每个线程用 256 个寄存器,你一次只能放得下 8 个(
256 * 1024 / (4 * 32 * 256))。
- 每个 CUDA core 一次最多只能访问 256 个寄存器,所以虽然每个 SM 最多可以调度 64 个「常驻 warp」,如果每个线程用 256 个寄存器,你一次只能放得下 8 个(
- 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 share (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.) 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. (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.)
- 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 共享(严格说,L2 缓存分成两半,所以在 H100 上每半个 SM 组可以访问 25MB。两半之间有一条链路相连,但带宽较低。)一个相对较大的约 50MB L2 缓存,用来减少主显存访问。
- 它的容量与 TPU 的 VMEM 相近,但慢得多,而且不受程序员控制。这导致了一点「隔山打牛」的现象:程序员需要修改显存访问模式来确保 L2 缓存被用好。(L2 缓存被所有 SM 共享这一事实,实际上迫使程序员以相当协调的方式运行 SM,尽管原则上它们是彼此独立的单元。)
- 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 Tensor Core 的带宽称为 HBM 带宽或显存带宽,H100 上约 3.35TB/s,B200 上约 9TB/s。
Summary of GPU specs
GPU 规格小结
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 | Generation | Clock Speed | SMs/chip | SMEM capacity/SM | L2 capacity/chip | HBM capacity/chip |
|---|---|---|---|---|---|---|
| V100 | Volta | 1.25GHz/1.38GHz | 80 | 96kB | 6MB | 32GB |
| A100 | Ampere | 1.10GHz/1.41GHz | 108 | 192kB | 40MB | 80GB |
| H100 | Hopper | 1.59GHz/1.98GHz | 132 | 256kB | 50MB | 80GB |
| H200 | Hopper | 1.59GHz/1.98GHz | 132 | 256kB | 50MB | 141GB |
| B200 | Blackwell | ? | 148 | 256kB | 126MB | 192GB |
| GPU | 代次 | 时钟频率 | SM 数/芯片 | SMEM 容量/SM | L2 容量/芯片 | HBM 容量/芯片 |
|---|---|---|---|---|---|---|
| V100 | Volta | 1.25GHz/1.38GHz | 80 | 96kB | 6MB | 32GB |
| A100 | Ampere | 1.10GHz/1.41GHz | 108 | 192kB | 40MB | 80GB |
| H100 | Hopper | 1.59GHz/1.98GHz | 132 | 256kB | 50MB | 80GB |
| H200 | Hopper | 1.59GHz/1.98GHz | 132 | 256kB | 50MB | 141GB |
| B200 | Blackwell | ? | 148 | 256kB | 126MB | 192GB |
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 与带宽数字:
| GPU | Generation | HBM BW/chip | FLOPs/s/chip (bf16/fp16) | FLOPs/s/chip (fp8/int8) | FLOPs/s/chip (fp4) |
|---|---|---|---|---|---|
| V100 | Volta | 9.0e11 | — | — | — |
| A100 | Ampere | 2.0e12 | 3.1e14 | 6.2e14 | — |
| H100 | Hopper | 3.4e12 | 9.9e14 | 2.0e15 | — |
| H200 | Hopper | 4.8e12 | 9.9e14 | 2.0e15 | — |
| B200 | Blackwell | 8.0e12 | 2.3e15 | 4.5e15 | 9.0e15 |
| GPU | 代次 | HBM 带宽/芯片 | FLOPs/s/芯片 (bf16/fp16) | FLOPs/s/芯片 (fp8/int8) | FLOPs/s/芯片 (fp4) |
|---|---|---|---|---|---|
| V100 | Volta | 9.0e11 | — | — | — |
| A100 | Ampere | 2.0e12 | 3.1e14 | 6.2e14 | — |
| H100 | Hopper | 3.4e12 | 9.9e14 | 2.0e15 | — |
| H200 | Hopper | 4.8e12 | 9.9e14 | 2.0e15 | — |
| B200 | Blackwell | 8.0e12 | 2.3e15 | 4.5e15 | 9.0e15 |
We exclude B100 since it wasn’t mass-produced. (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.) Some specs depend slightly on the precise version of the GPU, since NVIDIA GPUs aren’t as standard as TPUs.
我们排除了 B100,因为它没有被量产。(NVIDIA 确实出过 B100 一代,但只短暂地销售和生产过,据说是因为设计缺陷导致它无法接近宣称的规格。由于散热和功耗问题,它很难在不降频的情况下达到峰值 FLOPs。)有些规格会因 GPU 的精确版本而略有不同,因为 NVIDIA GPU 不像 TPU 那样标准化。
Here’s a helpful cheat sheet comparing GPU and TPU components:
下面是一张比较 GPU 与 TPU 组件的实用速查表:
| GPU | TPU | What is it? |
|---|---|---|
| Streaming Multiprocessor (SM) | Tensor Core | Core “cell” that contains other units |
| Warp Scheduler | VPU | SIMD vector arithmetic unit |
| CUDA Core | VPU ALU | SIMD ALU |
| SMEM (L1 Cache) | VMEM | Fast on-chip cache memory |
| Tensor Core | MXU | Matrix multiplication unit |
| HBM (aka GMEM) | HBM | High bandwidth high capacity memory |
| GPU | TPU | 它是什么? |
|---|---|---|
| Streaming Multiprocessor (SM) | Tensor Core | 包含其他单元的核心「单元」 |
| Warp Scheduler | VPU | SIMD 向量运算单元 |
| CUDA Core | VPU ALU | SIMD ALU |
| SMEM (L1 Cache) | VMEM | 快速片上缓存显存 |
| Tensor Core | MXU | 矩阵乘法单元 |
| HBM (aka GMEM) | HBM | 高带宽大容量显存 |
GPUs vs. TPUs at the chip level
芯片层面:GPU vs. 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. (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.) 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。(在深度学习热潮之前,GPU(「Graphics Processing Unit」,图形处理器)做的就是图形——主要是给电子游戏用。电子游戏用几百万个小三角形来表示物体,游戏把这些三角形渲染(或「光栅化」)成一张 2D 图像,以每秒 30-60 次的频率显示在屏幕上(这个频率叫帧率)。光栅化要把这些三角形投影到相机的坐标系,并计算哪些三角形覆盖哪些像素,每秒要算几十亿次。可以想象,这非常昂贵,而这只是开始。之后你还要给每个像素上色,把与光线相交的若干半透明三角形的颜色混合起来。GPU 被设计得极快地做这些操作,同时兼顾通用性;你需要同时运行许多不同的 GPU 工作负载(称为「shader」),且没有任何单一操作占主导。因此,面向消费级图形的 GPU 能做矩阵乘法,但那不是它的主要功能。)从某种程度上,这段历史解释了现代 GPU 为什么长这样。它们不是纯粹为 LLM 或 ML 模型设计的,而是作为通用加速器设计的,硬件追求的「通用性」既是福也是祸。GPU 应用到新任务上时更常「直接就能用」,对好编译器的依赖远低于 TPU。但这也让它们更难推理、更难压榨出 roofline 性能,因为太多编译器特性都可能造成瓶颈。
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 comparison of GPUs to TPU that highlights this point:
GPU 更模块化。 TPU 有 1-2 个大 Tensor Core,而 GPU 有几百个小 SM。同样,每个 TC 有一个大 VPU,由 4 个可独立编程的 8x128 单元组成(共 4096 个 ALU);相比之下,一块 H100 有 132 * 4 = 528 个独立的 SIMD 单元,每个 32 宽(总计 16k ALU)。下面是一张凸显这一点的 GPU 与 TPU 的 1 对比:
| GPU | TPU | H100 # | TPU v5p # |
|---|---|---|---|
| SM (streaming multiprocessor) | Tensor Core | 132 | 2 |
| Warp Scheduler | VPU slots | 528 | 8 |
| SMEM (L1 cache) | VMEM | 32MB | 128MB |
| Registers | Vector Registers (VRegs) | 32MB | 256kB |
| Tensor Core | MXU | 528 | 8 |
| GPU | TPU | H100 数量 | TPU v5p 数量 |
|---|---|---|---|
| SM(流多处理器) | Tensor Core | 132 | 2 |
| Warp Scheduler | VPU 槽位 | 528 | 8 |
| SMEM(L1 缓存) | VMEM | 32MB | 128MB |
| 寄存器 | 向量寄存器 (VRegs) | 32MB | 256kB |
| Tensor Core | MXU | 528 | 8 |
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 程序员可以直接启动几十个不同的 kernel,每个跑在一个完全独立的 SM 上。另一方面,这些 kernel 可能性能极差,因为它们在争抢 L2 缓存、或者无法合并显存加载;由于硬件控制了太多运行时行为,很难推理背后到底发生了什么。因此,TPU 往往能用更少的功夫更接近峰值 roofline 性能。
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 <span class=“katex-ignore”>$10/hour for an H200 compared to <span class=“katex-ignore”>$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 约 <span class=“katex-ignore”>$10/小时,而 TPU v5p 是 <span class=“katex-ignore”>$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,这能让 TPU 在 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 core]: 一块 H100 有多少个 fp32 CUDA core(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 core,所以 132 * 4 * 32 = 16896 个 CUDA core。B200 有 148 个 SM,共 18944 个。TPU v5p 有 2 个 TensorCore(通常通过 Megacore 相连),每个 TensorCore 有一个 (8, 128) lane 的 VPU,每条 lane 有 4 个独立 ALU,所以 2 * 4 * 8 * 128 = 8192 个 ALU。这大约是 H100 向量 lane 数量的一半,运行频率也大致相同。
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(boost 可达 1.98GHz)。假设每个 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(fused-multiply-add,融合乘加)算作两次 FLOPs,但大多数情况下这没什么用。我们能做 990 bfloat16 矩阵乘法 TFLOPs/s,所以忽略 FMA 的话,Tensor Core 的 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 的峰值 fp16 FLOPs 是 990e12,带宽是 3.35e12 字节/秒。所以临界强度是 990e12 / 3.35e12 = 295,和 TPU 的 240 相当接近。B200 是 2250e12 / 8e12 = 281,非常接近。这意味着和 TPU 类似,我们需要大约 280 的 batch size 才能在矩阵乘法里达到计算受限。
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 的 fp8 FLOPs 恰好都是 2 倍,所以峰值强度也分别翻倍到 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 + 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.
由上可知,在 batch size 低于 281 个 token 时我们是通信受限的。因此第一个纯粹是带宽受限。我们要读或写 $2BD + 2DF + 2BF$ 字节(2*64*4096 + 2*4096*8192 + 2*64*8192=69e6),带宽是 8e12 字节/秒,所以大约要 69e6 / 8e12 = 8.6us。实际上我们很可能只能拿到总带宽的一部分,所以可能接近 10-12us。当我们增大 batch size,就完全变成计算受限,所以预计 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 的 VMEM(120MB)的一半,尽管 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 core 在一次 FMA(融合乘加)操作里每周期能做 2 次 FLOPs,估算峰值时钟周期。
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 core,所以每周期能做 18944 * 2 = 37888 FLOPs。因此 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 $T_\text{math}$ and $T_\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] 向量相加应该花多久。分别算出 $T_\text{math}$ 和 $T_\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 字节。算比值,我们有 总 FLOPs / 总字节 = 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. (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.) So we’re going to be horribly comms bound. Thus our runtime is just
如上所算,忽略 FMA 我们能做大约 33.5 TFLOPs/s(boost)。这还只是所有 CUDA core 都用上的情况。对 N = 1024,我们最多只能用 1024 个 CUDA core 或 8 个 SM,会更慢(假设计算受限,大约慢 16 倍)。我们的显存带宽是 3.35e12 字节/秒。所以峰值硬件强度是 33.5e12 / 3.35e12 = 10。(值得注意的是,这个强度在近几代 GPU 中保持不变。H100 是 33.5 / 3.5,B200 是 80 / 8。原因不明,但这是个有趣的观察。)所以我们会严重通信受限。因此运行时就是
$$T = \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,roofline 约 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 环面(torus)连接,每颗 TPU 只与邻居相连。这意味着两颗 TPU 之间发消息必须经过中间的每一颗 TPU,也迫使我们在 mesh 上只使用均匀的通信模式。这在某些方面很不方便,但也意味着每颗 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 GB200 (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.)) 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 称为一个 node(节点,GB200 最多 72 颗(「node」这个词有点重载,可以指两件事:NVLink 域,即通过 NVLink 互连全连接的那组 GPU;或者连到单个 CPU host 的那组 GPU。在 B200 之前这两者通常相同,但在 GB200 NVL72 里,NVLink 域有 72 颗 GPU,而每台 host 仍只连 8 颗 GPU。我们这里用 node 指 NVLink 域,不过这一点有争议。)),它们用称为 NVLink 的高带宽互连在一跳之内彼此相连;这些节点再用挂到每颗 GPU 上的 NIC,通过带宽较低的 InfiniBand (IB) 或以太网连成更大的单元(称为 SU 或 Scalable Unit);这些单元又能用更高层的交换机连成任意大的规模。
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. (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.) 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 互连相连。(有人向我形容 NVLink 像是增强版的 PCIe 连接:延迟和协议开销低,但不是为可扩展性/容错设计的;而 InfiniBand 更像以太网,为更大的、有丢包的网络设计。)每个节点包含若干高带宽 NVSwitch,在本地所有 GPU 之间交换数据包。节点层面的实际拓扑随时间变化不小,包括每节点交换机数量;但对 H100,我们每节点有 4 个 NVSwitch,GPU 以 5 + 4 + 4 + 5 的链路模式连到它们上,如下图所示:
For the Hopper generation (NVLink 4.0), each NVLink link has 25GB/s of full-duplex (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.) 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 的全双工带宽(全双工在这里指每个方向各 25GB/s,两个方向相互独立。一条链路上总共可发 50GB/s,但每个方向最多 25GB/s。)(B200 是 50GB/s),所以每颗 GPU 进入网络有 18 * 25=450GB/s 的全双工带宽。巨大的 NVSwitch 最多有 64 个 NVLink 端口,意味着一个带 4 个交换机的 8xH100 节点最多能承载 64 * 25e9 * 4=6.4TB/s 的带宽。下面是这些数字随 GPU 代次的演变概览:
| NVLink Gen | NVSwitch Gen | GPU Generation | NVLink Bandwidth (GB/s, full-duplex) | NVLink Ports / GPU | Node GPU to GPU bandwidth (GB/s full-duplex) | Node size (NVLink domain) | NVSwitches per node |
|---|---|---|---|---|---|---|---|
| 3.0 | 2.0 | Ampere | 25 | 12 | 300 | 8 | 6 |
| 4.0 | 3.0 | Hopper | 25 | 18 | 450 | 8 | 4 |
| 5.0 | 4.0 | Blackwell | 50 | 18 | 900 | 8/72 | 2/18 |
| NVLink 代次 | NVSwitch 代次 | GPU 代次 | NVLink 带宽(GB/s,全双工) | NVLink 端口 / GPU | 节点内 GPU 到 GPU 带宽(GB/s,全双工) | 节点规模(NVLink 域) | 每节点 NVSwitch 数 |
|---|---|---|---|---|---|---|---|
| 3.0 | 2.0 | Ampere | 25 | 12 | 300 | 8 | 6 |
| 4.0 | 3.0 | Hopper | 25 | 18 | 450 | 8 | 4 |
| 5.0 | 4.0 | Blackwell | 50 | 18 | 900 | 8/72 | 2/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 颗和 72 颗两种系统的细节都列出来。
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 的 4 个 NVSwitch,每个有 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 [二分带宽]:二分带宽(bisection bandwidth)定义为把网络任意分成对等两半时,最小可用的带宽。换句话说,如果把一个网络切成相等的两半,横跨两半的带宽有多少?你能算出 8xH100 节点的二分带宽吗?提示: 二分带宽通常包含两个方向的流量。
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 在每一半,每颗都能向另一半出口 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 字节的数组,在一个 8xH100 节点上做一次(吞吐受限的)AllGather 要多久?对 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 / N$ bytes (where N=8, the node size). We can imagine each node sending its bytes to each of the other $N - 1$ nodes one after the other, leading to a total of (N - 1) turns each with $T_\text{comms} = (B / (N * W_\text{unidirectional}))$, or $T_\text{comms} = (N - 1) * B / (N * W_\text{unidirectional})$. This is approximately $B / W_\text{uni}$ or $B / \text{450e9}$.
答案: 每颗 GPU 能出口 450GB/s,每颗 GPU 有 $B / N$ 字节(N=8,即节点规模)。我们可以想象每个节点依次把它的字节发给其他 $N - 1$ 个节点,总共 (N - 1) 轮,每轮 $T_\text{comms} = (B / (N * W_\text{unidirectional}))$,即 $T_\text{comms} = (N - 1) * B / (N * W_\text{unidirectional})$。这近似等于 $B / W_\text{uni}$,或 $B / \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.5ms)。
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. (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.)
节点之上,GPU 网络的拓扑就没那么标准化了。NVIDIA 公布了一套参考的 DGX SuperPod 架构,用 InfiniBand 连接比单个节点更多的 GPU,但客户和数据中心厂商可以自由按需定制。(例如,Meta 在一个与这套描述差异很大的数据中心网络上训练 LLaMA-3,用的是以太网、三层交换架构,以及顶层超订(oversubscribed)的交换机。)
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 系统的示意图,最下面一行每个方块是一个 8xH100 节点,含 8 颗 GPU、8 张 400Gbps CX7 NIC(每颗 GPU 一张)和 4 个 NVSwitch。
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).
Scalable Unit: 每 32 个节点组成一个「Scalable Unit」(或 SU),挂在同一组 8 个 leaf InfiniBand 交换机下。这个 SU 有 256 颗 GPU、每节点 4 个 NVSwitch,以及 8 个 InfiniBand leaf 交换机。图中所有布线都是 InfiniBand NDR(50GB/s 全双工),配 64 端口 NDR IB 交换机(每个端口也是 50GB/s)。注意 IB 交换机的带宽是 NVSwitch 的 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 个顶层「spine」IB 交换机把 4 个这样的 SU 连起来,得到 1024 颗 GPU:512 个节点级 NVSwitch、32 个 leaf IB 交换机、16 个 spine IB 交换机,总共 512 + 32 + 16 = 560 个交换机。Leaf 交换机按每 32 个节点一组连到节点,所以每 256 颗 GPU 有 8 个 leaf 交换机。所有 leaf 交换机都连到所有 spine 交换机。
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 网络(称为「scale-out 网络」)的整体拓扑是一棵胖树(fat tree),其线缆和交换机保证节点层面之上的完整二分带宽(这里是 400GB/s)。也就是说,如果把节点分成两半,每个节点可以同时以 400GB/s 出口到另一半里的某个节点。更关键的是,这意味着 scale-out 网络里的 AllReduce 带宽大致是恒定的!虽然实现上未必如此,但你可以想象在 scale-out 网络里对任意多的节点做环形归约,因为你可以构造一个包含每一个节点的环。
| Level | GPUs | Switches per Unit | Switch Type | Bandwidth per Unit (TB/s, full-duplex) | GPU-to-GPU Bandwidth (GB/s, full-duplex) | Fat Tree Bandwidth (GB/s, full-duplex) |
|---|---|---|---|---|---|---|
| Node | 8 | 4 | NVL | 3.6 | 450 | 450 |
| Leaf | 256 | 8 | IB | 12.8 | 50 | 400 |
| Spine | 1024 | 16 | IB | 51.2 | 50 | 400 |
| 层级 | GPU 数 | 每单元交换机数 | 交换机类型 | 每单元带宽(TB/s,全双工) | GPU 到 GPU 带宽(GB/s,全双工) | 胖树带宽(GB/s,全双工) |
|---|---|---|---|---|---|---|
| Node | 8 | 4 | NVL | 3.6 | 450 | 450 |
| Leaf | 256 | 8 | IB | 12.8 | 50 | 400 |
| Spine | 1024 | 16 | IB | 51.2 | 50 | 400 |
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 的交换结构理论上可以通过添加更多交换机或更多层间接来扩展到任意规模,代价是额外的延迟和昂贵的网络交换机。
Takeaway: Within an H100 node, we have a full fat tree bandwidth of 450GB/s from each GPU, while beyond the node, this drops to 400GB/s node-to-node. This will turn out to be critical for communication primitives.
要点:在一个 H100 节点内,每颗 GPU 有 450GB/s 的完整胖树带宽,而在节点之上,这降到节点间 400GB/s。这对通信原语至关重要。
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 NVL72: NVIDIA 最近开始生产新的 GB200 NVL72 GPU 集群,把 72 颗 GPU 组合进一个 NVLink 域,具备完整的 900GB/s GPU 到 GPU 带宽。这些域随后可以连成更大的 SuperPod,IB 胖树带宽按比例提高(9 倍)。下面是该拓扑的示意图:
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.
从单个节点数出口带宽(上图中的橙色线),我们到 leaf 层有 4 * 18 * 400 / 8 = 3.6TB/s 的带宽,是 H100 的 9 倍(正如节点里的 GPU 数是 9 倍)。这意味着关键的节点出口带宽高得多,跨节点集合通信带宽实际上可能低于节点内带宽。更多讨论见附录 A。
| Node Type | GPUs per node | GPU egress bandwidth | Node egress bandwidth |
|---|---|---|---|
| H100 | 8 | 450e9 | 400e9 |
| B200 | 8 | 900e9 | 400e9 |
| GB200 NVL72 | 72 | 900e9 | 3600e9 |
| 节点类型 | 每节点 GPU 数 | GPU 出口带宽 | 节点出口带宽 |
|---|---|---|---|
| H100 | 8 | 450e9 | 400e9 |
| B200 | 8 | 900e9 | 400e9 |
| GB200 NVL72 | 72 | 900e9 | 3600e9 |
Takeaway: GB200 NVL72 SuperPods drastically increase the node size and egress bandwidth from a given node, which changes our rooflines significantly.
要点:GB200 NVL72 SuperPod 大幅增加了节点规模和单个节点的出口带宽,从而显著改变了我们的 roofline。
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/sof 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’s32 * 400 / 8 = 12.8TB/sfor 32 nodes, again exactly 400GB/s. - Then at the spine level we have
8 * 16 * 2400Gbps NDR IB cables connecting each SU to the spine, giving each SU8 * 16 * 2 * 400 / 8 = 12.8 TB/sof bandwidth to the leaf. Again, this is 400GB/s per node. We have 16 spine switches, each with 3.2TB/s, giving us16 * 3.2 = 51.2 TB/s, which with 128 nodes is again 400GB/s.
- 首先,每个节点有 8 条 400Gbps NDR IB 线缆连到 leaf 交换机,给每个节点
8 * 400 / 8 = 400 GB/s到 leaf 的带宽。我们有 8 个 leaf 交换机,每个 3.2TB/s(64 条 400 Gbps 链路),但 64 个端口里只能用 32 个来从 SU 入流量,所以是32 * 400 / 8 = 12.8TB/s(对应 32 个节点),仍是恰好 400GB/s。 - 然后在 spine 层,我们有
8 * 16 * 2条 400Gbps NDR IB 线缆把每个 SU 连到 spine,给每个 SU8 * 16 * 2 * 400 / 8 = 12.8 TB/s到 leaf 的带宽。同样,这是每节点 400GB/s。我们有 16 个 spine 交换机,每个 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.
因此无论怎么切分节点,节点之间都有 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 倍的 spine 交换机,于是会有 8 个 SU 配 32 个 spine 交换机,带宽足够了。
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.
一个问题是我们每个 leaf 交换机只有 64 个端口,而上图中已经把它们全用完了。不过,把每个 spine 的 2 条 400 Gbps NDR 线缆改成 1 条就很容易,带宽总量相同,还能省下一些端口。
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 称之为「core 交换机」,用一个 4096 GPU 集群配 128 个 spine 交换机和 64 个 core 交换机来搭建。你可以算一算,证明这能提供足够的带宽。
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.
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. (You can also think of each GPU sending its chunk of size $\text{bytes} / N$ to each of the other $N - 1$ GPUs, for a total of $(N - 1) * N * bytes / N$ bytes communicated, which gives us the same answer.) The cost of each hop is $T_\text{hop} = \text{bytes} / (N * \text{GPU egress bandwidth})$, so the overall cost is
AllGather 或 ReduceScatter: 对节点层面的 AllGather 或 ReduceScatter,你可以像 TPU 一样沿一个环来做,每一跳都用上完整的 GPU 到 GPU 带宽。把 GPU 任意排序,沿环发送数组的一部分,用满 GPU 到 GPU 带宽。(你也可以这样想:每颗 GPU 把大小为 $\text{bytes} / N$ 的块发给其他 $N - 1$ 颗 GPU,总共通信 $(N - 1) * N * bytes / N$ 字节,得到同样的答案。)每一跳的代价是 $T_\text{hop} = \text{bytes} / (N * \text{GPU egress bandwidth})$,所以总代价是
$$T_\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 组合起来,代价翻倍。
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)$ hops instead of $N - 1$, although the total cost is still the same.
如果你在意延迟(例如数组非常小),你可以做树形归约:先在 2 个一组内 AllReduce,然后 4 个、8 个,总共 $\log(N)$ 跳而不是 $N - 1$ 跳,尽管总代价仍然相同。
Takeaway: the cost to AllGather or ReduceScatter an array of B bytes within a single node is about $T_\text{comms} = B * (8 - 1) / (8 * W_\text{GPU egress}) \approx B / W_\text{GPU egress}$. This is theoretically around $B / \text{450e9}$ on an H100 and $B / \text{900e9}$ on a B200. An AllReduce has 2x this cost unless in-network reductions are enabled.
要点: 在单个节点内对 B 字节的数组做 AllGather 或 ReduceScatter 的代价大约是 $T_\text{comms} = B * (8 - 1) / (8 * W_\text{GPU egress}) \approx B / W_\text{GPU egress}$。理论上在 H100 上约 $B / \text{450e9}$,B200 上约 $B / \text{900e9}$。AllReduce 的代价是它的 2 倍,除非启用了网络内归约。
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=1024$, $F=16,384$.
随堂测验 1 [AllGather 时间]: 用一个 8xH100 节点、450 GB/s 全双工带宽,AllGather(bf16[BX, F]) 要多久?设 $B=1024$,$F=16,384$。
Click here for the answer.
点击这里看答案。
Answer: We have a total of $2 \cdot B \cdot F$ bytes, with 450e9 unidirectional bandwidth. This would take roughly $T_\text{comms} = (2 \cdot B \cdot F) / \text{450e9}$, or more precisely $(2 \cdot B \cdot F \cdot (8 - 1)) / (8 \cdot \text{450e9})$. Using the provided values, this gives us roughly $(2 \cdot 1024 \cdot 16384) / \text{450e9} = \text{75us}$, or more precisely, $\text{65us}$.
答案: 总共有 $2 \cdot B \cdot F$ 字节,单向带宽 450e9。这大约要 $T_\text{comms} = (2 \cdot B \cdot F) / \text{450e9}$,更精确地说是 $(2 \cdot B \cdot F \cdot (8 - 1)) / (8 \cdot \text{450e9})$。代入给定的值,大约是 $(2 \cdot 1024 \cdot 16384) / \text{450e9} = \text{75us}$,更精确地说是 $\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 / N$ bytes and sends $(B / N^2)$ bytes to $N - 1$ target nodes for a total of
AllToAll: 节点内的 GPU 是全互联的,这让 AllToAll 做起来相当容易。每颗 GPU 直接发给目标节点即可。在节点内,对 B 字节,每颗 GPU 有 $B / N$ 字节,并向 $N - 1$ 个目标节点各发 $(B / N^2)$ 字节,总共
$$T_\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)$. Thus, within a single node, we get a 2X theoretical speedup in runtime ($B / 4W$ vs. $B / 8W$).
与 TPU 相比,那里的代价是 $B / (4W)$。因此在单个节点内,我们在运行时上获得 2 倍的理论加速($B / 4W$ 对 $B / 8W$)。
For Mixture of Expert (MoE) models, we frequently want to do a sparse or ragged AllToAll, where we guarantee at most $k$ of $N$ shards on the output dimension are non-zero, that is to say $T_\text{AllToAll} \rightarrow K[B, N]$ where at most $k$ of $N$ entries on each axis are non-zero. The cost of this is reduced by $k/N$, for a total of about $\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 $k$ non-zero, giving us approximately $(N-1)/N \cdot \min(k/N, 1) \cdot B / (W \cdot N)$. (The true cost is actually $$(1 - \left(\frac{Z - 1}{Z}\right)^K) \cdot \frac{Z - 1}{Z}$$ the expected number of distinct outcomes in $K$ dice rolls, but it is very close to the approximation given. See the Appendix for more details.)
对混合专家(MoE)模型,我们经常想做稀疏或 ragged AllToAll,即保证输出维度上 $N$ 个分片里至多 $k$ 个非零,也就是说 $T_\text{AllToAll} \rightarrow K[B, N]$,其中每条轴上 $N$ 个条目里至多 $k$ 个非零。代价会降低 $k/N$,总共约 $\min(k/N, 1) \cdot B / (W \cdot N)$。对 MoE,我们常随机独立地挑非零值,所以有一定概率非零值少于 $k$,给出大约 $(N-1)/N \cdot \min(k/N, 1) \cdot B / (W \cdot N)$。(真实代价其实是 $$(1 - \left(\frac{Z - 1}{Z}\right)^K) \cdot \frac{Z - 1}{Z}$$,即 K 次掷骰中不同结果的期望数量,但与上面的近似非常接近。详见附录。)
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 时间]: 用一个 8xH100 节点、450 GB/s 单向带宽,AllToAllX->N(bf16[BX, N]) 要多久?如果已知 8 个条目里只有 4 个非零呢?
Click here for the answer.
点击这里看答案。
Answer: Note that here $B$ is the batch dimension of the array, so the total array size is $V = 2 \cdot B \cdot N$ bytes. From the above, we know that in the dense case, the cost is $V \cdot (N-1) / (W \cdot N^2)$, or roughly $V / (W \cdot N)$. If we know only $\frac{1}{2}$ the entries will be non-padding, we can send $V \cdot k/N / (W \cdot N) = V / (2 \cdot W \cdot N)$, roughly half the overall cost.
答案: 注意这里 $B$ 是数组的 batch 维,所以数组总大小是 $V = 2 \cdot B \cdot N$ 字节。由上可知,稠密情况下代价是 $V \cdot (N-1) / (W \cdot N^2)$,约 $V / (W \cdot N)$。如果已知只有 $\frac{1}{2}$ 的条目非 padding,我们可以发送 $V \cdot k/N / (W \cdot N) = V / (2 \cdot W \cdot N)$,约为总代价的一半。
Takeaway: The cost of an AllToAll on an array of $B$ bytes on GPU within a single node is about $T_\text{comms} = (B \cdot (8 - 1)) / (8^2 \cdot W_\text{GPU egress}) \approx B / (8 \cdot W_\text{GPU egress})$. For a ragged (top-$k$) AllToAll, this is decreased further to $(B \cdot k) / (64 \cdot W_\text{GPU egress})$.
要点: 在单个节点内对 $B$ 字节的数组做 AllToAll 的代价大约是 $T_\text{comms} = (B \cdot (8 - 1)) / (8^2 \cdot W_\text{GPU egress}) \approx B / (8 \cdot W_\text{GPU egress})$。对 ragged(top-$k$)AllToAll,这进一步降到 $(B \cdot k) / (64 \cdot W_\text{GPU egress})$。
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 \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 \cdot W \cdot (8 - 1) / 8$ 计算,理论上衡量的是实际链路带宽。你会注意到我们确实接近了 370GB/s,低于 450GB/s 但相当接近,不过只在约 10GB/设备时如此。这意味着虽然这些估计在理论上正确,但要实现它需要很大的消息。
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)。
Takeaway: although NVIDIA claims bandwidths of about 450GB/s over an H100 NVLink, it is difficult in practice to exceed 370 GB/s, so adjust the above estimates accordingly.
要点: 虽然 NVIDIA 声称 H100 NVLink 上有约 450GB/s 的带宽,但实践中很难超过 370 GB/s,所以上面的估计要相应调整。
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」(Scalable Hierarchical Aggregation and Reduction Protocol),允许「网络内归约」。这意味着网络交换机本身可以做归约操作,并把结果多播(MultiCast)到多个目标 GPU:
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 出口两次,同时还降低了网络延迟。
$$T_\text{SHARP AR comms} = \frac{\text{bytes}}{\text{GPU egress bandwidth}}$$
Note that this is exact and not off by a factor of $1/N$, since each GPU egresses $B \cdot (N - 1) / N$ first, then receives the partially reduced version of its local shard (ingress of $B/N$), finishes the reductions, then egresses $B/N$ again, then ingresses the fully reduced result (ingress of $B \cdot (N - 1) / N$), resulting in exactly $B$ bytes ingressed.
注意这是精确的,没有 $1/N$ 的偏差,因为每颗 GPU 先出口 $B \cdot (N - 1) / N$,然后收到它本地分片的部分归约版本(入流量 $B/N$),完成归约,再出口 $B/N$,然后收到完整归约的结果(入流量 $B \cdot (N - 1) / N$),结果恰好入流量为 $B$ 字节。
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 倍。
Takeaway: in theory, NVIDIA SHARP (available on most NVIDIA switches) should reduce the cost of an AllReduce on $B$ bytes from about $2 * B / W$ to $B / W$. However, in practice we only see a roughly 30% improvement in bandwidth. Since pure AllReduces are fairly rare in LLMs, this is not especially useful.
要点: 理论上,NVIDIA SHARP(大多数 NVIDIA 交换机都有)应把 $B$ 字节上 AllReduce 的代价从约 $2 * B / W$ 降到 $B / W$。但实践中我们只看到约 30% 的带宽提升。由于纯 AllReduce 在 LLM 里相当少见,这并不特别有用。
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 $B$ bytes up to the leaf instead of $B * N$.
当我们走到节点之上,代价就微妙一些。在树上做归约时,你可以想象从下往上归约:先在节点内,再在 leaf 层,然后在 spine 层,每层用常规算法。尤其对 AllReduce,你可以看到这让我们总体上通信更少的数据,因为节点层 AllReduce 之后,我们只需向上出口 $B$ 字节而不是 $B * 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),与树形归约的任何细节无关。
$$T_\text{AG or RS comms} = \frac{\text{bytes}}{W_\text{node egress}} \underset{H100}{=} \frac{\text{bytes}}{\text{400e9}}$$
where $W_\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 $W_\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
其中 $W_\text{node}$ 出口对上图 H100 网络(每个节点出口 8 条 400Gbps IB 链路)一般是 400GB/s。最清晰的想象方式,是假想对集群里的每个节点做一次环形归约。因为有胖树拓扑,我们总可以构造一个任意两个节点之间都有 $W_\text{node}$ 出口带宽的环,做一次常规归约。节点层归约(几乎)永远不会成为瓶颈,因为它总体带宽更高、延迟更好,尽管一般来说代价是
$$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:
我们可以更精确地指出,我们实际上是在网络的每一层做环形归约,而这些大多可以重叠,于是有:
$$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 $D_i$ is the degree at depth $i$ (the number of children at depth $i$), $W_\text{link i}$ is the bandwidth of the link connecting each child to node $i$.
其中 $D_i$ 是深度 $i$ 处的度(深度 $i$ 处子节点数量),$W_\text{link i}$ 是把每个子节点连到节点 $i$ 的链路带宽。
Using this, we can calculate the available AllGather/AllReduce bandwidth as $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 带宽算作 $min_\text{depth i}(D_i * W_\text{link i} / (D_i - 1))$。在上面的情形里,我们有:
- Node: $D_\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: $D_\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: $D_\text{spine}$ = 4 since we have 4 SUs with $W_\text{link i}$ = 12.8TB/s (from
8 * 16 * 2 * 400Gbpslinks above). Our bandwidth is12.8e12 * 4 / (4 - 1) = 17.1TB/s.
- Node: $D_\text{node}$ = 8,因为一个节点里有 8 颗 GPU,Wlink i = 450GB/s。于是 AG 带宽是
450e9 * 8 / (8 - 1) = 514GB/s。 - Leaf: $D_\text{leaf}$ = 32,因为一个 SU 里有 32 个节点,Wlink i = 400GB/s(8 条 400Gbps IB 链路)。于是带宽是
400e9 * 32 / (32 - 1) = 413GB/s。 - Spine: $D_\text{spine}$ = 4,因为有 4 个 SU,$W_\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 $T_\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$ 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(受 leaf 层限制),所以实践中 $T_\text{AG or RS comms} = B / \text{413GB/s}$,也就是说即便在最高层我们也有约 413GB/s 的 AllReduce 带宽。对启用 SHARP 的 AllReduce,会略低于此(约 400GB/s),因为我们没有 $(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 / 8$ nodes, the cost is
其他集合通信: 除非启用 SHARP,AllReduce 的代价仍是上面的 2 倍。NVIDIA 也卖支持 SHARP 的 IB 交换机,尽管不是所有供应商都有。AllToAll 跨节点时变化很大,因为它不像 AllReduce 那样「分层」。如果我们想把数据从每颗 GPU 发到其他每颗 GPU,就无法利用节点层面的完整二分带宽。也就是说,如果我们有一个跨 $M = N / 8$ 个节点的 N 路 AllToAll,代价是
$$T_\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 * \text{450e9})$ within a single H100 node to $B / (2 \cdot \text{400e9})$ when spanning 2 nodes, a more than 4x degradation.
这实际上只有 50GB/s 而不是 400GB/s 的带宽。我们从单个 H100 节点内的 $B / (8 * \text{450e9})$ 变成跨 2 个节点时的 $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 | Degree (# Children) | Switch Bandwidth (full-duplex, TB/s) | Cable Bandwidth (full-duplex, TB/s) | Collective Bandwidth (GB/s) |
|---|---|---|---|---|---|
| Node | 8 | 8 | 6.4 | 3.6 | 450 |
| Leaf (SU) | 256 | 32 | 25.6 | 12.8 | 400 |
| Spine | 1024 | 4 | 51.2 | 51.2 | 400 |
| 层级 | GPU 数 | 度(子节点数) | 交换机带宽(全双工,TB/s) | 线缆带宽(全双工,TB/s) | 集合通信带宽(GB/s) |
|---|---|---|---|---|---|
| Node | 8 | 8 | 6.4 | 3.6 | 450 |
| Leaf (SU) | 256 | 32 | 25.6 | 12.8 | 400 |
| Spine | 1024 | 4 | 51.2 | 51.2 | 400 |
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 $\text{bisection bandwidth} * 2 / N$.
我们用「集合通信带宽」这个词描述我们可出口 GPU 或节点的有效带宽。它也是 $\text{二分带宽} * 2 / N$。
Takeaway: beyond the node level, the cost of an AllGather or ReduceScatter on B bytes is roughly $B / W_\text{node egress}$, which is $B / \text{400e9}$ on an H100 DGX SuperPod, while AllReduces cost twice as much unless SHARP is enabled. The overall topology is a fat tree designed to give constant bandwidth between any two pairs of nodes.
要点: 节点之上,对 B 字节做 AllGather 或 ReduceScatter 的代价大致是 $B / W_\text{node egress}$,在 H100 DGX SuperPod 上是 $B / \text{400e9}$,而 AllReduce 代价是它的两倍,除非启用 SHARP。整体拓扑是一棵胖树,设计目标是让任意两对节点之间带宽恒定。
Reductions when array is sharded over a separate axis: Consider the cost of a reduction like
当数组在另一个轴上分片时的归约: 考虑如下归约的代价
$$\text{AllReduce}_X(A[I_Y, J]\ \{ U_X \})$$
where we are AllReducing over an array that is itself sharded along another axis $Y$. On TPUs, the overall cost of this operation is reduced by a factor of $1 / Y$ compared to the unsharded version since we’re sending $1 / 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 $Y$ is the inner axis, and the array has $\text{bytes}$ total bytes, the overall cost is reduced effectively by $Y$, but only if $Y$ spans multiple nodes:
我们是在对一个自身沿另一个轴 $Y$ 分片的数组做 AllReduce。在 TPU 上,这个操作的总体代价相比不分片版本降低 $1 / Y$,因为每个轴发送的数据只有 $1 / Y$。在 GPU 上,代价取决于哪个轴是「内层」轴(节点内 vs 节点间),以及每个分片是否跨多个节点。假设 $Y$ 是内层轴、数组总共有 $\text{bytes}$ 字节,则只有当 $Y$ 跨多个节点时,整体代价才实际降低 $Y$ 倍:
$$T_\text{comms at node} = \frac{\text{bytes}}{W_\text{GPU egress}} \cdot \frac{1}{\min(Y, D_\text{node})}$$
$$T_\text{comms in scale-out network} = \frac{\text{bytes}}{W_\text{node egress}} \cdot \frac{D_\text{node}}{\max(D_\text{node}, Y)}$$
$$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 $D_\text{node}$ is the number of GPUs in a node (the degree of the node). As you can see, if $Y < D_\text{node}$, we get a win at the node level but generally don’t see a reduction in overall runtime, while if $Y > D_\text{node}$, we get a speedup proportional to the number of nodes spanned.
其中 N 是 GPU 数,$D_\text{node}$ 又是一个节点里的 GPU 数(节点的度)。如你所见,如果 $Y < D_\text{node}$,我们在节点层面获益,但总体运行时不减;而如果 $Y > 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 是内层轴)的一般规则是
$$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 $S_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.
其中 $S_i$ 是 M * N * …,即树中第 i 层以下子节点的大小。这大致是说,我们跨的 GPU 或节点越多,可用带宽越大,但仅限那个节点之内。
Pop Quiz 3 [Sharding along 2 axes]: Say we want to perform $\text{AllGather}_X(\text{bf16}[D_X, F_Y])$ where $Y$ is the inner axis over a single SU (256 chips). How long will this take as a function of $D$, $F$, and $Y$?
随堂测验 3 [沿 2 个轴分片]: 假设我们想在一个 SU(256 芯片)上做 $\text{AllGather}_X(\text{bf16}[D_X, F_Y])$,其中 $Y$ 是内层轴。这要花多久,写成 $D$、$F$ 和 $Y$ 的函数?
Click here for the answer.
点击这里看答案。
Answer: We can break this into two cases, where Y <= 8 and when Y > 8. When $Y <= 8$, we remain bounded by the leaf switch, so the answer is, as usual, $T_\text{comms} = 2 * D * F * (32 - 1) / (32 * 400e9)$. When Y > 8, we have from above, roughly
答案: 我们可以分成两种情况:Y <= 8 和 Y > 8。当 $Y <= 8$,我们仍受 leaf 交换机限制,所以答案照旧是 $T_\text{comms} = 2 * D * F * (32 - 1) / (32 * 400e9)$。当 Y > 8,由上大约有
$$T_\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,我们有:
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,但整体代价不变,所以它是免费的,但对提升整体带宽没有帮助。
Takeaway: when we have multiple axes of sharding, the cost of the outer reduction is reduced by a factor of the number of nodes spanned by the inner axis.
要点: 当我们有多个分片轴时,外层归约的代价按内层轴跨越的节点数成比例降低。
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:
答案: 我们逐步过一遍归约的各个组件:
- Each GPU sends $B / MN$ bytes to the switch, for a total ingress of $NB / MN = B / M$ bytes ingress.
- We egress the full $B / M$ bytes up to the spine switch.
- We ingress $B * (M - 1) / M$ bytes from the spine switch
- We egress $B - B / MN$ bytes $N$ times, for a total of $N * (B - B / MN) = NB - B / M$.
- 每颗 GPU 向交换机发送 $B / MN$ 字节,总入流量为 $NB / MN = B / M$ 字节。
- 我们向 spine 交换机出口完整的 $B / M$ 字节。
- 我们从 spine 交换机入流量 $B * (M - 1) / M$ 字节。
- 我们向 N 颗 GPU 各出口 $B - B / MN$ 字节,共 $N * (B - B / MN) = NB - B / M$。
The total is $B$ ingress and $BN$ egress, so we should be bottlenecked by egress, and the total time would be $T_\text{AllGather} = BN / W_\text{node} = B / \text{450e9}$.
总量是入流量 $B$、出流量 $BN$,所以应该受出口限制,总时间为 $T_\text{AllGather} = BN / W_\text{node} = B / \text{450e9}$。
For the spine switch, the math is actually simpler. We must have $B / M$ bytes ingressed M times (for a total of $B$ bytes), and then $B (M - 1) / M$ egressed $M$ times, for a total of $B * (M - 1)$ out. Since this is significantly larger, the cost is $T_\text{AllGather} = B \cdot (M - 1) / (M \cdot W_\text{node}) = B \cdot (M - 1) / (M \cdot \text{400e9})$.
对 spine 交换机,数学其实更简单。我们必须入流量 $B / M$ 字节 M 次(共 $B$ 字节),然后出口 $B (M - 1) / M$ 字节 M 次,共出 $B * (M - 1)$。由于后者大得多,代价是 $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.
答案: 和之前一样,逐步来算。
- Each GPU sends $B * (N - 1) / N$ bytes, so we have $N * B * (N - 1) / N = B * (N - 1)$ ingressed.
- We accumulate the partial sums, and we send back $B / N$ bytes to each GPU, so $N * B / N = B$ bytes egressed.
- We do a partial sum on the residuals locally, then send this back to the switch. This is a total of $N * B / N = B$ bytes ingressed.
- We capture all the shards and multicast them, sending $B * (N - 1) / N$ to $N$ destinations, for a total of $B * (N - 1) / N * N = B * (N - 1)$ egressed.
- 每颗 GPU 发送 $B * (N - 1) / N$ 字节,所以入流量为 $N * B * (N - 1) / N = B * (N - 1)$。
- 我们累加部分和,并向每颗 GPU 回送 $B / N$ 字节,所以出口 $N * B / N = B$ 字节。
- 我们在本地对残差做部分和,再把它发回交换机。总入流量为 $N * B / N = B$ 字节。
- 我们收集所有分片并多播,向 $N$ 个目的地各发 $B * (N - 1) / N$,共出口 $B * (N - 1) / N * N = B * (N - 1)$。
Therefore the total is $B * (N - 1) + B = BN$ bytes ingressed and egressed. This supports the overall throughput being exactly $B / W_\text{egress}$.
因此总量是入流量和出流量各 $B * (N - 1) + B = BN$ 字节。这支持了整体吞吐恰好是 $B / 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]: 考虑数组 bf16[DX, FY] 分片在单个由 N 颗 GPU 组成的节点上。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) / XY$ bytes from each GPU, then send back $B / XY$ to each GPU, then send that same amount back to the switch, then send $B * (X - 1) / XY$ back to each GPU. The total is $NB / Y$ ingress and egress, so the total time is $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 $Y$.
答案: 我们可以试着修改上一题的答案。基本上,我们先从每颗 GPU 出口 $B * (X - 1) / XY$ 字节,然后向每颗 GPU 回送 $B / XY$,然后把同样多的量发回交换机,再把 $B * (X - 1) / XY$ 发回每颗 GPU。总量是入流量和出流量各 $NB / Y$,所以总时间是 $T_\text{comms} = NB / (Y * N * W_\text{link}) = N * 2DF / (Y * N * W_\text{link}) = 2 * D * F / (Y * W_\text{link})$,所以总时间确实随 $Y$ 减小。
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 / Y$. This is because we need to keep each shard separate.
如果我们超过单个节点,可以做与上面大致相同的归约,但当我们出口节点层交换机时,需要发送全部 B 字节,而不仅仅是 $B / Y$。这是因为我们需要让每个分片保持独立。
Question 4 [Spine level AR cost]: Consider the same setting as above, but with $Y = 256$ (so the AR happens at the spine level). How long does the AllReduce take? Again, feel free to assume in-network reductions.
问题 4 [Spine 层 AR 代价]: 考虑与上题相同的设置,但 $Y = 256$(因此 AR 发生在 spine 层)。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.
答案: 这让我们得以利用 spine 层那夸张的带宽。我们在 4 个 SU 上的 spine 层有 51.2TB/s 带宽,即每 SU 12.8TB/s。用 SHARP,这可以只需 2 * D * F / 12.8e12 秒。
Question 5 [2-way AllGather cost]: Calculate the precise cost of an AllGather of $B$ 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 个节点上对 $B$ 字节做一次 AllGather 的精确代价。确保算的是精确代价而非近似,并同时考虑节点内和跨节点代价。
Click here for the answer.
点击这里看答案。
Answer: At the node level, we have $T_\text{comms} = B * 7 / (8 * \text{450e9}) = B / \text{514e9}$ while beyond we actually have $T_\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.
答案: 在节点层面,我们有 $T_\text{comms} = B * 7 / (8 * \text{450e9}) = B / \text{514e9}$,而跨节点上实际是 $T_\text{comms} = B * (2 - 1) / (2 * \text{400e9}) = B / \text{800e9}$。因此我们实际上受节点层归约限制,而不是 leaf 层!这正是例如 DeepSeek v3 做 2 路数据并行的动机。
Rooflines for LLM Scaling on GPUs
GPU 上 LLM 扩展的 Roofline
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 $T_\text{math}$ and $T_\text{comms}$ for different parallelism strategies and understand at what point $T_\text{comms} > T_\text{math}$. As before, we consider only the MLP block with operations
现在我们来看这一切所铺垫的目标:理解 GPU 上 LLM 扩展的 roofline。这是对 TPU 训练章节这里的补充。和那里一样,这里的目标是考察不同并行策略的总 $T_\text{math}$ 和 $T_\text{comms}$,并理解在什么点上 $T_\text{comms} > T_\text{math}$。和之前一样,我们只考虑带如下运算的 MLP 块
$$\text{MLP}(x) \equiv x[B, D] *_D W_\text{in}[D, F] \cdot_F W_\text{out}[F, D]$$
where $B$ is the global batch size in tokens (i.e. $B = \text{batch size} \cdot \text{sequence length}$).
其中 $B$ 是以 token 计的全局 batch size(即 $B = \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 egress bandwidth | Node egress bandwidth |
|---|---|---|---|
| H100 | 8 | 450e9 | 400e9 |
| B200 | 8 | 900e9 | 400e9 |
| GB200 NVL72 | 72 | 900e9 | 3600e9 |
| 节点类型 | 每节点 GPU 数 | GPU 出口带宽 | 节点出口带宽 |
|---|---|---|---|
| H100 | 8 | 450e9 | 400e9 |
| B200 | 8 | 900e9 | 400e9 |
| GB200 NVL72 | 72 | 900e9 | 3600e9 |
Note: Both the GPU and node egress bandwidths determine rooflines for our LLMs. We’ll use the term $W_\text{collective}$ to describe either the GPU or node bandwidths depending on whether we are operating within or above the node level.
注意: GPU 和节点的出口带宽都会决定我们 LLM 的 roofline。我们用 $W_\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 那样,来看数据并行、张量并行、流水线并行、专家并行及其组合的计算-通信 roofline。本节余下部分我们聚焦 H100 的 roofline 来做具体计算。GB200-NVL72 有相同的总体 roofline,但由于节点出口带宽更大,我们有时反而会在节点层成为瓶颈。
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 的轴上,有
$$T_\text{math} = \frac{2 \cdot 2 \cdot 2 \cdot BDF}{X \cdot C}$$
$$T_\text{comms} = \frac{2 \cdot 2 \cdot 2 \cdot DF}{W_\text{collective}}$$
Therefore, for $T_\text{math} > T_\text{comms}$, we need $B / (XC) > 1 / W_\text{collective}$ or
因此,要 $T_\text{math} > T_\text{comms}$,我们需要 $B / (XC) > 1 / W_\text{collective}$,即
$$\frac{B}{X} > \frac{C}{W_\text{collective}}$$
where $W_\text{collective}$ is either the GPU or node level egress bandwidth depending on whether we’re sharding within a node or across nodes. Thus:
其中 $W_\text{collective}$ 是 GPU 层或节点层的出口带宽,取决于我们是在节点内还是跨节点分片。于是:
- Within a node, we just need the per-GPU token batch size > $\text{990e12} / \text{450e9} = 2200$.
- Within an SU or at the spine level, BS > $\text{990e12} / \text{400e9} = 2475$.
- 在节点内,我们只需每颗 GPU 的 token batch size > $\text{990e12} / \text{450e9} = 2200$。
- 在 SU 内或 spine 层,BS > $\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 $\text{990e12} / \text{300e9} = 3300$ tokens per GPU, or about 6.7M (in practice, they used 4M).
这比 TPU 高不少,那里在三个轴上都是 850。例如,在 16000 颗 H100 上训练的 LLaMA-3 至少需要 40M token 的 batch size(作为参考,他们用了 16M)。在 2048 颗 H800 GPU 上训练的 DeepSeek v3,带宽更低(300GB/s,而非 H100 的 450GB/s),需要每颗 GPU $\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 带宽翻倍,会让这两个数字减半。但实践中收益更接近 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 个专家,这会增加到
$$T_\text{math} = \frac{2 \cdot 2 \cdot 2 \cdot k \cdot BDF}{X \cdot C}$$
$$T_\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/k$, i.e.
这会把每颗 GPU 的 token batch size 放大 $E/k$ 倍,即
$$\frac{B}{X} > \frac{E}{k} \frac{C}{W_\text{collective}}$$
For example, the new OpenAI OSS model with $k=4$ and $E=128$, this increases to 32 * 2475 = 79,200 across nodes, a kind of ridiculously high number.
例如,新的 OpenAI OSS 模型 $k=4$、$E=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$ scaling, which gives us
X 很小时会怎样? 当我们只做例如 2 节点数据并行时,我们受益于 $(X - 1) / X$ 的缩放,给出
$$T_\text{math} = \frac{2 \cdot 2 \cdot 2 \cdot BDF}{N * C}$$
$$T_\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 \cdot X$. Then for a dense model we have $B / N > \alpha \cdot (X - 1) / X$, or e.g. $B / N > \text{1237}$, half the above value. You’ll notice 2-way data parallelism fairly often for this reason.
其中 X 是节点数,$N = 8 \cdot X$。那么对稠密模型有 $B / N > \alpha \cdot (X - 1) / X$,例如 $B / N > \text{1237}$,是上面值的一半。出于这个原因,你会经常看到 2 路数据并行。
Takeaway: Data parallelism and ZeRO sharding require a per-GPU batch size of about 2500 tokens to be compute-bound on an H100 or B200, assuming perfect overlap and FLOPs utilization. For MoE models, this increases by a factor of $E / k$, the ratio of total to activated parameters. When doing a small amount of data parallelism, the critical batch size decreases.
要点: 在假设完美重叠和 FLOPs 利用率的前提下,数据并行和 ZeRO 分片需要每颗 GPU 约 2500 token 的 batch size,才能在 H100 或 B200 上达到计算受限。对 MoE 模型,这要乘以 $E / k$(总参数与激活参数之比)。做少量数据并行时,临界 batch size 会下降。
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 重叠。换句话说,在前向传播中,我们有
$$T_\text{math} = \frac{2\cdot 2 \cdot BDF}{Y \cdot C}$$
$$T_\text{comms} = \frac{2\cdot 2 \cdot BD}{W_\text{collective}}$$
which to be compute-bound gives us the rule
要计算受限,就给出规则
$$Y < \frac{F \cdot W_\text{collective}}{C}$$
Within a node, this gives us about $F / 2200$ or $F / 2475$ beyond a node. For $F=\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 \cdot (Y - 8)$), which gives us up to 19-way model parallelism in theory.
在节点内这给出约 $F / 2200$,节点之上是 $F / 2475$。对 LLaMA-3 这样 $F=\text{28000}$,大约是 11 路 TP(或向下取整约 8 路,也就是一个节点的大小)。和上面一样,当我们恰好跨 2 个节点时能多 2 倍带宽,所以我们一般能做 16 路张量并行($F > 2475 \cdot (Y - 8)$),理论上最多到 19 路模型并行。
Takeaway: Tensor parallelism over an axis of size Y with feed-forward dimension F becomes communication-bound when the $Y > F / 2475$, which generally constrains us to only intra-node TP or at most 2-node TP.
要点: 在大小为 Y 的轴上、前馈维度为 F 的张量并行,当 $Y > F / 2475$ 时会变成通信受限,这通常把我们限制为只在节点内做 TP,或最多 2 节点 TP。
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 倍的模型权重但只有 k 倍的 FLOPs,让数据并行难得多。我们可以通过在专家维上分片权重来缓解,即 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 $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]) 如果跨多个节点,代价约为 $T_\text{AllToAll} = 2 \cdot B \cdot D \cdot (Z-8)/Z \min(8 * k / Z, 1)$,所以对纯专家并行我们需要
$$T_\text{math} = \frac{4 \cdot B \cdot k \cdot D \cdot F}{Z \cdot C}$$
$$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/8$ with $F > \alpha \cdot (Z - 8)/k$ or $Z \gg K$ and $F > 8 \cdot \alpha$, where $\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 $F$, or one with large $F$ and $Z$ arbitrarily large (up to E-way expert parallelism).
我们要么需要 $K > Z/8$ 且 $F > \alpha \cdot (Z - 8)/k$,要么 $Z \gg K$ 且 $F > 8 \cdot \alpha$,其中 $\alpha = C/W$。这给出专家并行可行的两个区间:一个是少量专家并行(约 2 节点)且 $F$ 小,另一个是 $F$ 大且 $Z$ 可以任意大(最多 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 很大的模型,这时我们可以在 TP 之外做大量跨节点 EP。
Takeaway: if $F < 8 * C / W_\text{node}$, expert parallelism can span 1-2 nodes with similar (slightly lower) cost to TP, or if $F > 8 * C / W_\text{node}$, we can do a significant amount of expert parallelism (up to $E$ nodes) with relatively low cost.
要点: 如果 $F < 8 * C / W_\text{node}$,专家并行可以跨 1-2 个节点,代价与 TP 相近(略低);或者如果 $F > 8 * C / W_\text{node}$,我们可以做大量专家并行(最多 $E$ 个节点),代价相对较低。
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.
流水线并行把层切分到不同节点,通信代价极低,因为我们只是每隔几层发送小批的激活 microbatch。历史上流水线受「流水线气泡」之苦,但有了新的零气泡(zero-bubble)流水线方法,通常可以避免。
The overall communication cost of pipelining is tiny: with $N_\text{MB}$ microbatches and $N_\text{stages}$, we have $T_\text{comms per hop} = 2 \cdot B \cdot D / (W \cdot N_\text{MB})$ and $N_\text{MB} + N_\text{stages} - 2$ hops, so roughly
流水的总体通信代价很小:有 $N_\text{MB}$ 个 microbatch 和 $N_\text{stages}$ 个阶段时,我们有 $T_\text{comms per hop} = 2 \cdot B \cdot D / (W \cdot N_\text{MB})$ 和 $N_\text{MB} + N_\text{stages} - 2$ 跳,所以大致是
$$T_\text{total PP comms} = \frac{2BD}{W \cdot N_\text{MB}} \cdot (N_\text{MB} + N_\text{stages} - 2)$$
$$T_\text{per-layer comms} \approx 1.5 \cdot \frac{2BD}{W \cdot N_\text{layers}}$$
Since we are dividing by $N_\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:
由于除以了 $N_\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)。因为它引入 microbatch 来隐藏流水线气泡,改变了程序结构,而自定义的零气泡流水线调度更要求对前向和反向做复杂的交错,让这个问题雪上加霜。
(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 / 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 分片表现很差,因为它要求对每个 microbatch 都 AllGather 权重,而当我们只有 $B / N_\text{microbatches}$ 个 token 来摊薄 AllGather 代价时,这行不通。此外,在反向传播中,我们必须等到最后一个 microbatch 通过某个阶段后才能对梯度做 AllReduce 或 ReduceScatter,这意味着有大量无法重叠的通信时间。
(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 步空闲,第二阶段在最后一步又空闲。虽然我们可以通过仔细调度在一定程度上避免这些,但往往还是会有一些气泡。我们还必须在关键路径上把激活从一个阶段传到下一个阶段,这会增加开销:
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 带宽。这意味着即便理论上我们能把例如专家并行的 AllToAll 扩展到多个节点,实际可能连总带宽的 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) = 2$ times more bandwidth in practice. This also helps reduce the cost of the final data-parallel AllReduce overlapping with the final pipeline stages.
他们的稳态 batch size 是 4096 * 15360 = 62,914,560 个 token,即每颗 GPU 30k token。你可以看到这已经相当大了,但他们的模型也非常稀疏(k=8,E=256),所以需要相当大的 batch size。你可以看到,用 64 路 EP 和 16 路 PP,总共得到 1024 路模型并行,这意味着 AllReduce 在 spine 层完成,而由于它只有 2 路,实践中我们最终获得 $2 / (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 倍,这帮助我们降低临界 batch size。
TLDR of LLM Scaling on GPUs
GPU 上 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 的本地 batch size,尽管理论上网络内归约 + 纯 DP 可以略微降低这个值。
- 张量并行最多约 8 路是计算受限的,但我们的带宽不足以在此之上继续扩展而不变成通信受限。这大体上把我们限制在一个 NVLink 域内(即单节点,或需要使用最多 72 颗 GPU 的 GB200NVL72)。
- 任何跨多个节点的模型并行都能进一步降低 FSDP 的代价,所以我们常想把 PP + EP + TP 混合起来跨多个节点,以降低 FSDP 代价。
- 如果你能应付零气泡流水线的代码复杂度,并保持 batch size 足够大以避免数据并行瓶颈,流水线并行效果很好。 流水线通常让 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 / W_\text{node}$, we can do a ton of multi-node expert parallelism, but otherwise we’re limited to roughly 2-node EP.
- 对相对较小的稠密模型,如果你有足够的 batch size,激进的 FSDP 效果很好,必要时可加一些流水线或张量并行。
- 对较大的稠密模型,1-2 节点 TP + 多节点 PP + 纯 DP 的组合效果不错。
- 对 MoE,上述规则适用,但我们还能做专家并行,总体上我们更偏好它而非 TP。如果 $F > 8 * C / W_\text{node}$,我们可以做大量多节点专家并行;否则我们被限制在大约 2 节点 EP。
Quiz 5: LLM rooflines
随堂测验 5:LLM roofline
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 roofline]: 一个 B200 DGX SuperPod(不是 GB200 NVL72)节点内有 2 倍带宽(900GB/s 出口),但 scale-out 网络中带宽相同(400GB/s)(来源)。总 FLOPs 见上文。这对模型并行和数据并行的 roofline 有何改变?
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 / 2500$, only slightly higher (and this doesn’t help us unless the node size increases).
答案: bfloat16 的 FLOPs/s 从 990 提到 2250 TFLOPs,增加 2.25 倍。节点内有 2 倍带宽,所以节点内的 roofline 大致不变。例如对 TP,临界强度升到 2250e12 / 900e9 = 2500,于是限制是 $Y < 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.
而在节点之上,缺少额外带宽反而让我们更难达到计算受限!例如对数据并行,临界 batch size 升到 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 优化器状态。
- At a minimum, how many H100s would we need simply to store the weights and optimizer?
- 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?
- LLaMA-3 70B has
F = 28,672and 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.
- 仅仅为了存权重和优化器,最少需要多少颗 H100?
- 假设我们想在 4096 颗 H100 GPU 上训练 15T token。假设达到 45% MFU(模型 FLOPs 利用率)。训练要多久?
- LLaMA-3 70B 的
F = 28,672,训练时 batch size 约 4M token。在不变成通信受限的前提下,我们最多能做多少模型并行?用它加上纯 DP,我们能在 4k 芯片上保持计算受限地训练 LLaMA-3 吗?ZeRO-3 呢?8 路流水线呢?注意:同时考虑通信代价和 GPU 显存占用。
Click here for the answer.
点击这里看答案。
- 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.
- This will require a total of
6 * 70e9 * 15e12 = 6.3e24 bf16 FLOPs. Each GPU can do990e12FLOPs, so at 45% MFU we can do 1.8e18 FLOPs/s. Thus the whole thing will take 3.5e6 seconds, or 40 days. - 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.- 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! - 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. - 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 is990e12 / 3200e9 = 309, so we should be good! We just need to implement pipelining efficiently.
- 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
- 权重需要 2 字节、优化器状态需要 8 字节,所以至少 700GB。以 80GB 显存算,最少需要 9 颗 GPU,取整后至少 2 个 8xH100 节点。这样训练要花到天荒地老,也存不下梯度 checkpoint,但这是个下界。
- 这总共需要
6 * 70e9 * 15e12 = 6.3e24次 bf16 FLOPs。每颗 GPU 能做990e12FLOPs,所以 45% MFU 下我们每秒能做 1.8e18 FLOPs。因此整个过程要 3.5e6 秒,即 40 天。 - 节点内我们有 450GB/s 带宽,所以限制约为
F / 1995 = 28672 / 1995 = 14.372。由于这没跨 2 个节点,现实地说我们会做到 8 路模型并行。- 这样就要求做 512 路 DP。首先得看显存够不够。由于模型只分 8 路,这意味着
700GB / 8 = 87.5GB / GPU,装不下,所以不行! - 用 ZeRO-3 加 8 路 TP,我们会做 512 路 ZeRO-3。这在显存上没问题,因为我们在激进地分片所有东西。每颗 GPU 的 batch size 是
4e6 / 4096 = 976。这相当低,甚至低于纯 DP 的下限,而且这个下限还要翻倍,因为我们要搬运权重。所以不行。 - 用 8 路流水线,每个模型并行分片现在跨 8 个节点。如我们所见,这把我们 leaf 层 AllGather 的代价降低了 8,那里的整体 AllReduce/AllGather 带宽从 400GB/s 变成
8 * 400GB/s = 3200GB/s。于是 roofline 是990e12 / 3200e9 = 309,所以应该没问题!我们只需要高效地实现流水线。
- 这样就要求做 512 路 DP。首先得看显存够不够。由于模型只分 8 路,这意味着
Question 3 [Megatron-LM hyperparams]: Consider this figure from the Megatron-LM repository highlighting their high MFU numbers.
问题 3 [Megatron-LM 超参数]: 看Megatron-LM 仓库里这张强调他们高 MFU 数字的图。
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 batch size 是多少?假设数据并行是最外层轴、归约用 bfloat16,判断这三者理论上分别是计算受限还是通信受限,以及是否存在更优的配置?
Click here for the answer.
点击这里看答案。
Answer: Let’s start with batch sizes per GPU.
答案: 先从每颗 GPU 的 batch size 开始。
- 16B:
192 * 4096 / 192 = 4096tokens per GPU - 70B:
384 * 4096 / 768 = 2048tokens per GPU - 314B:
1536 * 4096 / 3072 = 2048tokens per GPU
- 16B:每颗 GPU
192 * 4096 / 192 = 4096个 token - 70B:每颗 GPU
384 * 4096 / 768 = 2048个 token - 314B:每颗 GPU
1536 * 4096 / 3072 = 2048个 token
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 算出的临界阈值附近。我们曾基于 spine 层归约把那个下界算作 2,472 token/GPU,这里大致会起作用。不过对 70B 和 314B,因为我们分别有 16 路和 64 路模型并行(PP + TP),在 spine 层吞吐分别好 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 上 kernel 编程的真实情况。
- Swapnil Patil,他最先解释了 GPU 组网如何工作。
- Stas Bekman,他指出 GPU 的实测现实往往与宣称的规格不同。
- Reiner Pope,他帮助厘清了 GPU 与 TPU 在硬件层面的对比。
- Frédéric Bastien,他对芯片层面的故事给出了详细反馈。
- Nouamane Tazi,他在 GPU 上做 LLM 训练的经验帮助改进了 roofline 一节。
- Sanford Miller,他帮我理解了 GPU 如何组网、以及 NVIDIA 的规格与实际部署的对比。
There’s a great deal of good reading on GPUs, but some of my favorites include:
关于 GPU 有大量好材料可读,我最喜欢的一些包括:
- SemiAnalysis’ History of the NVIDIA Tensor Core: a fantastic article describing how GPUs transformed from video game engines to ML accelerators.
- SemiAnalysis’ Analysis of Blackwell Performance: worth reading to understand the next generation of NVIDIA GPUs.
- H100 DGX SuperPod Reference: dry but useful reading on how larger GPU clusters are networked. Here is a similar document about the GB200 systems.
- Hot Chips Talk about the NVLink Switch: fun reading about NVLink and NCCL collectives, especially including in-network reductions.
- DeepSeek-V3 Technical Report: a good example of a large semi-open LLM training report, describing how they picked their sharding setup.
- How to Optimize a CUDA Matmul: a great blog describing how to implement an efficient matmul using CUDA Cores, with an eye towards cache coherence on GPU.
- HuggingFace Ultra-Scale Playbook: a guide to LLM parallelism on GPUs, which partly inspired this chapter.
- Making Deep Learning Go Brrrr From First Principles: a more GPU and PyTorch-focused tutorial on LLM rooflines and performance engineering.
- Cornell Understanding GPU Architecture site: a similar guide to this book, comparing GPU and CPU internals more specifically.
- SemiAnalysis 的 NVIDIA Tensor Core 历史:一篇很棒的文章,讲述 GPU 如何从游戏引擎变成 ML 加速器。
- SemiAnalysis 对 Blackwell 性能的分析:想了解下一代 NVIDIA GPU 值得一读。
- H100 DGX SuperPod 参考:枯燥但有用,讲更大的 GPU 集群如何组网。这里是关于 GB200 系统的类似文档。
- 关于 NVLink Switch 的 Hot Chips 演讲:关于 NVLink 和 NCCL 集合通信的有趣读物,尤其包含网络内归约。
- DeepSeek-V3 技术报告:一个大型半开放 LLM 训练报告的好例子,描述了他们如何选择分片方案。
- 如何优化 CUDA 矩阵乘法:一篇很棒的博客,讲如何用 CUDA Core 实现高效的矩阵乘法,兼顾 GPU 上的缓存一致性。
- HuggingFace Ultra-Scale Playbook:一份 GPU 上 LLM 并行的指南,本章部分受它启发。
- Making Deep Learning Go Brrrr From First Principles:一篇更偏向 GPU 和 PyTorch 的教程,讲 LLM roofline 与性能工程。
- 康奈尔大学理解 GPU 架构的网站:与本书类似的一份指南,更具体地比较 GPU 和 CPU 内部结构。
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 仍像 H100 一样是 8 颗 GPU 的节点,但 GB200 系统(把 B200 GPU 与 Grace CPU 组合起来)引入了大得多的 NVLink 域(NVL72 中 72 颗 GPU,理论上最多到 576)。更大的 NVLink 域也有效增加了节点出口带宽,从而降低节点之上的集合通信代价。
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 也翻倍了。我们的 roofline 大体不变,不过因为 NVLink 带宽好得多,专家并行变得更容易。
Beyond a node, things change more. Here’s a SuperPod diagram from here.
节点之上,变化更大。下面是来自这里的一张 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 大幅提升。由于每颗芯片的 FLOPs 也翻倍,这大约把有效的跨节点 roofline 改善了 4 倍。现在我们要开始担心到底是在节点层还是 scale-out 层成为瓶颈了。
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 也卖把若干 GPU 与一颗 Grace CPU 配对的 GH200 和 GB200 系统。例如 GH200 有 1 颗 H200 和 1 颗 Grace CPU,而 GB200 系统有 2 颗 B200 和 1 颗 Grace CPU。这样的系统有一个优势:CPU 用全带宽 NVLink 连接(称为 NVLink C2C)接到 GPU 上,所以 CPU 到 GPU 带宽非常高,适合把参数 offload 到 host 内存。换句话说,对任意一颗 GPU,到达 host 内存的带宽和到达另一颗 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 条物理 lane),以及一个处理 lane 间交换的大型 crossbar。相比之下,TPU 用的是带反射镜、可动态重构的光交换机。
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.
- 节点层: 节点层我们有 4 * 1.6TB/s = 6.4TB/s 的 NVSwitch 带宽,但 8 颗 GPU 每颗只能向交换机出口 450GB/s,这意味着节点内实际峰值带宽是 450e9 * 8 = 3.6TB/s(全双工)。
- SU/leaf 层: 在 SU 层,我们有 8 个交换机以全互联方式连接 32 个节点,用 1x400 Gbps Infiniband。这给出节点侧
8 * 32 * 400 / 8 = 12.8TB/s的出口带宽,而交换机侧我们有8 * 1.6TB/s = 12.8TB/s,两者精确吻合。 - Spine 层: 在 spine 层,我们有 16 个交换机用 2x400 Gbps 链路连接 32 个 leaf 交换机,所以有
32 * 16 * 400 * 2 / 8 = 51.2TB/s的出口带宽。与 leaf 交换机不同,spine 交换机的 64 个端口全部朝下,所以每个交换机可搬运64 * 400 / 8 = 3.2TB/s流量,给出交换机侧16 * 3.2TB/s = 51.2TB/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,这给出节点层 450GB/s 的 GPU 到 GPU 带宽,以及 SU 层和 spine 层各 50GB/s。
GPU empirical AR bandwidth:
GPU 实测 AR 带宽:
TPU v5p bandwidth (1 axis):
TPU v5p 带宽(单个轴):
Here’s AllGather bandwidth as well:
下面是 AllGather 带宽:
More on AllToAll costs:
更多关于 AllToAll 代价:
Here we can compare the approximation $\min(K / Z) * (Z - 1) / Z$ to the true value of $(1 - ((Z - 1) / Z) ** K) * (Z - 1) / Z$. They’re similar except for small values of $Z$.
这里我们可以比较近似值 $\min(K / Z) * (Z - 1) / Z$ 与真值 $(1 - ((Z - 1) / Z) ** K) * (Z - 1) / Z$。除了 $Z$ 较小的情况,它们很接近。
讨论
用 GitHub 账号留言;评论保存在公开仓库chengshu-blog-discussions的 Discussions 里。也可通过 RSS 订阅后续文章。