The Alchemy of Silicon Minds: From Base Model Selection, DPO Alignment to QLoRA Fine-Tuning
Part 1: The Full LLM Lifecycle
A freshly pretrained base model is essentially a wild continuation engine with vast knowledge but no values or instruction-following ability. Turning it into a reliable assistant requires six stages:
1. Base model selection — under a VRAM budget of roughly M_VRAM ≈ 2×Φ (FP16 weights) + 0.5×Φ (KV-cache) GB, where Φ is parameter count in billions:
- Edge devices (≤ 8GB): Qwen2.5-1.5B/3B, MiniCPM-3
- Enterprise/private cloud (16–48GB): Qwen2.5-7B/14B, Llama-3.1-8B
- Complex reasoning / agent orchestration: DeepSeek-V3 / DeepSeek-R1 / Qwen2.5-72B
- RLHF (PPO): four models in memory simultaneously, fragile and hard to tune
- DPO: closed-form derivation eliminating the reward model and RL — the modern de facto standard
- RLAIF (Constitutional AI): LLM-generated preference labels, ~99% cost reduction
- NF4 (NormalFloat4): information-theoretically optimal 4-bit quantization for normally distributed weights
- Double quantization: quantizing the quantization constants, saving ~0.37 bits/parameter
- Paged optimizer: spills optimizer states to CPU memory on VRAM spikes, preventing OOM
2. Continual pretraining & SFT — data mixing rule of thumb: 70–85% domain data + 15–30% general corpora (to prevent catastrophic forgetting of general ability). For SFT, follow the LIMA principle: ~1,000 high-quality multi-turn dialogues beat 100,000 noisy ones. Loss masking is essential: the loss is backpropagated only over assistant response tokens, never over user prompts.
3. Preference alignment — three generations:
The DPO objective:
L_DPO(θ) = −E_(x,y_w,y_l)[ log σ( β log(π_θ(y_w|x)/π_ref(y_w|x)) − β log(π_θ(y_l|x)/π_ref(y_l|x)) ) ]
where y_w is the preferred response and y_l the rejected one.
4. Evaluation — three dimensions: objective benchmarks (MMLU-Pro, GSM8K/MATH, SWE-bench), LLM-as-judge blind tests (Arena-Hard-Auto, MT-Bench), and private industrial safety suites (hallucination rate, JSON compliance, injection defense).
5. Deployment — vLLM or SGLang with PagedAttention and continuous batching for high-concurrency cloud serving; llama.cpp or LocalAI with GGUF for zero-Python-dependency local/edge inference.
Part 2: Parameter-Efficient Fine-Tuning (PEFT)
PEFT freezes 99%+ of base weights and trains only ~0.1% of parameters.
LoRA (Low-Rank Adaptation)
Task weight updates have low intrinsic rank. LoRA freezes W₀ and adds a parallel low-rank branch:W = W₀ + ΔW = W₀ + (α/r) · B·A, with r ≪ min(d, k)
At deployment, matrices are merged (W_final = W₀ + (α/r)BA), so there is zero inference latency overhead.
QLoRA
Enables fine-tuning a 70B model on a single consumer GPU via three techniques:Adapter
The PEFT ancestor: serial bottleneck layers (down-projection → up-projection with residual) inserted after Attention/FFN blocks. Adds slight serial inference latency, but remains relevant for multi-task routing and hot-swappable plugins.Part 3: Decision Guide
| Scenario | Recommended route | Why | | :--- | :--- | :--- | | Domain brain (finance/medical/legal) | Continual pretraining (with replay) → SFT → DPO | Reshapes domain vocabulary, avoids forgetting | | Fine-tune 70B on a 24GB RTX 4090 | QLoRA (NF4 + double quant, r=16) | Extreme VRAM compression | | High-concurrency online serving | LoRA → merge weights → vLLM | Flexibility + max throughput, zero overhead | | Offline/private deployment | LoRA merge → GGUF → llama.cpp / LocalAI | No Python dependency, single binary |