Fine Tuning LLM: A Practical Guide to Doing It Well
Most teams reach for fine-tuning when prompting or RAG would have shipped faster and cheaper. This guide covers the real decision: when fine tuning an LLM pays off, how to prep data, LoRA vs QLoRA, evaluation, cost, and the pitfalls we see in production.

On this page

Most teams ask about fine tuning LLM models, in full or through LoRA and QLoRA, before they've ruled out the two cheaper options that usually win. Fine-tuning changes the weights of a large language model (LLM) so a behavior, format or domain style becomes its default. It's also the slowest and most expensive lever you have, and the hardest to change later. This guide follows the decision the way we run it on real projects: when LLM fine tuning pays off, how to prep data, where LoRA and QLoRA fit, how to evaluate the result, and the mistakes that cost teams weeks.
We ship AI in production, and the advice here comes from that work. For the wider lifecycle around the model, see our LLM application development guide. If you're still scoping the product itself, start with the generative AI development guide.
The short version
- Fine-tune to change model behavior: a strict output format, a domain voice, a narrow skill. Use RAG when the model needs fresh or changing knowledge.
- Exhaust prompt engineering first. A serious prompting pass resolves most requests that arrive framed as "we need to fine-tune."
- LoRA and QLoRA (parameter-efficient fine-tuning) train a small set of adapter weights on a frozen base, so a run on a small or mid-size model costs tens of dollars of GPU time and doesn't need a multi-GPU cluster.
- Data quality is usually the dominant factor in the outcome. A few hundred to a few thousand clean, consistent examples beat a larger contradictory set.
- Most of the budget goes to data work (sourcing, cleaning, labeling, building an eval set), then to hosting and retraining. The GPU bill is the small line.
- You only know it worked if the fine-tuned model beats the prompted base model on a held-out test set. A small general eval catches catastrophic forgetting.
What is fine tuning an LLM
Fine tuning an LLM means continuing to train a pretrained large language model on your own examples so it adopts a specific behavior, format or style. The base model already knows the language. Your examples change what it does by default, which is why fine-tuning works for behavior and works badly for facts that change.
Before you train: is fine tuning an LLM the right lever
Fine-tuning is the right lever when you're teaching the model a behavior, and the wrong one when you're giving it knowledge. Settle which of the two you have before anyone starts a training run, because they need different tools.
- Prompting changes behavior with instructions and examples in the context window. There's no training and no infrastructure, and you can iterate in minutes. Always start here.
- RAG (retrieval-augmented generation, formalized by Lewis et al. (2020)) gives the model fresh, specific knowledge at request time by pulling relevant documents into the prompt. The model stays frozen and your data layer does the work.
- Fine-tuning changes the model's weights to internalize a behavior or style you cannot reliably get from instructions: a strict output format, a domain tone, a classification skill, a way of reasoning through a narrow task.
The mistake we see most often is reaching for fine-tuning to inject knowledge. If the answer lives in documents that change, you want retrieval. Facts trained into weights are stale the day after you train, and every update means another training run. Our guide to building RAG systems covers that path in depth. If your problem is "the model doesn't know our docs," read that first.
Fine-tuning teaches the model how to behave. RAG tells it what's true right now. Mixing them up is the mistake that costs teams the most.
A rough rule we use:
- Need current or frequently changing information? RAG.
- Need a consistent format, voice, or narrow skill the base model fumbles? Fine-tune.
- Not sure yet, or still iterating on the task definition? Prompt until the requirement is stable, then decide.
These combine. A production system often prompts for control, retrieves for knowledge, and fine-tunes a small model to handle one well-defined job cheaply at scale. Fine-tuning is rarely the whole answer.
Good reasons to fine-tune
- You need rigid, machine-parseable output every time and prompting still drifts.
- You have a high-volume, narrow task (classification, extraction, routing) where a fine-tuned small model beats a large prompted one on cost and latency.
- You need a specific domain or brand voice that examples in the prompt only approximate.
- Latency or token cost matters and you want to move instructions out of the prompt into the weights.
Reasons that usually mean "don't fine-tune yet"
- The task definition is still moving. You'll retrain every time it changes.
- You need facts that update. That's a retrieval problem.
- You have fewer than a few hundred clean examples. Expect to rely on prompting first, and prove any gain on a held-out set.
- You haven't exhausted prompting. Most "we need fine-tuning" requests go away after a serious prompt-engineering pass.
Data prep for LLM fine tuning is the project
Data quality is usually the dominant factor in a fine-tune, well ahead of GPUs and hyperparameters, and most of the work is building a clean, consistent training set. A fine-tuned model reproduces its examples, mistakes included.
The LIMA study ("Less Is More for Alignment", Zhou et al., 2023) makes the case for small, careful sets: 1,000 curated examples were enough to align a 65B base model to a strong level, because most of the capability comes from pretraining. What that means in practice:
- Consistency beats volume. In our experience, a few hundred examples that all follow the exact format and style you want do better than several thousand inconsistent ones. The model learns the pattern across your set, and contradictions teach it to be unreliable.
- Match the production shape exactly. Training examples must look like real inference inputs, with the same system prompt, field names and structure. A mismatch between training and serving is common and throws no error.
- Curate, don't dump. Logs from your prototype are raw material. Every example needs review, and one bad batch of labels can drag the whole model down.
- Hold out a real test set early. Split before you train and never let test data leak into training. Otherwise you can't tell whether the model learned the task or memorized the examples.
- Cover the edges. Include the hard cases, the refusals, the "I don't know" responses. If every example is a clean happy path, the model will confidently fabricate on anything unusual.
For instruction-style tuning you typically need a few hundred to a few thousand high-quality pairs. A narrow behavior can need far fewer: OpenAI's supervised fine-tuning guide sets a minimum of 10 examples and suggests starting with around 50. More data helps only if it's as clean as the first batch.
Your training set is a specification written in examples. Every sloppy row is a bug in that spec.
LoRA fine tuning and QLoRA: the methods that made this affordable
LoRA and QLoRA train a small set of adapter weights on a frozen base model, which is why most teams no longer run full fine-tuning. Full fine-tuning updates every weight. For anything large that means serious GPU memory, long runs and a full copy of the weights per task.
What is LoRA
LoRA (Low-Rank Adaptation, Hu et al., 2021) freezes the base model and trains a small set of additional low-rank matrices that adjust its behavior. You train a small fraction of the parameters, commonly well under 1% depending on rank and target modules. Runs are much faster, and you ship a lightweight adapter, typically tens to a few hundred megabytes, in place of a whole new model.
LoRA fine tuning is the default starting point for most production work now. For narrow format and behavior tasks the quality gap versus full fine-tuning is usually small. For heavy domain adaptation such as code or math, LoRA can learn less than full fine-tuning, though it also forgets less (Biderman et al., 2024).
QLoRA: fine tuning a 65B model on one GPU
QLoRA (Dettmers et al., 2023) is LoRA applied to a 4-bit quantized frozen base model. It quantizes the base to 4-bit NormalFloat (NF4) with double quantization and paged optimizers, then trains LoRA adapters on top. The base weights take far less memory. The QLoRA paper fine-tunes a 65B parameter model on a single 48GB GPU, a job that would otherwise need a multi-GPU cluster, and 70B models can fit on one 80GB GPU with careful settings. You pay a small quality cost from quantization, which rarely matters in practice.
LoRA and QLoRA are the dominant forms of parameter-efficient fine-tuning, and libraries like Hugging Face PEFT support both out of the box. When teams say they fine-tune an LLM today, this is usually what they mean.
For planning, that changes three things:
- Cost drops sharply. QLoRA turns a job that needed multi-GPU infrastructure into something you can run on one rented GPU.
- Iteration gets fast. Small adapters train in hours, so you can run several experiments and compare them.
- Serving stays cheap. You can host one base model and load LoRA adapters per task at runtime (vLLM supports this), so each use case doesn't need its own large model.
Our defaults: start with LoRA or QLoRA and keep the learning rate low. Run a small number of epochs and watch for overfitting, because small datasets overfit fast. Leave rank and target modules alone until you have a clean dataset and a working eval.
Managed fine-tuning exists at some cloud and inference providers, but availability changes quickly. OpenAI closed its own fine-tuning platform to new users in May 2026, so check current options before you plan around one. Owning the stack with open-weight models pays off when volume, data sensitivity or cost give you a reason to keep everything in house. You can serve LoRA adapters on per-second serverless GPUs or on dedicated vLLM H100 clusters, as costed in Modal vs Baseten.
How to fine tune an LLM step by step
A fine-tune that ships usually follows the same five steps, and the order matters more than any single setting.
- Write down the behavior you want and the metric that proves it. If you can't state both in two sentences, keep prompting.
- Build the held-out test set and score the prompted base model on it. That number is your baseline.
- Curate the training set in the exact production format. This step takes longer than the other four combined.
- Train a LoRA or QLoRA adapter with conservative settings, for a few epochs.
- Score the adapter on the same test set, plus a small general eval. If it doesn't beat the baseline, fix the data before you touch hyperparameters.
Expect to loop through steps 3 to 5 several times. Most fine tuning LLM tutorials start at step 4, and that's the usual reason a first run disappoints.
Evaluation: how you know it worked
A fine-tune worked if it beats the prompted base model on a test set it never saw. Most fine-tuning projects fail here: the team trains a model, reads a dozen outputs, and ships. Then production surfaces the regressions.
Build evaluation before you train:
- Hold out a real test set the model never saw, drawn from the same distribution as production.
- Define task-specific metrics. For classification or extraction, measure accuracy, precision, and recall against labels. For generation, you need either human review on a rubric or an LLM-as-judge setup (controlling for position and verbosity biases as documented in Zheng et al., 2023 on MT-Bench) with a clear scoring guide, ideally both on a sample.
- Always compare against baselines. The comparison that counts is fine-tuned model vs the prompted base model on the same test set. If a good prompt on the base model matches your fine-tune, you just spent budget to break even.
- Watch for catastrophic forgetting. Fine-tuning hard on one task can degrade general capability. Keep a small general eval in the loop so you catch a model that got better at your task and worse at everything else.
LoRA forgets less than full fine-tuning, but it still forgets. Keep a general eval running next to your task metric.
A fine-tune that wins on your task metric but loses on robustness, latency under load or general competence isn't a win. Training loss won't tell you any of that, so measure what you care about in production.
What LLM fine tuning actually costs
The cost of fine-tuning splits into three buckets, and the GPU bill is usually the smallest. For how this sits inside a whole project budget, see our AI development cost breakdown.
- Data work is the biggest expense: sourcing, cleaning, labeling and reviewing examples, plus building the eval set. It's human time, and if you underbudget it the whole effort underperforms.
- Compute for a LoRA or QLoRA run on a sensibly sized model is modest, often tens of dollars of rented GPU time per experiment. You'll run several experiments, so multiply accordingly.
- Serving and maintenance is the recurring line. A fine-tuned model needs hosting, monitoring, and periodic retraining as your task or data drifts. You maintain a fine-tuned model for as long as it's in production.
Iteration time is the cost that doesn't show up on an invoice. Plan for several cycles of train, evaluate, fix the data, retrain. The first run is almost never the one you ship.
Common pitfalls we see in production
- Fine-tuning to add knowledge. Covered above and worth repeating, because it's the most common waste. Use RAG for facts.
- Skipping the prompt-engineering pass. A serious prompting effort solves a large share of "we need to fine-tune" requests for free.
- Training on dirty logs. Raw prototype output needs review before it counts as a dataset.
- Train/serve mismatch. The format at inference must match training exactly. Nothing errors when it doesn't, the outputs just get worse.
- No baseline. Without comparing to the prompted base model, you can't prove fine-tuning helped.
- Overfitting a tiny dataset. Too many epochs on too few examples produces a model that parrots training data and fails on anything new.
- Treating it as one-and-done. Tasks drift and data ages, so schedule retraining from the start.
Where this fits in a real system
Fine-tuning is one part of a production stack. The strongest systems we build combine a controlled prompt, retrieval for live knowledge, and a fine-tuned small model only where a narrow, high-volume task justifies it. Training the model is the easy part. The data pipeline, the evaluation harness and the serving infrastructure take more work, and they decide whether it holds up. Our AI implementation guide covers that rollout side.
If you're weighing whether to fine-tune, build RAG or invest in better prompting, settle that before you spend on compute. Our AI development team runs this evaluation with clients: we find which lever moves your metric, then build the smallest system that ships it. When the answer is a custom model, that work sits under our generative AI development service.
Start with prompting. Reach for RAG when you need knowledge. Fine-tune when you need behavior, you have clean data, and you can prove it beat the baseline. Taken in that order, fine tuning an LLM is a decision you can defend with a test set.

CTO and Co-founder at Idealogic. Directing engineering, systems architecture, security, and full-stack delivery across web, mobile, and blockchain.
Frequently asked questions
Fine-tune when you need to change how the model behaves: a strict output format, a domain voice, a narrow skill it fumbles. Use RAG when the model needs fresh or frequently changing knowledge. If the answer lives in documents, put it in retrieval. Facts trained into weights are stale the day after the run.
For instruction-style tuning, expect a few hundred to a few thousand consistent examples. A narrow behavior can need far fewer: OpenAI's supervised fine-tuning guide sets a minimum of 10 examples and suggests starting around 50. Consistency matters more than volume. In our experience a small uniform set beats a much larger contradictory one, and more data only helps if it's curated as carefully as your first batch.
LoRA freezes the base model and trains small low-rank adapter matrices, so you update a small fraction of the parameters and ship a lightweight adapter. QLoRA is LoRA applied to a 4-bit quantized frozen base, which cuts memory enough to fine-tune large models on a single GPU. You pay a small quality cost for that saving. Neither one needs a full fine-tuning run.
Compute for a LoRA or QLoRA run is often tens of dollars of GPU time per experiment, and you'll run several. Most of the money goes to people: sourcing, cleaning and labeling data, then building an evaluation set. After launch you keep paying for hosting, monitoring and periodic retraining.
It can. Training hard on a narrow task can cause catastrophic forgetting: the model improves at your task and gets worse at general work. LoRA forgets less than full fine-tuning, but it isn't immune. Keep a small general evaluation next to your task metric, use a lower learning rate, and don't run many epochs on a small dataset.
Improve the prompt first, almost always. A serious prompt-engineering pass resolves a large share of requests that started as 'we need to fine-tune.' Move to fine-tuning once the task definition is stable, prompting still drifts, and you have clean data plus an evaluation that shows the fine-tune beats the prompted base model.
There's no single best setting, but a common starting point is a LoRA rank of r=8 or r=16, alpha at 1x or 2x the rank, adapters on all linear projection layers (attention and MLP), and a learning rate around 1e-4 to 2e-4 over 2 to 4 epochs. Tune from there. Higher ranks rarely help narrow formatting or classification tasks until your dataset is more varied and your evaluation can show the difference.
A managed fine-tuning API suits moderate volume when you don't want to run GPU serving yourself, but check what's on offer before you plan around one: OpenAI closed its fine-tuning platform to new users in May 2026. Self-host an open-weight model with vLLM and LoRA adapters when data residency rules, tight latency targets or sustained high request volume make dedicated GPUs cheaper than per-token pricing.
More from the journal

RAG vs Fine Tuning: Which One Your LLM Actually Needs
RAG changes what a model knows. Fine tuning changes how it behaves. Teams pick wrong because they never ask which of the two is broken. Here's what the published benchmarks actually show, what each approach costs, how they stack, and how to diagnose your own case.

Modal vs Baseten in 2026: Serverless GPU, vLLM & H100 TCO
Engineering and 36-month TCO teardown of Modal vs Baseten, Replicate (Cloudflare), and Together AI in 2026: per-second Python H100/B200 containers and GPU memory snapshots vs Truss TensorRT-LLM, KV-cache prefix routing, and 3,200 H100-hr/mo math.

Portkey vs LiteLLM in 2026: AI Gateways, Latency & TCO
Engineering and 36-month TCO comparison of Portkey vs LiteLLM vs Helicone and compiled Go/Rust AI gateways in 2026: streaming overhead, enterprise SSO walls, PostgreSQL 17 FORCE RLS token-budget ledgers, and 120M req/mo math.