DS DevShelfHub Projects · AI tools
Tutorials / Fine-tuning / Pre-training vs Fine-tuning
Fine-tuning Intermediate · 10 min read Page 2 of 10

How LLMs Learn: Pre-training vs Fine-tuning

Understand the difference between pre-training (learning language) and fine-tuning (learning tasks). Explore SFT, RLHF, and DPO.

By DevShelfHub

Series progress 2 / 10
Fine-tuning pretraining vs finetuning tutorial — How LLMs Learn: Pre-training vs Fine-tuning

What pre-training does

Pre-training is the unsupervised learning phase where a model learns language from massive text corpora. The objective is simple: predict the next token given previous tokens. By training on hundreds of billions of tokens, models absorb:

  • Grammar and syntax — How language is structured
  • Factual knowledge — Names, dates, places, concepts
  • Reasoning patterns — How to solve problems step-by-step
  • Semantic relationships — How concepts connect

Pre-training is compute-intensive (months of training on thousands of GPUs) and produces a generalist model. The model works on many tasks, but not optimally on any specific one.

What fine-tuning adds

Fine-tuning adapts a pre-trained model to behave in a specific way for a specific task. Instead of learning language from scratch, you start with a model that already understands language and specialize it. Fine-tuning:

  • Modifies "personality" — Changes how the model responds
  • Teaches task-specific behavior — "Always respond in JSON" or "Write like a lawyer"
  • Adds domain expertise — Specialized language and patterns
  • Is fast and cheap — Hours on a single GPU, not months on thousands

Transfer learning analogy

🎓

Pre-training = University degree

Broad foundation in many subjects. General knowledge and critical thinking skills. Takes years.

🎯

Fine-tuning = Job-specific training

Specialized skills for your role. Builds on your degree. Takes weeks.

Types of fine-tuning

1. Supervised Fine-tuning (SFT)

Train on (instruction, response) pairs. The model learns to follow instructions and produce correct outputs. Most common method. Example: train on 500 customer support (question, answer) pairs.

2. Instruction Tuning

Special case of SFT with diverse instructions covering many tasks. Creates a more versatile model. Example: fine-tune on 10,000 instructions spanning writing, coding, analysis.

3. RLHF (Reinforcement Learning from Human Feedback)

Train a reward model on human preference comparisons (A vs B), then use RL to optimize for high-reward outputs. More complex, requires preference data. Produces aligned, safe models.

4. DPO (Direct Preference Optimization)

Simpler alternative to RLHF. Train directly on preference pairs without a separate reward model. Easier to implement, often same or better results than RLHF.

Comparison table

Method Compute Data Needed Use Case
Pre-training Massive (months, 1000s of GPUs) Billions of tokens (public internet) General-purpose language understanding
SFT Moderate (hours, 1 GPU) 100–10,000 examples Task-specific behavior
RLHF High (days, multiple GPUs) Preference comparisons (A vs B) Alignment, safety, user preference
DPO Moderate (hours, 1–2 GPUs) Preference pairs Alignment without reward model

Key takeaway

Pre-training teaches language, fine-tuning teaches tasks. You don't need to (and shouldn't) pre-train from scratch. Start with a pre-trained model and fine-tune it with your task-specific data.

Practical implications for developers

Understanding the pre-training and fine-tuning distinction matters for cost planning. Pre-training Llama 3.1 405B cost Meta an estimated $30 million in compute. Fine-tuning the 8B variant with LoRA on 500 examples costs under $1 on a cloud GPU. The two processes differ by five orders of magnitude in expense, yet fine-tuning captures the majority of the value for production applications because the pre-trained model already encodes language understanding.

When choosing a fine-tuning method, most teams should start with supervised fine-tuning (SFT) because it is the simplest and most predictable. DPO is worth exploring once you have preference data — pairs of outputs where one is clearly better than the other. RLHF remains the gold standard for alignment work at frontier labs, but its complexity (training a separate reward model, stabilizing RL training) makes it impractical for most production teams. If your goal is collecting training data from the web, our Firecrawl tutorial series shows how to extract clean, structured text from any website for use in training pipelines.

Pre-training vs Fine-tuning FAQ

What is pre-training in LLMs?

Pre-training is the initial phase where a model learns language patterns from massive text datasets. It learns grammar, facts, and reasoning by predicting the next token across billions of words.

What is supervised fine-tuning (SFT)?

SFT trains a pre-trained model on labeled input-output pairs for a specific task. You provide examples of desired behavior and the model learns to replicate that pattern.

What is RLHF and how does it work?

Reinforcement Learning from Human Feedback trains a reward model from human preferences, then uses it to guide the language model toward more helpful and safe responses.

What is DPO and how is it different from RLHF?

Direct Preference Optimization skips the separate reward model and directly optimizes the language model using preference pairs. It is simpler to implement and often produces comparable results.

Do I need to pre-train my own model?

Almost never. Pre-training requires millions of dollars in compute. Use an existing pre-trained model like Llama, Mistral, or GPT and fine-tune it for your task instead.

Continue learning with our when to fine-tune guide and fine-tuning introduction.