# Fine-Tuning

> The Fine-Tuning is a technique of additionally training a pre-trained model on specific data to adapt it to a task.

## What is fine-tuning an LLM and when should I use it?

The technique of additionally training a ready model on a smaller specialized dataset to adapt its style, format or domain knowledge. It is more expensive than prompting or RAG and is used when they are not enough.

- Topic: Training & Architecture
- Type: technique

## Example

Wrong:

```json
{
  "messages": [
    {"role": "user", "content": "Refund order 123"},
    {"role": "assistant", "content": "Sure, done!"}
  ]
}
```

Right:

```json
{
  "messages": [
    {"role": "system", "content": "You are the shop support agent. Reply in JSON."},
    {"role": "user", "content": "Refund order 123"},
    {"role": "assistant", "content": "{\"action\": \"refund\", \"orderId\": \"123\"}"}
  ]
}
```

The training example uses the same system prompt and output format as production, so the model learns the real task.

## Common mistakes

- Fine-tuning to teach new facts when retrieval with RAG would be cheaper and easier to update.
- Fine-tuning before trying a better prompt or a few examples in the prompt.

## Key points

- Training examples use the same format and system prompt the app sends in production.
- A held-out evaluation set compares the fine-tuned model against the base model.
- Training data contains no secrets or personal data that the model could repeat.

## Interview questions

### Fine-tuning vs RAG: which should I use?

Use RAG to give a model facts that change or must be cited. Use fine-tuning to change style, format or behavior on a narrow task.

### How much data do I need to fine-tune a model?

Often hundreds to a few thousand high-quality examples are enough for a narrow task. Quality and consistency matter more than volume.

### What is LoRA?

LoRA is a parameter-efficient fine-tuning method that trains small extra matrices instead of all weights, which cuts memory and cost.

## Related cards

- [RAG](https://wonderium.dev/ai/rag.md)
- [Few-Shot Prompting](https://wonderium.dev/ai/few-shot-prompting.md)
- [Post-Training](https://wonderium.dev/ai/post-training.md)
- [Evals](https://wonderium.dev/ai/evals.md)
- [Distillation](https://wonderium.dev/ai/distillation.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/fine-tuning
- Last updated: 2026-11-25
