Skip to content

Fine-Tuning in AI: Definition, LoRA and Examples

Quick answer

What fine-tuning in AI means, how LoRA trains few parameters, and when to fine-tune instead of using prompts or RAG.

Fine-Tuning in AI: Definition, LoRA and Examples

Fine-tuning in AI is the process of taking a model that has already been trained on broad data and training it further on a smaller, task-specific dataset so it behaves the way you need. It starts from existing weights instead of random ones, which usually costs far less than training a model from scratch.

Key takeaways

  • Fine-tuning adapts a pre-trained model to a specific task, style or format.
  • It is a form of transfer learning and needs less data and compute than training from scratch.
  • Parameter-efficient methods such as LoRA train only a tiny share of the weights.
  • Prompting and RAG are often tried first; fine-tune when you need consistent behaviour.

On this page:

ApproachWhat changesBest when
Prompt engineeringOnly the input textYou need a quick, cheap first attempt
RAGThe documents fetched at answer timeKnowledge changes often or needs citations
Fine-tuningThe model's weightsYou need a consistent style, format or narrow task behaviour
Training from scratchAll weights, from random startYou have very large data and budget

What does fine-tuning mean in AI?

According to IBM (15 March 2024), fine-tuning in machine learning is the process of adapting a pre-trained model for specific tasks or use cases. IBM calls it a subset of the broader technique of transfer learning.

The Google Machine Learning Glossary describes a base model as something that can serve as the starting point for fine-tuning to address specific tasks or applications.

How does fine-tuning work?

You keep the pre-trained weights as a starting point, feed the model examples of the behaviour you want, and nudge the weights with a low learning rate. IBM says this can reduce the expensive computing power and labelled data needed, and that training a large model from scratch on a small dataset risks overfitting.

Full fine-tuning updates every weight. IBM notes that parameter-efficient fine-tuning (PEFT) covers methods that reduce the number of trainable parameters. One such method is LoRA. In the LoRA paper on arXiv (Hu et al., 2021), it freezes the pre-trained weights and injects trainable rank decomposition matrices into each Transformer layer.

The authors report that, compared with GPT-3 175B fine-tuned with Adam, LoRA can reduce the number of trainable parameters by 10,000 times and the GPU memory requirement by 3 times. Those are the authors' own figures for that model.

An illustrative calculation with made-up numbers: a 7-billion-parameter model has 7,000,000,000 trainable values under full fine-tuning. A small adapter might train only a few million, so the optimiser has far less to store.

Pseudo-code, not a runnable library call:

model = load_pretrained("base-model")
for p in model.parameters():
    p.requires_grad = False        # freeze the base weights
adapter = add_small_adapter(model) # only these weights train
for batch in training_examples:
    loss = model(batch).loss
    loss.backward()
    optimizer.step()               # updates the adapter only

Where is fine-tuning used?

It is used when a general model needs to follow a fixed format or tone. An illustrative Indian scenario: a bank support bot must reply in a set structure in Hindi and English. Fine-tuning on about 500 approved replies is a plausible fit for the style, while RAG suits policy documents that change monthly. No figures here are real benchmarks.

Decision rule: try a prompt, add RAG for changing knowledge, and fine-tune only when behaviour stays inconsistent. Compare options in RAG vs fine-tuning vs AI agents and prompt engineering vs RAG vs fine-tuning.

What are the common mistakes?

  • Fine-tuning to add facts. Knowledge that changes is usually better served by retrieval.
  • Using too few or messy examples. Small noisy data can push a model to memorise, which is overfitting.
  • Assuming it is always cheaper. Costs depend on model size and method; none are claimed here.
  • Treating LoRA results as universal. The paper's claim of quality on par with full fine-tuning is the authors' own.

Transfer learning is the parent idea, and RAG is the usual alternative. For background, read the large language models guide, what is prompt engineering and running LLMs locally.

Next step

Write down the behaviour you want, then test whether a good prompt already delivers it. Only if it does not, collect a small set of clean examples to fine-tune on.

Frequently asked questions

What is fine-tuning in AI?

Fine-tuning adapts a pre-trained model to a specific task by training it further on a smaller dataset. It starts from existing weights, so it needs less data and compute than training from scratch.

How is fine-tuning different from training from scratch?

Training from scratch starts from random weights and needs large data and compute. Fine-tuning starts from a pre-trained model, and IBM notes it can reduce the computing power and labelled data needed.

Is fine-tuning the same as RAG or prompt engineering?

No. Prompting changes only the input and RAG changes the documents fetched at answer time. Fine-tuning changes the model's weights.

What is LoRA?

LoRA freezes the pre-trained weights and adds small trainable matrices into each Transformer layer. Its authors report it can cut trainable parameters by 10,000 times compared with GPT-3 175B fine-tuned with Adam.

How much data does fine-tuning need?

It depends on the task and model. IBM says fine-tuning can reduce the labelled data needed compared with training from scratch, but no fixed number applies, so test on a small clean set first.

Share LinkedIn X WhatsApp
×

Our Courses

Practice-Based Learning Tracks, Supercharged By A.I.