Unit 2 of 10 · about 3 hours · explain
Bandit, token-MDP and environment-MDP formulations and hidden state
The optimizer you can use follows from the formulation. Bandit methods cannot do token credit assignment, and token methods cannot see hidden state.
You'll be able to
- Contrast the contextual-bandit, token-MDP and environment-MDP formulations of one language task, naming what each treats as state, action and reward.
- State where the token-MDP view helps (intermediate rewards, value baselines) and where it breaks (hidden user, evaluator and environment state).
- Explain why single-turn RLHF is usually cast as a bandit problem and what must change for multi-turn tool tasks.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Bandit framing of single-turn RLHFRLHF Book - Introduction, Training Overview and Instruction Tuning
Manipulating the Standard RL Setup, point 2 (no state transitions) and point 3 (single-step bandit structure with ), with Table 1
- Classical RL versus RLHF versus RLVRRLHF Book Course - Lectures 0 and 1
Slides 32 and 55 of 70: Classical RL vs. RLHF (response-level bandit-style reward, KL penalty) and the Classical/RLHF/RLVR comparison table (transitions, granularity, challenge)
- POMDP view and partial observabilityBerkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - LLM RL
Slide 14 of 51 (Language models like POMDP solvers) and slides 41 and 42 of 51 (Part 5 bonus: Beyond MDPs with non-Markov observations, then information-gathering actions under Partially observed MDPs can be weird)
Focus on
- Bandit: state is the prompt, action is the whole completion, reward is response-level. Token-MDP: state is prompt plus prefix, action is the next token. Environment-MDP adds tool or user turns as transitions.
- The token view pays off exactly when there are intermediate rewards or value baselines; with a single terminal reward it collapses back to the bandit objective.
- Token strings are fully observed but the task state is not: user intent, evaluator criteria and tool side effects stay hidden, so the problem is partially observed even with a perfect context window.
Common mistakes · 3
- Reading fully observed token context as a fully observed state. The context is observed; the intent behind the prompt and the grader's rubric are not.
- Treating as a theorem. It is the convention for response-level rewards; per-step KL penalties and multi-turn rewards can need discounting again.
- Carrying the no-transitions claim into tool tasks. Once tool outputs condition later tokens, transitions exist and the bandit analysis no longer applies.
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.Why does the token-MDP view add nothing over the bandit view when the reward is a single terminal score and there is no critic?Answer
With and one terminal reward, every token shares the same return, so per-token advantages are all equal to the response-level advantage. The gradient matches the bandit gradient.
2.Name one hidden state in a code-repair task with a test-suite verifier.Answer
The contents of the hidden tests. The policy sees the prompt and its own code but not the tests the verifier will run, so identical contexts can have different true rewards.
3.A chat task scores only the final answer after three user turns. Which formulation fits, and why not the bandit?Answer
The environment-MDP (or multi-turn token-MDP). Later prompts depend on earlier answers through the user, so transitions exist and early turns need credit for steering the conversation.
You're done when
You can defend bandit versus token versus environment framing for a new task, including what is hidden and which methods the framing rules out.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 7 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.
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.
- 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. - 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.