A ai coolAId
Chapter 5 of 7

LLM Post-Training (RLHF, RLVR & GRPO)

How Transformers connect to Monte Carlo rollouts, why RLVR scales reasoning without human raters, and how GRPO removes the Critic network.

Mental Model

Pretraining teaches a Transformer how language and code work (flashcards). SFT shows it how to answer cleanly (worked examples). Post-Training RL runs Monte Carlo rollouts of whole answers and reinforces the token paths that actually win.

1. Transformers + Monte Carlo = LLM RL

If you map LLM generation onto standard RL vocabulary from Chapters 3 and 4, everything clicks into place:

RL Concept What It Is in an LLM
State \(s_t\) The prompt plus all tokens generated so far (prompt, y_1 ... y_{t-1})
Action \(a_t\) Choosing the next token y_t from the vocabulary
Policy \(\pi_\theta\) The Transformer's Softmax distribution over next tokens
Episode / Trajectory One complete generated answer from token 1 to <EOS> (Monte Carlo Rollout)
Reward \(R(x, y)\) Scalar score assigned once the answer finishes (human judge, reward model, or unit tests)

Once you sample \(N\) rollouts for a prompt with temperature \(T > 0\) and grade each completed answer, you reinforce the token paths that led to above-average outcomes:

\[\Delta\theta \propto \sum_{t=1}^{T} \nabla_\theta \log \pi_\theta(y_t \mid x, y_{<t})\, A_{\text{rollout}}\]

2. RLHF vs. RLVR (Why Verifiable Rewards Changed Everything)

Early LLM post-training relied on RLHF (Reinforcement Learning from Human Feedback): collect human comparisons ("Answer A is better than Answer B"), train a separate neural Reward Model, and optimize the LLM against it with PPO.

The catch: optimizing too hard against a learned reward model triggers reward hacking—the LLM discovers verbose, sycophantic, or formatted phrasing that flatters the reward model without actually being more accurate.

RLVR (Reinforcement Learning with Verifiable Rewards) replaces subjective reward models with deterministic, programmatic checkers wherever truth is checkable:

  • Coding: Does the patch compile and pass the test suite (pytest, cargo test)?
  • Math & Logic: Does the final symbolic expression simplify to the ground-truth answer?
  • SQL / Tool Use: Does the query execute cleanly and match the expected result set?

Because you cannot sweet-talk a compiler, RLVR lets models train for far longer—and spontaneously discover emergent habits like self-verification, backtracking, and decomposing hard problems.

3. GRPO: Dropping the Critic Network

Running classic PPO on a 70B LLM is expensive in GPU memory: you need the active Policy, a frozen Reference model (for KL penalty), a Reward model, and a 70B Value Critic network.

GRPO (Group Relative Policy Optimization) eliminates the Critic entirely:

  1. For each prompt \(x\), sample a group of \(G\) rollouts (e.g. \(G = 8\) or \(16\)) from the current policy.
  2. Score every rollout with your verifier: \(R_1, \dots, R_G\).
  3. Compute each rollout's advantage relative to its own group: \[A_i = \frac{R_i - \mu_R}{\sigma_R + \varepsilon}\]
  4. Apply a PPO-clipped policy-gradient update plus a KL tether to the reference model.

Rollouts that beat the prompt's group average get reinforced; rollouts below average get suppressed—no separate value network required.

4. Training-Time vs. Inference-Time Compute

The exact same Monte Carlo rollout machinery also works at inference time without changing a single weight:

  • Best-of-N / Rejection Sampling: Sample \(N\) candidate solutions at \(T \approx 0.7\), run unit tests or a verifier on all \(N\), and return the winner.
  • Test-Time Scaling: Let an RLVR-trained model spend more thinking tokens (chain-of-thought) on hard problems while staying fast on easy ones.