Fine-Tuning Guide Cheat Sheet

LLM fine-tuning practical guide — LoRA, QLoRA, dataset preparation, hyperparameter selection, validation strategies, and when fine-tuning beats prompt engineering.

Last Updated: May 1, 2025

When to Fine-Tune vs Prompt

ScenarioFine-TunePrompt/RAGWhy
Domain-specific terminologyYesMaybeModel doesn't know your jargon
Consistent output formatYesPartialFine-tuning guarantees format better
Tone/style matchingYesPartialCan learn from 50+ examples
Factual knowledgeNoYes (RAG)Fine-tuning doesn't add facts well
Simple task, clear instructionsNoYesPrompt engineering sufficient
Cost at scaleYesDependsFine-tuned small model < API costs at volume

Dataset Preparation

ItemDescription
Format: JSONL{messages: [{role:'system',content:...},{role:'user',content:...},{role:'assistant',content:...}]}
Minimum examples50-100 for basic tasks, 500+ for complex style/tone, 1000+ for difficult reasoning
Quality over quantity10 high-quality diverse examples > 100 near-identical ones
DiversityCover edge cases, different phrasings, varied complexity — not just happy path
Validation split90/10 train/val. Use val to detect overfitting early.
System messageInclude in training — model learns when/how to follow system instructions

LoRA & QLoRA (PEFT)

ItemDescription
LoRALow-Rank Adaptation — trains small adapter matrices instead of full model. ~1% of parameters.
QLoRAQuantized LoRA — 4-bit base model + LoRA adapters. Fine-tune 70B on single GPU.
Rank (r)8-64 typical. Higher = more capacity, more VRAM. Start at 16.
AlphaUsually 2× rank. Scales LoRA contribution. Alpha=32 with r=16 is common.
Target Modulesq_proj, v_proj (attention). Sometimes k_proj, o_proj, gate_proj, up_proj, down_proj.
Dropout0.05-0.1 — prevents overfitting, especially with small datasets.

Hyperparameters

ItemDescription
Learning Rate1e-4 to 5e-4 for LoRA. Lower (1e-5) for full fine-tuning. Use cosine scheduler.
Batch Size4-16 per GPU. Effective batch = per-GPU × gradient_accumulation_steps × num_GPUs.
Epochs1-5 typically. More epochs = more overfitting. Monitor validation loss.
Warmup Ratio0.03-0.1 — gradually increases LR at start. Prevents early instability.
Weight Decay0.01-0.1 — L2 regularization. Higher for small datasets.
Pro Tip: Fine-tune only when prompt engineering + RAG can't solve the problem. Signs you need fine-tuning: consistent format requirements, domain-specific vocabulary, or when prompt tokens cost more than fine-tuning.