LLMs & GenAI

Pretraining → SFT → RLHF

Mapping the three stage lifecycle of building production Large Language Models from raw pretraining to alignment.

🟡 intermediate5 min readllmmust-know
Building modern production Large Language Models involves three sequential training stages: Pretraining, Supervised Fine Tuning (SFT), and Reinforcement Learning from Human Feedback (RLHF / DPO). Pretraining consumes trillions of web text tokens via next token prediction to build raw world knowledge. SFT fine-tunes base models on high quality instruction prompt-response pairs to learn conversational formatting. RLHF / DPO aligns models with human preferences for helpfulness, honesty, and safety.

The LLM Lifecycle Pipeline

Building a production Large Language Model (like LLaMA 3, ChatGPT, or Claude 3) is not a single training run.

It requires a Three-Stage Training Pipeline:

  TRILLIONS OF RAW WEB TOKENS
              │
              ▼
  ┌─────────────────────────────────────────────────────────────┐
  │ STAGE 1: PRETRAINING (Self-Supervised Causal LM)             │ ──► Produces BASE MODEL
  │ Consumes 99% of total compute budget across 10,000 GPUs.   │     (Raw Autocomplete Generator!)
  └──────────────────────────┬──────────────────────────────────┘
                             │
                             ▼
  HIGH-QUALITY INSTRUCTION PAIRS (10,000 - 100,000 Samples)
                             │
                             ▼
  ┌─────────────────────────────────────────────────────────────┐
  │ STAGE 2: SUPERVISED FINE-TUNING (SFT)                       │ ──► Produces SFT INSTRUCT MODEL
  │ Teaches the model how to act as a conversational assistant. │     (Follows Chat Formats!)
  └──────────────────────────┬──────────────────────────────────┘
                             │
                             ▼
  PREFERENCE PAIRS (Chosen vs Rejected Responses)
                             │
                             ▼
  ┌─────────────────────────────────────────────────────────────┐
  │ STAGE 3: PREFERENCE ALIGNMENT (RLHF / DPO / KTO)            │ ──► Produces FINAL ALIGNED MODEL
  │ Aligns outputs for Helpfulness, Honesty, and Safety (HHH).  │     (Production Ready Assistant!)
  └─────────────────────────────────────────────────────────────┘

Stage 1: Self-Supervised Pretraining

Stage 2: Supervised Fine-Tuning (SFT)

Stage 3: Preference Alignment (RLHF / DPO)

Summary Comparison Matrix

StageData SourceCompute ShareCore Purpose
1. PretrainingTrillions of Raw Web Tokens99% of Total ComputeLearn language, facts, and reasoning
2. SFT10k-100k Instruction Pairs~0.9% of ComputeLearn chat formatting & intent following
3. Alignment (DPO)50k-100k Preference Pairs~0.1% of ComputeEnforce safety, tone, and helpfulness

Say this out loud

Building production LLMs follows a three stage pipeline: Pretraining acquires raw world knowledge by consuming trillions of web text tokens via next token prediction (99% of compute). Supervised Fine Tuning (SFT) fine tunes base models on instruction prompt response pairs to learn chat formatting. Preference Alignment (RLHF/DPO) aligns model outputs for helpfulness, honesty, and safety.

Followups to expect

  1. What is the LIMA Hypothesis (Less Is More for Alignment)? Zhou et al. (2023) proved that 1,000 carefully curated, exceptionally high-quality SFT instruction pairs can match the instruction-following performance of 50,000 noisy samples, proving that pretraining holds all knowledge while SFT merely unlocks formatting.
  2. What is Continuous Pretraining? Continuing Stage 1 pretraining on specialized domain corpora (e.g. 50 Billion medical or legal tokens) before running SFT and DPO.

Check yourself

Question 1 of 3

What are the three sequential training stages used to build modern production conversational LLMs like LLaMA 3 or ChatGPT?

More in LLMs & GenAI

See all →
Fine-Tune vs RAG vs Prompt: Choosing5 minRetrieval-Augmented Generation5 minWhy LLMs Hallucinate5 min