C.W.K.
Stream
Lesson 12 of 12 · published

GRPO and Constitutional AI: Alignment Beyond DPO

~14 min · grpo, constitutional-ai, reasoning

Level 0Token
0 XP0/94 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Two newer alignment recipes deserve attention: GRPO (DeepSeek's reasoning-model recipe) and Constitutional AI (Anthropic's safety recipe).

GRPO (Group Relative Policy Optimization)

Used to train DeepSeek-R1, a reasoning model competitive with OpenAI o1. The key insight: skip the reward model entirely; use rule-based rewards (does the math answer match? does the code pass tests?) and compare each generation against the group mean for the same prompt.

  1. Sample G outputs per prompt (e.g., G=16) from the current policy.
  2. Score each with rule-based rewards (correctness signals).
  3. Compute the advantage: A_i = r_i − (1/G) Σ_j r_j — how much better than the group average.
  4. Update the policy to increase the probability of above-average outputs.

No critic model needed. ~50% memory reduction vs PPO. Works exceptionally well for tasks where you can mechanically check correctness — math, code, structured output.

Constitutional AI (Anthropic)

Used by all Claude models. Replaces most human preference labeling with AI feedback guided by a written set of principles (the "constitution," ~16 in the original paper).

  1. Red-team and self-revise. Generate harmful prompts → have the model respond → ask the model to critique its own response against the constitution → revise. Fine-tune on the revised responses.
  2. RLAIF (RL from AI Feedback). Same as RLHF but the preference labels come from an AI (using the constitution) rather than humans. Scales beyond what human labelers can produce.

The win: alignment scales without proportionally scaling the human labeling effort, and the principles are written and inspectable rather than implicit in opaque human judgments.

Code

GRPO advantage computation·python
def grpo_advantage(rewards):
    # rewards: (G,) — rule-based scores for G generations from same prompt
    mean_r = rewards.mean()
    return rewards - mean_r           # A_i = r_i - group mean
# Then standard policy gradient with these advantages.
# No reward model, no critic, no value head.
Constitutional AI self-critique loop (sketch)·python
def constitutional_revise(model, prompt, constitution):
    response = model(prompt)
    critique_prompt = (
        f"Original prompt: {prompt}\n"
        f"Original response: {response}\n"
        f"Critique this response based on:\n{constitution}"
    )
    critique = model(critique_prompt)
    revise_prompt = (
        f"{critique_prompt}\n"
        f"Critique: {critique}\n"
        f"Now write a revised response addressing the critique."
    )
    return model(revise_prompt)
# Repeat to build a dataset; then SFT or RLAIF on (prompt, revised_response).

External links

Exercise

Read the DeepSeek-R1 paper. Outline GRPO in your own words: what is sampled, what is scored, what is updated. Then compare the procedure to RLHF and DPO in a 3-column table. Where does each save compute? Where does each constrain the kind of task you can train on?

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.