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.
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:
Before fine-tuning, always try these first (in order):
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"
)
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)
| Approach | Training cost | Inference cost vs base | Data needed |
|---|---|---|---|
| OpenAI gpt-4o-mini FT | ~$0.008/1K tokens | Same | 50-1,000 examples |
| LoRA on Llama 3 8B | ~$20-50 (A100 4hr) | Hardware cost | 100-10,000 examples |
| Full fine-tune 70B | $500-5,000+ | Hardware cost | 10,000+ examples |
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.
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 →