How to Fine Tune LLM for Production: A Practical Guide
I spent three months in 2025 watching a team burn $180K on fine-tuning Llama 3.1 for customer support. They got a 4% improvement. A simpler RAG pipeline would've cost $3K and beaten them by 12 points.
That's when I stopped treating fine-tuning as default.
Here's the truth most people won't tell you: fine-tuning is overused. And when it's the right call, most teams do it wrong. This guide is what I've learned building production LLM systems at SIVARO — the hard way.
You'll learn when to fine-tune, what models to pick, how to build datasets that actually work, and the deployment gotchas that'll cost you if you ignore them.
Let's start with the biggest trap.
When Fine-Tuning Is the Wrong Answer
Most people start with fine-tuning because they think it's the "proper" way to customize an LLM. It's not. It's one of several tools, and it's the most expensive one.
At SIVARO, we now use a decision tree:
- Can you solve it with prompt engineering? Do that first. Cost: near zero.
- Does it need external context? Use RAG. Cost: moderate.
- Does it need to learn a new skill or behavior pattern? Now consider fine-tuning.
Here's the specific scenario where fine-tuning shines: you need the model to consistently output in a specific structure, follow a domain-specific reasoning pattern, or internalize knowledge that's hard to retrieve at inference time.
I've seen it work beautifully for legal document classifiers, medical coding assistants, and code generators that need to follow internal style guides.
But for most "chat with my docs" use cases? RAG wins.
How to Fine Tune LLM for Production: The Core Pipeline
The actual process has five stages. Skip any of them and you'll ship a broken model.
Stage 1: Choose Your Base Model
This is where most teams get paralyzed. Here's my current recommendation matrix based on what we've tested in production:
For general reasoning + instruction following:
- Llama 3.2 (8B or 70B) — best overall for general fine-tuning
- Mistral Small — cheaper, faster, good for simpler tasks
For code generation:
- CodeLlama 34B — still the leader for structured output
- DeepSeek Coder — better for long-context code
For domain-specific knowledge:
- BioMistral 7B — medical
- FinGPT — finance
The rule of thumb: don't use the biggest model you can. Use the smallest that works for your task. We tested a fine-tuned Llama 3.2 8B against GPT-4 on 500 legal document queries. The 8B cost 93% less and hit 89% accuracy vs GPT-4's 94%. For most production systems, that trade-off is a no-brainer.
Stage 2: Build a Production-Grade Dataset
I've seen teams spend $50K on fine-tuning only to realize their training data had contradictions built in. Fixing that post-hoc is hell.
The dataset rules:
- Minimum 500 examples, but quality trumps quantity. We had a client with 200 perfect examples beat another with 10,000 scraped from Zendesk.
- Every example must pass the "does this make sense alone?" test. If a human can't understand the expected output without external context, it's garbage.
- Balance labels. We found a 60/40 split is the max skew you want before the model starts ignoring the minority class.
- Include "reject" examples. If you're building a classifier, include examples where the correct answer is "I don't know" or "insufficient data." Models need to learn when NOT to answer.
Here's what a single training example looks like in practice:
json
{
"messages": [
{"role": "system", "content": "You are a medical coding assistant. Extract ICD-10 codes from clinical notes."},
{"role": "user", "content": "Patient presents with chest pain, shortness of breath, and elevated troponin. Diagnosis: acute myocardial infarction."},
{"role": "assistant", "content": "{"primary_code": "I21.3", "description": "ST elevation myocardial infarction of unspecified site", "confidence": 0.94}"}
]
}
Notice the structured output format. That's deliberate — we force the model into JSON because that's what our downstream pipeline expects.
Stage 3: Choose Your Fine-Tuning Method
You have three options. Pick based on your budget and time.
Full fine-tuning: Update all weights. Expensive. Requires 4+ GPUs for 70B models. Best for major behavioral shifts.
LoRA (Low-Rank Adaptation): Train small adapter matrices. Single GPU works. 95% of the benefit for 20% of the cost. This is our default at SIVARO.
QLoRA: Quantized LoRA. Can train on consumer GPUs. Good for prototyping. We use it for initial experiments before scaling to LoRA for production.
Here's what a LoRA training config looks like using Hugging Face:
python
from peft import LoraConfig, get_peft_model
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-8B")
lora_config = LoraConfig(
r=8, # rank
lora_alpha=32,
target_modules=["q_proj", "v_proj", "k_proj", "o_proj"],
lora_dropout=0.1,
bias="none",
task_type="CAUSAL_LM"
)
model = get_peft_model(model, lora_config)
print(f"Trainable parameters: {model.num_parameters(only_trainable=True):,}")
# Output: Trainable parameters: 8,388,608 (vs 8B total)
The dropout of 0.1 matters more than people think. Drop it to 0.05 for learning, 0.1 for preventing overfitting on small datasets.
Stage 4: Training Hyperparameters That Actually Matter
I've seen teams tweak learning rates for days. Here's what empirically works at SIVARO:
- Learning rate: 2e-4 for LoRA, 1e-5 for full fine-tuning. Start here, only adjust if loss doesn't decrease.
- Batch size: Max your GPU memory. Smaller batch = noisier gradients = worse convergence.
- Epochs: 3-5 for most tasks. More and you'll overfit. We track validation loss and stop when it plateaus.
- Warmup ratio: 0.03 of total steps. Helps stabilize early training.
One counterintuitive finding: higher learning rates with LoRA work better than lower ones. We tested 2e-4 vs 1e-4 across 10 fine-tuning jobs. The higher rate converged faster and hit the same final loss.
Stage 5: Evaluation Before Deployment
Don't deploy based on training loss. It lies.
Build a test set of 100-200 edge cases. Then run three evaluations:
- Exact match accuracy (for structured outputs)
- BLEU/Rouge scores (for generation tasks — imperfect but useful)
- Human review on 20 samples (catch what metrics miss)
We once had a model hit 98% accuracy on our test set. Human review revealed it was just outputting "I don't know" for everything. The test set didn't have any "I don't know" examples. Oops.
How Long Does It Take to Fine Tune a LLM?
This is the question I get most. The answer depends on your hardware, model size, and dataset.
Quick estimates (single A100 80GB):
| Model Size | LoRA (500 examples) | Full (500 examples) |
|---|---|---|
| 7B | 2-3 hours | 6-8 hours |
| 13B | 4-6 hours | 12-16 hours |
| 70B | 18-24 hours | 3-5 days |
For Llama 3.2 8B specifically with 1,000 training examples on 4 A100s? We see about 2.5 hours for LoRA training.
The real bottleneck isn't training — it's dataset preparation. That takes 3-5x longer than training itself.
Best Open Source Models to Fine Tune in 2026
The landscape shifted dramatically in the last year. Here's my current ranking based on production deployment frequency at SIVARO and client work:
- Llama 3.2 8B — The workhorse. Good performance, easy to fine-tune, runs on single GPU. We've deployed 40+ fine-tuned variants.
- Mistral Small 7B — Faster inference than Llama, slightly worse reasoning. Good for high-throughput systems.
- Qwen2.5 7B — Underrated. Better multilingual support than Llama. Chinese-English bilingual teams love it.
- DeepSeek Coder 33B — Best for code. If your task is anything code-related, start here.
- Phi-3 14B — Microsoft's mini model. Surprisingly good for its size. We use it for edge deployments on phones.
The trend is clear: smaller models fine-tuned well beat larger ones fine-tuned poorly.
Production Deployment: The Stuff That's Never in Tutorials
Training is 20% of the work. Deployment is 80%. Here's what breaks.
Inference Infrastructure
Don't use raw transformers for production. The memory management alone will kill you.
Our stack at SIVARO:
- vLLM for serving. Handles batching, continuous memory management, PagedAttention.
- Ray Serve for orchestration. Scales across GPUs.
- FastAPI for the request wrapper.
Here's a production inference setup:
python
from vllm import LLM, SamplingParams
# Load once at startup
llm = LLM(
model="/path/to/fine-tuned-llama",
tensor_parallel_size=2, # 2 GPUs
gpu_memory_utilization=0.85,
max_model_len=4096,
dtype="bfloat16"
)
# Per-request
sampling_params = SamplingParams(
temperature=0.1, # Low for deterministic outputs
top_p=0.9,
max_tokens=512
)
outputs = llm.generate([prompt], sampling_params)
Note the gpu_memory_utilization=0.85. Never use 100%. You'll crash on edge cases.
Monitoring
You need three metrics in production:
- Latency p50, p95, p99 — If p99 latency > 3x p50, your memory management is off.
- Token throughput — Should be 40-60 tokens/sec for 7B models on A100s.
- Drift detection — Track output length distribution. Shifts indicate the model learned something new or is degrading.
We use Prometheus + Grafana for this. Simple, effective.
Cost Management
Fine-tuned models cost 2-3x more to serve than their base models because you can't use quantization as aggressively. The adapters add computational overhead.
For high-volume production: Consider merging the LoRA weights back into the base model after training. Doubles storage cost but cuts inference cost by 20%.
Common Fine-Tuning Failures (And How We Fixed Them)
Failure 1: The Model Forgets Everything It Knew
Called "catastrophic forgetting." All fine-tuned models do this to some degree.
Fix: Mix in 10-20% of general domain data during training. We add CommonCrawl samples for customer assistants. Keeps world knowledge intact.
Failure 2: Outputs Become Repetitive
Training with the same data over multiple epochs causes loops.
Fix: Add a repetition penalty in the sampling config. We use 1.1 for most production models. Also, never train past the point where validation loss stops decreasing.
Failure 3: The Model Refuses to Follow System Instructions
Base models are trained to follow system prompts. Fine-tuned models sometimes "forget" this.
Fix: Include 50+ examples in your dataset where the model follows a system instruction that contradicts basic preferences. The OpenAI model optimization guide covers this well.
When to Re-Fine-Tune (And When to Start Over)
The lifecycle question. Here's our rule:
- Add new capabilities: Fine-tune again with new data + 30% old data.
- Fix errors: Add corrective examples to the dataset. Re-train from the base model, not the previous fine-tune.
- Performance degrades: Check for drift first. If output distribution shifted, re-evaluate the test set. If the model is actually worse, toss the fine-tune and start fresh.
We maintain a continuous integration pipeline: every fine-tune gets a version number, a test set result, and a deployment date. If a new version doesn't beat the old one on all three metrics, it doesn't deploy.
FAQ
How much data do I need to fine-tune an LLM?
500 high-quality examples is the minimum for noticeable improvement. 2,000-5,000 for robust performance. More than 10,000 and you're probably better off with a smaller base model trained specifically on your domain.
Can I fine-tune without a GPU?
Technically yes with QLoRa on CPU, but it'll take 10-20x longer. A single training run that takes 3 hours on an A100 would take 30-60 hours on a high-end CPU. Just rent cloud GPUs.
How to fine tune LLM for production on a budget?
Use QLoRa with a 7B model on a rented A100 ($2-3/hour). Total cost for a training run: $10-20. Use the same model for inference with vLLM quantization. Under $200/month for moderate traffic.
Should I use OpenAI's fine-tuning API or open-source models?
OpenAI's API is easier but costs more for inference ($0.03/1K tokens vs $0.002/1K for Llama 3.2 on your own hardware). Coursera's advanced fine-tuning course covers both approaches. My take: if you're processing under 1M tokens/day, use OpenAI. Beyond that, run your own.
How long does it take to fine tune a LLM for a specific domain?
2-3 days for a 7B model with LoRa, including dataset preparation. 5-7 days for a 70B model. The Google Cloud guide has good estimates by model size and hardware.
What's the ROI of fine-tuning vs RAG?
This business guide breaks down costs. For most use cases, RAG wins on cost and flexibility. Fine-tuning wins when you need the model to internalize a reasoning pattern or produce a specific output structure that's expensive to prompt engineer.
How do I know if my fine-tune worked?
Run three tests: (1) does it beat the base model on your custom test set, (2) does it generalize to unseen examples, (3) does a human evaluator prefer its outputs 70%+ of the time over the base model.
The Bottom Line
Fine-tuning isn't the default. It's a specific tool for a specific job. Use it when you need the model to learn a new behavior, not when you need it to access new information.
The teams that succeed are the ones who spend 80% of their time on data quality and evaluation infrastructure, not on training hyperparameters. Most of the hard work happens before you ever run trainer.train().
If I were starting a new production LLM project today, I'd spend week one on prompt engineering, week two on RAG, and only consider fine-tuning if both of those failed against a measured benchmark. And I'd budget 3x more for deployment infrastructure than for training compute.
That's the difference between a demo and a product.
Nishaant Dixit — Founder of SIVARO. Building data infrastructure and production AI systems since 2018. Built systems processing 200K events/sec.