← Back to articles Blog

Fine-Tuning LLMs: When It's Worth It and When RAG Is the Better Call

Emmanuel Ekunsumi · 6 min read · 2026-07-12

Fine-tuning is the process of continuing to train a pre-trained LLM on your own dataset to specialize its behavior. It's the most powerful way to customize a model — but also the most expensive and complex. Most teams that think they need fine-tuning actually don't.

What fine-tuning actually does

Pre-trained LLMs learn from massive datasets. Fine-tuning adds a second training phase on a smaller, task-specific dataset — adjusting the model's weights to perform better on your specific use case. The model "forgets" some general capability while gaining specialized capability.

Use cases where fine-tuning genuinely helps:

The fine-tuning decision tree

Before fine-tuning, always try these first (in order):

  1. Prompt engineering — better instructions, examples, and constraints in the system prompt
  2. Few-shot examples — 3-10 examples of desired input/output pairs in the prompt
  3. RAG — if the problem is knowledge, not behavior
  4. Fine-tuning — only if the above don't work or cost too much at scale

How to fine-tune: the main approaches

OpenAI fine-tuning

The simplest path: upload a JSONL file of prompt-completion pairs, trigger a fine-tuning job via the API, and get back a custom model ID to use in place of the base model.

# Training data format: JSONL
{"messages": [{"role": "system", "content": "You are a support agent."}, {"role": "user", "content": "How do I reset my password?"}, {"role": "assistant", "content": "Click Forgot Password on the login page."}]}

# Trigger fine-tuning
from openai import OpenAI
client = OpenAI()

job = client.fine_tuning.jobs.create(
    training_file="file-abc123",
    model="gpt-4o-mini-2024-07-18"
)

Hugging Face + LoRA

For open-source models, Low-Rank Adaptation (LoRA) is the standard approach. LoRA freezes most model weights and only trains small adapter matrices, reducing GPU memory requirements by 10-100x vs full fine-tuning.

from peft import get_peft_model, LoraConfig
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-8B")
config = LoraConfig(r=8, lora_alpha=32, target_modules=["q_proj","v_proj"])
model = get_peft_model(model, config)

Fine-tuning costs

ApproachTraining costInference cost vs baseData needed
OpenAI gpt-4o-mini FT~$0.008/1K tokensSame50-1,000 examples
LoRA on Llama 3 8B~$20-50 (A100 4hr)Hardware cost100-10,000 examples
Full fine-tune 70B$500-5,000+Hardware cost10,000+ examples

The hidden cost: inference token savings

Fine-tuning's biggest ROI is often on inference, not training. A well-tuned model can replace a 1,500-token system prompt with a 50-token one — because the behavior is now baked in. At 1M calls/month, that's 1.45 billion fewer input tokens per month.

Fine-tuning is worth considering when your system prompt is over 1,000 tokens and you're making millions of API calls. The inference savings often pay back the training cost within a week.

Measure your system prompt overhead before fine-tuning

Tokoscope shows exactly how many tokens your system prompts consume per call. If it's over 500 tokens, fine-tuning ROI is worth calculating.

Get started free →