Fine-tuning is the correct solution for format adherence and style injection, but it is almost always the wrong solution for teaching a model new facts. For facts, use RAG; for behavior, use fine-tuning.
Full fine-tuning (updating all weights) is prohibitively expensive for most teams. LoRA (Low-Rank Adaptation) and its quantized sibling QLoRA are the production standards. They freeze the base model and train small adapter matrices (A and B) that are injected into the attention layers.
| Technique | VRAM (7B model) | Accuracy Impact | Training Time |
|---|---|---|---|
| Full Fine-Tuning | >160 GB | Baseline | Slow |
| LoRA | ~24-28 GB | Negligible | Fast |
| QLoRA (4-bit) | ~12-16 GB | 1-2% drop | Moderate |
For a Llama 3.1 8B or Mistral 7B model on a single 24GB A10G or 3090/4090:
# Reference config for Hugging Face PEFT/TRL
config = LoraConfig(
r=16, # Rank: Higher = more capacity, but higher VRAM
lora_alpha=32, # Scaling factor: typically 2 * r
target_modules=[ # Target ALL linear layers for best results
"q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj"
],
lora_dropout=0.05,
bias="none",
task_type="CAUSAL_LM"
)
Fine-tuning is extremely sensitive to data quality. 500 high-quality, human-curated examples will outperform 50,000 synthetic examples every time.
Never trust training loss. A model can have zero training loss but fail in production because it simply memorized the dataset (overfitting).
Do not merge the LoRA weights into the base model if you have multiple tasks. Serve the base model with vLLM or LoRAX, which allow you to swap adapters dynamically at request time with negligible latency overhead.