Unit 1 of 10 · about 4 hours · explain
Prompts as initial states, tokens as actions and trajectory choices
Every later estimator sums over these objects. A vague boundary attaches masks, rewards and KL terms to the wrong tokens.
You'll be able to
- Map a prompt, a completion and optional further turns onto an initial state, actions and a trajectory with an explicit episode boundary.
- Write the factorized trajectory probability for a completion, marking which factors come from the policy and which are deterministic.
- Choose a completion, conversation or tool episode for a task and state what the choice changes about rewards and evaluation.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Trajectory distribution and the three RLHF changesRLHF Book - Introduction, Training Overview and Instruction Tuning
Problem Formulation (trajectory Equation 1 and the Thermostat example) through Manipulating the Standard RL Setup: the three changes from standard RL, with Table 1
- Language models as an MDPRLHF Book Course - Lectures 0 and 1
Slides 27 and 28 of 31: the MDP-to-LM table (state as prompt plus tokens so far, deterministic append transition, terminal reward, ) and the autoregressive factorization
- Generation as an MDPHands-on Modern RL - Chapter 13 RLHF Pipeline
Rewriting Generation as an MDP: the MDP-to-generation table with the deterministic-transition and late-reward paragraphs (page read 2026-10-14)
Stop before A Minimal Probe. The probe compares base models, which is not this unit.
- One-step versus token-level formulationBerkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - LLM RL
Slides 20 and 21 of 51: A basic formulation (one-step RL on prompt and completion) and An equivalent formulation (token view for intermediate rewards and value baselines)
Focus on
- The prompt distribution is the initial-state distribution. In single-turn RLHF the completion does not produce the next prompt, so there is no environment transition between episodes.
- The transition inside a completion is deterministic appending: given state and action , the next state is with probability 1.
- Completion, conversation and tool episode are modeling choices, not facts. Each choice moves the episode boundary and decides which tokens can earn reward.
- The policy is the whole autoregressive factorization , not one response-level draw.
Common mistakes · 3
- Treating the next training prompt as caused by the previous completion. Single-turn sampling draws each prompt fresh from the dataset.
- Calling the prompt a state while letting the tokenizer or chat template differ between sampling and scoring. The state includes the exact token string.
- Confusing episode end with truncation. EOS ends the trajectory; a length cap cuts it, and the two need different reward handling.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.In single-turn RLHF, what is the initial-state distribution and what are the transition dynamics between episodes?Answer
The prompt dataset is the initial-state distribution. There are no transitions between episodes: each prompt is sampled fresh and the previous completion does not affect it.
2.Why is the token-append transition deterministic, and what does that remove from the trajectory probability?Answer
Appending the chosen token always yields the same next context, so every factor equals 1. Only the initial-prompt factor and the policy factors remain.
3.A task needs two tool calls before the answer. What changes if the episode is one completion versus the full tool interaction?Answer
A one-completion episode ends at the first EOS and cannot assign credit to tool results. The full-interaction episode keeps tool outputs inside the trajectory so later tokens can condition on them and rewards can reflect the whole attempt.
4.Where does the discount factor go in the single-turn objective, and why?Answer
It is set to . There is one response-level reward rather than a stream of per-step rewards, so there is no horizon to discount over. A in the token view would discount the outcome by completion length and favor shorter answers.
You're done when
You can draw the boundary for a new task (states, actions, episode end) and expand its trajectory probability without notes.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 6 more in the section
- RLHF Book - Introduction, Training Overview and Instruction TuningNathan Lambert · primary
Study Chapter 1 (introduction), Chapter 3 (training overview: problem formulation and canonical recipes), Chapter 4 (instruction tuning: chat templates and implementation details) and Appendix A (definitions) at https://rlhfbook.com/c/. Map every RLHF component into the track trajectory schema, then implement assistant-only sequence log probabilities and completion masks against hand examples.
- RLHF Book Course - Lectures 0 and 1Nathan Lambert · required
Watch Lecture 0 (the ML foundations of post-training, including KL) and Lecture 1 (overview of Chapters 1 to 3), with slides under https://rlhfbook.com/teach/course/. Produce a component and state-ownership diagram tied to executable tests, not a second set of general notes.
- Berkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - LLM RLUC Berkeley · support
Slides are public at https://rail.eecs.berkeley.edu/deeprlcourse/static/slides/lec-N.pdf; current videos are not, and the public Fall 2023 playlist numbers lectures differently. Study Lecture 14 (LLM RL) for the language-model-as-policy formulation and how it maps onto the policy-gradient lectures.
- Hands-on Modern RL - Chapter 13 RLHF PipelineWalking Labs · support
Use the base-model-to-assistant page and the PPO-RLHF loop page for the pipeline and the token-level ratio, clip and KL order of operations. Its KL sketch is the simple log-ratio difference; audit masks and log probabilities independently and defer scale engineering to RL-12. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its
code/chapterNNfolders do not follow the site chapter numbers.
Also in this section
- Training Language Models to Follow Instructions with Human FeedbackOpenAI · required
Study the demonstration, comparison, reward-model and PPO pipeline plus evaluation design. Reconstruct the data and policy dependencies and state which results cannot be inferred from the paper at small scale.
- KL Estimators - Schulman's Note and the RLHF Book CodeJohn Schulman; Nathan Lambert · required
Read John Schulman's note "Approximating KL Divergence" (on joschu.net, linked from the code) for the three Monte Carlo estimators , , and their bias and variance, then the
approx_kl1,approx_kl2andapprox_kl3functions in this file at commit 1042143. Compute all three on sampled tokens from two small policies whose exact KL you know, and say which one each library you use reports. - Build a Reasoning Model (From Scratch) - Chapters 2 to 5Sebastian Raschka (Manning) · support
Use Chapter 2 (loading Qwen3 0.6B and a minimal generation function), Chapter 4 (temperature, top-p and self-consistency) and Chapter 5 (token probabilities to log probabilities and sequence scores) as a code companion for log-probability, mask and inference-policy oracles. Chapters 2 to 5 run on a CPU.
- Stanford CS224R 2026 LLM RL Default ProjectStanford University · support
Read Sections 1.1 through 1.4 for the Countdown task, distinct SFT, preference and verifier datasets, objective boundaries and evaluation. Use it as a design specification and write independent code; do not submit, copy or publish Stanford course solutions.
- LLM Post-Training Laboratory - Baseline and State ContractRoadmap-Final · required
Build or reuse the laboratory frozen base, SFT and evaluation baseline plus immutable tokenizer, template, model, policy and rollout manifests. Complete fixed log-probability, mask and state-identity tests only in this stage.
- TRL GRPO Trainer - KL estimation and lossHugging Face · reference
Read Estimating the KL divergence for the k3 formula with the reference-over-policy ratio, and the default KL-coefficient note. Use it as the correct-ratio reference beside the RLHF Book code estimators.