MLGuerrillaStart M1 →
Free · in beta·intermediate·M41·60 min read·Prereq: Fine-Tuning Fundamentals (M21), which covers the training loop, adapters, dataset splits and reading a training run. The Model as a Component (M4) covers tokens and calling an LLM.

Fine-Tuning LLMs

The capability

What fine-tuning an LLM is

As you already know from M4, an LLM writes text one token at a time, and each token is its best guess at what comes next, based on everything that came before it. During pretraining it learned to guess the next token on a huge pile of internet text, and then the lab trained it some more on conversations so that it answers questions and follows instructions. That second stage is fine-tuning too, and it's pretty much the same thing you do when you fine-tune an LLM yourself, just with your own examples and a lot fewer of them.

M21 covered the parts that are the same for every kind of model, from the training loop all the way to reading a training run. What's different about LLMs is the kind of training signal you can give them.

The first one is supervised fine-tuning, which people usually shorten to SFT. Each training example is a prompt plus the response you wanted, and you train the model to make that response more likely, one token at a time. It's by far the most common kind, and it's what you use when you can show the model what a good answer looks like.

The second one is preference tuning. Here each example is a prompt with two responses, where one is marked as better than the other, and you train the model to make the better one more likely than the worse one. You'd use it when people can't easily write the perfect answer themselves but can reliably tell you which of two answers they prefer, and that turns out to be the situation with most questions of style and tone.

The third one is training against a grader, which you'll often see called reinforcement fine-tuning. The model writes its own responses, then a piece of code or another model scores each one, and training pushes the model toward the responses that scored well. You use it when you can check correctness automatically, like whether the SQL the model generated runs and returns the right rows.

Three kinds of training example for an LLM, side by side. Supervised fine-tuning shows one prompt, describe this nightstand, paired with one written response, and the model is trained to make that response more likely. Preference tuning shows the same prompt with two responses, a short specific one marked better and a generic one marked worse, and the model is trained to prefer the better one. Training against a grader shows the model writing four responses of its own, a grader scoring them pass or fail, and training pushing toward the ones that passed, which is highlighted.
Most projects start with supervised fine-tuning, and many never need anything else.

All three of them change how the model behaves, and none of them reliably teach it new facts, for the reasons M21 gave. They're also all ways of pushing a model toward one job, so if you fine-tune a model hard on product descriptions, it can get worse at things you didn't train it on, and that's what M21 called forgetting.

Some places it shows up

  • Cutting cost by distillation, where a large model's answers become the training data for a small one that then does the same job for a fraction of the price. Relist's title writer in M21 was one.
  • A house voice or format that a prompt only gets right most of the time, like support replies in a company's tone or reports with a fixed structure.
  • Tool calls for your own API, where a small model learns which of your functions to call and with which arguments, which M18 covers from the prompting side.
  • Domain language, like clinical notes or legal clauses, where the words and the structure are unusual, as long as what the model needs to know still comes from retrieval.

Keep reading

The rest of this lesson is free with an account

Create a free account to read the remaining 14 sections. It takes about twenty seconds and there's nothing to pay. The same account opens the slide decks and CV reviews.

  1. 02Relist's description writer said the right things in the wrong way
  2. 03Format every example the way the model will see it, and train only on the answer
  3. 04Choose the model you start from, then the LoRA settings
  4. 05Build the training dataset from the outputs you'd want to ship
  5. 06Use preference pairs when people can judge an answer better than they can write one
  6. and 9 more

That's the last one written so far

Pick your next module from the board.

All modules →