M1: Why Fine-Tune M2: Dataset Prep M3: LoRA M4: RLHF M5: Evaluation M6: Deployment Capstone
Intermediate Read time: 17 min Module 4 of 6

Instruction Tuning and RLHF

Before 2022, GPT-style models were impressive at predicting text — but they weren't actually helpful. Ask one to write a poem and it might write a poem, or it might continue writing more instructions on how to write poems. Instruction tuning changed this. RLHF made it reliable. This module explains both.

Module 4 of 6 — Fine-Tuning LLMs

By the end of this module, you will be able to explain the three stages of RLHF, describe what a reward model does, and understand when to use simple instruction tuning versus the full RLHF pipeline.

Stage 1: Supervised Fine-Tuning on Instructions (SFT)

The first step is standard instruction fine-tuning. You take a pre-trained model and fine-tune it on a dataset of (instruction, ideal response) pairs. This teaches the model to answer questions and follow directions rather than just continue text.

The SFT step on its own produces a genuinely useful model. Wei et al. (arXiv:2109.01652) showed that fine-tuning on a diverse set of instructions makes models better at following new, unseen instructions — a property called zero-shot generalization. This is what the FLAN series of models demonstrated.

For many practical applications, SFT alone is enough. You need RLHF when you need the model to learn preferences that are hard to specify with examples: "be helpful but not harmful," "be honest but not blunt," "be concise but complete."

Stage 2: Training a Reward Model

The reward model is a separate neural network trained to predict human preference. You collect data by having human raters compare two model responses to the same prompt and choose which one they prefer. The reward model learns to assign a high score to responses humans prefer and a low score to responses they don't.

RLHF three-stage pipeline Stage 1: SFT instruction pairs Stage 2: RM human preference comparisons Stage 3: PPO RL loop: generate score, update Aligned model directional illustration — Ouyang et al. arXiv:2203.02155
Key concept

The reward model is a proxy for human judgment. Instead of asking a human to rate every response the LLM generates during training (which would be prohibitively slow), you train a model to predict what humans would prefer — then use that model as an automated judge.

Stage 3: Reinforcement Learning from Human Feedback (PPO)

The third stage uses the reward model to fine-tune the LLM via reinforcement learning. The algorithm most commonly used is called PPO (Proximal Policy Optimization). The loop works like this:

  1. Generate a response from the current LLM
  2. Score the response using the reward model
  3. Update the LLM's weights to make higher-scoring responses more likely
  4. Repeat thousands of times

There's a crucial safeguard: a KL divergence penalty prevents the LLM from drifting too far from its SFT starting point. Without this, the model can "game" the reward model by generating responses that get high scores but are incoherent or unhelpful to actual humans — a phenomenon called reward hacking.

Research grounding Ouyang et al. (arXiv:2203.02155) described the full RLHF pipeline used for InstructGPT. They trained 1.3B, 6B, and 175B parameter models using this approach and found that the 1.3B RLHF model was preferred by human raters over the 175B model that had only been fine-tuned on instructions, without RLHF alignment. Alignment quality mattered more than model scale.

DPO: The Simpler Alternative to RLHF

Training a separate reward model and running PPO is complex and unstable. Direct Preference Optimization (DPO, Rafailov et al., arXiv:2305.18290) achieves similar results by reformulating the RLHF objective as a classification problem on preference pairs. The model is trained directly to prefer the chosen response over the rejected one, without ever training a separate reward model.

DPO is faster, more stable, and often matches or exceeds RLHF quality on many tasks. For most teams starting with alignment, DPO is the practical starting point.

RLHF Training Loop Visualizer Interactive

Watch how the reward score evolves as the PPO loop runs. Adjust the KL penalty to see reward hacking in action.

from trl import DPOTrainer, DPOConfig
from transformers import AutoModelForCausalLM, AutoTokenizer
from datasets import Dataset

# DPO is simpler than full RLHF — no separate reward model needed
# Dataset format: each row has prompt, chosen response, rejected response
preference_data = Dataset.from_dict({
    "prompt": [
        "Explain why the sky is blue.",
        "How do I reset my API key?"
    ],
    "chosen": [
        "Light from the sun contains all colors. Shorter blue wavelengths scatter more when they hit air molecules, so we see blue.",
        "Go to Settings > API Keys > Revoke, then click Generate New Key. Copy it immediately — you can't view it again."
    ],
    "rejected": [
        "The sky is blue due to Rayleigh scattering of solar electromagnetic radiation by atmospheric gaseous molecules.",
        "You can reset your API key in the settings section of the application interface."
    ]
})

model = AutoModelForCausalLM.from_pretrained("your-sft-model")
tokenizer = AutoTokenizer.from_pretrained("your-sft-model")
ref_model = AutoModelForCausalLM.from_pretrained("your-sft-model")  # frozen reference

dpo_config = DPOConfig(
    beta=0.1,           # KL penalty — higher = stays closer to reference model
    learning_rate=5e-5,
    num_train_epochs=1,
    per_device_train_batch_size=4,
    output_dir="./dpo-output"
)

trainer = DPOTrainer(
    model=model,
    ref_model=ref_model,
    args=dpo_config,
    train_dataset=preference_data,
    tokenizer=tokenizer,
)
trainer.train()

When Do You Need the Full RLHF Pipeline?

For most teams: you don't. DPO achieves competitive results at far lower complexity. Use the full PPO-based RLHF pipeline only when:

For a custom enterprise model serving a specific domain, SFT followed by DPO is the standard modern approach. It requires fewer compute resources and is easier to debug.

Try this — no setup required Open any AI assistant and give it two nearly identical prompts, one phrased as a question ("What is X?") and one as a command ("Explain X to me."). Notice how the response changes. That change reflects instruction tuning: the model has learned not just the content but the appropriate style for each type of request. Now try a request that seems ambiguous to you. Notice how the model interprets it. That disambiguation is learned preference — the model predicts what most humans would want in response to that phrasing.

Knowledge check

Q1: What problem does the KL divergence penalty solve in the PPO training loop?

A) It prevents the model from learning too fast and forgetting previous knowledge
B) It prevents the model from gaming the reward model by drifting into incoherent responses
C) It reduces the memory needed for PPO training
D) It ensures the reward model scores are calibrated correctly

Q2: A team wants to align a model to prefer concise answers over verbose ones. They have 500 (prompt, concise-answer, verbose-answer) preference pairs. What is the most practical approach?

A) Full RLHF with PPO — this requires online learning
B) DPO — directly train on the preference pairs without a separate reward model
C) Instruction tuning — add "be concise" to the system prompt
D) Pre-training from scratch on a dataset of short responses
Why does the reward model's quality determine the ceiling of RLHF? Think first. +
The LLM is being optimized to maximize the reward model's score. If the reward model has blind spots, the LLM will exploit them. If the reward model consistently scores verbose responses higher than it should, the LLM will become unnecessarily wordy. The LLM becomes as good as the human preferences the reward model learned from — no better. Garbage reward model, garbage alignment.

Before you go

Reflect: If you were collecting preference data for your domain, what would your raters compare? What does "better" mean for your specific use case?

Share this insight
"The reward model is the bottleneck of RLHF. A 1.3B model aligned with excellent human preferences beat a 175B model with no alignment in human evaluations. Alignment quality beats raw scale."

You might also like

Want to discuss alignment approaches for your model?

Book a free 30-min call with Arjun

References

  1. Ouyang, L. et al. (2022). Training language models to follow instructions with human feedback. arXiv:2203.02155.
  2. Rafailov, R. et al. (2023). Direct Preference Optimization: Your Language Model is Secretly a Reward Model. arXiv:2305.18290.
  3. Wei, J. et al. (2022). Finetuned Language Models are Zero-Shot Learners. arXiv:2109.01652.
  4. Christiano, P. et al. (2017). Deep Reinforcement Learning from Human Preferences. NeurIPS 2017. arXiv:1706.03741.
  5. Schulman, J. et al. (2017). Proximal Policy Optimization Algorithms. arXiv:1707.06347.
  6. Rao, A., Jaggi, A., Naidu, S. (2025). MEDFIT-LLM. IEEE RMKMATE 2025. DOI:10.1109/RMKMATE64574.2025.11042816.
← Module 3: LoRA Module 5: Evaluation →
Was this helpful?