Pretraining a Large Language Model
The model is not built from scratch in this step.
Why a Trained Model Still Needs Adapting
Imagine you want a program that can write fluent sentences. You could try writing rules for grammar and word choice by hand, but language is too varied for that to work. A different approach is to let a model learn patterns from a large body of text and then use what it learned to generate new text. The process of building that learned starting point is called pretraining. It is the stage where a model is first trained on text before anyone asks it to do a specific job.
What do you think happens?
A pretrained LLM has already been trained on a large body of text. Can it reliably follow a person's instruction, such as 'Summarize this paragraph in one sentence'?
Reveal answer
No. Training alone does not tell a pretrained LLM how to respond to a person who gives it an instruction.
This gap is the reason instruction fine-tuning exists. The process adapts the model so that it can follow human instructions and produce the responses people want.
The process that closes this gap is instruction fine-tuning. This article focuses on the process itself: what goes into it, what happens during it, and what the model looks like afterward. Throughout, keep one idea in mind. The model is not built from scratch in this step. It starts from a pretrained LLM and is adjusted so that its behavior shifts toward following instructions.
Defining Instruction Fine-Tuning
Instruction fine-tuning adapts a pretrained LLM to follow human instructions and generate desired responses.
The key word in this definition is adapting. The definition names two outcomes: the model follows human instructions, and it generates the responses that were desired. Both outcomes are about behavior. The model is not given new facts from scratch; its existing behavior is shifted in a particular direction.
Tracing the Model Through Fine-Tuning
The easiest way to picture instruction fine-tuning is to follow the model from its starting state to its finished state. The model's state is its set of learned weights. Before fine-tuning, the weights hold what pretraining produced. During fine-tuning, the training loop runs on instruction data and nudges those weights. After fine-tuning, the weights are the changed state, and the model is the one that follows human instructions.
Read the diagram from left to right. The pretrained model and the fine-tuned model are the same kind of object at different points in the process. The difference is the state each one is in. The only node marked as changed at the end is the fine-tuned LLM, because its behavior has been shifted toward following human instructions.
The Three Ingredients of the Process
Instruction fine-tuning combines three ingredients: a pretrained model, an instruction dataset, and a training loop. Each one plays a distinct role, and the process cannot be understood without all three. The sections below describe each ingredient in turn.
Comparing the Two Training Loops
The source states that the pretrained model is fine-tuned on the instruction dataset using a training loop similar to the one used in pretraining. This means the mechanics are familiar. The model is run through training iterations, just as it was during pretraining. The loop repeats a sequence of steps: a forward pass, a loss computation, a backward pass, and a weight update. Each pass through these steps adjusts the weights a little.
The steps above are the same in both stages. What differs is the data. Pretraining was the first training stage, and it learned from text. Instruction fine-tuning continues training on instruction data, with the aim of changing the model's behavior toward following instructions. So the procedure stays the same while the data and the goal change.
Tracing one fine-tuning iteration
A pretrained LLM is about to receive one batch of instruction examples. Trace what the training loop does to its state for that batch.
- 1Start state
The model holds the weights produced by pretraining. It has not yet seen any instruction examples in this process.
- 2Forward pass
The model is run on the instruction examples in the batch. This is the same kind of step used during pretraining, but the inputs now come from the instruction dataset.
- 3Loss and backward pass
The loop measures how far the model's output is from the desired output, then works backward through the model to find how the weights should change.
- 4Weight update
The weights are adjusted a small amount. The model's state has now changed slightly, moving toward instruction-following behavior.
- 5Repeat
The loop continues with further batches. After many iterations, the accumulated changes produce the fine-tuned model.
The pretrained model ends as a fine-tuned model. The procedure matches pretraining, and the change in state comes from training on instruction data.
Pretraining in the Course Path
In this course, pretraining is treated as the second major stage of work. The first stage prepares the ingredients: data preprocessing and the attention mechanism at the core of modern LLMs. The second stage puts those ingredients together, showing how to code and pretrain a GPT-like model that can generate new text, and then how to evaluate the result. Keeping these stages in mind helps you see why each topic exists.
Read the diagram from left to right. The first two steps belong to stage 1 and concern preparing data and understanding attention. The pretraining step belongs to stage 2. The branch for loading open model weights sits beside pretraining because it is an alternative way to reach a trained model without running the full training yourself. Both routes end at evaluation.
Preprocessing and Attention as Foundations
Data preprocessing is a crucial step in pretraining an LLM. Raw text is rarely in the shape a model can learn from directly, so it has to be prepared first. Preprocessing is the part of the workflow that turns collected text into training material. Because every later step depends on this preparation, it is worth understanding before you move on to the model itself.
The attention mechanism is the second ingredient from stage 1. The source describes it as being at the heart of every LLM, and it is the component the course asks you to code yourself. Think of attention as the part of the model that lets each position in a sequence take other positions into account when it builds its representation. Stage 1 builds this mechanism in isolation, so that stage 2 can use it as a working part rather than a mystery.
Training From Scratch Versus Loading Weights
There are two routes to a trained model. You can pretrain one yourself, or you can load openly available model weights that someone else produced. Pretraining an LLM from scratch is a significant undertaking. The source states that training a GPT-like model from scratch costs thousands to millions of dollars. That range is wide, so the practical lesson is that full-scale pretraining is a major commitment rather than a routine exercise.
| Aspect | Training from scratch | Loading openly available weights |
|---|---|---|
| Cost | Thousands to millions of dollars for GPT-like models, according to the source | Described as an alternative route, without the full training cost of the first route |
| Purpose in this course | Stage 2 focuses on implementing training for educational purposes with a small dataset | Reaches a trained model without running the full training yourself |
| Where the learned values come from | Your own training run | Weights produced elsewhere |
| Evaluation required | Yes | Yes, because the weights came from elsewhere and their behavior in your setting is not assumed |
Two routes to a trained model, as described in the source
This cost is the reason the course narrows its goal. Instead of pretraining at full scale, stage 2 implements training for educational purposes using a small dataset. The purpose is to understand how the process works, not to reproduce a large production model.
Why Evaluation Is Required
The third topic in stage 2 is evaluating LLMs. The source describes this as essential for developing capable NLP systems. A trained model is a set of learned values, and those values alone do not tell you whether the model produces good text. Evaluation is the step that measures what the model does, so that you can compare versions and decide what to change.
Evaluation applies to both routes. A model you pretrain on a small dataset needs to be evaluated, and so does a model whose weights you loaded from an open source. Because the weights in the second case came from elsewhere, you cannot assume they behave as you expect in your own setting. Measuring is how you find out.
Mistakes When Thinking About Pretraining
Common mistake Assuming a pretrained model already follows instructions
What it looks likeGiving a pretrained model a request and expecting a reliable, instruction-shaped answer.
Why it failsTraining alone does not tell a pretrained LLM how to respond to a person who gives it an instruction.
Do this insteadTreat instruction fine-tuning as the separate step that adapts the model to follow instructions.
Common mistake Thinking fine-tuning builds a model from scratch
What it looks likeDescribing instruction fine-tuning as creating a new model with a new architecture.
Why it failsThe model starts from a pretrained LLM and is adjusted, not built from scratch.
Do this insteadDescribe fine-tuning as adapting an existing pretrained model.
Common mistake Believing the fine-tuning loop is a completely different procedure
What it looks likeAssuming fine-tuning needs a new learning algorithm.
Why it failsThe source states fine-tuning uses a training loop similar to the one used in pretraining.
Do this insteadFocus on what changes: the data and the goal, not the basic mechanics of the loop.
Common mistake Skipping evaluation when weights are loaded from an open source
What it looks likeUsing downloaded weights directly without measuring their behavior.
Why it failsEvaluation is required on both routes, and the weights' behavior in your setting is not assumed.
Do this insteadAlways evaluate the model once it has been built or loaded.
Common mistake Treating full-scale pretraining as a routine exercise rather than a major commitment
Practice Tracing a Model's State
A team starts with a pretrained LLM, runs its training loop on an instruction dataset for many iterations, and then deploys the result. Describe the model's state at three points: before fine-tuning, during fine-tuning, and after fine-tuning. For each point, say which ingredients are involved and whether the weights have changed. Then explain why the team must still evaluate the model before relying on it.
Hints
- Recall that the model's state is its set of weights, and that the state changes only through the training loop.
- Think about which of the three ingredients is present at each point: the pretrained model, the instruction dataset, and the training loop.
- Consider what the source says about evaluation: a trained model's learned values alone do not tell you whether it produces good text.
Key Takeaways
- Instruction fine-tuning adapts a pretrained LLM to follow human instructions and generate desired responses, starting from the pretrained model rather than building from scratch.
- The process combines three ingredients: the pretrained model, the instruction dataset, and a training loop. The fine-tuned LLM is the changed state at the end.
- The fine-tuning training loop is similar to the pretraining loop; what differs is the data and the goal of the training.
- In this course, pretraining is the second major stage, built on data preprocessing and the attention mechanism. Training from scratch is costly, so the course focuses on a small educational dataset, and both that route and loading open weights require evaluation.