Module 14. Learning from Feedback: RLHF, DPO, RLOO, and GRPO
Try each exercise first. Expand worked answers or project guidance when needed; their open state is shared between RU/EN.
Download course files (.zip) 2588.1 KBThe archive preserves the source folder structure, both languages, and supporting files.
E1. Bradley–Terry and DPO by hand
Compute for and recover the logit associated with a 75% win rate. Then evaluate two DPO pairs at . The policy sequence log probabilities are for both pairs. The reference values are for pair I and for pair II. The preferred completion is listed first.
Show answer and solution
Solution. The sigmoid values are 0.622459, 0.731059, 0.880797, and 0.982014. The inverse logit is .
For pair I, policy chosen-minus-rejected margin is and reference margin is . Their difference is 1.7, so and . For pair II, reference margin is ; the margin gap is 0.65, giving and .
The derivative sign matters: , so the values are −0.457602 and −0.483756. At , pair I has , loss 0.355865, and . The full parameter gradient also contains and log-probability derivatives.
E2. GRPO group and persistent-state memory
For rewards [1,0,0,1,0,0,1,0], compute population-standardized advantages and the probability of a degenerate group of size 8 when the independent success probability is 0.3. Then compare the teaching PPO and DPO memory models for 8.03B parameters using 16 bytes per trainable parameter and 2 bytes per frozen bf16 parameter.
Show answer and solution
Solution. Three of eight rewards equal one, so and population standard deviation is . Standardization gives 1.290994 to successes and −0.774597 to failures; advantages sum to zero. A group is degenerate if all samples succeed or all fail: .
For 8.03B parameters, trainable state is GiB and a frozen bf16 copy is GiB. The teaching PPO anatomy has two trainable networks (policy and value) plus two frozen ones (reference and reward), giving GiB. DPO has one trainable policy plus one frozen reference, giving 134.613 GiB. These are persistent-state floors without activations or rollout buffers.
E3. Rollout economics
Generate 8 completions of 4,000 tokens for each of 256 prompts. Estimate generation time on eight accelerators at 209.4 tokens/s each. Compare it with a training estimate for an 8.03B model at 990 TFLOP/s per accelerator and 40% MFU.
Show answer and solution
Solution. Rollout volume is tokens. Eight devices provide aggregate rate tok/s, so generation takes s = 81.50 minutes.
Training arithmetic is
Effective throughput is FLOP/s, hence 124.6 s = 2.076 minutes. The ratio is 39.25: autoregressive rollout, not one training pass, dominates this scenario. It is not a universal RLVR constant.
E4 [project]
Compare run_dpo at and using the same pairs and 140 updates. Begin with the default zero initialization, which makes both runs deterministic. Then set init_std=0.02 and repeat the comparison for seeds 41, 42 and 43. Within each seed, both values must start from identical weights and an identical reference copied from those weights.
Record initial and final loss, training-pair ordering accuracy, held-out correct-answer probability and reference KL. Explain why losses measured at different values are not a direct scale of answer quality, and why correct training-pair ordering does not establish generation quality. As an optional extension, use an open 0.5–3B model with pinned templates and masks, then inspect response lengths and 50 generated answers.
Project demos and guidance
Demo for this project exercise: English project-demo notebook for Module 14, section “Demo 1”. It shows a compact reproducible example on small inputs, not a completed solution to the full-scale project.
E5 [project]
Implement a GRPO-like loop for a binary-verifier task. Compare skipping, zeroing, and resampling equal-reward groups. Measure rollout cost, zero-variance rate, and sensitivity to the number of completions .
Project demos and guidance
Demo for this project exercise: English project-demo notebook for Module 14, section “Demo 2”. It shows a compact reproducible example on small inputs, not a completed solution to the full-scale project.