Modern AI & LLMs Guide 5 of 7 · tap to switch
LoRA Fine-Tuning, RLHF & DPO (Post-Training)
How raw internet autocomplete becomes a helpful, aligned assistant via SFT, RLHF/DPO, and verifiable reasoning RL, plus low-cost LoRA adaptation.
Imagine hiring a brilliant scholar who has memorized every book, textbook, and website in a national library. Sounds unbeatable, right? Yet the very first time you ask “Explain gravity to a 10-year-old”, they do not answer you. Instead, they start reciting “2. Explain magnetism to a 10-year-old. 3. Explain friction…” because their only habit is autocompleting whatever words usually come next on a printed page!
Turning a raw library-memorizer into a helpful conversation partner takes three stages:
- Reading the whole library (Pretraining): The model reads trillions of words just trying to guess the next word. This uses roughly 98% of the total training compute and builds raw world knowledge, yet leaves the model acting like internet autocomplete.
- Q&A coaching (Supervised Fine-Tuning, or SFT): Coaches show the model tens of thousands of clean “User asks -> Helpful answer” examples so it learns how to hold a conversation and follow instructions.
- Taste, safety, and reasoning practice (Alignment via RLHF, DPO, or Reasoning RL): Even after Q&A coaching, answers can sound stiff, wordy, or careless. This final polish teaches warmth, honesty, and careful step-by-step problem solving.
Together, Stages 2 and 3 are called Post-Training: they take only about 2% of the total compute, yet completely transform how the model behaves. Start at Stage 1 below (the broken autocomplete state) and click Next Stage to watch the exact same prompt transform into a warm, crystal-clear answer!
Adapting giants on one GPU: LoRA (Low-Rank Adaptation)
Suppose you want to adapt a massive 70-billion-parameter open model so it matches your company’s legal tone or strict output format. Rewriting every single number inside a model that huge requires an enormous cluster of server GPUs, because the computer has to keep the entire giant network active and track edits to every single weight at once.
In 2021, researchers (Hu et al.) found a clever sticky-note shortcut called LoRA (Low-Rank Adaptation). Picture the pretrained model as a huge printed encyclopedia that you lock shut so you never have to reprint it. Instead of rewriting a gigantic 16.78-million-entry grid (4,096 × 4,096 frozen base weights W₀), you leave the original book frozen and attach two skinny trainable helper strips (B and A) on the side!
The thickness of those two strips is called the rank (r): a thinner strip learns a light style nudge, while a wider strip gives the model more room to learn deeper new habits. Because two skinny strips contain far fewer numbers than a full square grid, LoRA shrinks the number of trainable weights by 99% or more.
Even better: once training finishes, multiplying the two skinny strips produces a correction grid with the exact same 4,096 × 4,096 shape as the original frozen grid. You simply add that correction straight into the original grid once before going live, giving you 0 ms extra delay when serving users!
Try switching the strip width below from Thin (r=4) to Wide (r=64), then click Merge Adapter Into Base to see why merged LoRA runs with zero slowdown!
Pair LoRA with QLoRA (Dettmers et al., 2023), which shrinks the frozen base weights into compact 4-bit numbers so they take a quarter of the usual memory, and a single everyday workstation GPU can adapt massive open models overnight!
Alignment & reasoning: RLHF (PPO) vs. DPO vs. Reasoning RL (GRPO)
Once Q&A coaching teaches a model how to answer questions, how do AI teams teach it which answer humans actually prefer, or teach modern reasoning models (o1, DeepSeek-R1, Gemini Thinking) to double-check their own math and code before replying? Three main Stage-3 coaching methods evolved between 2022 and today:
- Human-Judge Coach (RLHF / PPO): Human reviewers rank pairs of replies so a separate Judge model (Reward Model) can learn what people like. The AI then practices answering while the Judge scores each attempt, nudging the AI toward higher scores without drifting off the rails.
- Direct Pair Nudge (DPO, Direct Preference Optimization): Skip the separate Judge model completely! Show the AI a Good Reply next to a Bad Reply for the same prompt and directly nudge the Good Reply’s odds up and the Bad Reply’s odds down.
- Auto-Graded Test Practice (Reasoning RL / GRPO): For math or coding problems with a clear right or wrong answer, let the AI try several step-by-step paths, grade each one automatically with a math checker or code unit test, and reinforce the thinking paths that pass!
Click through all three coaching setups below to compare the real prompt example, how many models sit in GPU memory, and when teams pick each approach!
The #1 engineering trap: Prompting vs. RAG vs. Fine-Tuning
Before spinning up a single GPU fine-tuning job, ask one simple question: do you want to change what the model KNOWS (fresh facts), or HOW the model acts (behavior, format, or speed)?
Most teams reach for fine-tuning way too early, when a simpler tool on the ladder works faster and better:
- Prompting: Write clearer instructions and 3 to 5 crisp examples directly inside your request (takes minutes and costs $0 to train).
- Open-Book Search (RAG, Retrieval-Augmented Generation): Look up your company’s latest documents right before the model answers, handing it the exact relevant paragraphs so it can quote fresh facts with source links without retraining weights.
- LoRA Fine-Tuning: Adjust the model’s weights to bake in a consistent brand voice, strict output format, or compact fast model behavior.
Click the four real-world situations below to watch the winning rung of the ladder light up every time!
See LoRA Decomposition, RLHF KL-Regularized Objective & DPO LossThesis / Reference
1. Low-Rank Adaptation (Hu et al., 2021): For a frozen pretrained weight matrix and chosen rank , LoRA parameterizes the weight delta as with (initialized to zero) and (Gaussian init), scaled by :
Starting guarantees at step 0, preserving base capabilities cleanly.
2. KL-Regularized RLHF vs. Direct Preference Optimization (Rafailov et al., 2023): Standard RLHF maximizes expected reward while constraining policy not to drift far from reference SFT model via KL divergence penalty . DPO eliminates the explicit reward model via a closed-form change of variables over preferred () vs. rejected () completions:
3. Verifiable Reasoning RL (GRPO, Shao et al., 2024): Group Relative Policy Optimization drops the critic network too, sampling rollouts per prompt, grading each with deterministic verifiers (), and computing normalized group advantages to reinforce winning chain-of-thought strategies!
See Clean LoRA Setup Using Hugging Face PEFT in PythonOptional Code
from peft import LoraConfig, get_peft_model
# Attach lightweight r=16 LoRA adapters to Attention Q/K/V/O projections
lora_cfg = LoraConfig(
r=16,
lora_alpha=32,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
lora_dropout=0.05,
task_type="CAUSAL_LM",
)
model = get_peft_model(base_model, lora_cfg)
model.print_trainable_parameters() # typically ~0.2% to 0.8% trainable!
# After training finishes, merge B*A directly into W0 for 0 ms latency overhead:
merged_model = model.merge_and_unload()Giving an aligned LLM live knowledge and real-world hands!
Even after Pretraining, SFT, LoRA, and RLHF, a standalone LLM stays trapped inside a soundproof glass box: it cannot read your company’s new Q4 PDFs, query your Postgres database, or check today’s live weather!
Before we wire up full retrieval pipelines in RAG & AI Agents, fly inside the 3D engine that makes semantic retrieval over millions of embeddings instantaneous: Vector Databases & HNSW.
Quick Intuition Check
Four quick real-world scenarios. No scores, just test your intuition.
Why does a raw Pretrained Base Model often fail to act like a helpful assistant until Supervised Fine-Tuning (SFT) and Alignment (RLHF / DPO) are applied?
How does LoRA adapt a giant model cheaply while adding ZERO extra waiting time once deployed?
Your startup's internal HR policies and pricing tables change every week, and your chatbot must quote exact current rules with source links. Should you fine-tune or use Open-Book Search (RAG)?
Direct Preference Optimization (DPO) teaches a model human preferences without training a separate Judge (Reward) model.
Common Questions
What is the difference between Pretraining, SFT, and RLHF?
How does LoRA (Low-Rank Adaptation) fine-tune huge LLMs so cheaply?
What is QLoRA?
What is the difference between RLHF (PPO) and DPO?
Should I fine-tune an LLM or use RAG for my company's private documents?
Related Visual Guides
Vector Spaces, Span & Basis
See how two basis arrows tile an entire 2D plane, watch dependent columns collapse into a 1D rail, and rotate rulers like PCA.
Vector Databases & HNSW
Fly inside a 3D multi-layer HNSW skip graph to see how vector databases search millions of embeddings in milliseconds, compare IVF vs. HNSW, and shrink RAM 32x with Product Quantization.
RAG & AI Agents
Give LLMs an open-book library with Retrieval-Augmented Generation (RAG) and real-world hands with ReAct tool-calling AI Agents.
Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference
Cite this guide in a paper, thesis, or course (BibTeX & APA)
@misc{irshad2026finetuninglorarlhf,
author = {Irshad, Muhammad Aashir},
title = {LoRA Fine-Tuning, RLHF & DPO (Post-Training): Interactive Visual Guide},
howpublished = {SeeingML},
year = {2026},
month = {dec},
url = {https://seeingml.com/learn/fine-tuning-lora-rlhf/},
note = {Interactive visual guide}
} Irshad, M. A. (2026). LoRA Fine-Tuning, RLHF & DPO (Post-Training): Interactive Visual Guide. SeeingML. https://seeingml.com/learn/fine-tuning-lora-rlhf/