What training computes, and why it needs thousands of GPUs訓練在算什麼,又為何需要上千顆 GPU
Learn what one training step does, how much arithmetic a large model needs, why thousands of GPUs must work in lockstep, and how to measure how well they are used.了解一個訓練步驟做了什麼、大型模型需要多少算術、為何上千顆 GPU 必須同步前進,以及如何衡量它們被用得多好。
Nothing. This chapter assumes no background in networking or machine learning.
不需要任何背景。本章不假設你懂網路或機器學習。
New terms in this chapter (19)本章新名詞(19)
Each term is defined in the text where it first appears; the link jumps there. Terms from earlier chapters are listed under "Before you start".
每個名詞都在它第一次出現的段落中定義,點連結可跳過去。前面各章的名詞列在「開始之前」。
- Parameter參數 One number in the model that training adjusts. A large language model has billions of them. 模型中由訓練調整的一個數字。大型語言模型有數十億個參數。
- Token詞元(token) A piece of text, about three quarters of a word, that the model reads as one unit. 文字的一小段,約四分之三個英文單字,模型把它當成一個單位讀入。
- Training step訓練步驟 One forward pass, one backward pass and one optimizer step over one batch. A run repeats it millions of times. 對一個批次做一次前向傳播、一次反向傳播與一次最佳化器更新。整個訓練重複它數百萬次。
- Batch批次(batch) The set of training examples (tokens) that one training step processes. 一個訓練步驟處理的一組訓練資料(詞元)。
- GPUGPU Graphics processing unit: the chip that does the arithmetic of training. An NVIDIA H100 is one. 圖形處理器:負責訓練中算術運算的晶片,例如 NVIDIA H100。
- Forward pass前向傳播 The model reads the batch layer by layer and computes its prediction and its error (the loss). 模型逐層讀入批次,算出預測與誤差(損失)。
- Loss損失(loss) One number that says how wrong the model's prediction was. 表示模型預測錯得多嚴重的一個數字。
- Backward pass反向傳播 The model walks the layers in reverse and computes a gradient for every parameter. 模型反向走過各層,為每個參數算出梯度。
- Gradient梯度 How sensitive the loss is to each parameter: the rate of change of the loss with respect to it. Its opposite direction lowers the loss fastest locally. 描述損失對每個參數有多敏感,也就是損失函數對參數的變化率;其反方向是局部降低損失最快的方向。
- Optimizer step優化器步驟 The part of a step that applies the gradients to the parameters. Adam is the common optimizer. 把梯度套用到參數上的那一段。常用的優化器是 Adam。
- Synchronization同步 The part of a step in which GPUs exchange results so that every copy of the model stays the same. 一個步驟中 GPU 交換結果、讓每份模型副本保持一致的那一段。
- Rankrank One process of a distributed job, numbered 0, 1, 2 …; in training, one rank drives one GPU. 分散式工作中的一個行程,編號 0、1、2……;訓練中一個 rank 驅動一顆 GPU。
- FLOP, FLOP/sFLOP、FLOP/s A floating-point operation (one multiply or one add). FLOP/s is the rate; a TFLOP/s is 10¹² per second. 一次浮點運算(一次乘法或加法)。FLOP/s 是速率;1 TFLOP/s 是每秒 10¹² 次。
- Peak rate峰值速率 The most FLOP/s a GPU can do in theory. Real training reaches 30–60% of it. GPU 理論上最多能做的 FLOP/s。實際訓練約達到其 30–60%。
- GPU-hourGPU 小時 One GPU busy for one hour; the unit in which training runs are bought and priced. 一顆 GPU 忙碌一小時;訓練用量以此單位購買與計價。
- MFUMFU Model FLOPs utilization: the arithmetic the model needs, per second, divided by the GPUs' peak rate. 模型 FLOPs 使用率:模型所需的運算量每秒除以 GPU 峰值速率。
- HFUHFU Hardware FLOPs utilization: like MFU, but it also counts recomputed work, so HFU ≥ MFU. 硬體 FLOPs 使用率:與 MFU 類似,但也計入重算的運算,所以 HFU ≥ MFU。
- Straggler落後者(straggler) A rank or machine that is persistently slower than the others, and so sets the pace of the whole job. 持續比其他 rank 慢的 rank 或機器,因而決定整個工作的速度。
- Barrier柵欄(barrier) A point that no rank may pass until every rank has reached it. The step lasts as long as the slowest rank. 所有 rank 都抵達前,誰都不能通過的點。步驟時間由最慢的 rank 決定。
1.1What one training step does一個訓練步驟做了什麼
A language model is a large set of numbers, called parameters. Llama 3 405B, the example this book uses most, has 405 billion of them. The model reads text in pieces called tokens; a token is about three quarters of an English word. Training adjusts the parameters so that the model predicts the next token better. It does so in small steps. Each training step works on one batch: a fixed set of training text, millions of tokens for a large model. The arithmetic runs on GPUs (graphics processing units), chips built to do many multiplications at once. The NVIDIA H100 is the GPU in most of the systems in this book.
語言模型是一大組數字,稱為參數。本書最常用的例子 Llama 3 405B 有 4,050 億個參數。模型以稱為 token(詞元)的小段落讀入文字;一個 token 約為英文單字的四分之三。訓練就是調整參數,讓模型更準確地預測下一個 token。訓練一小步一小步地進行,每一個訓練步驟處理一個批次(batch):一組固定的訓練文字,大型模型一次有數百萬個 token。這些算術在 GPU(圖形處理器)上執行;GPU 是專為同時做大量乘法而設計的晶片。本書大多數系統用的是 NVIDIA H100。
One training step turns one batch of tokens into one update of every parameter. It has four phases, and they always run in the same order. The forward pass pushes the batch through every layer and produces a loss: one number that says how wrong the model was. The backward pass walks the layers in reverse and produces a gradient for every parameter: how sensitive the loss is to that parameter, which tells which way the parameter should be adjusted. In other words, it is the rate of change of the loss with respect to the parameter, and its opposite direction is the one in which the loss falls fastest locally. The optimizer step reads each gradient and moves the parameter a small distance. The synchronization makes every copy of the model agree on the result. The first three phases need only computation on a single GPU; the fourth involves communication between GPUs. Chapter 5 shows that the first three phases shrink when you add GPUs and the fourth does not; that is why this book is about the network.
一個訓練步把一批 token 變成對每一個參數的一次更新。它有四個階段,順序永遠一樣。前向傳播把這批資料推過每一層,產生損失值:一個表示模型錯多少的數字。反向傳播反向走過各層,為每個參數算出梯度:描述參數對損失有多敏感,並指出參數應往哪個方向調整。換言之,即損失函數對參數的變化率,其反方向是局部降低損失最快的方向。優化器步驟讀取每個梯度,把參數移動一小段距離。同步讓模型的每一份副本對結果取得一致。前三個階段只需要在單顆 GPU 上運算,第四項則牽扯到 GPU 之間的通訊。第 5 章會說明:加 GPU 時前三個階段會縮小,第四個不會;這就是本書談網路的原因。
Section 1.2 shows that one GPU would need thousands of years for a model of this size, so thousands of GPUs share each step. The simplest way to share it is to give every GPU its own copy of the model and a different part of the batch. Each GPU computes gradients for its own part. Before the optimizer step, the gradients from all GPUs must be added together, so that every copy makes the same update and the copies stay identical. An operation called an all-reduce computes this sum: every GPU sends its gradients in, and every GPU receives the total. That exchange is the synchronization phase, and it is the reason the GPUs need a network. This way of splitting the work is called data parallelism. Chapter 3 introduces it properly, together with four other ways to split a job, and Chapter 4 shows how an all-reduce is done. In a program that runs on many GPUs, the process that drives one GPU is called a rank; ranks are numbered 0, 1, 2 and so on.
第 1.2 節會算出:這種規模的模型若只用一顆 GPU,要花上數千年,所以每一步都由數千顆 GPU 分擔。最簡單的分擔方式,是讓每顆 GPU 各持有一份完整的模型,並處理批次中不同的一部分。每顆 GPU 為自己那一部分算出梯度。在優化器步驟之前,必須把所有 GPU 的梯度加總,讓每份副本做出相同的更新、彼此保持一致。這個加總由一種稱為 all-reduce 的操作完成:每顆 GPU 送出自己的梯度,每顆 GPU 都收到總和。這次交換就是同步階段,也是 GPU 需要網路的原因。這種分工方式稱為資料平行。第 3 章會正式介紹它以及另外四種切分方式,第 4 章說明 all-reduce 實際上怎麼做。在跨多顆 GPU 執行的程式中,驅動一顆 GPU 的行程稱為 rank,編號為 0、1、2 等等。
1.2How much arithmetic: the 6ND rule算術有多少:6ND 法則
Training is arithmetic, so the first question is how much of it there is. Count it in FLOPs, floating-point operations: one multiplication or one addition on numbers with a fractional part. A GPU's speed is counted in FLOP per second, FLOP/s; one TFLOP/s is of them per second.
訓練就是算術,所以第一個問題是:算術有多少?以 FLOP(浮點運算)計數:對帶小數的數字做一次乘法或一次加法。GPU 的速度以每秒 FLOP 數,即 FLOP/s 計;1 TFLOP/s 是每秒 次。
Start with one weight matrix with inputs and outputs, applied to one token. The forward pass computes sums, each of products: multiply-adds, which is floating-point operations, or exactly 2 FLOPs per weight. Sum over all the weight matrices in the model and the forward pass costs about FLOPs per token, where is the number of parameters the token passes through. In a dense model that is every parameter. In a mixture-of-experts (MoE) model, each layer holds many small sub-networks and each token passes through only a few of them, so is the active parameter count, much smaller than the total (Chapter 3). The backward pass does two matrix multiplies of the same size for each one in the forward pass: one to get the gradient with respect to the layer's input, which the layer below needs, and one to get the gradient with respect to the weights. That is . Together, FLOPs per token, and for a run over tokens
從一個有 個輸入、 個輸出的權重矩陣開始,作用在一個 token 上。前向算 個和,每個和有 個乘積: 次乘加,即 次浮點運算,恰好每個權重 2 FLOPs。把模型裡所有權重矩陣加起來,前向每個 token 約 FLOPs, 是這個 token 經過的參數量。dense 模型就是全部參數;混合專家(MoE)模型的每一層含有許多小型子網路,每個 token 只經過其中少數幾個,所以 是啟用參數量,遠小於總參數量(第 3 章)。反向對前向的每一次矩陣乘法都做兩次同樣大小的乘法:一次算對該層輸入的梯度(往回的下一層需要它),一次算對權重的梯度。這是 。合計每個 token FLOPs,跑過 個 token 就是
Figure 1.1 shows the three products for one weight matrix.
圖 1.1 畫出一個權重矩陣的三次乘法。
where is the number of parameters and is the number of training tokens. For Llama 3 405B, with about 15 trillion tokens, this is about floating-point operations. One GPU cannot do this in a human lifetime. The worked example below shows by how much.
其中 是參數量, 是訓練 token 數。以 Llama 3 405B、約 15 兆 token 計算,大約是 次浮點運算。一顆 GPU 在人的一生之內做不完。下面的算例會說明差距有多大。
The rule ignores the attention scores, which add about per token and matter when sequences are very long. It ignores recomputation, extra work that some systems do to save memory (Chapter 3). It also ignores the optimizer, which touches each parameter a handful of times per step, keeps about 16 bytes of numbers per parameter (Chapter 3 counts them), and is limited by memory speed, not by arithmetic.
這條法則忽略了注意力分數——每個 token 另外約需 ,序列很長時才重要。它忽略重算,也就是某些系統為了省記憶體而多做的工作(第 3 章)。它也忽略優化器:優化器每步只碰每個參數少數幾次、每個參數約保留 16 位元組的數字(第 3 章會逐項計算),受限於記憶體速度而非算術。
To turn FLOPs into time, divide by the rate at which a GPU computes. Its peak rate is the most it can do in theory. The table gives the peaks of three GPU generations for BF16, the 16-bit number format of training (Chapter 3). "Dense" means without the 2:1 structured-sparsity figure that product sheets often quote, which training does not use. Chapter 2 explains the memory columns and the NVLink column, the connections between the GPUs inside one machine.
要把 FLOP 換成時間,就除以 GPU 的運算速率。它的峰值速率是理論上的上限。下表列出三個 GPU 世代在 BF16(訓練用的 16 位元數字格式,第 3 章)下的峰值。「稠密」是指不含產品規格表常引用的 2:1 結構化稀疏數字,訓練用不到那個。第 2 章會解釋記憶體兩欄,以及 NVLink(一台機器內 GPU 之間的連接)一欄。
| GPU | Dense BF16 peak | 稠密 BF16 峰值 | Memory | 記憶體 | Memory bandwidth | 記憶體頻寬 | NVLink per GPU | 每 GPU NVLink |
|---|---|---|---|---|---|---|---|---|
| A100 (2020) | 312 TFLOP/s | 80 GB | about 2.0 TB/s | 約 2.0 TB/s | about 600 GB/s | 約 600 GB/s | ||
| H100 SXM (2022) | 989 TFLOP/s | 80 GB | about 3.35 TB/s | 約 3.35 TB/s | about 900 GB/s | 約 900 GB/s | ||
| B200 (2024) | about 2.2 PFLOP/s | 約 2.2 PFLOP/s | about 180 GB | 約 180 GB | about 8 TB/s | 約 8 TB/s | about 1.8 TB/s | 約 1.8 TB/s |
Now the worked example: Llama 3 405B, pre-trained on about 15.6 trillion tokens. The arithmetic, one question per row; a GPU-hour is one GPU busy for one hour, the unit in which training time is bought:
現在看實例:Llama 3 405B,以約 15.6 兆 token 預訓練。逐列計算如下;GPU 小時是一顆 GPU 忙碌一小時,也是購買訓練時間的單位:
| Question問題 | Calculation算式 | Result結果 |
|---|---|---|
| Training compute ()訓練計算量() | FLOP | |
| One H100 at its 989 TFLOP/s peak一顆 H100、989 TFLOP/s 峰值 | sabout 1,200 years約 1,200 年 | |
| One H100 at the 400 TFLOP/s achieved (Llama 3 Table 4, 16K-GPU row)一顆 H100、實際達到的 400 TFLOP/s(Llama 3 Table 4 的 16K GPU 那一行) | sabout 3,000 years約 3,000 年 | |
| Aggregate rate of 16,384 GPUs at 400 TFLOP/s16,384 顆 GPU、每顆 400 TFLOP/s 的總速率 | FLOP/s | |
| Pure stepping time on those 16,384 GPUs這 16,384 顆 GPU 的純步進時間 | sabout 67 days約 67 天 | |
| Average rate per GPU from the model card's 31 million GPU-hours由模型卡的 3,100 萬 GPU 小時反推每顆 GPU 的平均速率 | FLOP/sabout 340 TFLOP/s, 34% of peak約 340 TFLOP/s,峰值的 34% | |
| One H100 GPU-year at 40% of peak一個 H100 GPU 年、40% 峰值 | FLOP |
So pure stepping on 16,384 GPUs would take about 67 days. The real run took longer: averaged over everything, each GPU delivered about 340 TFLOP/s, about 34% of peak. The difference is a long-context phase that ran less efficiently (Section 1.3), the restarts after 466 interruptions in 54 days, and the work lost between each failure and the last saved copy of the training state, called a checkpoint (Chapter 9). Keep two numbers from this section: a GPU-year of H100 time at 40% of peak is about FLOP, and a frontier model needs thousands of them.
所以 16,384 顆 GPU 的純步進時間約 67 天。實際的運行更久:全程平均下來,每顆 GPU 只發揮約 340 TFLOP/s,約為峰值的 34%。差距來自效率較低的長上下文階段(第 1.3 節)、54 天內 466 次中斷之後的重啟,以及每次故障與上一份訓練狀態存檔之間損失的工作;這種存檔稱為檢查點(第 9 章)。從這一節記住兩個數字:一個 H100 GPU 年在 40% 峰值下約為 FLOP,而一個前沿模型需要數千個。
Figure 1.2 puts the three per-GPU rates side by side, and Panel 1.1 repeats the calculation for other models and clusters.
圖 1.2 把每顆 GPU 的三種速率並排,面板 1.1 則對其他模型與叢集重做這個計算。
1.3Utilization: how much of the peak a run uses使用率:一次訓練用到多少峰值
The number that tells you how well a run uses its GPUs is MFU, model FLOPs utilization: the tokens per second the job actually trains, multiplied by , divided by the number of GPUs times their peak FLOP/s. It counts only the arithmetic the model needs. HFU, hardware FLOPs utilization, counts every FLOP the hardware executed, including recomputation. When a system saves memory by keeping fewer intermediate results and recomputing them in the backward pass (activation checkpointing, Chapter 3), it performs an extra forward pass, about per token instead of , and HFU credits it. HFU is therefore always at least MFU, and the gap is extra computation (recomputing the forward pass during the backward pass) traded for less memory use. The PaLM authors, who proposed MFU as the metric to report, gave 46.2% MFU and 57.8% HFU for the same run. The TPU v4 paper quotes the 57.8% figure and reports that TPU v4 sustains about 60% of peak on large language models (TPU v4 guided reading). When you compare systems, check which of the two is being quoted, and against which peak: dense or sparse, BF16 or FP8.
衡量一次訓練把 GPU 用得多好的數字是 MFU(模型 FLOPs 使用率):任務實際訓練的每秒 token 數乘以 ,除以 GPU 數乘上它們的峰值 FLOP/s。它只計入模型需要的算術。HFU(硬體 FLOPs 使用率)計入硬體執行的每一次 FLOP,包括重算。當系統為了省記憶體而少存中間結果、在反向傳播時重算它們(激活值檢查點,第 3 章),它多做一次前向,每個 token 約 而非 ,HFU 會把它算進去。所以 HFU 永遠不低於 MFU,兩者的差距,就是用額外的運算(在反向傳播時重算前向)換取更少的記憶體使用。提議以 MFU 作為回報指標的 PaLM 作者,對同一次運行給出 46.2% MFU 與 57.8% HFU。TPU v4 論文引用的是 57.8% 這個數字,並回報 TPU v4 在大型語言模型上持續達到約 60% 的峰值(TPU v4 導讀)。比較系統時,要確認引用的是兩者中的哪一個,以及相對於哪個峰值:稠密或稀疏、BF16 或 FP8。
Figure 1.3 shows what each metric counts.
圖 1.3 畫出兩種指標各計入什麼。
| System | 系統 | Scale | 規模 | Reported | 回報值 | Source | 來源 |
|---|---|---|---|---|---|---|---|
| MegaScale, 175B | 256 Ampere GPUs | 256 顆 Ampere GPU | 65.3% MFU | MegaScale Table 2 | MegaScale Table 2 | ||
| MegaScale, 175B | 12,288 Ampere GPUs | 12,288 顆 Ampere GPU | 55.2% MFU | MegaScale Table 2; Megatron-LM 41.2% | MegaScale Table 2;Megatron-LM 41.2% | ||
| Llama 3 405B | 8,192 H100 | 8,192 顆 H100 | 43% BF16 MFU | Llama 3 Table 4 | Llama 3 Table 4 | ||
| Llama 3 405B | 16,384 H100 | 16,384 顆 H100 | 41% / 38% BF16 MFU | Llama 3 Table 4; 8K / 128K context | Llama 3 Table 4;8K / 128K 上下文 | ||
| PaLM 540B | 6,144 TPU v4 | 6,144 顆 TPU v4 | 46.2% MFU, 57.8% HFU | PaLM paper; TPU v4 paper quotes 57.8% | PaLM 論文;TPU v4 論文引用 57.8% | ||
| LLMs on TPU v4 | TPU v4 上的 LLM | up to 4,096 chips | 最多 4,096 顆晶片 | about 60% of peak | 約 60% 峰值 | TPU v4 paper, results section | TPU v4 論文,結果一節 |
Why does MFU remain so far below peak GPU performance? Three factors account for most of the gap. First, GPU execution is imperfect. Small matrix operations fail to fully utilize the hardware, while layer normalization, softmax and optimizer updates are often memory-bound, limited by how fast data moves in and out of GPU memory rather than by arithmetic. Second, communication introduces idle time, because GPUs must wait for data transfers across devices (Chapter 4 and Chapter 5). Third, synchronization amplifies stragglers, GPUs that run persistently slower than the rest. Faster GPUs remain idle until the slowest worker finishes (Section 1.4). These overheads reduce MFU within each training step. Beyond that, checkpointing, data loading and failure recovery introduce additional downtime, including the 466 interruptions recorded over 54 days. Because reported MFU typically excludes this downtime, actual end-to-end training efficiency can be even lower. Effective training time, the share of wall-clock time in which the job makes progress it keeps, measures it separately; it was above 90% for both MegaScale and Llama 3 (Chapter 10). Multiply the two to get the fraction of purchased GPU-time that became model: about for the Llama 3 run, which is consistent with the 34% that the model card's GPU-hours imply.
為什麼 MFU 會遠低於 GPU 的峰值效能?差距大部分來自三個因素。第一,GPU 的執行並不完美。小型矩陣運算無法充分利用硬體,而 layer normalization、softmax 與優化器更新往往受記憶體限制,速度取決於資料進出 GPU 記憶體有多快,而不是算術有多快。第二,通訊帶來閒置時間,因為 GPU 必須等待跨裝置的資料傳輸(第 4 章與第 5 章)。第三,同步會放大落後者(持續比其他 GPU 慢的 GPU)的影響。較快的 GPU 必須閒置,直到最慢的那一個完成(第 1.4 節)。這些開銷都在每個訓練步之內降低 MFU。除此之外,檢查點、資料載入與故障恢復還帶來額外的停機時間,包括 54 天內記錄到的 466 次中斷。由於回報的 MFU 通常不含這些停機時間,實際端到端的訓練效率可能更低。有效訓練時間——工作在牆鐘時間中產生可保留進度的比例——把它分開量;MegaScale 與 Llama 3 都高於 90%(第 10 章)。把兩者相乘就得到買來的 GPU 時間中真正變成模型的比例:Llama 3 這次運行約 ,與模型卡的 GPU 小時所隱含的 34% 一致。
Figure 1.4 follows the purchased GPU time down to that 37%.
圖 1.4 把買來的 GPU 時間一路追到這 37%。
Here is what one MFU point buys on the FLOP of Llama 3 405B. The price is about $2 per H100-hour, a round number in the range of public cloud rates in 2024–2025, and the power is 700 W per GPU:
一個 MFU 百分點值多少,以 Llama 3 405B 的 FLOP 算給你看。價格以每 H100 小時約 2 美元計——這是 2024–2025 年公有雲價格範圍內的一個整數——功率以每顆 GPU 700 W 計:
| Question問題 | Calculation算式 | Result結果 |
|---|---|---|
| GPU-hours at 100% of the H100 peak在 H100 峰值 100% 下的 GPU 小時 | GPU-habout 10.6 million約 1,060 萬 | |
| GPU-hours at 41% MFU41% MFU 時的 GPU 小時 | GPU-habout 26.0 million約 2,600 萬 | |
| GPU-hours at 42% MFU42% MFU 時的 GPU 小時 | GPU-habout 25.3 million約 2,530 萬 | |
| One MFU point, 41% → 42%一個 MFU 百分點,41% → 42% | GPU-habout 620,000約 62 萬 | |
| The same in hours of the whole 16,384-GPU cluster換算成整個 16,384 顆 GPU 叢集的小時數 | h | |
| The same in dollars at $2 per H100-hour以每 H100 小時 2 美元計的金額 | USDabout $1.2 million約 120 萬美元 | |
| The same in GPU energy at 700 W (0.7 kW)以 700 W(0.7 kW)計的 GPU 用電 | kWhabout 430 MWh約 430 MWh |
One point is therefore about 620,000 GPU-hours, about 38 hours of the whole cluster, about $1.2 million, and about 430 MWh of GPU power alone, before cooling and the rest of the machine. These are the stakes behind the gains in later chapters: 14.9% from a better way of wiring the network at Alibaba (Chapter 6), more than 2× for the exchanges between GPUs from tuning the network and the communication library together at Meta (Chapter 4), and 0.7 points from removing 0.5% of slow machines at ByteDance (Section 1.4). The network is a few percent of a cluster's cost. The utilization it decides is worth far more than the network itself.
所以一個百分點約為 62 萬 GPU 小時,相當於整個叢集約 38 小時,約值 120 萬美元,光是 GPU 電力就約 430 MWh,還不含冷卻與機器的其他部分。這就是後面各章那些增益背後的賭注:Alibaba 靠更好的網路接法得到 14.9%(第 6 章)、Meta 靠同時調校網路與通訊函式庫讓 GPU 之間的交換快了超過 2 倍(第 4 章)、ByteDance 靠移除 0.5% 的慢機器拿回 0.7 個百分點(第 1.4 節)。網路只占叢集成本的幾個百分點。它所決定的使用率,價值遠超過網路本身。
Panel 1.2 recomputes the value of one point for other MFU levels, prices and power draws.
面板 1.2 對其他 MFU、價格與功率重算一個百分點的價值。
1.4Many GPUs, one step: the barrier多顆 GPU、一個步驟:柵欄
Every exchange of this kind is a barrier: a point that no rank can pass until every rank has reached it. The all-reduce cannot produce its result until the last GPU's gradients have arrived, and the optimizer cannot update until the sum is complete. So the time of a step is not the average time of its participants but the maximum. If one GPU in 16,384 is 10% slower, the other 16,383 wait 10% of a step, every step, for as long as that GPU stays in the job. MegaScale found that about 0.5% of its machines were substantially slower than the rest, in one case about 10% longer on identical forward computations, and that removing them regained about 0.7 MFU points and made peak MFU consistent from run to run (MegaScale §6.3). Llama 3 states the rule in one sentence: a single straggler, a rank that is persistently slower than the others, can slow thousands of GPUs. That is why Meta built tools to find the slowest ranks (Llama 3 §3.3.4). The network is one source of such delay. A part of the network that is overloaded makes one rank's data arrive late in exactly the way a slow GPU does, and the rest of the job cannot tell the difference.
每一次這類交換都是一道柵欄(barrier):所有 rank 都抵達之前,誰也不能通過的點。all-reduce 要等最後一顆 GPU 的梯度到達才能產生結果,優化器要等總和完成才能更新。所以一步的時間不是參與者的平均時間,而是最大值。如果 16,384 顆 GPU 中有一顆慢 10%,其他 16,383 顆每一步都等 10% 的步時間,只要那顆 GPU 還在任務裡就一直如此。MegaScale 發現約 0.5% 的機器明顯比其他慢,其中一例在相同的前向計算上多花約 10%,而移除它們拿回約 0.7 個 MFU 百分點,並讓各次運行的峰值 MFU 變得一致(MegaScale §6.3)。Llama 3 用一句話說出這條規則:單一個 straggler(持續比其他 rank 慢的 rank)就能拖慢數千顆 GPU。所以 Meta 建了工具來找出最慢的 rank(Llama 3 §3.3.4)。網路是這類拖慢的來源之一。網路中某個超載的部分讓某個 rank 的資料晚到,效果和一顆慢 GPU 完全相同,任務的其餘部分分不出差別。
Figure 1.5 draws one step of eight ranks with one straggler.
圖 1.5 畫出八個 rank、其中一個是 straggler 的一步。
Animation 1.1 plays the step of Figure 1.5 in time order: each rank reaches the barrier and waits there.
動畫 1.1 依時間順序播放圖 1.5 的那一步:每個 rank 抵達柵欄,然後在那裡等待。
Random variation adds to this. Every rank's step time varies a little from step to step, and the step waits for the largest of thousands of such values, which grows with the number of ranks. Chapter 10 works out how large that effect is, and how operators find and remove stragglers. The network is part of the same story: a part of the network that is slow for one step delays every rank, exactly as a slow GPU does.
隨機變動會讓情況更糟。每個 rank 的步驟時間每一步都略有不同,而一步要等數千個這種數值中的最大者,這個最大值會隨 rank 數增加而變大。第 10 章會算出這個效應有多大,以及營運者如何找出並移除 straggler。網路也在同一個故事裡:只要網路的某一部分在某一步變慢,所有 rank 都會被拖慢,和一顆慢 GPU 的效果完全一樣。
Numbers in this book come from four kinds of evidence, and the text says which one each number is.
Papers mix the four, and so did the first edition of this book. When a paper's figure is computed, this edition says so in the caption. Chapter 12 explains how to judge each kind.
本書的數字來自四種證據,文中會註明每個數字屬於哪一種。
論文常混用這四種,本書第一版也是。這一版遇到論文中計算所得的圖時,會在圖說中註明。第 12 章說明如何判讀每一種。
A training step is a forward pass, a backward pass, an optimizer step and a synchronization. Its arithmetic is about 6 FLOPs per parameter per token, so a model of 405 billion parameters trained on 15.6 trillion tokens needs about FLOPs: thousands of GPU-years. Thousands of GPUs therefore share each step, and they must add their gradients together before every update. MFU measures how much of the GPUs' peak rate a run turns into the arithmetic the model needs; at Llama 3's scale one point of MFU is worth about a million dollars. Because the synchronization is a barrier, a step lasts as long as its slowest GPU, or the slowest part of the network between them.
一個訓練步驟包含前向傳播、反向傳播、優化器步驟與同步。它的算術量約為每個參數、每個 token 6 個 FLOP,所以用 15.6 兆個 token 訓練 4,050 億參數的模型約需 FLOP,相當於數千個 GPU 年。因此每一步都由數千顆 GPU 分擔,而且每次更新前都必須把梯度加總。MFU 衡量一次訓練把 GPU 峰值速率的多少轉成模型需要的算術;在 Llama 3 的規模,一個 MFU 百分點約值一百萬美元。由於同步是一道柵欄,一個步驟的長度由最慢的 GPU,或兩者之間網路中最慢的部分決定。
Chapter 2 introduces the hardware: the GPU's memory, the links inside a server, the network card and the switch, and the speed of each. Chapter 3 shows how a model is split across GPUs, and Chapter 4 how GPUs exchange data. Chapter 5 adds up the bytes of one step and shows why the network decides how fast training runs.
第 2 章介紹硬體:GPU 的記憶體、伺服器內的鏈路、網路卡與交換器,以及各自的速度。第 3 章說明模型如何切到多顆 GPU 上,第 4 章說明 GPU 如何交換資料。第 5 章把一個步驟的位元組加總,說明為何網路決定了訓練的速度。