<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dali Abid on Medium]]></title>
        <description><![CDATA[Stories by Dali Abid on Medium]]></description>
        <link>https://medium.com/@dali-abid?source=rss-57e045a937be------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QeLXTQkW5WmvF7x1RY3oEQ.png</url>
            <title>Stories by Dali Abid on Medium</title>
            <link>https://medium.com/@dali-abid?source=rss-57e045a937be------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:34:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dali-abid/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Before You Fine-Tune an LLM: A Map for When LoRA, RLHF and SFT All Sound the Same]]></title>
            <link>https://dali-abid.medium.com/before-you-fine-tune-an-llm-a-map-for-when-lora-rlhf-and-sft-all-sound-the-same-931ad42314d8?source=rss-57e045a937be------2</link>
            <guid isPermaLink="false">https://medium.com/p/931ad42314d8</guid>
            <category><![CDATA[fine-tuning]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Dali Abid]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 19:01:01 GMT</pubDate>
            <atom:updated>2026-10-29T19:01:01.945Z</atom:updated>
            <content:encoded><![CDATA[<h4>Three questions that sort every fine-tuning method, how to tell if you need fine-tuning at all, and how a base model learns to follow instructions. Part 1 of 3.</h4><p>During an AI internship this summer, my task was to research LLM fine-tuning and turn it into a practical guide that an engineering team could use to choose a method. I’m a data engineering student, and at the start I knew almost nothing about the topic. I opened the first few papers and blog posts and found a wall of names: SFT, LoRA, QLoRA, RLHF, PPO, DPO, GRPO, CPT, distillation, merging. Each source explained one method well. None of them explained how the methods fit together, and I couldn’t find a clear, structured way to learn the field.</p><p>So I built my own. Over about a month, based on my research and some intuition, I came up with a simple way to sort every method by three questions, and used it to write a 23-page visual guide. I’m not a fine-tuning expert: I fine-tuned only small models, to test ideas as I learned. This series is the guided tour of that map, in three parts. This first part covers the foundations: how to think about the choice, when not to fine-tune, and what supervised fine-tuning actually does. I used an AI assistant to help draft and edit this article; the framework, diagrams and checking come from my guide.</p><h3>“Should I use LoRA or RLHF?” is the wrong question</h3><p>Here are two sentences you hear a lot when people talk about fine-tuning:</p><p>“Should we use LoRA or RLHF?”<br>“We tried instruction tuning, then switched to QLoRA.”</p><p>They sound reasonable. They are not. They compare things from different categories, a bit like asking “Should I travel with a passport or an airplane?” You need both, and they do different jobs.</p><p>The way I organized the field is to notice that every fine-tuning decision answers three separate questions:</p><p><strong>1. Goal.</strong> What should the model do better after training? Follow instructions, know a domain, give safer answers, solve maths problems.</p><p><strong>2. Data strategy.</strong> What kind of signal can teach that? Example answers to copy, pairs of answers where one is better, or a checker that says right or wrong.</p><p><strong>3. Compute technique.</strong> How do we actually change the model? Update every weight, or freeze the model and train a small add-on.</p><figure><img alt="On the left, a tangle of method names (LoRA, RLHF, DPO, SFT, QLoRA, PPO). An arrow points to three buckets labeled Goal, Data Strategy and Compute Technique." src="https://cdn-images-1.medium.com/max/1024/1*8w0pGl4rqIEVbuau3UfM0Q.jpeg" /><figcaption>The same method names, sorted into three questions. Diagram from my fine-tuning guide, generated with an AI image tool from my prompt.</figcaption></figure><p><strong>Caption:</strong> The same method names, sorted into three questions. Diagram from my fine-tuning guide, generated with an AI image tool from my prompt.</p><p><strong>Alt text:</strong> On the left, a tangle of method names (LoRA, RLHF, DPO, SFT, QLoRA, PPO). An arrow points to three buckets labeled Goal, Data Strategy and Compute Technique.</p><p>Now look at LoRA and RLHF again. LoRA is a compute technique: it freezes the model and trains small extra matrices. RLHF is a data strategy: it turns human preferences into a training signal. They answer different questions, so you don’t pick one. You can run RLHF with LoRA adapters.</p><p>The same goes for the most common confusion of all: “LoRA or SFT?” SFT (supervised fine-tuning) is what the model learns from: example answers. LoRA is how the update is stored. Asking which one to use is like asking “engine or steering wheel?” In practice, a lot of fine-tuning today is SFT done with LoRA.</p><p>Once I started labeling each method with its three answers, the field stopped looking like a random pile of acronyms. Every later method in this series fits somewhere on this map.</p><h3>First question: do you need to fine-tune at all?</h3><p>Before choosing a method, it’s worth asking whether training is the right tool. This question can save more time than any training trick.</p><p>New knowledge or behavior can live in three places.</p><p><strong>The prompt.</strong> You give clearer instructions or a few examples when you make the request. Nothing is trained. This is often called in-context learning.</p><p><strong>An external database (RAG).</strong> RAG means retrieval-augmented generation. When a question arrives, the system searches your documents and puts the relevant passages into the prompt. The model’s weights don’t change. You can update the documents at any time, and the answer can cite them.</p><p><strong>The model’s weights (fine-tuning).</strong> Training changes the parameters, or adds trained parameters such as adapters. The new behavior stays for every request, without extra instructions.</p><figure><img alt="A model in the center connected to three cylinders: Model Weights (fine-tuning), External Database (RAG), and The Prompt (in-context learning), each with a one-line description." src="https://cdn-images-1.medium.com/max/1024/1*h1cZsW4ZxGoRiWoasczFdg.jpeg" /><figcaption>Where data can live: in the weights, in an external database, or in the prompt. Only the first one is fine-tuning. Diagram from my guide, generated with an AI image tool from my prompt.</figcaption></figure><p><strong>Caption:</strong> Where data can live: in the weights, in an external database, or in the prompt. Only the first one is fine-tuning. Diagram from my guide, generated with an AI image tool from my prompt.</p><p><strong>Alt text:</strong> A model in the center connected to three cylinders: Model Weights (fine-tuning), External Database (RAG), and The Prompt (in-context learning), each with a one-line description.</p><p>So the useful question is: what exactly is failing?</p><p>If the model doesn’t know a company document from last week, fine-tuning is a poor fit. Facts change, and a fact stored in the weights is hard to update and impossible to cite. RAG is built for this.</p><p>If the answers come back in the wrong format, try a clearer prompt or an output validator first. Many format problems disappear there.</p><p>If the model needs a lasting change in behavior, such as a skill, a style or a way of answering that must hold for every request, fine-tuning starts to make sense.</p><p>These options also combine. Many real systems use RAG for current facts and fine-tuning for how to answer. The rule I took from this part of the guide is simple: start with the smallest change that solves the problem you actually measured.</p><h3>Where a base model’s skills come from</h3><p>To understand what fine-tuning changes, it helps to know what it starts from.</p><p>A large language model begins as a base model. It is trained on a huge collection of text with one task: read a sequence and predict the next token (a word or part of a word). Each wrong prediction slightly updates the parameters. After enough examples, the model has learned useful patterns of language, facts and reasoning. It doesn’t store them like a searchable database; they are spread across billions of weights.</p><p>This is why fine-tuning works with relatively little data. You are not teaching from zero. You are redirecting abilities that pre-training already built. GPT-1 and BERT made this pattern standard for language models around 2018: pre-train once on general text, then adapt to a task with a much smaller dataset. That reuse of earlier learning is called transfer learning.</p><p>The base model has one big gap, though. It is very good at continuing text. It is not reliably good at doing what you ask. We’ll come back to that gap in a moment, because it is the reason SFT exists.</p><h3>When the whole domain is the problem: continued pre-training</h3><p>Sometimes a model writes good general English but struggles with a specialized field: medical notes, legal contracts, financial filings. If the weakness shows up across many different tasks in the same domain, a few thousand question-and-answer examples may not be enough. The problem is broader than one task.</p><p>One option is continued pre-training (CPT). You keep doing the same next-token training, but on a large collection of domain text. It moves the model toward the vocabulary, style and patterns of that field. The paper “Don’t Stop Pretraining” (Gururangan et al., 2020) tested two versions:</p><ul><li><strong>DAPT</strong> (domain-adaptive pre-training) uses broad text from the domain.</li><li><strong>TAPT</strong> (task-adaptive pre-training) uses unlabeled text that is close to the specific task.</li></ul><p>Both improved downstream results in their experiments.</p><figure><img alt="A domain corpus and an optional general-data mixture feed a base model, which is trained with the language-model objective into an adapted checkpoint. Two outputs: domain performance may improve, and retained capabilities must be tested." src="https://cdn-images-1.medium.com/max/1024/1*EaduPqYeDvhr_0YmXgg4Ug.jpeg" /><figcaption>Continued pre-training shifts a base model toward a domain. Whether old abilities survive has to be tested. Diagram from my guide, generated with an AI image tool from my prompt.</figcaption></figure><p><strong>Caption:</strong> Continued pre-training shifts a base model toward a domain. Whether old abilities survive has to be tested. Diagram from my guide, generated with an AI image tool from my prompt.</p><p><strong>Alt text:</strong> A domain corpus and an optional general-data mixture feed a base model, which is trained with the language-model objective into an adapted checkpoint. Two outputs: domain performance may improve, and retained capabilities must be tested.</p><p>CPT has two risks that I now check first.</p><p><strong>Tokenization.</strong> The tokenizer splits text into tokens. Specialized terms can be cut into many small pieces, which makes sequences longer and training less efficient. Adding new tokens to the vocabulary is possible, but it is optional and comes with work: new embeddings to learn and compatibility checks. Only do it if a tokenization audit shows a real benefit.</p><p><strong>Forgetting.</strong> Training on a narrow corpus can make the model worse outside that domain. This is called catastrophic forgetting. Mixing some general data into training and using smaller updates can help, but there is no universal mixing ratio. You have to measure what the model could do before and after.</p><p>Also, CPT does not guarantee that the model will remember every fact in the corpus exactly. If you need exact, current, citable facts, that is still a job for RAG.</p><p>The way I separate them now: CPT changes how the model understands a domain. RAG gives it documents it can point to. Many domain systems need both.</p><h3>“It autocompletes; it doesn’t obey”: supervised fine-tuning</h3><p>Here is the gap I mentioned. Ask a base model:</p><p>“Write a short poem about autumn.”</p><p>It might write the poem. It might also write another request, as if it were continuing a list of writing prompts it once saw. Pre-training taught it to predict likely text, not to act as an assistant. It has the language ability, but not a reliable habit of using it when asked.</p><p>Supervised fine-tuning (SFT) builds that habit with examples. Each training example is a conversation: a user message, then a good assistant answer. After thousands of them, the model learns that when a user asks for something, the next text should be the answer. This was the first stage of the InstructGPT pipeline that later became the standard recipe for chat assistants.</p><p>Under the hood, SFT is still next-token prediction, the same objective as pre-training. What changes is the data, and three details decide whether it works.</p><h4>1. The chat template</h4><p>Each example is wrapped in special tokens that mark who is speaking: system, user, assistant, and the end of each turn. This wrapping is the chat template.</p><p>The template used in training must match the one used in production exactly: the same tokens, the same order, the same end-of-turn markers. A mismatch is one of the worst bugs in fine-tuning because nothing crashes. The model just answers worse, and you may not know why.</p><h4>2. Loss masking</h4><p>The model reads the whole conversation during training, but we usually don’t want it to learn to imitate the user. So in a common setup, the error (the loss) is measured only on the assistant’s tokens. The user’s words stay in the input as context, but they don’t count toward the score.</p><figure><img alt="A training example with three blocks wrapped in role tokens: a system message, a crossed-out user message labeled “masked, not graded”, and an assistant answer labeled “graded, loss here”. A note says assistant-only loss is common for chat but not universal." src="https://cdn-images-1.medium.com/max/1024/1*XdErpeo7J8z5HQ_9KVE5vA.jpeg" /><figcaption>One SFT training example. The user turn is context only; the assistant turn is where the loss is measured. Diagram from my guide, generated with an AI image tool from my prompt.</figcaption></figure><p><strong>Caption:</strong> One SFT training example. The user turn is context only; the assistant turn is where the loss is measured. Diagram from my guide, generated with an AI image tool from my prompt.</p><p><strong>Alt text:</strong> A training example with three blocks wrapped in role tokens: a system message, a crossed-out user message labeled “masked, not graded”, and an assistant answer labeled “graded, loss here”. A note says assistant-only loss is common for chat but not universal.</p><p>This is called assistant-only loss masking. It is common for chat models, but it is a choice, not a rule. Other tasks may compute the loss on the full sequence or on custom parts of it. The mask should match what the model will have to generate in production.</p><h4>3. Data quality over data size</h4><p>The model can only learn patterns that exist in its examples. If every example has the same task or format, it will struggle when a request looks different.</p><p>The LIMA paper (Zhou et al., 2023) reported strong results from only 1,000 carefully selected examples. That is not a magic number, and it doesn’t prove that more data is worse. What it shows is that curation matters. In practice that means removing duplicates, covering different kinds of tasks, and checking that no test questions leaked into the training set, because leaked test questions make the evaluation look better than the model really is.</p><p>Two data strategies are commonly used to improve coverage. Instruction tuning mixes many different tasks written as instructions, which can help the model handle instructions it never saw in training (FLAN is a well-known example). Reasoning traces show intermediate steps before the final answer, which can help on some multi-step problems. One caution I keep in mind: the written steps are generated text. They are not guaranteed to show how the model actually reached the answer.</p><h3>What SFT can’t do</h3><p>SFT gives the model one target answer per prompt. For many tasks that is fine. But for a request like “Explain quantum entanglement to a 12-year-old,” there are many acceptable answers. Some are clearer, safer or more useful than others.</p><p>SFT has no easy way to say “this answer is better than that one.” It can only say “copy this.” Teaching relative quality needs a different data strategy, preference data, and that is where RLHF and DPO come in.</p><p>There is also a practical cost problem. Updating every weight of a large model takes a lot of memory, and it can damage abilities the model already had. That is what LoRA and QLoRA address.</p><p>Both are the topic of Part 2.</p><h3>A short decision checklist</h3><p>This is the version I keep next to me when someone asks “should we fine-tune?”</p><ul><li><strong>Name the failure.</strong> Collect real examples of what goes wrong before choosing anything.</li><li><strong>Try the smallest fix.</strong> A clearer prompt for format, RAG for current or citable facts, a tool or workflow change for actions.</li><li><strong>If training is justified, answer the three questions separately.</strong> Goal, data strategy, compute technique.</li><li><strong>Broad weakness across a whole domain?</strong> Consider continued pre-training, and measure forgetting.</li><li><strong>The model has the skill but doesn’t follow requests?</strong> SFT with a matching chat template and a deliberate loss mask.</li><li><strong>Decide how you’ll measure success before training,</strong> including what the model could already do.</li></ul><h3>Next in this series</h3><p>Part 2: Cheaper and Better: LoRA, QLoRA, RLHF and DPO Explained. [LINK when published]<br>Part 3: Synthetic Data, GRPO, Merging, and How to Plan a Fine-Tuning Project. [LINK when published]</p><p>If you want the full detail now, the complete guide is free to read. This article covers its Parts 0 to 2:</p><ul><li>The Map (start here): <a href="https://claude.ai/code/artifact/5c8ad1c9-9f44-4570-ab37-9d81af8b4e41">https://claude.ai/code/artifact/5c8ad1c9-9f44-4570-ab37-9d81af8b4e41</a></li><li>Part 0, Choosing How to Adapt an LLM: <a href="https://claude.ai/code/artifact/8b07cf72-dcee-4229-9107-145c8b562fbc">https://claude.ai/code/artifact/8b07cf72-dcee-4229-9107-145c8b562fbc</a></li><li>Part 1, Pre-Training and Domain Adaptation: <a href="https://claude.ai/code/artifact/74a5ba54-240e-45ca-a637-0e5d0d0ca0c4">https://claude.ai/code/artifact/74a5ba54-240e-45ca-a637-0e5d0d0ca0c4</a></li><li>Part 2, Supervised Fine-Tuning: <a href="https://claude.ai/code/artifact/370fd240-ed5a-4f21-bc46-715f9e835417">https://claude.ai/code/artifact/370fd240-ed5a-4f21-bc46-715f9e835417</a></li></ul><p>I built the guide during my AI internship. Thank you to the company and to my supervisor for their support.</p><h3>References</h3><p>[1] A. Radford, K. Narasimhan, T. Salimans and I. Sutskever, Improving Language Understanding by Generative Pre-Training (2018), OpenAI</p><p>[2] J. Devlin, M. Chang, K. Lee and K. Toutanova, BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding (2019), NAACL</p><p>[3] S. Gururangan, A. Marasović, S. Swayamdipta, K. Lo, I. Beltagy, D. Downey and N. A. Smith, Don’t Stop Pretraining: Adapt Language Models to Domains and Tasks (2020), ACL</p><p>[4] J. Wei et al., Finetuned Language Models Are Zero-Shot Learners (2022), ICLR</p><p>[5] L. Ouyang et al., Training Language Models to Follow Instructions with Human Feedback (2022), NeurIPS</p><p>[6] C. Zhou et al., LIMA: Less Is More for Alignment (2023), NeurIPS</p><p>[7] J. Wei et al., Chain-of-Thought Prompting Elicits Reasoning in Large Language Models (2022), NeurIPS</p><p>[8] M. Turpin, J. Michael, E. Perez and S. Bowman, Language Models Don’t Always Say What They Think (2023), NeurIPS</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=931ad42314d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>