Skip to content

LLM fine-tuning: when it pays off, the kinds of tuning and how LoRA and QLoRA work

What fine-tuning is, when it beats prompting and RAG, the kinds of tuning (SFT, DPO, GRPO, distillation), how LoRA and QLoRA work inside and the step by step of a project in 2026.

Ramon Gomes 17 min read Level: Intermediate

Also available in: Español, Français, Português

"Let's fine-tune a model on our documents" is one of the most common lines in AI projects, and the real request is almost always something else. The team wants the model to know the company's rules, and RAG handles that better and cheaper. Fine-tuning shines somewhere else: when the problem isn't what the model knows, but how it behaves.

This article breaks the term down from start to finish: what it is, when it's worth it, each kind of tuning, how LoRA and QLoRA work under the hood, the steps of a project and where to do it in 2026. Each part has an animation, so the idea gets in through your eyes before the formula does.

An Analogy to Start

Think of the model as a doctor fresh out of medical school. They studied for years (the pre-training, on trillions of tokens) and know a lot of general things.

  • Prompt is the instruction for the shift: "today, prioritize the pediatric cases and answer in bullet points".
  • RAG is handing over the patient's chart during the appointment: they read it and answer based on what's in there.
  • Fine-tuning is residency: months practicing one kind of case until the way they work changes. After it, they no longer need the instruction every shift.

Residency changes habits. It isn't meant for memorizing every patient's chart, and that's where the most common mistake lives.

Luthier in a woodworking shop adjusting the tuning pegs of a violin, with fine tools spread across the bench and a tuning fork beside it
The violin is already built. Fine-tuning doesn't make the instrument: it just makes it sound the way you need.

Prompt, RAG or Fine-tuning: What Solves What

The question that decides it: what is the model missing?

Three paths for the model: an editor with JSON links clear instructions to Prompt; documents and a magnifying glass link changing knowledge to RAG; examples and a server link repeated behavior to fine-tuning.
Always start with the cheapest path. Fine-tuning comes in when the problem is how things are done, not information.
What's missing Example Best path Why
A clear instruction "Answer in JSON with these fields" Prompt, structured output Solved in minutes, and you can change it whenever you want
Knowledge that changes Prices, policies, help center RAG You update the document, not the model, and it cites the source
Repeated behavior Classifying tickets the house way, brand voice, rigid format Fine-tuning Examples teach what's hard to describe in text
Cost and latency A narrow task running millions of times Fine-tuning a smaller model, or distillation A small tuned model can replace a large one

OpenAI itself writes in its optimization guide that the prompt engineering process "may be all you need", and Anthropic points out that not every failure is fixed with a prompt: sometimes switching models improves cost and latency with less effort. The article on RAG vs CAG goes deeper on the knowledge side, and the one on RAG techniques shows how to get the most out of it before you think about training.

The Kinds of Tuning, One by One

"Fine-tuning" is an umbrella term. Under it sit techniques with different goals.

A timeline of five techniques, their data and effects: documents for continued pre-training, dialogue for SFT, compared answers for DPO and RLHF, checked steps for GRPO, and a large server teaching a small one for distillation.
Each kind consumes different data. Knowing which data you have already rules out half the options.
Kind The data that goes in What changes in the model When it makes sense
Continued pre-training Lots of raw domain text Vocabulary and familiarity with the subject A very specific domain (legal, medical) with plenty of text available
Supervised (SFT) Pairs of question and ideal answer Format, tone, a specific task The starting point of almost every project
Preference-based (RLHF, DPO) Pairs of a good answer and a bad answer What "better" means between similar options Tuning style, safety, helpfulness
Reinforcement for reasoning (GRPO) Problems with a verifiable answer The ability to reason in steps Math, code, tasks with automatic checks
Distillation Answers from a large model A small model imitating the large one Cutting cost and latency while keeping quality on one task

Supervised: Learning by Example

This is the most common one. You build examples in conversation format, with the question and the answer you'd like to see, and the model learns to imitate them. At OpenAI the format is JSONL, one conversation per line, with a messages list of roles and contents. The minimum accepted is 10 examples, and the guide says improvements show up with 50 to 100.

json
{"messages": [
  {"role": "system", "content": "Classify the ticket."},
  {"role": "user", "content": "My bill is past due and I can't generate a new one."},
  {"role": "assistant", "content": "{\"category\": \"billing\", \"urgency\": \"high\"}"}
]}

One detail that sinks a lot of projects: the chat template. Each open model was trained with its own control tokens that mark where each message starts and ends. The Hugging Face docs warn that with the wrong control tokens, these models perform "drastically worse". Always train with the same template the model uses. If the idea of a token is still fuzzy, the article on tokens explains it with measured examples.

Preference-based: Learning by Comparing

Sometimes it's easy to say which answer is better and hard to write the perfect one. Preference tuning uses pairs: for the same question, a chosen answer and a rejected one.

A question about cancelling a plan receives two answers side by side: the chosen answer has steps and the right link; the rejected one is vague. Qualitative charts show the chosen answer becoming more likely and the rejected answer less likely over three rounds.
DPO doesn't need a separate reward model: it learns straight from the pair, pushing the chosen answer up and the rejected one down.

Classic RLHF first trains a reward model and then optimizes the main model against it, with reinforcement learning. The article on reinforcement learning and RLHF tells that story at a slower pace. In 2023, the DPO (Direct Preference Optimization) paper showed a shortcut: by rewriting the math, you can solve the same problem "with only a simple classification loss". In practice, it's simpler and more stable to train, which is why it became the default in libraries like TRL and Axolotl.

Reinforcement for Reasoning: Learning by Checking

On tasks with a verifiable answer (the math works out, the test passes), you can let the model try several times and reward the attempts that get it right. GRPO, introduced in the DeepSeekMath paper in 2024, is a variant of PPO that compares answers within the same group against each other and saves the memory PPO used to spend. DeepSeek-R1, published in Nature in 2025, showed that reasoning ability "can be incentivized through pure reinforcement learning", without relying on reasoning traces written by humans.

It's the most expensive and most delicate technique on the list. For most company projects, SFT and DPO get the job done.

Distillation: The Big One Teaches the Small One

The idea dates back to 2015, from Hinton and coauthors: compress the knowledge of a large model (or an ensemble of models) into a smaller one. With LLMsAI model trained on large amounts of text to predict the next word, which lets it chat, summarize, translate and write code., the typical playbook is to generate high-quality answers for your task with a large model and use them for SFT on a small model. It works well when the task is narrow and the volume is high. Before you start, check whether the large model's license allows using its outputs to train another one.

Full Tuning or Just a Piece

In full fine-tuning, every weight in the model changes. It gives you the most freedom, but it needs memory to hold the weights, gradients and optimizer states of billions of parameters, and it produces a whole copy of the model for each tuning run.

PEFT (Parameter-Efficient Fine-Tuning) is the family of techniques that tune only a small part, "a small number of (extra) model parameters instead of all the model's parameters", in the words of the PEFT library. The most widely used one is LoRA.

LoRA: Two Small Matrices Next to the Model

A model is, for the most part, a pile of weight matrices. Tuning means adding a correction to each of them. LoRA's insight (Low-Rank Adaptation, 2021) is that this correction can be written as the product of two thin matrices, called A and B. The original model stays frozen, and only A and B learn.

Frozen matrix W with a padlock, 4,096 by 4,096 with about 16.8 million weights. Beside it, trainable strips B and A have rank 8 and 65,536 weights, 0.4%. A third panel shows the B·A correction added to W: W + B·A.
The original model doesn't change. What learns are the two thin strips, and the result is the sum of both parts.

An example with round numbers helps show how big the savings are. A 4,096 by 4,096 matrix has about 16.8 million weights. With a LoRA of rank 8, the two strips have 4,096 × 8 + 8 × 4,096 = 65,536 weights. That's less than 0.4% of the original, and the rank is the knob you turn: higher means more capacity and more memory.

In the original paper, compared with full fine-tuning of GPT-3 175B, LoRA cut "the number of trainable parameters by 10,000 times and the GPU memory requirement by 3 times". And since the result is a small file (the adapter), you can keep dozens of specializations on top of the same base model.

There's a price. The study "LoRA Learns Less and Forgets Less" (2024) measured that, at the common low-rank settings, LoRA "substantially underperforms full finetuning" on new and hard tasks such as code and math. In exchange, it better preserves what the model already knew outside the tuning domain. For changing format and tone, that's usually an advantage.

QLoRA: The Base Model Compressed to 4 Bits

LoRA saves on what gets trained, but the base model still has to fit on the GPU. QLoRA (2023) goes after that part: it stores the base model in 4 bits instead of 16 and trains the LoRA adapters on top. The paper fine-tuned a 65-billion-parameter model "on a single 48GB GPU" while matching the performance of 16-bit tuning.

Two bars on the same scale compare the weights of a 65B model: at 16 bits, about 130 GB exceed the 48 GB limit; at 4 bits, about 33 GB stay below it. The LoRA adapter appears separately from the scale and connects to a 48 GB GPU where training fits.
Compressing the base model to 4 bits is what makes training fit. The adapters stay in high precision.

There are three tricks: a 4-bit format designed for how weights are distributed (NF4), double quantization (it even compresses the compression constants) and paged optimizers, which move data to regular memory during spikes so the GPU doesn't overflow.

How much memory does that come to in practice? The Unsloth docs publish the absolute minimums:

Model QLoRA (4 bits) LoRA (16 bits)
7B 5 GB 19 GB
8B 6 GB 22 GB
70B 41 GB 164 GB

In other words: with QLoRA, an 8B model fits for training on a consumer graphics card, and a 70B model fits on a single data center GPU.

The Steps of a Project

An isometric workbench with 50 good examples and an open 7B to 8B model feeding LoRA or QLoRA training. An evaluation gate sends back what fails to beat the baseline and passes improvements to vLLM. One base server serves support, legal and sales adapters.
Evaluation is the gate. A tuned model that doesn't beat a well-written prompt doesn't go to production.
  1. Define the task and the metric. "Getting better" isn't a metric. "Getting the category right on 95% of the tickets in the test set" is.
  2. Measure the baseline. Run the task with a good prompt, with and without RAG. That's the number the tuning has to beat.
  3. Build the data. Start with 50 well-made examples, as OpenAI recommends. Quality beats volume: a wrong example teaches the mistake. Set aside a test set that never goes into training.
  4. Pick the model and the method. For most people: SFT with LoRA or QLoRA on an open 7B to 8B model. Use the model's chat template.
  5. Train. The most used tools are in the table below. Start with few epochs and watch the loss on the validation set.
  6. Evaluate. On your test set first. Then on general benchmarks, to see whether the model forgot something important. EleutherAI's lm-evaluation-harness has "over 60 standard academic benchmarks".
  7. Serve. vLLM loads LoRA adapters on top of the base model with --enable-lora and --lora-modules, and the client picks the adapter through the request's model field. The S-LoRA paper showed you can serve "thousands of LoRA adapters" on one GPU.
Tool What it is Version (Nov 21, 2026)
TRL Hugging Face library with trainers for SFT, DPO, GRPO, KTO and reward models 1.18.2
PEFT LoRA and other techniques that tune few parameters 0.22.0
Unsloth Optimized training; promises "2× faster with 70% less VRAM" 2026.11.9
Axolotl Config-file framework: full, LoRA, QLoRA, DPO, GRPO 0.21.1
LLaMA-Factory Unified interface for over 100 models, with SFT, DPO, PPO and more 0.9.5
Cartoon of a robot wearing glasses rewriting a giant encyclopedia by hand, page by page, while another robot next to it just sticks colorful sticky notes on the pages and is already done
Full fine-tuning rewrites the book. LoRA puts sticky notes on the right pages.

Fine-tuning Through an API in 2026

Training through an APIContract that defines how one program asks another for data or actions: which endpoints to call, what to send and what comes back. On the web, usually HTTP with JSON. is simpler (you send the data and get a model back), but the landscape has changed a lot:

  • OpenAI: the docs say the company "is winding down the fine-tuning platform" and that the platform "is no longer accessible to new users". Eligible customers can create jobs until January 6, 2027, unless the base model is retired first.
  • Google Vertex AI: offers supervised tuning of Gemini on models such as 3.5 Flash, 3.1 Flash-Lite and 2.5 Pro.
  • Anthropic: there's no documented Claude fine-tuning on its own API. The official route I found is Claude 3 Haiku on Amazon Bedrock, only in the us-west-2 region.

For anyone starting a project today, that pushes the decision in two directions: prompt, RAG and tools on a closed model, or tuning an open model you control.

Quick check

1. The company wants the assistant to answer based on the refund policy, which changes every month. What should you do?
Show answer

Answer: RAG with the policy as a retrieved document

Knowledge that changes is RAG's job: you update the document, not the model, and you can still cite the source.

2. What does LoRA train?
Show answer

Answer: Two small matrices next to the weights, which stay frozen

The original model stays frozen. The correction is the product of two thin matrices, A and B, which are the only ones that learn.

3. What's the core difference between DPO and classic RLHF?
Show answer

Answer: DPO learns straight from the preference pairs, without a separate reward model

RLHF trains a reward model and optimizes against it. DPO solves the same problem with a simple classification loss over the pairs.

4. Why does QLoRA let you train larger models on the same GPU?
Show answer

Answer: Because it stores the base model in 4 bits and trains the adapters on top

Compressing the base model is what frees up memory. That's how the paper tuned a 65B model on a 48 GB GPU.

Frequently Asked Questions

Does fine-tuning teach the model new things?

A little, but poorly: it mixes things up, forgets and can't tell you where it got them. For knowledge, especially knowledge that changes, RAG is the way. Fine-tuning is for behavior: format, tone, task.

How many examples do I need?

OpenAI accepts as few as 10 and says improvements show up with 50 to 100. If 50 well-made examples don't change anything, the guide recommends rethinking the task or the prompt before collecting more data.

Do I need my own GPU?

Not necessarily. With QLoRA, an 8B model trains with about 6 GB of video memory, according to Unsloth. You can rent a GPU by the hour or use a cloud notebook with a GPU.

Can I fine-tune ChatGPT or Claude?

At OpenAI, the platform is being shut down and is closed to new users. At Anthropic, there's no documented tuning on its own API; the official route is Claude 3 Haiku on Amazon Bedrock. At Google, Vertex AI tunes Gemini models.

Is LoRA worse than full fine-tuning?

On new and hard tasks, such as code and math, full fine-tuning learns more. In exchange, LoRA better preserves what the model already knew and costs much less. For format and tone, it's usually enough.

References

Source: https://ramongomessilva.com.br/blog/llm-fine-tuning · Accessed on December 02, 2026

Share Share on LinkedIn Share on X
Cite this article

Ready-made reference, with today as the access date.

ABNT

Brazilian standard (NBR 6023). Use it in theses and academic papers submitted in Brazil.

GOMES, Ramon. LLM fine-tuning: when it pays off, the kinds of tuning and how LoRA and QLoRA work. Ramon Gomes, 23 nov. 2026. Disponível em: https://ramongomessilva.com.br/blog/llm-fine-tuning. Acesso em: 2 dez. 2026.

APA

American Psychological Association style. Common in scientific papers and journals, especially in the social, behavioral and health sciences.

Gomes, R. (2026, November 23). LLM fine-tuning: when it pays off, the kinds of tuning and how LoRA and QLoRA work. Ramon Gomes. https://ramongomessilva.com.br/blog/llm-fine-tuning

BibTeX

Format for LaTeX users (Overleaf, for example). Paste it into your .bib file or import it into Zotero or Mendeley.

@online{gomes2026llmfinetuning,
  author = {Gomes, Ramon},
  title = {{LLM fine-tuning: when it pays off, the kinds of tuning and how LoRA and QLoRA work}},
  organization = {Ramon Gomes},
  year = {2026},
  month = nov,
  date = {2026-11-23},
  url = {https://ramongomessilva.com.br/blog/llm-fine-tuning},
  urldate = {2026-12-02}
}
Found a mistake?

Wrong fact, broken link, outdated information: tell me and I will fix it.

10 to 2,000 characters. If you can, point to the right source.

Only so I can reply. It never shows on any page of the site.

Written by

Ramon Gomes

Software Engineer

Full stack software engineer. I like taking a messy problem, listening to the people who live with it and shipping something that holds up day to day. These days I split my time between my own products, applied AI and client work.

Available for projects

Need Something Like This Built?

I build websites, systems, apps and AI automations, from design to deploy. Tell me what you need or see what I offer.

Related Articles