Fine-tuning used to mean expensive GPU clusters and millions of examples. Today, a well-prepared dataset of a few thousand examples and a single consumer GPU can adapt a small language model (SLM) to your exact task. This is the workflow we use at Code Language Hub to ship production agents.
What counts as a "small" language model?
We use "small" to mean models roughly in the 0.5B–8B parameter range — think Llama 3 8B, Qwen 2.5 7B, Gemma 2, Mistral 7B, or Phi-3. These models are big enough to be genuinely useful, yet small enough to fine-tune with parameter-efficient methods and serve at low cost and low latency, even on-premise.
For most businesses, an SLM specialised to one job — classifying support tickets, extracting fields from invoices, answering questions in a fixed tone — will beat a giant general model on that job while costing a fraction to run.
Step 1 — Decide whether you should fine-tune at all
Fine-tuning is the right tool for teaching behaviour: a consistent format, tone, or task. It is the wrong tool for injecting facts that change — that is what Retrieval-Augmented Generation (RAG) is for.
| Use fine-tuning when… | Use RAG when… |
|---|---|
| You need a consistent style, tone or output format | Your knowledge changes weekly or must be cited |
| The task is narrow and repeatable | You have a large, growing document base |
| You want lower latency / smaller prompts | You need answers traceable to a source |
In practice we often do both: fine-tune the model for behaviour and wrap it in RAG for fresh facts. See our companion article, RAG vs Fine-Tuning: When to Use Which.
Step 2 — Prepare the dataset (this is 80% of the work)
Model quality is downstream of data quality. For instruction-style fine-tuning, format each example as a message triplet — a system instruction, the user input, and the ideal assistant response:
# one example per line (JSONL) {"messages": [ {"role":"system", "content":"You are a support agent for CLH. Reply in 2 sentences."}, {"role":"user", "content":"How long does a website project take?"}, {"role":"assistant", "content":"Most sites take 3–6 weeks depending on scope. We confirm a timeline after a free consultation."} ]}
- Quality over quantity. A few hundred clean, consistent examples beat tens of thousands of noisy ones.
- Cover the edges. Include the awkward inputs, refusals, and "I don't know" cases you actually want.
- Hold out 10–15% as a validation set the model never trains on.
- De-duplicate and check for leakage between train and validation.
Step 3 — Train efficiently with LoRA / QLoRA
You almost never need to update all of a model's weights. LoRA (Low-Rank Adaptation) trains a tiny set of adapter weights while freezing the base model. QLoRA adds 4-bit quantisation so a 7B–8B model fine-tunes comfortably on a single 16–24GB GPU.
- Start with a small learning rate (e.g.
2e-4for LoRA) and 1–3 epochs. - Watch the validation loss — stop when it flattens or ticks up (overfitting).
- Keep the adapter separate from the base model so you can swap or roll back.
Step 4 — Evaluate on the job, not on loss
Training loss tells you the model is learning something; it does not tell you the model is good. Build a small, honest evaluation set that mirrors real usage and score it:
- Task metrics — exact-match / F1 for extraction, accuracy for classification.
- LLM-as-judge — a stronger model rates helpfulness and format adherence.
- Human spot-checks — always look at 20–30 real outputs before shipping.
Step 5 — Deploy and monitor
Serve the merged model (or base + adapter) behind an inference server such as vLLM, Ollama, or a managed endpoint. Then close the loop: log real inputs and outputs, flag failures, and fold them back into the next dataset. Fine-tuning is not a one-off — it is a cycle.
Want this done for you? Code Language Hub designs, fine-tunes and deploys production AI agents end-to-end. Tell us about your use case →
Key takeaways
- SLMs (0.5B–8B) are the sweet spot for cost, latency and specialisation.
- Fine-tune for behaviour; use RAG for facts.
- Dataset quality decides everything — invest there first.
- LoRA/QLoRA makes single-GPU fine-tuning realistic.
- Evaluate on the real task and keep iterating.
Raphael Ting