Part 6

Training at Scale

Mehmet Kerem Turkcan
Associate Research Scientist
Center for Smart Streetscapes, Columbia University
New York, USA
keremturkcan.com; mkt2126@columbia.edu

Move through the deck with (i) the arrow keys, (ii) a presentation clicker, or (iii) the buttons at the bottom left. The gear at the bottom right opens the slide settings.

Part 5 Overview

  1. The loop: Training repeats four stages: forward computation, loss, backward computation, and weight update. Part 5 ran the loop on toy networks with a dozen weights.
  2. The losses: Cross entropy counts halvings for token answers, and squared loss measures distance for number answers.
  3. The gap: The assistant in your browser holds hundreds of billions of weights, and the same loop trained every one of them.
  4. Today: the three training stages that shape an assistant, the machines that run them, and the bill in dollars, megawatt hours, and tonnes of CO2.

Part 9 opens attention, the gray box from Parts 2 and 3.

The three stages of training

Every modern assistant is shaped in three stages, each running Part 5's loop on a different kind of data.

raw text trillions of tokens Stage 1: pretraining written answers thousands to a million Stage 2: supervised fine tuning base model choices between answers tens of thousands and up Stage 3: preference tuning assistant the model you talk to
Rough scales; the documented figures follow.

All three stages run the same training loop; the stages differ in their data and their loss.

Stage 1: pretraining

Pretraining plays Part 1's game at planetary scale: read text, predict the next token, and update the weights after every position. Because the text itself supplies each correct next token, no person labels anything.

\mathcal{L}(\theta)=-\sum_{t}\log_2\, p_\theta\!\left(x_t\mid x_{<t}\right)

Each position t charges the halving loss of the true next token x_t given everything before it, and the sum runs over every position of every document. One halving is one bit; published implementations sum base e logarithms, where one halving equals 0.69 nats (Part 5's reconciliation).

One position, worked with illustrative numbers: after thecatsatonthe the model gives mat probability 0.25, so this position costs -\log_2 0.25 = 2 halvings; a sharper model that gives 0.5 pays 1 halving.

History: Next token pretraining at modern scale entered through GPT (Radford et al. 2018) and GPT-2 (2019); GPT-3 (Brown et al. 2020) trained 175 billion weights on 300 billion tokens.

How large is the pretraining dataset?

modelyearpretraining tokens
GPT-3 (OpenAI)2020300 billion
Chinchilla (DeepMind)20221.4 trillion
DeepSeek-V3202414.8 trillion
Llama 3.1 405B (Meta)202415.6 trillion

Passes over the data (epochs): about one. Chinchilla paired 70 billion weights with 1.4 trillion tokens and doubled tokens whenever weights double, roughly 20 tokens per weight (a derived ratio). Muennighoff et al. (2023) measured that repeating the same data up to about 4 passes loses almost no quality, and that past about 16 passes further repetition adds almost no improvement.

Llama 3.1's dataset printed on paper
\begin{aligned}15.6\text{T tokens}&\approx 11.7\text{T words}&&\scriptstyle(0.75\text{ words per token})\\&\approx 23.4\text{B pages}&&\scriptstyle(500\text{ words per page})\\&\approx 2{,}340\text{ km of paper}&&\scriptstyle(500\text{ sheets}\approx 5\text{ cm})\end{aligned}

Printed one page per sheet, the stack stands about 2,340 km tall, nearly six times the altitude of the International Space Station's orbit (about 400 km). The token to word ratio is OpenAI's published rule of thumb.

Sources: Brown et al. 2020 (Table 2.1); Hoffmann et al. 2022; DeepSeek-AI 2024; Grattafiori et al. 2024 (the Llama 3 herd paper states 15.6T in its introduction).

Stage 2: supervised fine tuning

A pretrained base model continues text; asked a question, it may continue with more questions. Supervised fine tuning (SFT) teaches the assistant role from demonstrations: a prompt paired with an answer that a person wrote or approved.

\mathcal{L}_{\text{SFT}}(\theta)=-\sum_{t\,\in\,\text{answer}}\log_2\, p_\theta\!\left(x_t\mid x_{<t}\right)

The formula is Stage 1's loss restricted by a mask to the answer tokens, and the mask is Part 5's elementwise product: a zero switches a position's loss off. The model reads the prompt and is charged loss only on the answer tokens.

positionNameoneplanet.Marsisaplanet.
rolepromptpromptpromptpromptansweransweransweransweranswer
mask000011111

Documented scale: InstructGPT (Ouyang et al. 2022) tuned GPT-3 on about 13,000 demonstration prompts for 16 epochs; the paper reports validation loss overfitting after one epoch while human ratings kept improving. Tülu 3 (Ai2, 2024) mixed 939,344 demonstrations. While pretraining runs for weeks to months, this stage finishes in hours to days.

Stage 3: learning from comparisons

Because people compare two answers more reliably than they compose an ideal one, the training data takes a new form: one prompt, two answers, and a choice. A reward model, a copy of the LLM whose output head produces one score, learns to predict the choice.

P(A\ \text{preferred over}\ B)=\sigma\!\left(r_A-r_B\right)

This is the Bradley and Terry comparison model (1952), and \sigma is Part 3's sigmoid applied to a score difference. With illustrative scores: r_A=1.5 and r_B=0.5 give \sigma(1.0)\approx 0.73, so answer A should win about 73 of 100 comparisons.

The reward model trains on the loss -\log\sigma\big(r_{\text{chosen}}-r_{\text{rejected}}\big), which falls as the chosen answer's score climbs above the rejected answer's. InstructGPT trained its reward model on 33,000 comparison prompts (Ouyang et al. 2022).

The same comparison mathematics ranks chess players: Arpad Elo's rating system, adopted by FIDE in 1970, reads a rating gap as an expected score.

Reinforcement learning from human feedback

prompts31,000 in InstructGPT the policy writes answersthe model being tuned reward model scoresone number per answer weight updatehigh scoring answersgain probability repeat with the tuned policy
The loop that shaped ChatGPT (OpenAI, November 2022), following Ouyang et al. 2022.
\max_\theta\ \ \mathbb{E}\big[\,r(x,y)\,\big]\;-\;\beta\,\mathrm{KL}\!\left(\pi_\theta\,\|\,\pi_{\text{ref}}\right)

The policy \pi_\theta is the model being tuned. KL divergence measures how far its probabilities have drifted from \pi_{\text{ref}}, a frozen copy made before tuning, and \beta sets the penalty for that drift, so however hard the update chases reward, it cannot push the model's probabilities far from the pretrained ones.

PPO: small clipped steps

Proximal Policy Optimization (Schulman et al. 2017) performs the update, working with the probability ratio between the new and the previous policy, and it clips every step:

\rho=\frac{\pi_\theta(y\mid x)}{\pi_{\text{old}}(y\mid x)},\qquad L=\min\!\big(\rho\,A,\ \ \mathrm{clip}(\rho,\,1-\varepsilon,\,1+\varepsilon)\,A\big)

A is the advantage: how much better the answer scored than expected, where the expectation comes from a separate value network. With the paper's suggested \varepsilon=0.2, an advantage of +1 and a ratio already at 1.3 earn \min(1.3,\,1.2)=1.2, so a step past the clip range adds nothing to the objective; PPO enforces Part 4's small steps inside the loss itself.

network held in memory during PPOrole
policythe model being tuned
reference copy (frozen)anchors the KL drift penalty
reward model (frozen)scores each sampled answer
value networkestimates the expected score, giving A

Four LLM sized networks resident at once make PPO the most memory hungry stage; the two methods on the next slides each drop parts of this list.

DPO: the algebra shortcut

Direct Preference Optimization (Rafailov et al., NeurIPS 2023) starts from the RLHF objective, solves it in closed form, and substitutes the solution back. Because the reward model and the sampling loop cancel out of the algebra, one supervised loss on preference pairs remains:

\mathcal{L}_{\text{DPO}}=-\log\sigma\!\left(\beta\log\frac{\pi_\theta(y_w\mid x)}{\pi_{\text{ref}}(y_w\mid x)}-\beta\log\frac{\pi_\theta(y_l\mid x)}{\pi_{\text{ref}}(y_l\mid x)}\right)

Here y_w is the chosen answer and y_l the rejected one; each log ratio measures how much the tuned model has raised that answer's probability relative to the frozen reference; the loss falls when the chosen answer's ratio climbs above the rejected answer's; and \beta sets the drift penalty exactly as it did in the RL objective.

With illustrative numbers: at the start both ratios equal 1, the bracket is 0, \sigma(0)=0.5, and the loss is one halving. When training lifts the bracket to 1.0, \sigma(1.0)\approx 0.73 and the loss falls to about 0.45 halvings.

What remains in memory: the policy and the frozen reference; no reward model, no value network, no sampling during training. Meta's Llama 3 post training ran rounds of SFT and DPO (Grattafiori et al. 2024).

GRPO: the group baseline

PPO's value network answers one question: how well should answers to this prompt score? Group Relative Policy Optimization (Shao et al. 2024) answers it with a sample: draw G answers to the same prompt, score them all, and grade each against the group.

A_i=\frac{r_i-\mathrm{mean}(r_1,\dots,r_G)}{\mathrm{std}(r_1,\dots,r_G)}

A concrete group: four answers earn rewards (1,0,0,1) from an automatic checker; the mean is 0.5, the standard deviation 0.5, so the advantages are (+1,-1,-1,+1), and the update takes PPO's clipped step.

Because a checker can mark a final mathematics or code answer, the reward there needs no model at all; DeepSeek-R1 (2025) was trained for reasoning this way.

one problem G = 4 samples answer 1: reward 1 advantage +1 answer 2: reward 0 advantage −1 answer 3: reward 0 advantage −1 answer 4: reward 1 advantage +1
Illustrative rewards. The paper states that GRPO "foregoes the critic model, instead estimating the baseline from group scores."

The pipeline in numbers

stagedocumented datapassesdocumented compute
pretraining15.6T tokens (Llama 3.1 405B, 2024)about 130.84M H100 hours; about 78 days at the peak 16,384 GPUs (derived)
SFT13k demonstrations (InstructGPT, 2022); 939,344 (Tülu 3, 2024)16 (InstructGPT)hours to days
preference tuning33k comparison + 31k tuning prompts (InstructGPT, 2022)a fewdays

DeepSeek-V3's own ledger (2024 technical report, Table 1) splits 2.788M H800 GPU hours as: pretraining 2,664K; context extension 119K; post training 5K. In that ledger, post training amounts to about 0.2% of the total (a derived share).

The loop is identical across the stages, while the compute spans three orders of magnitude.

For the classroom: have students place DeepSeek-V3's ledger on a log scale of GPU hours: 2,664,000; 119,000; 5,000. The drawing makes the 0.2% vivid.

Drawing triangles

The machine that supplies this arithmetic was built to draw game frames. Every shape on a screen is a mesh of triangles; smooth surfaces, such as Martin Newell's 1975 Utah teapot, are tessellated into triangles before drawing.

To turn a shape, one small matrix multiplies every vertex, the matrix by vector multiplication of Part 5. A quarter turn:

\begin{pmatrix}0&-1\\1&0\end{pmatrix}\begin{pmatrix}1\\0\end{pmatrix}=\begin{pmatrix}0\\1\end{pmatrix}

Real pipelines use 4 by 4 matrices, so one product carries rotation, scale, and perspective together (Akenine-Möller et al., Real-Time Rendering, 2018). At 60 frames per second, the pipeline repeats the multiplication for millions of vertices in every frame, every one independent of the others.

(1, 0) (0, 1)
One vertex computed by hand; the pipeline repeats it for millions.

Why is a GPU good at matrix multiplication?

A CPU spends its silicon on a few cores that finish one task quickly; a GPU spends it on thousands of small cores that run one instruction on thousands of numbers at once. Rasterization, filling in the pixels of each triangle, repeats the same small calculation millions of times per frame.

Matrix multiplication has the same shape of work. Multiplying two n\times n tables takes n^3 multiplications on 2n^2 input numbers. At n=1{,}000: two million numbers enter, one billion multiplications run, and every number is reused a thousand times, so the arithmetic outpaces the memory traffic and thousands of cores stay fed.

NVIDIA's Volta generation (2017) added Tensor Cores, circuits that multiply whole 4 by 4 matrices in a single clock cycle, reading FP16 inputs and accumulating in FP32. The H100 makes Part 5's scale note concrete:

H100 SXM (NVIDIA, 2022)figure
dense BF16 tensor throughput989 trillion operations per second
transistors80 billion (custom TSMC 4N process)
powerup to 700 W

A short history of the GPU

1993NVIDIA founded 19963dfx Voodoo 1997RIVA 128 1999GeForce 256 2001shaders 2004Brook for GPUs 2006CUDA 2012AlexNet 2017Tensor Cores 2022H100 2025worth $4T
Graphics era in blue, general computation in amber, the AI era in green.

Jensen Huang, Chris Malachowsky, and Curtis Priem planned NVIDIA over meetings at a Denny's in East San Jose in late 1992 and incorporated on April 5, 1993. The GeForce 256 (October 1999) shipped with the marketing line "the world's first GPU" because it moved transform and lighting, the vertex matrix work, onto the chip.

Because only graphics programs could reach the cores, researchers first phrased general arithmetic as drawing operations; Ian Buck's Brook for GPUs (SIGGRAPH 2004) systematized the approach, and Buck then led CUDA at NVIDIA, which removed the graphics phrasing altogether.

AlexNet (Krizhevsky, Sutskever, and Hinton, 2012) trained "between five and six days on two GTX 580 3GB GPUs" and won ImageNet. Because researchers across the field then moved to GPU training, NVIDIA became the first company to end a trading day valued above four trillion dollars (July 10, 2025) and the first to reach five trillion (October 29, 2025; CNBC).

The cluster and the invoice

training runGPUsGPU hoursdurationstated cost basis
Llama 3.1 405B (Meta, 2024)up to 16,384 H10030.84Mabout 78 days at the peak count (derived)hardware: about $0.4B to $0.5B of GPUs at reported prices (derived)
DeepSeek-V3 (2024)2,048 H8002.788Mabout 57 days (derived)$5.576M at the report's assumed $2 per GPU hour rental

Raymond James analysts estimated in 2023 that an H100 sells for $25,000 to $30,000, and shortage era retail listings reached $40,000 (CNBC reporting). At $25,000 to $30,000, the peak Llama cluster's 16,384 GPUs represent $410M to $492M of hardware before servers, networking, and buildings.

DeepSeek-V3's report states its cost figure covers "only the official training", excluding "prior research and ablation experiments on architectures, algorithms, or data". Power, derived from the model card's 700 W per GPU: the peak Llama cluster draws about 11.5 MW for the GPUs alone.

Duration derivations: 30.84M GPU hours across 16,384 GPUs give 1,882 hours, about 78 days, and longer in practice because early stages ran on 8,192 GPUs; 2.788M across 2,048 give about 57 days.

The energy and carbon bill

training runelectricityemissions (tCO2eq)
GPT-3 (Patterson et al. 2021)1,287 MWh552
BLOOM (Luccioni et al. 2022)433 MWh24.7; 50.5 with manufacturing and idle
Llama 3.1 herd (Meta model card, 2024)GPUs alone: ≈21.6 GWh (derived)11,390 location based; 0 market based

The location based figure counts what the local grid actually emitted, while the market based figure subtracts renewable energy that the company bought to match its use, which is how Meta reports 0. The 405B model alone accounts for 8,930 of the 11,390 tonnes.

An average US passenger car emits about 4.6 tonnes per year (EPA), and a transatlantic round trip seat costs about 1 tonne of CO2, roughly 2 with high altitude effects included (carbonfootprint.com calculator, 2025), so GPT-3's training equals about 120 car years, or the annual electricity of about 123 US households (EIA average, 10,500 kWh).

The 21.6 GWh line is a derivation from 30.84M GPU hours at 700 W; it covers the GPUs alone and excludes cooling and facility overhead, so the true facility figure sits higher.

AI in the world's energy budget

Data centres of every kind, AI included, drew about 415 TWh in 2024, about 1.5% of the world's roughly 30,700 TWh of electricity; the IEA's base case reaches about 945 TWh by 2030, just under 3% (IEA, Energy and AI, 2025; Ember, 2025).

Sector comparisons need care, because the units differ: data centres above are measured as a share of electricity, while aviation contributes about 2.5% and cement about 7% of global CO2 (Our World in Data from Lee et al. 2021; IEA). The shares therefore indicate rough magnitude only.

Per use, the cost is small: about 0.3 Wh per chatbot query (Epoch AI, February 2025), which runs a 60 W bulb for 18 seconds; OpenAI's June 2025 blog states 0.34 Wh, a company figure. The older 3 Wh estimate (de Vries, 2023, Joule) predates measured efficiency gains.

One frontier training run draws about as much electricity as 2,000 US households use in a year (derived from the EIA average), while the whole data centre sector remains a small, quickly growing share of the world's grid.

Reading note: published energy and emission estimates for AI change quickly, so every figure above carries its year.

Check for understanding

Exercise 1. A GRPO group of four answers earns rewards (1,0,1,0). Compute each answer's advantage.

The mean is 0.5 and the standard deviation is 0.5, so the advantages are (+1,-1,+1,-1): both correct answers gain probability, both wrong answers lose it.

Exercise 2. GPT-3 trained on about 300 billion tokens (Brown et al. 2020). Using 0.75 words per token, 500 words per page, and 500 sheets per 5 cm, how tall is the printed stack?

About 225 billion words, 450 million pages, and 900,000 reams: a stack of about 45 km, five times the height of Mount Everest.

Part 6 Overview

  1. Three stages: Pretraining reads raw text, SFT reads written answers, and preference tuning reads choices; all three run Part 5's loop.
  2. The losses: SFT masks pretraining's loss to the answer tokens. The reward model applies the sigmoid to a score difference. PPO clips each step and incurs a KL penalty for drift. DPO collapses the reward model and the loop into one supervised loss. GRPO grades each answer against its group.
  3. The machines: Triangles made the GPU: millions of identical vertex and pixel jobs built hardware that now runs matrix multiplication at 989 trillion operations per second on an H100.
  4. The measurements: 15.6 trillion tokens, one pass, 30.84 million GPU hours, and about 78 derived days for Llama 3.1 405B; post training adds about 0.2% of compute in DeepSeek-V3's ledger.
  5. The bill: hundreds of millions of dollars of GPUs for a frontier cluster; hundreds of megawatt hours to tens of gigawatt hours per run; tonnes of CO2 that depend on the accounting; about 1.5% of world electricity for the whole sector.

Next: Part 7 hands the model tools: the agent loop, web search, MCP, and skills. Part 9 opens attention.

Sources: the training pipeline

  • T. Brown et al., 2020, “Language Models are Few-Shot Learners,” NeurIPS; 175B parameters, 300B training tokens (Table 2.1).
  • J. Hoffmann et al., 2022, “Training Compute-Optimal Large Language Models,” (Chinchilla); equal scaling of parameters and tokens; 70B parameters, 1.4T tokens.
  • N. Muennighoff et al., 2023, “Scaling Data-Constrained Language Models,” NeurIPS; up to 4 epochs of repeated data cost little.
  • L. Ouyang et al., 2022, “Training language models to follow instructions with human feedback” (InstructGPT); 13k SFT, 33k reward, 31k PPO prompts; 16 SFT epochs.
  • J. Schulman, F. Wolski, P. Dhariwal, A. Radford, O. Klimov, 2017, “Proximal Policy Optimization Algorithms”; the clipped objective; “say, ε = 0.2.”
  • R. Rafailov, A. Sharma, E. Mitchell, C. D. Manning, S. Ermon, C. Finn, 2023, “Direct Preference Optimization: Your Language Model is Secretly a Reward Model,” NeurIPS.
  • Z. Shao et al., 2024, “DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models”; GRPO.
  • DeepSeek-AI, 2024, “DeepSeek-V3 Technical Report”; 14.8T tokens; 2,048 H800; 2.788M GPU hours; $5.576M at $2 per hour. DeepSeek-AI, 2025, “DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning.”
  • A. Grattafiori et al. (Meta), 2024, “The Llama 3 Herd of Models”; 15.6T tokens; up to 16,384 H100s; 3.8×10²⁵ FLOPs. Meta, 2024, Llama 3.1 Model Card; 30.84M GPU hours; 11,390 tCO2eq location based, 0 market based.
  • N. Lambert et al. (Ai2), 2024, “Tülu 3: Pushing Frontiers in Open Language Model Post-Training”; SFT mixture of 939,344 samples.
  • R. A. Bradley, M. E. Terry, 1952, “Rank Analysis of Incomplete Block Designs”; A. Elo's rating system, adopted by FIDE in 1970.
  • OpenAI help center: the rule of thumb of about 0.75 English words per token, used in the printed page arithmetic.

Sources: hardware, energy, and history

  • D. Patterson et al., 2021, “Carbon Emissions and Large Neural Network Training”; GPT-3 at 1,287 MWh and 552 tCO2e.
  • A. S. Luccioni, S. Viguier, A. Ligozat, 2022, “Estimating the Carbon Footprint of BLOOM”; 433 MWh; 24.7 to 50.5 tCO2eq.
  • IEA, 2025, Energy and AI; 415 TWh in 2024, about 945 TWh by 2030. Ember, 2025, Global Electricity Review; about 30,700 TWh generated in 2024.
  • Our World in Data, from D. S. Lee et al., 2021: aviation about 2.5% of global CO2. IEA cement sector tracking: about 7%.
  • US EPA, “Greenhouse Gas Emissions from a Typical Passenger Vehicle”: 4.6 t per year. US EIA: about 10,500 kWh per household per year. carbonfootprint.com calculator, 2025: about 1 t CO2 per transatlantic round trip seat, about 2 t with high altitude effects.
  • Epoch AI, February 2025, “How much energy does ChatGPT use?”: about 0.3 Wh per query. A. de Vries, 2023, Joule: the earlier 3 Wh estimate. S. Altman, June 2025 blog: 0.34 Wh (company figure).
  • A. Krizhevsky, I. Sutskever, G. Hinton, 2012, “ImageNet Classification with Deep Convolutional Neural Networks”; two GTX 580 3GB GPUs, five to six days.
  • NVIDIA: H100 datasheet (989 TFLOPS dense BF16; 700 W; 80B transistors); Volta whitepaper, 2017 (Tensor Cores); GeForce 256 materials, 1999 (“the world's first GPU”); corporate history (founded April 5, 1993). I. Buck et al., 2004, “Brook for GPUs,” SIGGRAPH.
  • CNBC, July 10, 2025 and October 29, 2025: first closes above $4T and $5T. CNBC, 2023/2024: Raymond James H100 price estimate of $25,000 to $30,000. T. Akenine-Möller, E. Haines, N. Hoffman, 2018, Real-Time Rendering, 4th ed. Computer History Museum: the Utah teapot (M. Newell, 1975).
  • Owner: Mehmet Kerem Turkcan; Associate Research Scientist; Center for Smart Streetscapes, Columbia University; New York, USA; keremturkcan.com; mkt2126@columbia.edu.
Intro to AI, Part 6: Training at ScaleM. K. Turkcan, Columbia University