Key points
A raw base model is essentially a "wild next-token continuation engine" — knowledgeable but unaligned. Turning it into a useful, safe, low-latency assistant requires six lifecycle stages, followed by parameter-efficient fine-tuning (PEFT) when compute is limited.
Part 1: Full LLM Lifecycle
1. Base Model Selection
Choose by VRAM budget, roughlyM_VRAM ≈ 2×Φ GB for FP16 weights plus 0.5×Φ GB KV-cache headroom (Φ = parameter count in billions).
- Edge / ≤8GB VRAM: Qwen2.5-1.5B/3B, MiniCPM-3
- Enterprise / 16–48GB: Qwen2.5-7B/14B, Llama-3.1-8B
- Complex reasoning / agent orchestration: DeepSeek-V3, DeepSeek-R1, Qwen2.5-72B
- Continual pretraining data mix: 70–85% domain data + 15–30% general corpora to avoid catastrophic forgetting of general knowledge.
- Follow the LIMA principle: ~1,000 curated high-quality multi-turn dialogues beat 100,000 noisy ones for SFT.
- Apply loss masking: gradients backpropagate only on assistant response tokens, never on user prompts.
- Objective benchmarks: MMLU-Pro (knowledge), GSM8K/MATH (reasoning), SWE-bench (coding)
- LLM-as-judge blind tests: Arena-Hard-Auto, MT-Bench
- Industrial safety suite: private gold sets for hallucination rate, JSON format compliance, prompt-injection defense
- Cloud, high concurrency: vLLM or SGLang — PagedAttention fragments-free KV-cache management plus continuous batching for multi-fold throughput gains.
- Private / edge: llama.cpp or LocalAI — pure C++, GGUF memory mapping, zero Python dependency.
2. Continual Pretraining & SFT
3. Preference Alignment
Evolution of alignment techniques:1. RLHF (PPO): four models in memory simultaneously; fragile and hard to tune. 2. DPO: closed-form solution that removes the reward model and RL entirely — the modern de facto standard. 3. RLAIF / Constitutional AI: replace human labeling with frontier-model scoring, cutting costs by ~99%.
DPO loss, where y_w is the preferred and y_l the rejected response:
4. Evaluation (three dimensions)
5. Deployment
Part 2: Parameter-Efficient Fine-Tuning (PEFT)
Freeze 99%+ of backbone weights and tune only ~0.1% of parameters.
LoRA
Task adaptation updates have very low intrinsic rank. FreezeW_0 and add a low-rank side branch:At deployment, merge weights (W_final = W_0 + (α/r)BA) for zero inference latency overhead.
QLoRA — tuning a 70B model on one consumer GPU
Three pillars: 1. NF4 (NormalFloat4): information-theoretically optimal 4-bit quantization for normally distributed weights 2. Double quantization: quantize the quantization constants too, saving ~0.37 bits/parameter 3. Paged optimizer: spills optimizer state to CPU memory on VRAM spikes, preventing OOMForward pass: 4-bit weights → dequantize on the fly to BF16 → matmul → gradients flow to 16-bit LoRA adapters.
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.
Decision Matrix
| Scenario | Recommended route | Rationale | | :--- | :--- | :--- | | Vertical domain brain (finance/medical/legal) | Continual pretraining (with replay) → SFT → DPO | Reshape domain vocabulary, avoid forgetting | | Tune 70B on a single RTX 4090 (24GB) | QLoRA (NF4 + double quant, r=16) | Extreme VRAM compression | | High-concurrency online serving | LoRA fine-tune → merge weights → vLLM | Flexibility + maximum throughput | | Offline private deployment | LoRA merge → GGUF quantization → llama.cpp / LocalAI | Single binary, no Python dependency |
References
1. LoRA: Hu et al., *LoRA: Low-Rank Adaptation of Large Language Models*, ICLR 2022 — arXiv:2106.09685 2. QLoRA: Dettmers et al., *QLoRA: Efficient Finetuning of Quantized LLMs*, NeurIPS 2023 — arXiv:2305.14314 3. DPO: Rafailov et al., *Direct Preference Optimization: Your Language Model is Secretly a Reward Model*, NeurIPS 2023 — arXiv:2305.18290 4. vLLM: Kwon et al., *Efficient Memory Management for Large Language Model Serving with PagedAttention*, SOSP 2023 — arXiv:2309.06180