Recommended resources
The freely available resources this lesson will direct you to.
Hello! In our previous lesson, we established a framework for choosing the right pre-trained LLM by balancing capability, latency, and cost. This is a critical skill for any AI Engineer. However, what happens when no off-the-shelf model perfectly fits your needs? Sometimes, you need to go beyond simply prompting a general-purpose model and adapt it more deeply.
This lesson introduces fine-tuning, the process of taking a pre-trained model and further training it on your own data. Our goal is to understand precisely what fine-tuning is, its primary use cases, and the operational requirements involved. This knowledge is crucial for making strategic decisions in AI system design, particularly when weighing fine-tuning against other techniques like Retrieval-Augmented Generation (RAG), a topic central to your goals.
What is Fine-Tuning?
At its core, fine-tuning is a form of transfer learning. Imagine a seasoned software engineer who knows multiple programming paradigms. To learn a new framework like Svelte or HTMX, they don't start from "Hello, World!" and relearn what a variable or a loop is. Instead, they leverage their vast existing knowledge and adapt it to the specific syntax and concepts of the new framework.
Fine-tuning an LLM works similarly. A base model like Llama 3 or Mistral has already been pre-trained on a massive corpus of public internet data, giving it a broad understanding of language, reasoning, and world knowledge. Fine-tuning takes this powerful base and continues the training process on a much smaller, curated, and task-specific dataset. This doesn't teach the model from scratch; it specializes its existing capabilities.
This is fundamentally different from prompt engineering, where you guide the model with instructions at the time of the request (inference time). Fine-tuning actually changes the model's internal parameters (its weights), durably altering its default behavior.
The Databricks blog post "A Practical Guide to LLM Fine Tuning" provides an excellent overview of this concept.
A Practical Guide to LLM Fine Tuning | Databricks Blog
This article from Databricks clearly defines fine-tuning and contrasts it with prompt engineering, which is the perfect starting point for our discussion.
Read the overview section to grasp the core definition, benefits, and trade-offs. Next, focus on the section Deciding Between Prompting and Fine-Tuning. This addresses the critical first decision you'll face in any project.
When to Fine-Tune: The Primary Use Cases
As an AI Engineer, your most important question isn't "how do I fine-tune?" but "should I fine-tune?". The decision hinges on whether you need to change the model's inherent behavior and style, or simply provide it with new facts.
Fine-tuning excels in these scenarios:
-
Adopting a Specific Style, Tone, or Persona: You want the LLM to consistently write in a specific voice—perhaps your own, or your company's brand voice. Simple instructions in a prompt can be inconsistent, but fine-tuning can bake this style into the model's DNA. The video below gives a fantastic demonstration of this.
-
Learning a New Behavior or Reasoning Pattern: You need the model to follow a complex, structured thought process that is difficult to specify in a prompt. A great example is teaching a model to perform "chain-of-thought" style reasoning for solving math puzzles.
-
Mastering a Domain-Specific Language: If you work in a field like medicine, finance, or law, or even within a company with its own internal jargon, fine-tuning on domain-specific documents can teach the model the nuanced meaning of specialized terminology.
-
Enforcing a Reliable Output Format: While techniques like JSON mode (which we've discussed) are powerful, they can sometimes fail with complex schemas. Fine-tuning on examples of the desired output format can dramatically improve reliability.
This is distinct from merely providing the model with new information. For that, RAG is often the better tool.
RAG vs. Fine-Tuning: The System Design Trade-Off
This is one of the most common system design questions you'll face in an AI Engineer interview. Understanding this trade-off is non-negotiable.
- Retrieval-Augmented Generation (RAG) is about knowledge injection. It's best when you need to provide the model with up-to-date, external, or proprietary information to answer a question. The model's core behavior doesn't change; it just gets more context to work with at inference time.
- Choose RAG when: The knowledge base is volatile and changes frequently (e.g., product inventory, news articles, customer support documents). You need to cite sources and ensure factual grounding.
- Fine-Tuning is about behavior modification. It's best when you want to change how the model responds, regardless of the specific facts.
- Choose Fine-Tuning when: You need to teach the model a new skill, style, or format that is static and can be learned from examples.
The following video and chart provide a clear framework for this decision.
LLM Fine Tuning Crash Course | LLM Fine Tuning Tutorial
The "LLM Fine Tuning Crash Course" video by codebasics offers a simple and effective analogy to distinguish between RAG and fine-tuning.
Watch the segment from retrieval augmented generation to understand the practical differences, benefits, and disadvantages of each approach.
The table below summarizes the decision-making process for various use cases.

It's also crucial to remember that RAG and fine-tuning are not mutually exclusive. They are powerful partners. A common advanced pattern is to fine-tune a model to be better at following instructions or using tools, and then integrate that specialized model into a RAG system.
This graph visualizes the decision space. If your task requires a lot of external knowledge but little model adaptation, RAG is the clear winner. If you need significant behavioral changes but the task doesn't rely on external documents, fine-tuning is the way to go. The hybrid approach shines when you need both.

The Operational Requirements: What Does It Take?
Fine-tuning is a significant step up in complexity from calling an API. As a software engineer, you can think of it as moving from using a third-party library to maintaining your own fork. It involves a distinct process and resource commitment.
1. The Fine-Tuning Process
The workflow generally follows these steps, which require a blend of data engineering and ML operations skills.
A Practical Guide to LLM Fine Tuning | Databricks Blog
This article lays out the end-to-end process in a structured way that will resonate with your engineering background.
First, read the overview of the end-to-end steps. Next, pay close attention to the Data Preparation section. This is often the most labor-intensive part of the entire process. Then, review the section on choosing a base model, which builds on our previous lesson. Finally, read about Evaluation, Deployment, and Monitoring to understand the full lifecycle.
2. Data Requirements
The success of fine-tuning is almost entirely dependent on the quality of your training data. The mantra is "Garbage In, Garbage Out."
- Format: The data must be structured, typically as prompt/response pairs. For instruction-following models, this is a set of
(instruction, output)examples. - Quality: The examples must be high-quality, clean, and accurately reflect the desired behavior. A small set of a few hundred high-quality examples is often better than thousands of noisy ones.
- Quantity: For style or behavior adaptation, you might only need a few hundred to a couple of thousand examples. For teaching substantial new knowledge (which is less common), you would need much more.
3. Compute Requirements (Hardware)
Fine-tuning is computationally expensive.
- You cannot run it on a standard CPU; it requires GPUs (Graphics Processing Units).
- The amount of GPU memory (VRAM) needed depends on the size of the model and the fine-tuning method used. Fine-tuning large models has historically required multiple high-end, enterprise-grade GPUs, costing thousands of dollars.
- However, modern techniques have made this much more accessible, which we'll touch on next.
The Honest Guide To Fine-Tuning Local AI In 2026
The video "The Honest Guide To Fine-Tuning Local AI" provides a candid look at the hardware realities of fine-tuning.
Watch the segment on hardware, which compares the pros and cons of using GPUs from different vendors like Nvidia, AMD, and Apple Silicon for fine-tuning tasks (hardware that you need to fine-tune). This will give you a practical sense of the infrastructure landscape.
A Glimpse into the "How": Modern Fine-Tuning Methods
While we're avoiding deep ML theory, it's important to be familiar with the terminology for two key methods that have revolutionized fine-tuning.
-
Full Fine-Tuning: This is the traditional approach where all of the model's billions of parameters are updated. It's the most powerful method but also the most expensive, time-consuming, and runs the risk of "catastrophic forgetting" (where the model learns the new task but forgets its general abilities).
-
Parameter-Efficient Fine-Tuning (PEFT): This is the modern, more practical approach. Instead of updating all the weights, you freeze the massive base model and train only a tiny fraction of new, additional parameters (called "adapters").
The most popular PEFT technique is LoRA (Low-Rank Adaptation). The codebasics video provides one of the best explanations of how this works without getting bogged down in math. The core idea is that instead of updating a huge weight matrix W, you approximate the update with two much smaller "low-rank" matrices, A and B. You only train A and B, which might represent less than 1% of the total parameters, drastically saving compute and memory.
Building on this is QLoRA, which combines LoRA with Quantization. Quantization is the process of reducing the precision of the model's weights (e.g., from a 32-bit number to a 4-bit number). This massively reduces the model's memory footprint, making it possible to fine-tune very large models on a single, consumer-grade GPU.
LLM Fine Tuning Crash Course | LLM Fine Tuning Tutorial
This video brilliantly explains the concepts behind LoRA and QLoRA, which are essential terms in any modern AI engineering discussion.
First, watch the explanation of LoRA (low-rank adaptation technique). Focus on the intuition of freezing the main weights and training smaller, decomposed matrices. Next, watch the detailed breakdown of Quantization and QLoRA (very efficient). This part is longer, but it walks through the concepts of quantization, normal-float quantization (NF4), and how QLoRA combines these ideas to make fine-tuning incredibly efficient.
Conclusion
You now have a conceptual map of LLM fine-tuning, grounded in the strategic perspective of an AI Engineer. You understand what it is, when to use it versus RAG, and what operational and resource commitments it entails.
Key Takeaways:
- Fine-tuning adapts a model's behavior, style, or implicit knowledge by continuing its training on a custom dataset.
- Use RAG for injecting facts (especially volatile ones) and fine-tuning for modifying skills and style. They are complementary and can be used together.
- The fine-tuning process requires a high-quality dataset of prompt-response pairs, access to GPU compute, and a structured ML operations workflow.
- Modern PEFT methods like LoRA and QLoRA have made fine-tuning dramatically more efficient and accessible by training only a small fraction of parameters and reducing the model's memory footprint.
So far, we have covered advanced prompting, context management, and the high-level strategies of RAG and fine-tuning. In our next module, we will transition from theory to practice and begin building a core RAG system from the ground up. Our first step will be to tackle the crucial task of document ingestion, specifically how to chunk large texts into manageable pieces for effective retrieval.