← Back to articles Blog

How to Train an LLM: From Pre-Training to Fine-Tuning and Alignment

Emmanuel Ekunsumi · 6 min read · 2026-07-22

Training an LLM from scratch is a multi-stage process that costs tens of millions of dollars and requires clusters of thousands of GPUs. Most developers never need to do it. But understanding how training works helps you make better decisions about when to fine-tune, which alignment techniques to use, and why models behave the way they do.

The three stages of LLM training

Stage 1 — Pre-training

The base model is trained on a massive corpus of text (typically 1-15 trillion tokens) to predict the next token in a sequence. This is where the model learns language, facts, reasoning patterns, and world knowledge.

Stage 2 — Supervised Fine-Tuning (SFT)

The pre-trained base model is fine-tuned on a curated dataset of instruction-response pairs to teach it to be a helpful assistant. This is where the model learns to follow instructions, format responses, and behave appropriately.

Stage 3 — Alignment (RLHF or DPO)

The SFT model is aligned with human preferences to make it helpful, honest, and safe. This is where RLHF or DPO comes in — training the model to produce responses humans rate as better over ones they rate as worse.

What most teams actually do: fine-tuning not pre-training

Starting from scratch is almost never the right choice. Pre-training requires resources only frontier labs have. Most teams start from an existing pre-trained base model and apply:

from peft import get_peft_model, LoraConfig
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-8B")
config = LoraConfig(r=8, lora_alpha=32, target_modules=["q_proj", "v_proj"])
model = get_peft_model(model, config)
# Now train normally on your dataset

When you actually need to train vs when you don't

GoalRecommended approach
Domain knowledge / Q&ARAG — no training needed
Custom output format/styleSFT with LoRA
Reduce system prompt sizeSFT — bake behavior into weights
Safety/alignment adjustmentsDPO on preference data
New language or domainContinued pre-training + SFT
Frontier capabilityNot feasible — use cloud API

The cost of fine-tuning in 2026

LoRA fine-tuning has become remarkably accessible:

The hidden cost is data preparation — high-quality instruction pairs take significant time to create or curate. Budget 10-50 hours of human effort per 1,000 high-quality examples.

Track your fine-tuned model's inference costs

Tokoscope works with any fine-tuned model via OpenAI-compatible endpoints. See whether training actually improved cost-efficiency. Free to start.

Get started free →