Part V · Putting it together
Ch 15. From predictor to assistant
A chat is still just text
A model trained on web text, a base modelbase model: A model trained only to predict the next token of ordinary text, before any tuning to act as an assistant. Ch 15, just continues whatever it’s given. A chat app writes the whole conversation out as one piece of text, with special markers for who’s speaking, and lets the model continue it. That format is the chat templatechat template: The fixed text format, with special marker tokens, that turns a conversation into one piece of text for the model. Ch 15. Here’s the real one the Qwen2.5 chat models use:[1]
A model trained on web text is a base modelbase model: A model trained only to predict the next token of ordinary text, before any tuning to act as an assistant. Ch 15: it continues whatever it’s given. So how does a chat app get answers out of one? It writes the conversation out as a single piece of text, in a fixed format with special marker tokens, and lets the model continue it. That format is the chat templatechat template: The fixed text format, with special marker tokens, that turns a conversation into one piece of text for the model. Ch 15. Here is the real one used by the Qwen2.5 chat models:[1][1]
The text ends by opening the assistant’s turn, so the likeliest continuation is an answer. When the model writes the end marker, the app stops and shows the reply.
The conversation ends with the marker that opens the assistant’s turn, so the most likely
continuation is an answer. When the model writes <|im_end|>, the chat app stops the loop
from Ch 11 and shows the reply.
Base model or assistant?
Here are the same prompts given to three models: GPT-2; Qwen2.5-0.5B, a small base model from 2024; and Qwen2.5-0.5B-Instruct, the same model after tuning it to be an assistant.
Notice that the base models just continue the text: sometimes they answer, and sometimes they write a quiz or repeat themselves. The tuned model answers and stops, but only when it gets its chat format.
A few things to notice:
- Base models continue text. Asked how to boil an egg, the Qwen base model writes another question and a multiple-choice quiz, the way that question might continue on a web page. GPT-2 repeats itself.
- Modern base models already know a lot. The Qwen base model answers the capital question and writes a haiku. On the web, a question is often followed by its answer, so an answer is a likely continuation.
- The format matters. The tuned model, given the bare question without its chat template, answers and then keeps going: about checking the answer with Python code, or with a stray line of its own template. In its chat format, it answers and stops.
How the tuning works
Turning a base model into an assistant usually takes two more rounds of training, after the long first one. Step through them:
A 2022 paper found that people preferred the answers of a small tuned model over those of a model more than 100 times bigger that it was built from.[2]
A 2022 paper on InstructGPT describes this recipe. People preferred the answers of a 1.3-billion-weight tuned model over those of the 175-billion-weight GPT-3 it was built from.[2][2] Qwen2.5’s tuning used over a million examples in the second stage, followed by several stages of the third.[1][1] Learning from people’s preferences has a catch: people tend to prefer answers that agree with them, so the model learns that too (Ch 16).[3][3]
The three stages, written down
The second stage is the same next-token loss as pretraining, counted only on the example answers. The third trains a reward model to score an answer to a prompt , from pairs where people preferred over :
where turns the gap between the two scores into a chance. The loss is small when the preferred answer scores clearly higher. Then the assistant itself is trained to earn high scores without drifting far from the tuned model it started as:
where is the model being trained, is the model after the second stage, and sets how far it may drift. Without that last term, the model learns to please the reward model in ways people wouldn’t.[2]
Tuning for your own job
Tuning is just more training, and it works for any job: fine-tuningfine-tuning: Training an existing model further on examples of one task, so it does that task better. Ch 15 a model on your own examples teaches it your task and wording. Two tricks make it cheaper. LoRALoRA: Fine-tuning that freezes a model’s weights and trains small add-on tables next to some of its big tables of weights. Ch 15 trains a small add-on instead of changing every weight.[3] Distillationdistillation: Training a smaller model, the student, to copy the outputs of a bigger one, the teacher. Ch 15 trains a small model to copy a big one.[4]
Tuning is just more training, the same measure-and-nudge loop as in Ch 7, and it works for any job, not only chat. Fine-tuningfine-tuning: Training an existing model further on examples of one task, so it does that task better. Ch 15 a model on your own examples, such as support questions with the replies you’d want, teaches it your task, format, and wording. Two tricks make it cheaper:
- Train a small add-on. Changing every weight of a big model takes memory for all of them and a full copy of the model for each job. LoRALoRA: Fine-tuning that freezes a model’s weights and trains small add-on tables next to some of its big tables of weights. Ch 15 leaves the weights alone and trains two thin tables next to some of the big tables of weights; their product is added to the big table. GPT-2 small turns a token’s vector into its query with a 768 × 768 table: 589,824 weights. Two thin tables, 768 × 8 and 8 × 768, hold 12,288 numbers, about 2% as many. On GPT-3, LoRA trained 10,000 times fewer numbers than changing every weight, needed a third of the memory, and did about as well.[4][4]
- Learn from a bigger model. Distillationdistillation: Training a smaller model, the student, to copy the outputs of a bigger one, the teacher. Ch 15 trains a small model, the student, to copy a big one, the teacher. The student can learn from the teacher’s whole list of probabilities (Ch 2), not just from which token came next, so it also learns which other answers were nearly right.[5][5]
In symbols, LoRA replaces a frozen table (here ) with
where is , is , is the small rank (8 above), and is a fixed scale. Only and are trained. starts at all zeros, so training starts from exactly the original model.[4]
Distillation softens both models’ probabilities with a temperature above 1, so the near misses show, and trains the student’s to match the teacher’s :
where the keeps the slopes at the same size whatever is.[5]
Recipe card
Recap
- A chat is written out as one text in a chat template, and the model continues it.
- A base model just continues text; tuning teaches it to answer in the chat format and stop.
- Tuning has two usual stages after pretraining: learning from example answers, then from people’s preferences between answers.
- Fine-tuning trains a model further for your own task. LoRA trains a small add-on instead of every weight; distillation trains a small model to copy a big one’s probabilities.
- Preference tuning trains a reward model with ; LoRA adds a trained to a frozen .
Next question: even tuned assistants sometimes make things up or trip over simple questions. Why?
Sources
- Qwen Team et al. (2024). Qwen2.5 Technical Report. arXiv.
- Long Ouyang et al. (2022). Training language models to follow instructions with human feedback. NeurIPS 2022.
- Edward J. Hu et al. (2022). LoRA: Low-Rank Adaptation of Large Language Models. ICLR 2022.
- Geoffrey Hinton et al. (2015). Distilling the Knowledge in a Neural Network. NIPS 2014 Deep Learning Workshop.
Sources
- Qwen Team et al. (2024). Qwen2.5 Technical Report. arXiv.
- Long Ouyang et al. (2022). Training language models to follow instructions with human feedback. NeurIPS 2022.
- Mrinank Sharma et al. (2024). Towards Understanding Sycophancy in Language Models. ICLR 2024.
- Edward J. Hu et al. (2022). LoRA: Low-Rank Adaptation of Large Language Models. ICLR 2022.
- Geoffrey Hinton et al. (2015). Distilling the Knowledge in a Neural Network. NIPS 2014 Deep Learning Workshop.
Sources
- Qwen Team et al. (2024). Qwen2.5 Technical Report. arXiv.
- Long Ouyang et al. (2022). Training language models to follow instructions with human feedback. NeurIPS 2022.
- Mrinank Sharma et al. (2024). Towards Understanding Sycophancy in Language Models. ICLR 2024.
- Edward J. Hu et al. (2022). LoRA: Low-Rank Adaptation of Large Language Models. ICLR 2022.
- Geoffrey Hinton et al. (2015). Distilling the Knowledge in a Neural Network. NIPS 2014 Deep Learning Workshop.