Skip to main content
>_ supraj.dev
TOPIC AI
Fine-Tuning specializing a base model on your domain data
IN 10 SECONDS

Fine-tuning takes a pre-trained LLM and trains it further on a smaller, domain-specific dataset. Unlike RAG (which retrieves context at inference), fine-tuning embeds knowledge into the model's weights — it learns the style, terminology, and patterns of your data. The result: better performance on your specific tasks without needing to prompt with context every time.

GOTCHA Fine-tuning doesn't add new factual knowledge — it teaches the model format, tone, and patterns. If your goal is to answer questions about internal docs, use RAG, not fine-tuning. Fine-tuning is for output style, not factual recall.
HOW FINE-TUNING WORKS
01 Base model a general-purpose model (e.g., Llama 3, GPT-4o) is the starting point.
02 Training data hundreds to thousands of examples in a consistent format — `{"messages": [{"role": "user", "content": "..."}, {"role": "assistant", "content": "..."}]}`.
03 Training loop the model processes batches, computes loss (how wrong its predictions are), and updates weights via backpropagation.
04 LoRA/QLoRA parameter-efficient techniques that train small adapter matrices instead of all weights — much faster and cheaper while retaining most of the quality gain.
05 Deployment the fine-tuned model (or adapter) is deployed alongside the base model for inference.
POKE IT YOURSELF
ollama create my-model -f Modelfile — create a custom model from a base + template
python -c "from transformers import Trainer; ..." — HuggingFace transforminer training script