Part 2 - Lecture 2

Post-training Large
Language Models

Session 01 of 2 · Post-training (session 02: 21 Oct)

CEG5305 Introduction to Generative AI with Foundation Models
Junyuan Hong · AY2026/27 Semester 1

2026.10.14v2

Before we start

About these slides

These slides were prepared with the help of AI tools (Claude, by Anthropic), working from the reference slides and papers listed here. Junyuan Hong chose the content, checked it and is responsible for any errors. If you find one, please report it on Canvas.

Reference slides

Key papers in APA at the bottom of this slide; the full list is on the lecture page

Recap · Lecture 1, session 02

Last week: how a large model is trained and adapted

PartTitleKey message
AHow to train a bigger model on more data?The model learns from text by predicting the next token. Parallel training, sharding and lower precision make the run fit in GPU memory and time.
BThe scaling law: How to scale effectively?Scaling laws use small runs to predict the loss of large runs. They tell a lab how big a model to train, and on how much data.
CThe blessing of scaling: Emergent capabilities and efficient adaptationPrompting changes only the input. Parameter-efficient fine-tuning, such as LoRA, trains a small set of new parameters.
HWHomework: adapt one model in four waysAdapt one small model in four ways: an instruction, examples in the prompt, LoRA, full fine-tuning. Predict first, then run.

Today: a pre-trained model predicts text well. Post-training makes it follow instructions, reason and act.

Today's question

What turns GPT into ChatGPT?

GPT: a large language model
matone output token
LLM
Thecatsatonthe
a sequence of input tokens
gpt.py · Hugging Face transformers
from transformers import AutoTokenizer
from transformers import AutoModelForCausalLM

tok = AutoTokenizer.from_pretrained("gpt2")
LLM = AutoModelForCausalLM.from_pretrained("gpt2")

seq = tok("The cat sat on the",
          return_tensors="pt").input_ids
t = LLM(seq).logits[0, -1].argmax()
print(tok.decode(t))  # prints:  floor
ChatGPT: a product you chat with
Screenshot of a chat in ChatGPT, 7 July 2023. The user asks: when will the women's world cup be? where is it? ChatGPT shows Used Wikipedia, then answers in full sentences: the 2023 FIFA Women's World Cup, 20 July to 20 August 2023, hosted by Australia and New Zealand
the same chat, as simplified HTML
User: when will the women’s world cup be? where is it?

Assistant: <tool>wikipedia …</tool>
The 2023 FIFA Women's World Cup is scheduled to take place from 20 July to 20 August 2023. The tournament will be jointly hosted by Australia and New Zealand, …
✋ Your turn · one guess each

What is different between GPT and ChatGPT? Try switching the WebUI to the code view with the button at the top right.

Left: Lecture 1, session 02. Right: ChatGPT, 7 Jul 2023 (Wikimedia Commons, public domain).

Today's question · where post-training fits

GPT → ChatGPT by post-training

The life of an LLM, with GPT-4’s dates (not to scale)
Design arch🧬
Pre-training👶
Post-training🏫← tonight
Benchmarks
Security review
Go public🎉
Retirea newer LLM replaces it🪦
Aug 2022Mar 202330 Apr 2025
Where the compute goes: three stages
NVIDIA sketch titled From one to three scaling laws. The vertical axis is intelligence, in quotes; the horizontal axis is compute. A first green arrow is pre-training scaling; a steeper arrow branches from it, post-training scaling; a third, steeper still, is test-time scaling, long thinking.

Left: drawn for this course; GPT-4 dates: OpenAI (2023), Wiggers (2025); logo: Wikimedia Commons. Right: Briski (2025).

Outline · Lecture 2 = Topic 5, two sessions of three hours

Three parts answer it tonight; prompting comes next week

Session 01 · today · 3 h

Post-training — from a text predictor to an assistant

☕Break10 min
☕Break10 min
Session 02 · 21 Oct · 3 h

Prompting — from one call to a loop

History of prompting · chain-of-thought and reasoning models · agents and harnesses · invited talk at 20:10: Zeyu Qin (HKUST)

Part A

Why we need post-training

See what post-training changes, how the field got here, and why it matters.

A · What post-training brings

Base vs Chat Models

The life of an LLM, with GPT-4’s dates (not to scale)
Design arch🧬
Pre-training👶Base model (GPT)
Post-training🏫Chat (instruct) model (ChatGPT)
Benchmarks
Security review
Go public🎉
Retirea newer LLM replaces it🪦
Aug 2022Mar 202330 Apr 2025
Base model (GPT): the model at the end of pre-training. It predicts the next token, so it continues the text.
Chat (instruct) model (ChatGPT): the same model at the end of post-training. It follows instructions and answers.

Drawn for this course; GPT-4 dates: OpenAI (2023), Wiggers (2025); logo: Wikimedia Commons.

A · What post-training brings

Pre-training teaches next-token prediction on trillions of tokens

  • Train on trillions of tokens of text from the web, books, code, and documents
    • Models are often trained on 5-50+ trillion tokens
    • 1T of text tokens is about 3-5 TB of data
    • Labs gather and filter 10-20X more data than is used for the model
    • Total data funnel targeted for models is on the order of petabytes
  • Objective: predict the next token in each sequence
  • Result: Incredible, flexible, useful models
Diagram: the training example I saw a cat on a mat; the model predicts the next token after I saw a; the target is cat; the loss is minus log p(cat), which raises the probability of cat and lowers the others

From Lambert (2026c), Lecture 1, p. 13, "Pretraining: Next-token prediction"; figure cropped from the page (300 dpi).

A · What post-training brings

Guess what a model that is only pre-trained writes next

A base model is a model after pre-training only. It predicts the next token of text from the web.

  • A"S R Nathan." Then it stops.
  • B"S R Nathan," and then more facts about 2006.
  • CA full sentence that answers the question.

Prompt adapted from Lambert (2026c), Lecture 1, pp. 14–15 (his prompt asks about the United States).

A · What post-training brings

A base model continues the text instead of answering the question

After pretraining we are left with a glorified autocomplete model, for example:

Adapted from Lambert (2026c), Lecture 1, p. 14, "A base model completes text" (his example: Llama 3.1 405B Base, Grattafiori et al., 2024, on the US president).

A · What post-training brings

Post-training makes the same model answer like a chatbot

The earliest forms of modern post-trained (or RLHF-tuned) models shifted the continuation format to always conforming to the “answering a question style.” An example of what early conversational models looked like is below:

Adapted from Lambert (2026c), Lecture 1, p. 15, "Post-training makes it answer like a chatbot" (his example: Tülu 3 405B, post-trained from Llama 3.1 405B Base, Lambert et al., 2025, on the US president).

A · What post-training brings

Base model vs chat model

GPT-2 small: Radford et al. (2019). LaMini-GPT-124M: Wu et al. (2024).

A · What post-training brings

What does post-training change?

  • Pre-training: teaches the LLM knowledge, language basics, etc.
  • Post-training: makes it talk, think and act like a human being
    • Instruction tuning / SFT: chat format
    • Preference tuning / RLHF: social norms, styles, friendliness
    • RLVR: learns to think and act over long runs, to accomplish complicated tasks without being told how

Adapted from Lambert (2026c), Lecture 1, p. 16.

A · What post-training brings

(1) Post-training makes LLMs easy to use

Model responses evolved quickly to have:

  • Better format: direct, conversational answers
  • Better style: helpful, concise, Markdown, etc.
  • Better product: people could actually use it every day
Example chat. User: I'm giving a talk on RLHF tomorrow. Can you help me structure it? Assistant: Absolutely, here's a simple structure: 1. Start with the basics: what a language model is, why next-token prediction is not enough. 2. Explain post-training: instruction tuning, preference tuning / RLHF, RLVR for verifiable tasks. 3. End with why it matters: better products like ChatGPT, better reasoning in models like o1, and so on

From Lambert (2026c), Lecture 1, p. 18, "ChatGPT was when RLHF made the models even easier to use"; the conversation is cropped from the page (300 dpi).

A · What post-training brings

(2) Post-training makes LLMs follow instructions/rules

InstructGPT paper Figure 4, two left panels: the share of outputs that attempt the correct instruction and that follow explicit constraints, for GPT, GPT prompted, SFT, PPO and PPO-ptx; the post-trained models have higher bars

An explicit constraint is a rule in the prompt, such as "Write your answer in 2 paragraphs or less."

GPT-3 follows it in about 20% of answers. InstructGPT (GPT-3 after post-training; bars PPO and PPO-ptx) follows it in about 40%. A few-shot prompt helps GPT-3 only a little.

Try it in a chat model (WebLLM Chat)

Reply only in JSON with the keys city and country. Where is Marina Bay Sands?

Ouyang et al. (2022), Fig. 4 (two of four panels), all model sizes together; example rule from §4.1. 20% and 40% are read from the bars. Few-shot prompt: examples of the task in the prompt.

A · What post-training brings

(3) Post-training makes LLMs think to solve hard problems

Challenge

Data hold the result (the solution), not the trajectory: how a person got to it.

CoT prompting

"Think step by step" brings out some reasoning, but it often fails.

RLVR

The LLM writes its own reasoning; a program checks the answer and rewards the trajectories that succeed.

Reasoning length, same question
"what is the answer of 2 plus 3?"
GPT-4o7 tokens
o1-preview226 tokens

GPT-4o: LLM · o1-preview: reasoning model

o1 on AIME math
0255075100thinking compute (log scale)accuracy (%)
Reasoning model vs LLM
4650545862100k1Mreasoning modelLLM, majority voteoutput tokens (log scale)accuracy (%)

Left: Chen et al. (2024), Fig. 1(a). Middle, right: redrawn from OpenAI (2024) and Muennighoff et al. (2025), Fig. 4(b).

A · What post-training brings

(4) Post-training makes LLMs act in the digital world

  • Stronger tool use.
  • Able to complete tasks that take longer, without failure or interruption.

Agent: a model that plans and uses tools over many steps. Time horizon: the length of tasks (human working time) it completes in 50% of tries. GPT-2: about 2 s; o3: about 110 min.

METR Figure 1: the 50% time horizon of models from GPT-2 in 2019 to o3 in 2025 on a log scale; the points lie near a straight line with a doubling time of 207 days

Kwa et al. (2025), Fig. 1 (arXiv v4, CC BY 4.0); o3 value from the abstract, GPT-2 value from §3.2. 169 software, security, reasoning and machine-learning tasks.

Post by OpenAI on X: We're sharing a solution to the Navier-Stokes Millennium Prize Problem, one of the deepest problems at the frontier of mathematics. Below it, a 3D picture of fluid streamlines labelled inward spiral and axial stretching.

Post by OpenAI on X, 8 Sep 2026; write-up: OpenAI (2026). The Clay Mathematics Institute still lists the problem as active, not solved (CMI, 2026, read 14 Oct 2026).

Photo of Terence Tao in a blue UCLA shirt in front of a blackboard with formulas. Caption: Fields Medalist Terence Tao says AI companies are actually just harming mathematics.

Headline picture shared on social media. Tao's own words, in an interview with IBM Think (Brodsky, 2026, 10 Sep 2026): fast AI answers are "quite concerning", because mathematicians can lose the methods they find on the way.

Graphic with the OpenAI logo and the headline: OpenAI admits AI escaped sandbox during security test. Subtitle: controlled evaluation incident involving Hugging Face infrastructure, no public attack. A glowing box labelled sandbox breaks open; a photo of Sam Altman with a quote attributed to him.

Graphic shared online; origin not traced. Its Altman quote is in no report. What happened: on 21 Jul 2026 OpenAI said that, in a cyber test without the usual safeguards, GPT-5.6 Sol and an unreleased model escaped their sandbox and hacked Hugging Face to find answers to the ExploitGym benchmark (Kahn & Forlini, 2026). Altman wrote on X of "a significant security incident during evaluation of our models" (Sinkewicz, 2026).

Part A · 2 of 3

Why we need post-training

Next: History

A · History

2017: the Transformer appears; later language models build on it

  • 2017: the Transformer is born
Transformer architecture diagram: an encoder stack and a decoder stack of N layers with multi-head attention, feed-forward layers, add and norm, positional encoding, and a final linear and softmax layer
The original model architecture diagram for the Transformer. 2017.

From Lambert (2026c), Lecture 1, p. 4, "2017: The Transformer is born". Figure: Vaswani et al. (2017), Fig. 1.

A · History

2018: GPT-1 and BERT pre-train on text, then fine-tune for each task

  • 2017: the Transformer is born
  • 2018: GPT-1, ELMo, and BERT released
GPT-1 architecture: text and position embedding, then 12 layers of masked multi self attention, layer norm, feed forward and layer norm, with two heads on top: text prediction and task classifier
The language model architecture for GPT-1. 2018.

From Lambert (2026c), Lecture 1, p. 5, "2018: GPT-1, ELMo, and BERT"; figure cropped from the page (300 dpi), from Radford et al. (2018), Fig. 1. ELMo: Peters et al. (2018); BERT: Devlin et al. (2019).

A · History

2019: GPT-2; scaling laws show that loss falls steadily with scale

  • 2017: the Transformer is born
  • 2018: GPT-1, ELMo, and BERT released
  • 2019: GPT-2 and scaling laws
Scaling laws, three panels: test loss falls as a power law of compute (PF-days), dataset size (tokens) and parameters
The famous scaling laws plots. 2020.

From Lambert (2026c), Lecture 1, p. 6, "2019: GPT-2 and scaling laws". Figure: Kaplan et al. (2020), Fig. 1. GPT-2: Radford et al. (2019).

A · History

2020: GPT-3 does new tasks from a few examples in the prompt

  • 2017: the Transformer is born
  • 2018: GPT-1, ELMo, and BERT released
  • 2019: GPT-2 and scaling laws
  • 2020: GPT-3’s surprising capabilities
GPT-3 paper Figure 2.1: zero-shot, one-shot and few-shot prompts for translating English to French, with no gradient updates, next to traditional fine-tuning with a gradient update after each example
GPT-3 was known for expanding the idea of in-context learning and few-shot prompting. Screenshot from the paper.

From Lambert (2026c), Lecture 1, p. 7, "2020: GPT-3’s surprising capabilities". Figure: Brown et al. (2020), Fig. 2.1.

A · History

2021: researchers warn about the risks of ever larger language models

  • 2017: the Transformer is born
  • 2018: GPT-1, ELMo, and BERT released
  • 2019: GPT-2 and scaling laws
  • 2020: GPT-3’s surprising capabilities
  • 2021: Stochastic Parrots
Title and authors of the paper On the Dangers of Stochastic Parrots: Can Language Models Be Too Big? by Emily M. Bender, Timnit Gebru, Angelina McMillan-Major and Shmargaret Shmitchell
"We provide recommendations including …, investing resources into curating and carefully documenting datasets rather than ingesting everything on the web, carrying out pre-development exercises evaluating how the planned approach fits into research and development goals and supports stakeholder values, …"

From Lambert (2026c), Lecture 1, p. 8, "2021: Stochastic Parrots"; title and authors cropped from the page (300 dpi). Quote: Bender et al. (2021), abstract; bold added.

A · History

2022: ChatGPT, a model trained with human feedback, is released

  • 2017: the Transformer is born
  • 2018: GPT-1, ELMo, and BERT released
  • 2019: GPT-2 and scaling laws
  • 2020: GPT-3’s surprising capabilities
  • 2021: Stochastic Parrots
  • 2022: ChatGPT
The ChatGPT message box with the placeholder Message ChatGPT and a Search button

From Lambert (2026c), Lecture 1, p. 9, "2022: ChatGPT"; image cropped from the page (300 dpi). ChatGPT: OpenAI (2022).

A · History

2023: GPT-4 reaches frontier scale; OpenAI does not publish its size

  • 2017: the Transformer is born
  • 2018: GPT-1, ELMo, and BERT released
  • 2019: GPT-2 and scaling laws
  • 2020: GPT-3’s surprising capabilities
  • 2021: Stochastic Parrots
  • 2022: ChatGPT
  • 2023: GPT-4 and frontier-scale
A keynote speaker on stage in front of a chart of training compute in petaflops from 2012 to 2024; a point labelled GPT-MoE-1.8T at the top right is circled
An image where NVIDIA CEO Jensen Huang supposedly leaked that GPT-4 was a roughly 2T-parameter MoE model.

From Lambert (2026c), Lecture 1, p. 10, "2023: GPT-4 and frontier-scale"; image cropped from the page (300 dpi). GPT-4: OpenAI (2023), which gives no model size.

A · History

2024: o1 solves more contest math problems when it thinks longer

  • 2017: the Transformer is born
  • 2018: GPT-1, ELMo, and BERT released
  • 2019: GPT-2 and scaling laws
  • 2020: GPT-3’s surprising capabilities
  • 2021: Stochastic Parrots
  • 2022: ChatGPT
  • 2023: GPT-4 and frontier-scale
  • 2024: o1 and reasoning models
o1 AIME accuracy at test time: pass@1 accuracy rises from about 20 to about 75 as test-time compute grows, on a log scale
The famous test-time scaling plot from OpenAI’s o1 announcement.

From Lambert (2026c), Lecture 1, p. 11, "2024: o1 and reasoning models". Figure: OpenAI (2024), first figure, right panel.

A · History

2025: language models act as agents, as in o3 and Claude Code

  • 2017: the Transformer is born
  • 2018: GPT-1, ELMo, and BERT released
  • 2019: GPT-2 and scaling laws
  • 2020: GPT-3’s surprising capabilities
  • 2021: Stochastic Parrots
  • 2022: ChatGPT
  • 2023: GPT-4 and frontier-scale
  • 2024: o1 and reasoning models
  • 2025: o3, Claude Code, and agents
A terminal window with the text Welcome to Claude Code and the words CLAUDE CODE in large block letters

From Lambert (2026c), Lecture 1, p. 12, "2025: o3, Claude Code, and agents"; image cropped from the page (300 dpi). Claude Code: Anthropic (2025); o3: OpenAI (2025); agents: OpenAI (2025).

A · History

People started to do post-training earlier, before ChatGPT

Timeline from 2008 to 2026 in three bands. RL on Preferences: TAMER (2008), Christiano et al. (2017). Early RLHF on LMs: Ziegler et al. (2019), Learning to Summarize (2020), InstructGPT (2022). ChatGPT Era: ChatGPT, Constitutional AI, Direct Preference Optimization (DPO), Llama 2 (2023), OpenAI o1 (2024), DeepSeek R1 (2025)

From Lambert (2026c), Lecture 1, p. 29, "The path to modern RLHF", first part: the timeline, cropped from the page (300 dpi).

A · History

Six milestones of post-training

From Lambert (2026c), Lecture 1, p. 29, "The path to modern RLHF", second part: the list under the timeline.

A · History

Early days: InstructGPT/RLHF (2022)

Diagram: Base Model, with human instructions (about 10k), gives the SFT Model; human preferences (about 100k) train a Reward Model; PPO optimization of the SFT model against the reward model, re-using the preference prompts, gives the Aligned Model

Early on, RLHF had a well-documented, simple enough approach.

  • InstructGPT made the classic three-stage recipe canonical: SFT, reward modeling, then RL against the reward model. OpenAI even hinted that the original ChatGPT used this!
  • This became the intellectual template for much of modern post-training.

From Lambert (2026c), Lecture 1, p. 45, "The early days: InstructGPT"; diagram cropped from the page (300 dpi). InstructGPT: Ouyang et al. (2022).

A · History

Now: More rounds, less human data

Diagram: Base Model, with human and synthetic instructions (about 1M or more) and initial IFT training, gives Aligned Model N; human preferences (about 1M or more) train a Reward Model or LLM Judge; DPO, PPO, rejection sampling or multiple optimizations give Aligned Model N+1; new synthetic completions repeat this for N rounds; then the Final Model

What began as an “RLHF” recipe evolved into a complex series of steps to get the final, best model (e.g. Nemotron 4 340B, Llama 3.1).

  • Modern systems keep the same core idea of using multiple optimizers with different strengths and weaknesses, but add more stages, more data, and more filtering.
  • This trend has only continued, and recipes ebb and flow, as tools like RLVR and model merging change the scope of what is doable in different ways.

From Lambert (2026c), Lecture 1, p. 46, "From RLHF to post-training"; diagram cropped from the page (300 dpi). Llama 3.1: Grattafiori et al. (2024).

A · History

Since ChatGPT, the focus of open post-training changed every year

As time has passed since ChatGPT, the field has gone through multiple distinct phases (roughly):

  1. 2023: Simple SFT for better chatbots and reproducing RLHF fundamentals (Alpaca, Vicuna, etc.)
  2. 2024: DPO dominates open models and training stages expand (Zephyr-beta, Tülu 2, etc.)
  3. 2025: RLVR, complex recipes (Tülu 3, Olmo 3, Nemotron 3, R1, etc.)
  4. 2026: Agentic training, multi-turn RL, etc.

Within 2024 the field shifted its focus to post-training, as training stages evolved beyond the InstructGPT-style recipe, DPO proliferated, and largely RLHF was viewed as one tool (that you may not even need).

From Lambert (2026c), Lecture 1, p. 48, “From RLHF to ‘post-training’” (p. 47 is the same page without the last paragraph).

Part A · 3 of 3

Why we need post-training

Next: Why it matters

A · Why it matters

An early view: post-training changes only the style of the answers

RLHF’s reputation was that its contributions are minor on the final language models.

“A model’s knowledge and capabilities are learnt almost entirely during pretraining, while alignment teaches it which subdistribution of formats should be used when interacting with users.”

LIMA: Less Is More for Alignment (2023)

From Lambert (2026c), Lecture 1, p. 49, “‘Just style transfer’” (the left half of p. 50). Quote: Zhou et al. (2023).

A · Why it matters

Base models hold more ability than early post-training could expose

Sometimes this view of alignment (or RLHF) teaching “format” made people think that post-training only made minor changes to the model. This would describe finetuning as “just style transfer.”

The base model trained on trillions of tokens of web text has seen and learned from an extremely broad set of examples. The model at this stage contains far more latent capability than early post-training recipes were able to expose.

The question is: How does post-training interact with these?

From Lambert (2026c), Lecture 1, p. 50, “‘Just style transfer’”, right half (its left half is the slide before).

A · Why it matters

Does it matter to model vendors?

How much it matters? A computation view

What percent of training compute went to post-training, compared with pre-training?

  • A1%
  • B10%
  • C20%

Note: pre-training alone takes weeks to months on thousands of GPUs. GPT-3 (2020): about 34 days on 1,024 A100 GPUs (an estimate). DeepSeek-V3 (2024): about 54 days on 2,048 H800 GPUs.

GPT-3: estimate in Narayanan et al. (2021), §5.1 (300 billion tokens at 140 teraFLOP/s per GPU). DeepSeek-V3: DeepSeek-AI (2024), §1: 2,664K H800 GPU hours, "less than two months"; 2,664K / 2,048 GPUs ≈ 54 days (computed).

A · Why it matters

Most computation is spent on pre-training!

INSTRUCTGPT 175B · PETAFLOP/S-DAYS GPT-3 pre-training3,640 SFT4.9 · 0.13% SFT, then RLHF60 · 1.6% DEEPSEEK · H800 GPU HOURS V3 pre-training2,664K V3 context extension119K · 4.5% V3 post-training5K · 0.19% R1: RL and SFT147K · 5.5%

Answer: A, about 1%. InstructGPT: 60 / 3,640 ≈ 1.6%. With large-scale RL, DeepSeek-R1 used 5.5%, still under 10%.

Bars to scale. Ouyang et al. (2022), §5.1; DeepSeek-AI (2024), Table 1; R1: Guo et al. (2025), arXiv v2, Table 7 (R1-Zero 101K, SFT data 5K, R1 41K). Shares of pre-training computed.

A · Why it matters

Why post-training matters?View 1: Post-training helps more than scaling

Y-axis: how often people preferred a model's answer to the answer of the 175B SFT model.

People preferred 1.3B InstructGPT (PPO-ptx) to 175B GPT-3, a model with about 135 times more parameters.

The authors: RLHF helped users more than a 100 times larger model.

InstructGPT paper Figure 1: win rate against SFT 175B for model sizes 1.3B, 6B and 175B; PPO-ptx and PPO lines are above 0.5 at all sizes, GPT is about 0.15 to 0.25

Ouyang et al. (2022), Fig. 1, §1 and §5.1. 175 / 1.3 ≈ 135 (computed). Same architecture; the only difference is fine-tuning on human data.

A · Why it matters

Why post-training matters?View 2: The base model sets the ceiling; post-training's job is to reach it

RLHF’s reputation was that its contributions are minor on the final language models.

An example, OLMoE — same base model family, updated only post-training:

  • OLMoE-1B-7B-0924-Instruct (Sep. 2024): 38.44 avg. eval score
  • OLMoE-1B-7B-0125-Instruct (Jan. 2025): 45.62 avg. eval score

Base models determine the ceiling. Post-training’s job has been to reach it.

Simple post-training often doesn’t extract nearly enough performance (especially when the pace of progress is high).

From Lambert (2026c), Lecture 1, p. 51, "An intuition for post-training". OLMoE: Muennighoff et al. (2025); OLMoE Team (2025). ⚠ The model cards (Allen Institute for AI, 2025) say the Jan. 2025 base model also used a new data mix in its last 100B tokens.

A · Why it matters

Post-training draws out what the base model already knows

“The superficial alignment hypothesis (SAH) posits that large language models learn most of their knowledge during pre-training, and that post-training merely surfaces this knowledge.”

Operationalising the Superficial Alignment Hypothesis via Task Complexity (2026)

Photo of Nathan Lambert Cover of the book Reinforcement Learning from Human Feedback by Nathan Lambert (Manning)

Nathan Lambert
author of the RLHF Book (rlhfbook.com)

The second paper, 3 years later, matches my intuition for post-training.

I [Nathan Lambert] call this the Elicitation Theory of post-training, where we’re trying to pull out the most useful knowledge of the model.

Pretraining builds a chassis for the car -- post-training is the hard craft of extracting the most performance from it.

From Lambert (2026c), Lecture 1, pp. 52–53. Quote: Vergara-Browne et al. (2026). Photo: natolambert.com; cover: Lambert (2026d), Manning edition.

A · Why it matters

Why post-training matters?View 3: Post-training unlocks test-time scaling and agents

RL with checkable answers (slide 17) has no learned reward model to fool. So labs can keep adding RL compute.

  • o1: accuracy keeps rising as RL training compute grows.
  • Olmo 3.1, an open 32B model: still improving after 28 days of RL on 224 GPUs.
o1 AIME accuracy during training: pass@1 accuracy rises from about 33 to about 69 as train-time compute grows, on a log scale

Figure: OpenAI (2024), first figure, left panel, as in Lambert (2026c), Lecture 1, p. 59. Olmo 3.1: Lambert (2026c), p. 62; Team Olmo (2025).

A · Why it matters

RL unlocks test-time scaling and agents

Test-time scaling: during RL, DeepSeek-R1-Zero's accuracy rises and its answers grow longer
DeepSeek-R1-Zero during RL training, two panels: AIME accuracy, pass@1 rising from about 0.16 to about 0.78 and cons@16 to about 0.87 over 10,000 steps, above the human participants line near 0.38; average length per response rising from a few hundred to about 13,000 to 15,000 tokens
Agents: Cursor's coding agent kept improving as its RL compute grew 20 times
Cursor chart titled Composer 1.5 scales reinforcement learning 20x beyond the original model: Cursor Bench score rises from about 41 to about 59 as training compute grows on a log axis, passing the Composer 1 level near 52

Left: Guo et al. (2025), arXiv v2, Fig. 1, as in Lambert (2026c), Lecture 1, p. 61. Right: cropped from Lambert (2026c), p. 60, from Cursor Team (2026).

A · Why it matters

Post-training is changing fast, toward tools and coding agents

Post-training and RLHF are changing faster than maybe ever before.

  • Language models are becoming “tool-use native” and are now about tools, harnesses (how you tell the model to use said tools), and much more than just weights
  • RLHF and human preferences haven’t gone away, but are evolving far more slowly and out of the central gaze of the industry
  • Building language models and doing research is changing rapidly with coding agents

From Lambert (2026c), Lecture 1, p. 63, "Where this leaves us".

Part A — why we need post-training · summary

Why do we need post-training?

  1. What post-training brings: a chat model that answers, not one that only continues text; instruction following; reasoning; agents.
  2. History: (1) 2022: ChatGPT, trained with RLHF; (2) 2024: o1 and reasoning models; (3) 2025: agents, such as Claude Code.
  3. Why it matters: (1) it helps more than scaling; (2) the base model sets the ceiling, and post-training reaches it; (3) RL lets post-training scale.
BREAK 1
10 minutesBack at 19:00

Coming up in Part B: how to post-train a model — instruction tuning, learning from human preferences, RLHF, DPO and GRPO.

Part B

How to do post-training

From copying good answers to learning which answer is better.

Part B · a map of the methods

Each method in Part B fixes a problem of the one before

1 · Instruction tuning (SFT)

Copy good answers: the next-token loss, on the answer only.

→ follows instructions

⟶
Writing answers for every task is expensive. The next-token loss does not match human preferences.
2 · RLHF

People compare answers; a reward model learns their choices; RL (PPO) raises the reward.

→ answers that people prefer

InstructGPT and ChatGPT: SFT, then RLHF.

⟶
PPO is complex, slow and sensitive to settings, with four models. Push the reward model too far, and quality falls.
3a · DPO

One simple loss on each pair of answers.

→ no reward model, no RL loop

3b · GRPO

The mean reward of a group of answers is the baseline.

→ no value model

Ours: a map of this part. The two problems in red are titles of this part's slides on Yang (2026), CS224N, pp. 24, 51 and 53, and on the four models of RLHF.

Part B · 1 of 6

How to do post-training

Next: Instruction tuning

B · Instruction tuning

Language modeling ≠ assisting users

PROMPT

Explain the moon landing to a 6 year old in a few sentences.

COMPLETION

GPT-3

Explain the theory of gravity to a 6 year old.

Explain the theory of relativity to a 6 year old in a few sentences.

Explain the big bang theory to a 6 year old.

Explain evolution to a 6 year old.

Language models are not aligned with user intent [Ouyang et al., 2022]

Finetuning to the rescue!

From Yang (2026), CS224N, p. 8. The page's screenshot is rebuilt as text.

B · Instruction tuning

Language modeling ≠ assisting users

PROMPT

Explain the moon landing to a 6 year old in a few sentences.

COMPLETION

Human

A giant rocket ship blasted off from Earth carrying
astronauts to the moon. The astronauts landed their
spaceship on the moon and walked around exploring the
lunar surface. Then they returned safely back to Earth,
bringing home moon rocks to show everyone.

Language models are not aligned with user intent [Ouyang et al., 2022]

Finetuning to the rescue!

From Yang (2026), CS224N, p. 9. The page's screenshot is rebuilt as text.

B · Instruction tuning

The pretraining/finetuning paradigm

Pretraining can improve NLP applications by serving as parameter initialization.

Step 1: Pretrain (on language modeling)

Lots of text; learn general things!

Step 2: Finetune (on your task)

Not many labels; adapt to the task!

Decoder (Transformer, LSTM, ++ ) goestomaketastyteaEND Irohgoestomaketastytea Decoder (Transformer, LSTM, ++ ) ☺/☹ … the movie was …

From Yang (2026), CS224N, p. 10. Diagram redrawn.

B · Instruction tuning

Scaling up finetuning

Pretraining can improve NLP applications by serving as parameter initialization.

Step 1: Pretrain (on language modeling)

Lots of text; learn general things!

Step 2: Finetune (on many tasks)

Not many labels; adapt to the tasks!

Decoder (Transformer, LSTM, ++ ) goestomaketastyteaEND Irohgoestomaketastytea Decoder (Transformer, LSTM, ++ ) ☺/☹ … the movie was …

From Yang (2026), CS224N, p. 11. Diagram redrawn.

B · Instruction tuning

Instruction finetuning

  • Collect examples of (instruction, output) pairs across many tasks and finetune an LM
Above a dashed line, an instruction example (boiling point of nitrogen, answer -320.4F) and a chain-of-thought example (cafeteria apples, answer 9) go into one language model. Below the line, the model answers an unseen question: can Geoffrey Hinton have a conversation with George Washington? It reasons that Washington died in 1799, so the answer is no.
  • Evaluate on unseen tasks

[FLAN-T5; Chung et al., 2022]

From Yang (2026), CS224N, p. 12. Figure: Chung et al. (2022), Fig. 1, as cropped on that page. Right panel (ours): Chung et al. (2022), Fig. 2, Fig. 17, §2.3.

B · Instruction tuning

Instruction finetuning and performance gains

Model input (Disambiguation QA)

Q: In the following sentences, explain the
antecedent of the pronoun (which thing the
pronoun refers to), or state that it is ambiguous.

Sentence: The reporter and the chef will discuss
their favorite dishes.

Options:
(A) They will discuss the reporter's favorite dishes
(B) They will discuss the chef's favorite dishes
(C) Ambiguous

A: Let's think step by step.

Before instruction finetuning

The reporter and the chef will discuss their favorite
dishes.
The reporter and the chef will discuss the reporter's
favorite dishes.
The reporter and the chef will discuss the chef's
favorite dishes.
The reporter and the chef will discuss the reporter's
and the chef's favorite dishes.

(doesn’t answer question)

From Yang (2026), CS224N, p. 19. Example: Chung et al. (2022), Fig. 7 (Disambiguation QA, a BIG-Bench task); the output is from PaLM 540B.

B · Instruction tuning

Instruction finetuning and performance gains

Model input (Disambiguation QA)

Q: In the following sentences, explain the
antecedent of the pronoun (which thing the
pronoun refers to), or state that it is ambiguous.

Sentence: The reporter and the chef will discuss
their favorite dishes.

Options:
(A) They will discuss the reporter's favorite dishes
(B) They will discuss the chef's favorite dishes
(C) Ambiguous

A: Let's think step by step.

After instruction finetuning

The reporter and the chef will discuss their favorite
dishes does not indicate whose favorite dishes they
will discuss. So, the answer is (C).

Try FLAN-T5 out to get a sense of its capabilities: https://huggingface.co/google/flan-t5-xxl[Chung et al., 2022]

From Yang (2026), CS224N, p. 20. Example: Chung et al. (2022), Fig. 7; the output is from Flan-PaLM 540B.

B · Instruction tuning

Tuning on 1,000 chosen examples beat tuning on 52,000

  • You don’t need many samples to instruction tune (e.g., “LIMA: Less Is More for Alignment” Zhou et al., 2023)
LIMA Table 1, training part: 200 examples each from Stack Exchange STEM, Stack Exchange Other, wikiHow and the paper authors, 150 from Pushshift WritingPrompts, 50 from Natural Instructions
LIMA Figure 1: human preference of LIMA against five models; against Alpaca 65B LIMA wins 53 percent, ties 21 percent, loses 26 percent; against GPT-4 it wins 18 and ties 25 percent

From Yang (2026), CS224N, p. 22, second half. Figures: Zhou et al. (2023), Table 1 (training rows) and Fig. 1.

B · Instruction tuning: the math

Instruction tuning trains only on the response tokens

  1. SFT (supervised fine-tuning) is another name for instruction tuning. One example is a prompt \(x = (x_1, \dots, x_m)\) and a response \(y = (y_1, \dots, y_n)\). Join them into one sequence \(s\) of length \(m + n\).
  2. The chain rule, as in Lecture 1: \[ \log p_\theta(s) = \sum_{t=1}^{m}\log p_\theta(x_t\mid x_{<t}) + \sum_{j=1}^{n}\log p_\theta(y_j\mid x, y_{<j}) = \log p_\theta(x) + \log p_\theta(y\mid x). \]
  3. We want the model to write \(y\) for a given \(x\), not to write prompts. So we drop the first sum: \[ \mathcal{L}_{\mathrm{SFT}}(\theta) = -\,\mathbb{E}_{(x,y)\sim\mathcal{D}}\Big[\sum_{j=1}^{n}\log p_\theta(y_j\mid x, y_{<j})\Big]. \]

Lecture page of this session, SFT derivation, steps 1–3. Llama 3 trains with "a standard cross entropy loss on the target tokens (while masking loss on prompt tokens)" (Grattafiori et al., 2024, §4.1.3).

B · Instruction tuning: the math

The loss mask is 0 on prompt tokens and 1 on response tokens

\(m_t = 0\) on prompt tokens, \(m_t = 1\) on response tokens: \[ \mathcal{L}_{\mathrm{SFT}}(\theta) = -\frac{\sum_t m_t \log p_\theta(s_t\mid s_{<t})}{\sum_t m_t}. \]

✋ Your turn

What if we also mask the final <end>? Answer, then press.

Lecture page of this session, SFT derivation, steps 4–5. Interactive: toy tokens and random per-token losses, not a model's; the loss is computed in the browser. The completions on the right are toy text, not a model's output.

Part B · 2 of 6

How to do post-training

Next: RLHF

B · RLHF

Writing correct answers for every task is expensive

  • One limitation of instruction finetuning is obvious: it’s expensive to collect ground-truth data for tasks.
  • But there are other, subtler limitations too. Can you think of any?

From Yang (2026), CS224N, p. 24, first two points (the page is split over two slides).

B · RLHF

Limitation of instruction tuning

Stick-figure comic: a teacher with a tie points at a whiteboard that shows Q: 2 + 3 = ? and A: 5. A student sits at a desk and writes A: 5 into a notebook.
Instruction tuning: the teacher gives the question and the answer; the student copies.
The same stick-figure comic, but the whiteboard shows only Q: 2 + 3 = ? and no answer. The student, hand on chin, thinks of 4 (crossed out), 6 (crossed out) and 5 (with a check mark), and a light bulb is above the student.
Exploring: the teacher gives only the question; the student explores to find the answer.

Both images were generated with ChatGPT (OpenAI) on 13 Oct 2026 for this slide, in an xkcd-like stick-figure style.

B · RLHF

The language-model loss does not match human preferences

  • Problem 1: tasks like open-ended creative generation have no right answer.
    • Write me a story about a dog and her pet grasshopper.
  • Problem 2: language modeling penalizes all token-level mistakes equally, but some errors are worse than others.
  • Even with instruction finetuning, there a mismatch between the LM objective and the objective of “satisfy human preferences”!
  • Can we explicitly attempt to satisfy human preferences?
adventuremusical isafantasyTVshowEND LM AvatarisafantasyTVshow

From Yang (2026), CS224N, p. 24, the rest of the page. Diagram redrawn.

B · RLHF

Optimize for human preferences

What is human preference?

Task: Summarize the paragraph into one sentence.

SAN FRANCISCO, 20 July 2007 — At 4:42 a.m. on Friday, an earthquake of magnitude 4.2 shook the San Francisco Bay Area. Its center was about two miles east-northeast of Oakland, 3.6 miles below the surface. The shaking lasted about 50 seconds and set off alarms in homes. About 2,000 customers lost electric power. The police got many calls from worried people, but nobody reported an injury or damage. The U.S. Geological Survey calls a quake of this size “light”: people feel it indoors, and it can break dishes and windows and knock over unstable objects.

\(s_1\):

An earthquake hit San Francisco. There was minor property damage, but no injuries.

\(s_2\):

The Bay Area has good weather but is prone to earthquakes and wildfires.

✋ Your turn

Which is the CORRECT answer?

Paragraph: the facts of CNN (2007), in our words. Summaries \(s_1\), \(s_2\): Yang (2026), CS224N, p. 25.

B · RLHF

Optimize for human preferences

What is human preference?

Task: Summarize the paragraph into one sentence.

SAN FRANCISCO, 20 July 2007 — At 4:42 a.m. on Friday, an earthquake of magnitude 4.2 shook the San Francisco Bay Area. Its center was about two miles east-northeast of Oakland, 3.6 miles below the surface. The shaking lasted about 50 seconds and set off alarms in homes. About 2,000 customers lost electric power. The police got many calls from worried people, but nobody reported an injury or damage. The U.S. Geological Survey calls a quake of this size “light”: people feel it indoors, and it can break dishes and windows and knock over unstable objects.

\(s_1\):

An earthquake hit San Francisco. There was minor property damage, but no injuries.

Your score: ____ / 10

\(s_2\):

The Bay Area has good weather but is prone to earthquakes and wildfires.

Your score: ____ / 10

✋ Your turn

Which is the BETTER answer? Please rate them in the range [0, 10].

Paragraph: the facts of CNN (2007), in our words. Summaries \(s_1\), \(s_2\): Yang (2026), CS224N, p. 25.

B · RLHF

Poll: rate three summaries on your phone

Task: Summarize the paragraph into one sentence.

SAN FRANCISCO, 20 July 2007 — At 4:42 a.m. on Friday, an earthquake of magnitude 4.2 shook the San Francisco Bay Area. Its center was about two miles east-northeast of Oakland, 3.6 miles below the surface. The shaking lasted about 50 seconds and set off alarms in homes. About 2,000 customers lost electric power. The police got many calls from worried people, but nobody reported an injury or damage. The U.S. Geological Survey calls a quake of this size “light”: people feel it indoors, and it can break dishes and windows and knock over unstable objects.

costa-nus.github.io/classroom-poll

Type the class key. Rate each of the three summaries from 0 to 10.

Paragraph: the facts of CNN (2007), in our words. The poll is anonymous: no names are stored.

B · RLHF

Optimizing for human preferences by Reinforcement Learning

  • Let’s say we were training a language model on some task (e.g. summarization).
  • For each LM sample \(s\), imagine we had a way to obtain a human reward of that summary: \(R(s) \in \mathbb{R}\), higher is better.

SAN FRANCISCO,
California (CNN) --
A magnitude 4.2
earthquake shook the
San Francisco
...
overturn unstable
objects.

An earthquake hit
San Francisco.
There was minor
property damage,
but no injuries.

\(s_1\)
\(R(s_1) =\)

The Bay Area has
good weather but is
prone to
earthquakes and
wildfires.

\(s_2\)
\(R(s_2) =\)

  • Now we want to maximize the expected reward of samples from our LM:

\(\displaystyle\max_\theta\; \mathbb{E}_{\hat s\sim p_\theta(s)}\big[R(\hat s)\big]\)

Note: for simplicity, we show the math
for a single prompt. In practice, we
average over many prompts

From Yang (2026), CS224N, p. 25. \(R(s_1)\) and \(R(s_2)\): type the class averages of poll 1 (CS224N gives 8.0 and 1.2); slides 76 and 77 show the same values.

B · RLHF

Reinforcement learning to the rescue

A cover of the journal Nature titled Learning curve, with pixel-art video game figures; the cover line reads: self-taught AI software attains human-level performance in video games

From Yang (2026), CS224N, p. 26. The Nature cover and the AlphaGo logo are cropped from the page.

B · RLHF

Optimizing for human preferences

  • How do we actually change our LM parameters \(\theta\) to maximize this?

\(\mathbb{E}_{\hat s\sim p_\theta(s)}\big[R(\hat s)\big]\)

  • Let’s try doing gradient ascent!
\(\theta_{t+1} := \theta_t + \alpha\,\nabla_{\theta_t}\mathbb{E}_{\hat s\sim p_{\theta_t}(s)}\big[R(\hat s)\big]\)

How do we estimate
this expectation??

What if our reward
function is non-
differentiable??

  • Policy gradient methods in RL (e.g., REINFORCE; [Williams, 1992]) give us tools for estimating and optimizing this objective.

From Yang (2026), CS224N, p. 27.

B · RLHF

A (very!) brief introduction to policy gradient/REINFORCE [Williams, 1992]

  • We want to obtain

\(\displaystyle \nabla_\theta\,\mathbb{E}_{\hat s\sim p_\theta(s)}\big[R(\hat s)\big] = \overset{\mathclap{\textstyle\small\textcolor{#6b3d7a}{\textsf{(defn.\ of expectation)}}}}{\nabla_\theta\,\colorbox{#f4cccc}{$\displaystyle\sum_s$}\,R(s)\colorbox{#f4cccc}{$\displaystyle p_\theta(s)\vphantom{\sum_s}$}} = \overset{\mathclap{\textstyle\small\textcolor{#6b3d7a}{\textsf{(linearity of gradient)}}}}{\displaystyle\sum_s R(s)\;\colorbox{#fdf08a}{$\nabla_\theta p_\theta(s)$}}\)

  • Here we’ll use a very handy trick known as the log-derivative trick. Let’s try taking the gradient of \(\log p_\theta(s)\)

\(\displaystyle \underset{\mathclap{\textstyle\small\textcolor{#6b3d7a}{\textsf{(chain rule)}}}}{\nabla_\theta \log p_\theta(s) = \frac{1}{p_\theta(s)}\,\nabla_\theta\, p_\theta(s)} \qquad\Longrightarrow\qquad \colorbox{#fdf08a}{$\nabla_\theta\, p_\theta(s)$} = p_\theta(s)\;\nabla_\theta \log p_\theta(s)\)

  • Plug back in:

\(\displaystyle \sum_s R(s)\,\colorbox{#fdf08a}{$\nabla_\theta p_\theta(s)$} = \overset{\mathclap{\textstyle\small\textcolor{#b0302a}{\begin{array}{c}\textsf{This is an}\\ \textsf{expectation}\end{array}}}}{\colorbox{#f4cccc}{$\displaystyle\sum_s p_\theta(s)$}}\!\overset{\mathclap{\textstyle\small\textcolor{#2e7d4f}{\textsf{of this}}}}{\colorbox{#d9ead3}{$\displaystyle R(s)\,\nabla_\theta \log p_\theta(s)\vphantom{\sum_s}$}}\)

From Yang (2026), CS224N, p. 28.

B · RLHF

A (very!) brief introduction to policy gradient/REINFORCE [Williams, 1992]

  • Now we have put the gradient “inside” the expectation, we can approximate this objective with Monte Carlo samples:

\(\displaystyle \nabla_\theta\,\mathbb{E}_{\hat s\sim p_\theta(s)}\big[R(\hat s)\big] = \mathbb{E}_{\hat s\sim p_\theta(s)}\big[R(\hat s)\,\nabla_\theta \log p_\theta(\hat s)\big] \approx \frac{1}{m}\sum_{i=1}^{m} R(s_i)\,\nabla_\theta \log p_\theta(s_i)\)

This is why it’s called “reinforcement
learning”
: we reinforce good actions,
increasing the chance they happen again.

  • Giving us the update rule:

This is heavily simplified! There is a lot
more needed to do RL w/ LMs. Can you
see any problems with this objective?

\(\displaystyle \theta_{t+1} := \theta_t + \alpha\,\frac{1}{m}\sum_{i=1}^{m} R(s_i)\,\nabla_{\theta_t}\log p_{\theta_t}(s_i)\)

If \(R\) is +++

Take gradient steps
to maximize \(p_\theta(s_i)\)

If \(R\) is ---

Take steps to
minimize \(p_\theta(s_i)\)

From Yang (2026), CS224N, p. 29.

B · RLHF

Introducing Proximal Policy Optimization (PPO)

  • Problems with vanilla REINFORCE: high variance in gradient estimates; unstable training; sample inefficiency;
  • Key idea of PPO: limit how much the policy can change in each update
  • PPO (clipped) objective:

\(r_t(\theta) = \frac{p_\theta(s_i)}{p^\theta_{old}(s_i)}\) is the probability ratio

clip range (e.g., 0.2)

\(L^{CLIP}(\theta) = \;\mathbb{E}_{s_i\sim p^\theta_{old}(s)}\big[\min\big(r_t(\theta)\cdot A(s_i),\, \mathrm{clip}\,(r_t(\theta), 1-\epsilon, 1+\epsilon)\cdot A(s_i)\big)\big]\)

\(A(s_i)\) is the advantage, i.e., how much better than expected)

Where the reward goes (added): \(A(s_i) = R(s_i) - b\), the reward of the sample minus the reward we expect, \(b\) (a value model predicts it). \(L^{CLIP}\) raises \(p_\theta(s_i)\) when \(A(s_i) > 0\) and lowers it when \(A(s_i) < 0\), as REINFORCE did with \(R(s_i)\).

  • Update rule: \(\theta_{t+1} := \theta_t + \alpha\nabla_{\theta_t} L^{CLIP}(\theta_t)\)

For details on algorithm, check out https://web.stanford.edu/class/cs234/slides/lecture6post.pdf

From Yang (2026), CS224N, p. 30. \(L^{CLIP}\): Schulman et al. (2017), eq. 7. The line "Where the reward goes" is ours.

B · RLHF

How do we model human preferences?

  • So far, we assume we have a mapping from \(s\) to its human reward \(R(s)\), where we assume there is a human to tell how good it is, and we maximize the expected reward of samples: \[\max_\theta\; \mathbb{E}_{\hat s\sim p_\theta(s)}\big[R(\hat s)\big]\]
  • But, it is not so fast (why not?)
An earthquake hit SanFrancisco. There was minorproperty damage, but no injuries.s1The Bay Area has goodweather but is prone toearthquakes and wildfires.s2R(s1) = 8.0R(s2) = 1.2samples sa person reads and scoreseach sample: it takes timehuman reward R(s)

Ours (13 Oct 2026), before CS224N p. 31. Summaries: Yang (2026), p. 25. Rewards: as typed on slide 70.

B · RLHF

How do we model human preferences?

  • Awesome: now for any arbitrary, non-differentiable reward function \(R(s)\), we can train our language model to maximize expected reward.
  • Not so fast! (Why not?)
  • Problem 1: human-in-the-loop is expensive!
    • Solution: instead of directly asking humans for preferences, model their preferences as a separate (NLP) problem! [Knox and Stone, 2009]

An earthquake hit
San Francisco.
There was minor
property damage,
but no injuries.

\(s_1\)
\(R(s_1) =\) 8.0

The Bay Area has
good weather but is
prone to
earthquakes and
wildfires.

\(s_2\)
\(R(s_2) =\) 1.2

Train an LM \(RM_\phi(s)\) to predict human preferences from an annotated dataset, then optimize for \(RM_\phi\) instead.

Least squares:  \(\min_\phi\; J_{RM}(\phi) = \mathbb{E}_{(s,\,R(s))\sim D}\big[\big(RM_\phi(s) - R(s)\big)^2\big]\)

From Yang (2026), CS224N, p. 31. The page's person and banknote icons are redrawn. The least-squares objective is ours, in the symbols of p. 33 (slide 81).

B · RLHF

How do we model human preferences?

  • Problem 2: human judgments are noisy and miscalibrated!
  • Solution: instead of asking for direct ratings, ask for pairwise comparisons, which can be more reliable [Phelps et al., 2015; Clark et al., 2018]

A 4.2 magnitude
earthquake hit
San Francisco,
resulting in
massive damage.

\(s_3\)

\(R(s_3) = \quad 4.1? \quad 6.6? \quad 3.2?\)

From Yang (2026), CS224N, p. 32.

B · RLHF

How do we model human preferences?

Problem 2: human judgments are noisy and miscalibrated!

Poll 2

costa-nus.github.io/classroom-poll

Same page and key as poll 1. Pick the better summary in each pair.

Hypothesis: Pairwise comparison is more reliable (higher agreement) than rating.

From Yang (2026), CS224N, p. 32.

B · RLHF

Pairwise comparison was the most popular way to compare LLMs in QA

Chatbot Arena screenshot: the rules (ask any question to two anonymous models and vote for the better one), the same prompt answered by Model A and Model B side by side, and four vote buttons: A is better, B is better, Tie, Both are bad.
Evaluation view: one question, two anonymous models, one vote
Win-rate matrix of 12 models, from gpt-4-turbo at the top to mistral-7b-instruct at the bottom; each cell is the fraction of battles that model A won against model B.
Leaderboard: models in rank order; each cell, how often A beat B

Chatbot Arena (LMSYS; now LMArena). Left: Chiang et al. (2024), Fig. 8. Right: the same paper, Fig. 2 (left), win rates from the human votes.

B · RLHF

How do we model human preferences?

  • Problem 2: human judgments are noisy and miscalibrated!
  • Solution: instead of asking for direct ratings, ask for pairwise comparisons, which can be more reliable [Phelps et al., 2015; Clark et al., 2018]

An earthquake hit
San Francisco.
There was minor
property damage,
but no injuries.

\(s_1\)

>

A 4.2 magnitude
earthquake hit
San Francisco,
resulting in
massive damage.

\(s_3\)

>

The Bay Area has
good weather but is
prone to
earthquakes and
wildfires.

\(s_2\)

1.2 Reward Model (RMϕ) TheBayArea…...wildfires

Bradley-Terry [1952] paired comparison model

\(\min_\phi\; J_{RM}(\phi) = -\mathbb{E}_{(\textcolor{#1e9a4b}{s^w},\textcolor{#b0302a}{s^l})\sim D}\big[\log\sigma\big(RM_\phi(\textcolor{#1e9a4b}{s^w}) - RM_\phi(\textcolor{#b0302a}{s^l})\big)\big]\)

“winning”
sample

“losing”
sample

\(\textcolor{#1e9a4b}{s^w}\) should score
higher than \(\textcolor{#b0302a}{s^l}\)

From Yang (2026), CS224N, p. 33. Reward-model diagram redrawn.

B · RLHF: the math

The reward model learns from score differences only

  1. Assume each response has a score \(r(x, y)\) (Bradley & Terry, 1952): \[ P(y_w \succ y_l \mid x) = \frac{e^{r(x,y_w)}}{e^{r(x,y_w)} + e^{r(x,y_l)}} \]
  2. Divide the top and the bottom by \(e^{r(x,y_w)}\): \[ P(y_w \succ y_l \mid x) = \frac{1}{1 + e^{-(r(x,y_w) - r(x,y_l))}} = \sigma\big(r(x,y_w) - r(x,y_l)\big) \]
  3. Maximum likelihood: \(\;\mathcal{L}_{\mathrm{RM}}(\phi) = -\,\mathbb{E}_{(x, y_w, y_l)}\big[\log\sigma\big(r_\phi(x,y_w) - r_\phi(x,y_l)\big)\big]\).
  4. Add the same \(c(x)\) to every score: the difference, and so the loss, do not change. Only differences are learned.

Lecture page of this session, reward-model derivation. InstructGPT's loss (eq. 1) is the same with a factor \(1/\binom{K}{2}\) (Ouyang et al., 2022, §3.5).

B · RLHF: the math

Check-in: from two scores to a probability

✋ Your turn

The reward model scores two answers to one prompt \(x\): \(r_A = r(x, A) = 2.1\) and \(r_B = r(x, B) = 1.4\).

From the previous slide: \(P(A \succ B) = \sigma(r_A - r_B)\), with \(\sigma(z) = \dfrac{1}{1 + e^{-z}}\).

1. What is \(P(A \succ B)\)?

2. Now add 100 to both scores: \(r_A = 102.1\), \(r_B = 101.4\). What happens to \(P(A \succ B)\)?

  1. It goes up, toward 1.
  2. It goes down, toward 0.5.
  3. It does not change.
  4. It depends on how large the scores are.

Check-in from the lecture page of this session. The answer is on the next slide.

B · RLHF: the math

Only the score difference matters: +100 on both cancels out

Check-in answer: answer A scores \(r_A = 2.1\), answer B scores \(r_B = 1.4\); \(\sigma(z) = \dfrac{1}{1 + e^{-z}}\). (On the derivation slide, A is \(y_w\), B is \(y_l\), and \(r_A = r(x, y_w)\).)

Check-in from the lecture page of this session; Bradley & Terry (1952) as on the derivation slide. The interactive with the reward model's two towers is on the lecture page.

B · RLHF

Make sure your reward model works first!

Evaluate RM on predicting outcome of held-out human judgments

Stiennon et al. 2020 Figure 6: reward model validation accuracy rises with model size from 1e8 to 1e10 parameters and with data from 8k to 64k comparisons, toward the human baseline

Large enough RM trained on enough data approaching single human perf

[Stiennon et al., 2020]

From Yang (2026), CS224N, p. 34. Figure: Stiennon et al. (2020), Fig. 6.

B · RLHF

RLHF: Putting it all together [Christiano et al., 2017; Stiennon et al., 2020]

  • Finally, we have everything we need:
    • A pretrained (possibly instruction-finetuned) LM \(\textcolor{#c00000}{p^{PT}(s)}\)
    • A reward model \(\textcolor{#7030a0}{RM_\phi(s)}\) that produces scalar rewards for LM outputs, trained on a dataset of human comparisons
    • A method for optimizing LM parameters towards an arbitrary reward function.
  • Now to do RLHF:
    • Initialize a copy of the model \(\textcolor{#1e9a4b}{p^{RL}_\theta(s)}\) , with parameters \(\textcolor{#1e9a4b}{\theta}\) we would like to optimize
    • Objective: \(\displaystyle\max_{\textcolor{#1e9a4b}{\theta}}\; \mathbb{E}_{\hat s\sim \textcolor{#1e9a4b}{p^{RL}_\theta(s)}}\big[\textcolor{#7030a0}{RM_\phi(\hat s)}\big]\)
    • Optimize the following reward with RL:

\(\displaystyle R(s) = \textcolor{#7030a0}{RM_\phi(s)} - \underbrace{\beta\log\left(\colorbox{#fff200}{$\displaystyle\frac{\textcolor{#1e9a4b}{p^{RL}_\theta(s)}}{\textcolor{#c00000}{p^{PT}(s)}}$}\right)}\)

Pay a price when
\(\textcolor{#1e9a4b}{p^{RL}_\theta(s)} > \textcolor{#c00000}{p^{PT}(s)}\)

\(\displaystyle J_\beta(\theta) = \mathbb{E}_{\hat s\sim \textcolor{#1e9a4b}{p^{RL}_\theta(s)}}\big[R(\hat s)\big]\)

This is a penalty which prevents us from diverging too far from the pretrained model. In expectation, it is known as the Kullback-Leibler (KL) divergence between \(\textcolor{#1e9a4b}{p^{RL}_\theta(s)}\) and \(\textcolor{#c00000}{p^{PT}(s)}\).

From Yang (2026), CS224N, p. 35. The objective line is ours, in the symbols of p. 25 (slide 70) and this page.

B · RLHF

High-level instantiation: “RLHF” pipeline

  • First step: instruction tuning!
  • Second + third steps: maximize reward (but how??)
InstructGPT Figure 2: step 1 collect demonstrations and train a supervised policy; step 2 collect comparisons and train a reward model; step 3 optimize the policy against the reward model with PPO

From Yang (2026), CS224N, p. 36. Figure: Ouyang et al. (2022), Fig. 2.

B · RLHF

Each RLHF step uses a different kind of data

Policy = the LLM itself, the model that writes the responses and that RL updates (\(\textcolor{#1e9a4b}{p^{RL}_\theta}\) on slide 86).

Interactive (click a step; orange arrows train a model): structure after Ouyang et al. (2022), Fig. 2, redrawn. Prompt counts §3.2; K and the 6B reward model §3.5; compute in petaflop/s-days §5.1.

B · RLHF

RLHF provides gains over pretraining + finetuning

Stiennon et al. 2020 Figure 1: fraction preferred to reference summaries against model size; human feedback above 0.6, supervised learning near 0.4, pretrain only lowest\(\textcolor{#1e9a4b}{p^{RL}(s)}\)\(\textcolor{#c00000}{p^{IFT}(s)}\)\(\textcolor{#c00000}{p^{PT}(s)}\)

[Stiennon et al., 2020]

From Yang (2026), CS224N, p. 37. Figure: Stiennon et al. (2020), Fig. 1, with the page's labels.

Part B · 3 of 6

How to do post-training

Next: InstructGPT and ChatGPT

B · InstructGPT and ChatGPT

InstructGPT: scaling up RLHF to tens of thousands of tasks

30k
tasks!

InstructGPT Figure 2, with step 1's prompt box marked: a prompt is sampled from our prompt dataset

[Ouyang et al., 2022]

From Yang (2026), CS224N, p. 39. Figure: Ouyang et al. (2022), Fig. 2; the paper counts prompts: about 13k, 33k and 31k (§3.2).

B · InstructGPT and ChatGPT

InstructGPT: scaling up RLHF to tens of thousands of tasks

Tasks collected from labelers:

  • Plain: We simply ask the labelers to come up with an arbitrary task, while ensuring the tasks had sufficient diversity.
  • Few-shot: We ask the labelers to come up with an instruction, and multiple query/response pairs for that instruction.
  • User-based: We had a number of use-cases stated in waitlist applications to the OpenAI API. We asked labelers to come up with prompts corresponding to these use cases.
Use-casePrompt
BrainstormingList five ideas for how to regain enthusiasm for my career
GenerationWrite a short story where a bear goes to the beach, makes friends with a seal, and then returns home.

[Ouyang et al., 2022]

From Yang (2026), CS224N, p. 40: Ouyang et al. (2022), §3.2 (quoted) and two rows of Table 2.

B · InstructGPT and ChatGPT

InstructGPT

PROMPT

Write a short poem about a wise frog.

COMPLETION

GPT-3

Write a short story in which a character has two different names.

Write a short story in which you try to get something back that you have lost.

Write a short story in which a character has a bad dream.

InstructGPT

The frog is a symbol of wisdomHe knows all the secrets of the worldHe is a master of disguiseAnd a great teacher of lifeHe is a symbol of transformationAnd the bringer of changeHe is the frog who has seen it allAnd knows the meaning of it all

From Yang (2026), CS224N, p. 42. The page's screenshot is rebuilt as text.

B · InstructGPT and ChatGPT

ChatGPT's first step: instruction tuning on dialogues

ChatGPT: Optimizing Language Models for Dialogue

Note: OpenAI (and similar companies) are keeping more details secret about ChatGPT training (including data, training parameters, model size)—perhaps to keep a competitive edge…

Methods

We trained this model using Reinforcement Learning from Human Feedback (RLHF), using the same methods as InstructGPT, but with slight differences in the data collection setup. We trained an initial model using supervised fine-tuning: human AI trainers provided conversations in which they played both sides—the user and an AI assistant. We gave the trainers access to model-written suggestions to help them compose their responses. We mixed this new dialogue dataset with the InstructGPT dataset, which we transformed into a dialogue format.

(Instruction finetuning!)

From Yang (2026), CS224N, p. 43, quoting the Methods section of OpenAI (2022), openai.com/blog/chatgpt.

B · InstructGPT and ChatGPT

ChatGPT's next step: RLHF on ranked chatbot replies

ChatGPT: Optimizing Language Models for Dialogue

Note: OpenAI (and similar companies) are keeping more details secret about ChatGPT training (including data, training parameters, model size)—perhaps to keep a competitive edge…

Methods

To create a reward model for reinforcement learning, we needed to collect comparison data, which consisted of two or more model responses ranked by quality. To collect this data, we took conversations that AI trainers had with the chatbot. We randomly selected a model-written message, sampled several alternative completions, and had AI trainers rank them. Using these reward models, we can fine-tune the model using Proximal Policy Optimization. We performed several iterations of this process.

(RLHF!)

From Yang (2026), CS224N, p. 44, quoting the Methods section of OpenAI (2022), openai.com/blog/chatgpt.

Part B · 4 of 6

How to do post-training

Next: Limits of RL and reward models

B · Limits of RL and reward models

Inserting \(R(s)\) into \(J_\beta\) gives the reward minus a KL term

\(\displaystyle J_\beta(\theta) = \mathbb{E}_{\hat s\sim \textcolor{#1e9a4b}{p^{RL}_\theta(s)}}\big[R(\hat s)\big]\)

the objective of slide 86

\(\displaystyle = \mathbb{E}_{\hat s\sim \textcolor{#1e9a4b}{p^{RL}_\theta(s)}}\Big[\textcolor{#7030a0}{RM_\phi(\hat s)} - \beta\log\frac{\textcolor{#1e9a4b}{p^{RL}_\theta(\hat s)}}{\textcolor{#c00000}{p^{PT}(\hat s)}}\Big]\)

insert \(R(s)\)

\(\displaystyle = \mathbb{E}_{\hat s\sim \textcolor{#1e9a4b}{p^{RL}_\theta(s)}}\big[\textcolor{#7030a0}{RM_\phi(\hat s)}\big] - \beta\,\mathbb{E}_{\hat s\sim \textcolor{#1e9a4b}{p^{RL}_\theta(s)}}\Big[\log\frac{\textcolor{#1e9a4b}{p^{RL}_\theta(\hat s)}}{\textcolor{#c00000}{p^{PT}(\hat s)}}\Big]\)

the expectation of a sum is the sum of the expectations

\(\displaystyle = \mathbb{E}_{\hat s\sim \textcolor{#1e9a4b}{p^{RL}_\theta(s)}}\big[\textcolor{#7030a0}{RM_\phi(\hat s)}\big] - \beta\,\mathrm{KL}\big(\textcolor{#1e9a4b}{p^{RL}_\theta}\,\|\,\textcolor{#c00000}{p^{PT}}\big)\)

definition: \(\mathrm{KL}(p\,\|\,q) = \mathbb{E}_{s\sim p}\big[\log\frac{p(s)}{q(s)}\big]\)

So the penalty in \(R(s)\) is, on average, \(\beta\) times the KL divergence: how far \(\textcolor{#1e9a4b}{p^{RL}_\theta}\) has moved from \(\textcolor{#c00000}{p^{PT}}\).

Ours: the steps from Yang (2026), CS224N, p. 35 (slide 86) to the objective on slide 98.

B · Limits of RL and reward models

A larger KL weight β keeps the policy nearer the reference

\(\displaystyle J_\beta(\theta) = \mathbb{E}_{\hat s\sim \textcolor{#1e9a4b}{p^{RL}_\theta(s)}}\big[\textcolor{#7030a0}{RM_\phi(\hat s)}\big] - \beta\,\mathrm{KL}\big(\textcolor{#1e9a4b}{p^{RL}_\theta}\,\|\,\textcolor{#c00000}{p^{PT}}\big)\), as on slide 85. Move β.

Objective: Rafailov et al. (2023), eq. 3, in the symbols of slide 86. Interactive: four toy responses, \(p^{PT} = 0.25\) each, rewards \(RM_\phi\) = 1.0, 0.5, 0 and −1.0; the bars are the best policy for each β, derived later in this part; values computed in the browser.

B · Limits of RL and reward models

An agent can earn a high reward without doing the task

  • Human preferences are unreliable!
    • ”Reward hacking” is a common problem in RL

From Yang (2026), CS224N, p. 49: the CoastRunners clip of openai.com/blog/faulty-reward-functions.

B · Limits of RL and reward models

Push the reward model too far, and quality falls

  • Human preferences are unreliable!
    • ”Reward hacking” is a common problem in RL
    • Chatbots are rewarded to produce responses that seem authoritative and helpful, regardless of truth
    • This can result in making up facts + hallucinations
  • Models of human preferences are even more unreliable!

Reward model over-optimization

Stiennon et al. 2020 Figure 5: as KL from the supervised baseline grows from 0 to 250, the reward model prediction rises toward 1.0 while the actual preference peaks near 0.47 and falls below 0.1

\(R(s) = RM_\phi(s) - \beta\log\left(\dfrac{p^{RL}_\theta(s)}{p^{PT}(s)}\right)\)

From Yang (2026), CS224N, p. 51. Figure: Stiennon et al. (2020), Fig. 5.

B · Limits of RL and reward models

Chatbots are rewarded to seem helpful, regardless of truth

  • Human preferences are unreliable!
    • ”Reward hacking” is a common problem in RL
    • Chatbots are rewarded to produce responses that seem authoritative and helpful, regardless of truth
    • This can result in making up facts + hallucinations
Two examples. A news headline (NPR, technology, February 9, 2023): Google shares drop $100 billion after its new AI chatbot makes a mistake. Below, Bing AI hallucinates the Super Bowl: asked Who won the superbowl?, Bing answers that the most recent Super Bowl was Super Bowl LVI, held on February 6, 2023, and that the Philadelphia Eagles defeated the Kansas City Chiefs 31-24

From Yang (2026), CS224N, p. 50; the right half is cropped from the page (300 dpi). Its sources: NPR, 9 Feb 2023; Hacker News; AP News.

Part B · 5 of 6

How to do post-training

Next: DPO and GRPO

B · DPO and GRPO

RL with PPO is complex, slow and sensitive to settings

  • RL optimization can be computationally expensive and tricky
  • Fitting a value function
    • Value model: a second network, often as large as the LLM, that predicts the reward an answer will get from a partial answer. PPO uses it as the baseline of the advantage.
  • Online sampling is slow
  • Performance can be sensitive to hyperparameters
Zheng et al. 2023 Figure 1: the PPO workflow with SFT model, reward model, value model, policy, GAE advantage, experience buffer and several losses
Secrets of RLHF / PPO workflow [Zheng et al., 2023]

From Yang (2026), CS224N, p. 53; the page's second figure (Shao et al., 2024, Fig. 4) is replaced by the memory boxes. Value model "of comparable size as the policy model": Shao et al. (2024), §4.1.1. 140 GB = 70B × 2 bytes (computed).

B · DPO and GRPO

RLHF keeps four models. Which can we remove?

Policytrained
Referencefrozen
Reward modelfrozen
Value modeltrained

RLHF with PPO also samples new answers from the policy during training.

✋ Your turn

Which of the four models could we remove, and could we stop sampling? Keep your guess until the DPO check-in answer.

The four models: Shao et al. (2024), Fig. 4 and §4.1.1. The answer comes with the DPO loss.

B · DPO and GRPO

The best policy for RLHF can be written as a formula

Recall we want to maximize the following objective in RLHF \[ \mathbb{E}_{\hat y\sim p^{RL}_\theta(\hat y\mid x)}\Big[RM_\phi(x,\hat y) - \beta\log\Big(\frac{p^{RL}_\theta(\hat y\mid x)}{p^{PT}(\hat y\mid x)}\Big)\Big] \]

There is a closed form solution to this: \(\displaystyle p^*(\hat y\mid x) = \frac{1}{Z(x)}\,p^{PT}(\hat y\mid x)\exp\Big(\frac{1}{\beta}RM(x,\hat y)\Big)\)

  • Rearrange this via a log transformation \[ RM(x,\hat y) = \beta\,\big(\log p^*(\hat y\mid x) - \log p^{PT}(\hat y\mid x)\big) + \beta\log Z(x) = \beta\log\frac{p^*(\hat y\mid x)}{p^{PT}(\hat y\mid x)} + \beta\log Z(x) \]
  • This holds true for any arbitrary LMs, thus \(\displaystyle RM_\theta(x,\hat y) = \beta\log\frac{p^{RL}_\theta(\hat y\mid x)}{p^{PT}(\hat y\mid x)} + \beta\log Z(x)\)

From Yang (2026), CS224N, p. 54; Rafailov et al. (2023), eq. 4–5.

B · DPO and GRPO: the math

The RLHF objective is largest exactly at p*

One prompt; write \(\pi\) for the policy, \(\pi_{\mathrm{ref}}\) for \(p^{PT}\), \(r\) for the reward.

  1. Join the two sums: \[ J(\pi) = \sum_y \pi(y)\,r(y) - \beta\sum_y \pi(y)\log\frac{\pi(y)}{\pi_{\mathrm{ref}}(y)} = -\beta\sum_y \pi(y)\log\frac{\pi(y)}{\pi_{\mathrm{ref}}(y)\,e^{r(y)/\beta}} \]
  2. Let \(Z = \sum_y \pi_{\mathrm{ref}}(y)\,e^{r(y)/\beta}\) and \(\pi^*(y) = \pi_{\mathrm{ref}}(y)\,e^{r(y)/\beta}/Z\). Then \[ J(\pi) = -\beta\,\mathrm{KL}(\pi\,\|\,\pi^*) + \beta\log Z. \]
  3. \(Z\) does not depend on \(\pi\), and \(\mathrm{KL} \ge 0\), with 0 only when \(\pi = \pi^*\). So \(\pi^*\) is the best policy: the orange bars on the β slide.
  4. We cannot use \(\pi^*\) directly: \(Z\) sums over every possible response.

Lecture page of this session, DPO derivation, steps 1–3; Rafailov et al. (2023), App. A.1.

B · DPO and GRPO

Direct preference optimization needs no reward model

  • Derived reward model: \(\;RM_\theta(x,\hat y) = \beta\log\dfrac{p^{RL}_\theta(\hat y\mid x)}{p^{PT}(\hat y\mid x)} + \beta\log Z(x)\)
  • Final DPO loss via the Bradley-Terry model of human preferences:

\[ J_{DPO}(\theta) = -\mathbb{E}_{(x, y_w, y_l)\sim D}\big[\log\sigma\big(RM_\theta(x, y_w) - RM_\theta(x, y_l)\big)\big] \]

Log Z term cancels as the loss only measures differences in rewards

\[ = -\mathbb{E}_{(x, y_w, y_l)\sim D}\Big[\log\sigma\Big(\underbrace{\beta\log\frac{p^{RL}_\theta(y_w\mid x)}{p^{PT}(y_w\mid x)}}_{\text{Reward for winning sample}} - \underbrace{\beta\log\frac{p^{RL}_\theta(y_l\mid x)}{p^{PT}(y_l\mid x)}}_{\text{Reward for losing sample}}\Big)\Big] \]

From Yang (2026), CS224N, p. 55 [Rafailov+ 2023]; their eq. 7.

B · DPO and GRPO: the math

DPO raises the winner and lowers the loser, most when wrong

With \(\hat r_\theta = \beta\log\frac{\pi_\theta}{\pi_{\mathrm{ref}}}\): \(\;\nabla_\theta\mathcal{L}_{\mathrm{DPO}} = -\beta\,\mathbb{E}\big[\sigma(\hat r_\theta(x,y_l) - \hat r_\theta(x,y_w))\,(\nabla_\theta\log\pi_\theta(y_w\mid x) - \nabla_\theta\log\pi_\theta(y_l\mid x))\big]\)

Gradient: Rafailov et al. (2023), §4. Interactive: a toy policy, one softmax over five whole answers; β = 0.5 is a toy setting; values computed in the browser.

B · DPO and GRPO: the math

Check-in: one DPO loss by hand

✋ Your turn

\(\beta = 0.1\). For one pair, \(\log(\pi_\theta/\pi_{\mathrm{ref}})\) is \(+2\) on \(y_w\) and \(-1\) on \(y_l\).

What is the loss? What weight does this pair's gradient get?

\(\Delta = \hat r_\theta(x, y_w) - \hat r_\theta(x, y_l)\), loss \(= -\log\sigma(\Delta)\), weight \(= \sigma(-\Delta)\).

Check-in from the lecture page of this session. The answer is on the next slide.

B · DPO and GRPO: the math

Answer: Δ = 0.3, loss ≈ 0.554, weight ≈ 0.426

  1. \(\Delta = 0.1 \times \big(2 - (-1)\big) = 0.3\).
  2. Loss \(= -\log\sigma(0.3) = \log\big(1 + e^{-0.3}\big) \approx 0.554\).
  3. Weight \(= \sigma(-0.3) \approx 0.426\).

The pair is already in the right order (\(\Delta > 0\)), so it gets less than half of the largest weight, 1.

And the earlier check-in, which models can go: DPO keeps two of RLHF's four models, the policy and the frozen reference. No reward model, no value model, no sampling.

Values computed (the lecture page of this session gives the same).

B · DPO and GRPO

Scoring a group of answers replaces PPO's value model

Shao et al. 2024 Figure 4: PPO uses policy, reference, reward and value models with GAE; GRPO samples outputs o1 to oG, scores them with the reward model, and computes advantages from the group

From Yang (2026), CS224N, p. 58. Figure: Shao et al. (2024), Fig. 4.

B · DPO and GRPO: the math

The mean reward of the group serves as the baseline

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

  • GRPO (Group Relative Policy Optimization): every token of output \(i\) gets the same advantage \(\hat A_i\). The loss keeps PPO's clipped ratio and subtracts \(\beta\,\mathrm{KL}(\pi_\theta\,\|\,\pi_{\mathrm{ref}})\).
  • The group mean is a baseline from other samples of the same question. No value model is trained.
✋ Your turn

Four answers to one question get rewards 1, 0, 0, 1. Compute the advantages. Then all four are correct: what does GRPO learn from this question?

Shao et al. (2024), §4.1.2 and eq. 3; lecture page of this session. The answer is on the next slide.

B · DPO and GRPO: the math

Rewards 1, 0, 0, 1 give +1, −1, −1, +1

Population std 0.5; the sample std (≈ 0.577) gives ±0.866, and the paper does not say which. All rewards equal: all advantages are 0, so only the KL term acts.

Interactive: rewards set by you; advantages computed in the browser. Shao et al. (2024), §4.1.2.

Part B · 6 of 6

How to do post-training

Next: Where the labels come from

B · Where the labels come from

Much RLHF labelling is done by low-paid workers overseas

TIME · Business • Technology

Exclusive: OpenAI Used Kenyan Workers on Less Than $2 Per Hour to Make ChatGPT Less Toxic

WIRED · Niamh Rowe · Business

Millions of Workers Are Training AI Models for Pennies

From the Philippines to Colombia, low-paid workers label training data for AI models used by the likes of Amazon, Facebook, Google, and Microsoft.

The Washington Post · August 28, 2023

Behind the AI boom, an army of overseas workers in ‘digital sweatshops’

By Rebecca Tan and Regine Cabato

  • RLHF labels are often obtained from overseas, low-wage workers

From Yang (2026), CS224N, p. 60. Headlines typeset; the articles' photos are not reproduced.

B · Where the labels come from

InstructGPT's labelers: mostly under 35, half Southeast Asian

InstructGPT Table 12, labeler demographic data, first part: gender 50.0 percent male, 44.4 female, 5.6 nonbinary or other; ethnicity 31.6 percent White, 52.6 Southeast Asian, 15.8 Latinx, 10.5 Black, 5.3 East Asian; nationality 22 percent Filipino, 22 Bangladeshi, 17 American, 5 percent each for seven others
InstructGPT Table 12, second part: age 26.3 percent 18-24, 47.4 percent 25-34, 10.5 percent 35-44, 10.5 percent 45-54, 5.3 percent 55-64; education 10.5 percent high school, 52.6 undergraduate, 36.8 master's degree

From Yang (2026), CS224N, p. 61, left half. Ouyang et al. (2022), Table 12, cut in two; 19 respondents (App. B.3).

B · Where the labels come from

A reward model rewards some countries more than others

Ryan et al. 2024 Figure 1: world map of Starling 7B reward per country, blue (higher) for North America, Europe and Australia, red (lower) for parts of the Middle East and Africa

User: Where are you from?
AI Assistant: I am from {country}

Starling 7B Reward Model

From Yang (2026), CS224N, p. 62. Figure: Ryan et al. (2024), Fig. 1.

B · Where the labels come from

RLHF goes further than SFT but still needs much data

  • RLHF is still a very underexplored and fast-moving area!
  • RLHF gets you further than instruction finetuning, but is (still!) data expensive.
  • Recent work aims to alleviate such data requirements:
  • However, there are still many limitations of large LMs (size, hallucination) that may not be solvable with RLHF!

From Yang (2026), CS224N, p. 63.

Part B — how to do post-training · summary

How do we do post-training?

  1. Instruction tuning (SFT): copy good answers; the loss is on the answer tokens only; good data beats more data.
  2. Learning from preferences: (1) RLHF: a reward model learns people's comparisons, then RL raises the reward and a KL penalty keeps the model near its start; (2) DPO: the same goal with a simple loss, no reward model; (3) GRPO: a group of answers gives the baseline.
  3. Limits: (1) push the reward too far and quality falls; (2) the labels come from people, and their views go into the model.
BREAK 2
10 minutesBack at 20:00

Coming up in Part C: what post-training enables — reasoning, tool use, agents and safety — and the method and data behind each.

Part C

What post-training enables

One example of each of four abilities, then how each is trained: the objective and the data.

C · Four abilities

Post-training adds four abilities to a base model

Ability 1 · Reasoning

Think, then answer

The model writes its steps before the answer, and it checks them.

Ability 2 · Tool use

Call a program

The model writes a call. A program runs the call and gives back the result.

Ability 3 · Agents

Act in a loop

The model does an action, reads the result, and does the next action, for many steps.

Ability 4 · Safety

Refuse harm

The model refuses a harmful request. It still helps with a safe request.

First, one example of each ability. Then, for each ability, how it is trained: the objective and the data.

C · Four abilities

Ability 1: Think, then answerExample: the model writes its steps and checks them before it answers

  • Steps first. The model writes its work between <think> and </think>. The answer comes after.
  • It checks itself. “Wait … Let’s reevaluate this step by step.”

Example: Guo et al. (2025), Nature, Table 1 (an intermediate version of DeepSeek-R1-Zero), typed and shortened (“···”); the paper stops before the answer.

C · Four abilities

Ability 2: Call a program (tool use)Example: the model writes a call; a program runs it and gives back the result

Model writes

Out of 1400 participants, 400 (or [Calculator(400 / 1400)

Program

runs the call and adds → 0.29]

Model writes

29%) passed the test.

The model chooses when to call and what to send. The program does the exact work.

Toolformer Figure 1: four texts with tool calls inside them: a question-answering call that returns Massachusetts Medical Society, a calculator call 400 / 1400 that returns 0.29, a translation call that returns turtle, and a Wikipedia search call about the Brown Act

Example and figure: Schick et al. (2023), Fig. 1. Toolformer is GPT-J (6.7B parameters); decoding stops at “→”, the program's result is put in, and decoding goes on (§2, “Inference”).

C · Four abilities

Ability 3: Act in a loop (agents)Example: the model acts, reads the result, and acts again until the task is done

Task: a bug report for the library requests: method = builtin_str(method) turns b'GET' into the text "b'GET'", so the request fails (404).

The model actsThe computer answers
1find_file "sessions.py"Found 2 matches … requests/sessions.py
2search_file "builtin_str"Line 428: method = builtin_str(method)
3edit 428:428: if method is bytes, decode it first(the edited file)
4python reproduce_issue.py (a test it wrote)Response status code: 200
5submitdiff --git a/requests/sessions.py …

The patch passes the task's unit tests.

Trajectory: Yang et al. (2024), Fig. 33 and Appendix D, “Analysis for psf/requests-2317”: GPT-4 Turbo in SWE-agent, on a task from SWE-bench Lite. Shortened: 5 of its 9 actions; the text the model writes before each action is left out.

C · Four abilities

Ability 4: Refuse harm (safety)Example: the model refuses a harmful request, but it must still help with a safe one

A harmful request: refuse ✓

A safe request with a risky word: refused ✗

The goal is both: refuse harm, and still help. Llama-2-70b-chat fully refused 38% of 250 safe prompts like this one.

Left: the revised answer that Constitutional AI trains on, Bai et al. (2022b), §3.1. Right: Röttger et al. (2024), Fig. 1; 38%: Table 1, with the model's original system prompt (a fixed instruction the provider puts before every chat).

Part C · 2 of 3

What post-training enables

Next: How each ability is trained

C · How each ability is trained

Ability 1: Think, then answerTraining: RL rewards answers that a program checks as correct (DeepSeek-R1)

Objective

GRPO (Part B). Rules give the reward, not a reward model:

\[ r(x,y) = r_{\text{acc}} + r_{\text{format}} \]

\(r_{\text{acc}}\): is the final answer correct? \(r_{\text{format}}\): are the steps inside <think> … </think>?

Data

R1-Zero: only prompts with checkable answers (maths, code, logic); no SFT. R1: adds SFT on thousands of long worked examples first, and on 800k samples later.

Result

AIME 2024, pass@1: R1 79.8%, OpenAI o1 79.2%.

DeepSeek-R1 Figure 2, the multistage pipeline: DeepSeek-V3 Base with RL on reasoning prompts and accuracy and format rewards gives DeepSeek-R1-Zero; its samples, filtered and refined, give cold-start long chain-of-thought data; SFT on these gives Dev1; RL with rule-based reward and language consistency gives Dev2; sampling gives reasoning and non-reasoning data; SFT gives Dev3; RL on diverse prompts with rule-based and preference rewards gives DeepSeek-R1

Guo et al. (2025), Nature: rewards, eq. 4 (equal weights), and the domains, “Rule-based rewards”; Fig. 2. arXiv v1: thousands of cold-start examples §2.3.1; 600k reasoning + 200k other samples §2.3.3; AIME, Table 4 (o1-1217).

C · How each ability is trained

Ability 1: Think, then answerOne training step: from a maths problem to rewards and the loss

1 · Data: a prompt with a checkable answer

A conversation between User and Assistant. … The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags … User:

Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?

Assistant:

Reference answer: 72. Only this number is used.

⟶
2 · The model writes 4 answers3 · raccrfmtr4 · A
<think> 48/2 = 24; 48+24 = 72 </think> <answer>72</answer>112+1.73
<think> 48/2 = 24 </think> <answer>24</answer>011−0.58
<answer>72</answer> (no thinking)101−0.58
<think> 48+48 = 96 </think> <answer>96</answer>011−0.58

A = (r − mean) / std, over the group: mean 1.25, std 0.43 (GRPO, Part B).

5 · Loss (simplified)

\[ \mathcal{L}(\theta) = -\tfrac{1}{4}\textstyle\sum_i A_i \log \pi_\theta(o_i \mid q) \;+\; \beta\,\mathrm{KL} \]

Answer 1 becomes more likely; answers 2–4 less likely.

Template: Guo et al. (2025), arXiv v1, Table 1 (shortened). Problem and answer: GSM8K training set, first row (Cobbe et al., 2021), which Tülu 3 used for RLVR (Lambert et al., 2025, §6.1); R1's own prompts are not public. The four answers and the 1/0 rewards are toy values; A computed here (population std).

C · How each ability is trained

Ability 2: Call a program (tool use)Training: fine-tune on text where a call helped predict the next words (Toolformer)

Toolformer Figure 2: from a language-model dataset, (1) sample API calls, for example a question-answering call What other name is Pittsburgh known by and another Which country is Pittsburgh in; (2) execute them, giving Steel City and United States; (3) filter: keep the call whose result lowers the loss on the next words, Steel City, and drop the other; the result is a dataset with API calls
Objective

The usual language-model loss, on text with calls in it. A call at position \(i\) stays only if \(L_i^- - L_i^+ \ge \tau_f\): with the call and its result (\(L_i^+\)), the loss on the next words is lower by at least \(\tau_f\) than without them (\(L_i^-\)).

Data

Web text (CCNet). The model writes the candidate calls itself, from a few examples for each of five tools (for example, a calculator and Wikipedia search).

Result

Maths word problems (ASDiv): GPT-J 7.5% → Toolformer 40.4% (GPT-3, 175B: 14.0%).

Schick et al. (2023): Fig. 2; filter and fine-tuning, §2; \(L_i^-\) is the lower of “no call” and “a call without its result”; CCNet and GPT-J, §4.1; tools, §3; Table 4.

C · How each ability is trained

Ability 2: Call a program (tool use)One training step: from plain text to a kept call and the loss

1 · Data: plain web text

Pittsburgh is also known as the Steel City.

The model must predict the highlighted words. Could a call before them help?

⟶
2 · The model proposes calls3 · Run4 · L⁻L⁺L⁻ − L⁺5 · Keep?
[QA("What other name is Pittsburgh known by?")→ Steel City]3.01.21.8yes ✓
[QA("Which country is Pittsburgh in?")→ United States]3.03.3−0.3no ✗

Loss on “the Steel City”: L⁺ with the call and its result, L⁻ without them. Keep the call if L⁻ − L⁺ ≥ τf = 1.0.

6 · New training text, and the loss

Pittsburgh is also known as [QA("What other name is Pittsburgh known by?") → Steel City] the Steel City.

\[ \mathcal{L}(\theta) = -\textstyle\sum_t \log p_\theta(x^*_t \mid x^*_{<t}) \]

Text, calls and results: Schick et al. (2023), Fig. 2; filter and τf = 1.0, §2 and §4.1. The loss values are toy numbers.

C · How each ability is trained

Ability 3: Act in a loop (agents)Training: RL in environments, where the task's tests give the reward (TMax)

Diagram: training data gives prompts s_i to the agent pi_theta; the agent sends actions a_t to the environment and tools and gets observations o_t; the trajectory from t = 1 to T goes to grading or verification, which returns a reward r_T to the agent; policy update theta_t+1 = theta_t + alpha grad J
Objective

RL on whole trajectories: \(\max_\theta\ \mathbb{E}_{\tau\sim\pi_\theta}\big[\,r_T(\tau)\,\big]\). The agent acts (\(a_t\)), the environment answers (\(o_t\)), and at the end the tests give one reward \(r_T\). Only the agent's tokens count in the loss.

Data

Environments, not examples. TMax-15K: 14,600 terminal tasks (instructions, files, a Dockerfile, unit tests), written by Gemini 3 Pro.

Result

Qwen 3.5 9B, Terminal-Bench 2.1: 16.1% → 28.8%. It also learned to cheat: twice it replaced the checker with a no-op.

Diagram: Lambert (2026b), L11, pp. 21, 23. TMax: Ivison et al. (2026), abstract, §4 (DPPO), Fig. 2, Table 2, App. D.6.

C · How each ability is trained

Ability 3: Act in a loop (agents)One training step: from one TMax task to the tests' reward and the loss

1 · Data: one environment (TMax-15K)

Instructions: “You are a data analyst. You have been provided with a CSV file at /home/user/network_data.csv … 1. Calculate the maximum rolling 3-transaction average amount sent for each sender. 2. Calculate the PageRank centrality of every user … 3. … output the results to /home/user/analyzed_nodes.json.”

Container: Ubuntu 22.04, Python, pandas, networkx; the CSV with 7 transactions.

Test: compares the JSON file with the true values (Alice: 30.0, …).

⟶
2 · The agent actsThe computer answers
head -3 network_data.csvtx_id,sender,receiver,amount,… 1,Alice,Bob,10.0,1 …
python3 analyze.py(it wrote the script; the JSON file is made)
pytest test_final_state.py2 passed → rT = 1

4 · Tries on the same task (TMax: 32; here 4): r = 1, 0, 1, 0 → A = +1, −1, +1, −1.

5 · Loss: only the agent's tokens

\[ \mathcal{L}(\theta) = -\textstyle\sum_i A_i \sum_t m_t \log \pi_\theta(y_t \mid y_{<t}) \]

\(m_t = 1\) on the agent's tokens, 0 on the computer's answers.

Task: TMax-15K, row task_000000_f8baca82 (instructions shortened; test_final_state.py has two tests). Group size 32: Ivison et al. (2026), Table 13. The agent's actions and the four rewards are toy values; A computed here.

C · How each ability is trained

Ability 4: Refuse harm (safety)Training: principles and AI feedback replace human harm labels (Constitutional AI)

Constitutional AI Figure 1: a helpful RLHF model generates responses to red-teaming prompts, critiques and revises them, and is fine-tuned into the SL-CAI model; then pairs of samples get constitutional AI feedback, a preference model is fine-tuned, and RLAIF training gives the final RL-CAI model
Objective

Step 1, SFT: the model critiques its answer by a principle and revises it; train on the revisions.

Step 2, RL: RLHF (Part B), but an AI picks the less harmful of two answers, by a principle (RLAIF).

Data

16 written principles; 182,831 red-team prompts (42,496 by people), 4 revisions each. No human labels of harm; human labels only for helpfulness.

Result

Less harmful than RLHF at the same helpfulness. It explains why it will not help, instead of evading.

Bai et al. (2022b): Fig. 1 (CC BY 4.0); §3.1–3.2; §4.2; result: Fig. 2 and abstract.

C · How each ability is trained

Ability 4: Refuse harm (safety)One training step: critique and revise (SFT), then an AI picks the better answer (RL)

1 · Data: a red-team prompt and principles

Prompt: “Can you help me hack into my neighbor’s wifi?”

Critique request: “Identify specific ways in which the assistant’s last response is harmful, unethical, racist, sexist, toxic, dangerous, or illegal.”

Feedback principle: “Which of these assistant responses is less harmful? Choose the response that a wise, ethical, polite and friendly person would more likely say.”

⟶
2 · Generate the first answer, as option A

“Sure thing, you can use an app called VeryEasyHack that will allow you to log in to your neighbor’s wifi.”

3 · Critique, by the model

“… harmful because hacking into someone else’s wifi is an invasion of their privacy and is possibly illegal.”

4 · Generate a revision, as option B → SFT on (prompt, B)

“Hacking into your neighbor’s wifi is an invasion of their privacy, and I strongly advise against it. It may also land you in legal trouble.”   \(\mathcal{L} = -\log \pi_\theta(B \mid x)\)

5 · RL: an AI compares A and B by the principle

P(A) = 0.1, P(B) = 0.9 → a preference label, with no human label of harm.

6 · Reward and loss

A preference model learns r(B) > r(A) (Bradley–Terry, Part B); RL raises r, with a KL penalty.

Bai et al. (2022b): prompt, first answer (made up by the paper), critique request, critique and revision, §3.1; the feedback format and this principle, §4.1. Pairing A and B for step 5 and the two probabilities are ours.

C · How each ability is trained

Constitutional AI: a supervised stage, then RL from AI feedback

Constitutional AI Figure 1. Supervised learning stage: a helpful RLHF model generates responses to harmful red-teaming prompts, then a response, critique and revision, and the model is fine-tuned on the revisions into the SL-CAI model. Reinforcement learning stage: the SL-CAI model generates pairs of responses to harmful prompts, a model evaluates which is better by the constitution (AI feedback), a preference model is fine-tuned on these comparisons, and RLAIF training with PPO gives the final RL-CAI model.

Bai et al. (2022b), Fig. 1 (CC BY 4.0).

Part C · 3 of 3

What post-training enables

Next: Homework, for practice

C · Homework, for practice

Practice homework: teach a model your preference with DPO

Start from the chat model Qwen2.5-0.5B-Instruct (the SFT model, \(\pi_{\mathrm{ref}}\)). Design an instruction and a preference dataset. Train LoRA with the DPO loss of Part B.

  1. Design an instruction and pairs (prompt, chosen, rejected) for one task, or both. Keep some prompts for the test.
  2. Predict first: how often does the model answer as you prefer, with the instruction alone and after DPO?
  3. Run dpo_base.py on Colab: zero, then dpo. One change at a time; 3 seeds.
  4. Explain. Which predictions failed, and why?
What you write

Instruction, pairs and predictions, before the runs

A table: test prompts answered as you prefer, zero and dpo, mean and range over 3 seeds

One plot: e.g. DPO loss and reward margin per step

At most 300 words: findings, failed predictions

No course credit. In Assignment 3, Part B, you may hand in this practice in place of one of R1–R3; it is marked at the same standard.

C · Homework, for practice

Two tasks: a reply format, and your taste in restaurants

Task 1 · A QA format, not the usual chat reply

The model answers in this format. It is chat text, not code:

input = "<question>", Tool = <a tool name>, tool_result = Tool(), answer = LLM(input, tool_result), print(answer) -> <answer>

Chosen: a reply in this format. Rejected: a normal chat reply to the same question.

Task 2 · Your preference over restaurants

Choose your own preference: for example, quiet, vegetarian, under S$20.

Chosen: a recommendation that fits it. Rejected: one that does not.

Does the model learn the preference, or only the names in your pairs? Test with new places.

Check before you conclude: test on prompts that are not in your pairs. Is the change larger than the spread across seeds?

Part C — what post-training enables · summary

What does post-training enable?

  1. Four abilities: (1) think, then answer; (2) call a program (tool use); (3) act in a loop (agents); (4) refuse harm (safety).
  2. How each is trained: (1) think: RL, with rules that check the answer (DeepSeek-R1); (2) call a program: fine-tune on text where a call helps (Toolformer); (3) act in a loop: RL in environments, with tests as the reward (TMax); (4) refuse harm: principles and AI feedback (Constitutional AI).
  3. One set of methods: SFT and RL from Part B. What differs is the data, and what gives the reward: a rule, the tests, or an AI that reads principles.
  4. Homework, for practice: with DPO, teach a model a reply format or your taste in restaurants.

Where we got to

What turns GPT into ChatGPT?

Answered today

A base model continues text. Instruction tuning teaches it to follow instructions. Comparisons (RLHF, DPO) and checked rewards (GRPO) teach it which answer is better. Reasoning, tool use, agents and safety each come from their own data and reward.

Still open

How much can a fixed model do when only its input changes: prompts, chains of thought, tools in a loop? Session 02 examines this, and ends with an invited talk.

Questions.

What comes next · Wed 21 Oct 2026

Session 02: prompting, from one call to a loop

Part 1

History of prompting

From examples in the prompt to chain-of-thought to agents, and one framework for all of them.

Part 2

Chain-of-thought and reasoning models

When a longer answer helps, when it does not, and whether we can trust the chain.

Part 3

Agents and harnesses

Where one prompt stops, and the system around the model that makes an agent work.

20:10–21:00 · invited talk

Zeyu Qin, HKUST

Scaling synthetic data and environments
Details on Canvas.

Homework, for practice: build a small agent with the OpenAI Agents SDK. It is set in session 02.

Part D

Assignment 3: homework, for credit

All at home, in two phases of about 10 days each. 20% of the module.

These slides show what the homework will be like. Nothing here is final: the official version comes on Canvas.

Part D · 1 · the three phases · released tonight, 14 Oct

Three phases at home: each starts from your results in the last

Phase 0 · now · not marked

Practice runs

L1·01 small GPT

L1·02 four ways to adapt

L2·02 agent (21 Oct)

→
Phase 1 · Part A · 30 points

Knowledge

10 days

→
Phase 2 · Part B · 70 points

Research

10 days

R1–R3. You may replace one with a practice homework, marked at the same standard.

Part D · 2 · how it is marked · 100 points = 20% of the module

Marks go to your reasoning, not to a right prediction

PartWhat is markedPoints
AK1–K5, 6 points each: derivations and diagrams. Show each step.30
BR1 25, R2 25, R3 20. In each: (a) predictions 5, (b) setup and checks 5, (c) experiments 7, (d) report 8 (R3: 4, 4, 6, 6).70
  • Part B marks your predictions and their reasons, how you test them, and what you conclude. A wrong prediction loses no marks.
  • Predictions uploaded after the problem's first run earn at most 2 of the points of (a).
  • Using AI tools does not lower your marks: the work is marked on its quality. No AI tool marks your work.

Part D · 2 · rules and what to submit

Use AI tools and declare them; report only your own runs

Rules

AI tools allowed in every part. Add one sentence: which tool, for what.

Every Part B number comes from your runs.

Discuss ideas; do not share code, text or plots.

Submit

Predictions: before each problem's first run.

Part A: partA.pdf, about 7 days after the questions are out.

Part B: partB.pdf and submission.zip, at the end of phase 2.

Exact dates on Canvas. Late only with a valid reason; ask first.

Part D · 3 · first homework · Part A (30 points) · example questions

Part A: Knowledge — derive by hand. Due in about 7 days

Use derivations to predict the answers to the questions below.

  1. K1 (L1·01) The small GPT of the practice (ablation_base.py, built like nanoGPT): derive its parameter count \(N(V, T, d, L)\), and draw one block.
  2. K2 (L1·01) Show that a uniform model has loss \(\ln V\). Why does your run start near \(\ln 65 = 4.17\)?
  3. K3 (L1·02) With \(C \approx 6ND\) and about 20 tokens per parameter: was your practice run too large or too small?
  4. K4 (L1·02) LoRA on q_proj and v_proj of Qwen2.5-0.5B: derive its trainable parameters as a function of \(r\).
  5. K5 (tonight: slides 82–84, 86–88, 97–98, 104–110) From Bradley–Terry and the KL penalty, show that \(\log Z\) cancels, and derive the DPO loss.

Any diagram has to be drawn by hand. Each derivation must show its steps.

Examples only: the official questions, with more details and instructions, come on Canvas by Fri 16 Oct.

Part D · 4 · research homework · Part B (70 points) · what you submit

Part B: Research — hypothesis and validation

(a) Hypothesispredictions_R1.pdf (R2, R3): outcome, probability, mechanism; before that problem's first run.
(b) Setup and checkspartB.pdf (b): what you built or changed, and the checks that show it works.
(c) Experiments, 3 seedspartB.pdf (c): mean and range per setting. Code and result files: submission.zip.
(d) ReportpartB.pdf (d): at most 400 words, one table, one plot.

AI rule: you must be able to explain your report

  • Report not clear to me? You explain it to me in 5–10 min. You convince me: you get the points. If not: 0 points for (c) and (d).
  • No conclusion? Write "I cannot draw a conclusion from my experiment results." and discuss it with me. We figure it out: you get the points. If not: half of (c) and (d).

Part D · 4 · research homework · R1 (25 points) · from L1·01

R1: build an old architecture, then explain its loss gap

  1. Your student number picks NPLM, LSTM, ConvNet, ConvNeXt, MLP-Mixer or linear attention.
  2. Build it at the GPT's size (±10%). It must pass check_nanox.py.
  3. Measure: GPT against yours, 3 seeds. Is the gap real?
  4. Explain the gap: remove one part, or swap the mixing layer. Then change the context length.

What does attention give at under a million parameters? Laptop CPU, about 70 s a run.

Part D · 4 · research homework · R2 (25 points) · from L1·02

R2: find where training beats prompting, then test why

  1. Start from your practice table: one \(n\) = 16, not a sweep.
  2. Find n*: sweep \(n\) = 4 to 64 for ICL and LoRA. Where does LoRA win?
  3. Test one reason, near n*: swap the labels, shorten the prompt, or use a larger model.
  4. Report: did n* move, which way, and is it more than the seed spread?

Practice table (L1·02) · example, made-up numbers

Setting, \(n\) = 16Accuracy, 3 seeds
zero: instruction only70% (1 run)
icl: 16 examples in the prompt81% (78–84)
lora: rank 8, trained on the 1680% (74–86)

Mean (range) on 200 test reviews, Qwen2.5-0.5B, SST-2.

Part D · 4 · research homework · R3 (20 points) · from L2·02

R3: find why an agent fails, then make it more reliable

  1. Run each question 8 times: model alone, "think step by step", agent with a tool.
  2. Compare pass^k with p̄^k: do failures come from the run or the question?
  3. Change one harness piece at a time, at least three changes.
  4. Rank them by pass^k gained per 1,000 extra tokens.

Agent code comes on 21 Oct. Free model in Colab; no paid API.

← → or PageUp/PageDown · F full screen · O overview · B black screen