An exercise to try
Debug one training row
A training row, one example in a fine-tuning file, can look fine and still teach the model nothing. Reading it the way the training software sees it, part by part, is the cheapest check before a run.
- Time
- 15 minutes
- What you need
- This page, a place to write and simple addition. No chatbot or code is needed.
Illustration. The row, its markers and every token count are invented teaching material. Real chat templates use their own markers, and real counts come from the model's tokenizer. The 990-token system part belongs to this one training row. The 2,500-token block on the Prompt caching and What a reply costs pages is a separate invented example of what a live service sends with every question, so the two numbers are not meant to match.
The row in the file
One example from a training file for the library assistant has three messages:
- System: the assistant's instructions, followed by all six passages of the library notice, D1 to D6.
- User: “Can I renew a book that another member has reserved?”
- Assistant: “No. A borrowed book can be renewed twice, for two weeks each time, unless another member has reserved it [D4].”
The row as the training software sees it
A chat template, the model's fixed recipe for laying out a conversation, turns the messages into one sequence of tokens, the pieces of text a model reads, with markers for who is speaking and where each turn ends. The tokenizer, the program that cuts text into tokens, sets the counts. Here is that sequence, part by part.
| Part, in order | Tokens |
|---|---|
| 1. Start-of-text marker | 1 |
| 2. <|system|> marker | 1 |
| 3. Instructions and passages D1 to D6 | 990 |
| 4. <|end|> marker | 1 |
| 5. <|user|> marker | 1 |
| 6. The question | 28 |
| 7. <|end|> marker | 1 |
| 8. <|assistant|> marker | 1 |
| 9. The answer | 32 |
| 10. <|end|> marker | 1 |
Two settings of the training run, the job that updates the model from the file, matter:
- Assistant-only loss. This is loss masking, choosing which tokens count. Only the assistant's reply and the end marker after it count toward the loss, the penalty training reduces. Everything else is read as context and scores nothing.
- Maximum length of 1,024 tokens. A longer row is cut, and the cut keeps the start. That length and that cut are the defaults in the TRL training library, the same in version 1.16, as the long read gives, and in version 1.18.1, checked 19 November 2026 (TRL docs); other tools differ, so check yours.
Step 1. Add up the row
What is the row's total length in tokens, and how far over 1,024 is it?
Step 2. Mark what survives the cut
The training software keeps the first 1,024 tokens. Which parts are dropped?
Step 3. Mark what teaches the model anything
Among the tokens that survive, which count toward the loss? How many is that?
Step 4. Fix it
Write two fixes and what each one costs.
Check your work
- Step 1. The row is 1,057 tokens: 990 + 28 + 32 for the text, plus 7 markers. That is 33 over the limit.
- Step 2. Everything up to and including the <|assistant|> marker is exactly 1,024 tokens: 990 + 28 for the text, plus 6 markers. The cut drops the last 33, which are the whole answer (32) and its end marker (1).
- Step 3. None. The only scored parts were the answer and its end marker, and both were cut. The row costs training time, teaches nothing, and nothing in the file looks wrong.
- Step 4. Raise the maximum length to at least 1,057, which needs more memory for long rows. Or shorten the system part, but only if the assistant will see the same shorter context in use, since training on a context it never meets teaches the wrong situation. Or drop the row. Then count how many other rows have a prompt that alone fills the limit: one such row usually means more.
- Common wrong answer. Switching off loss masking so the row scores something. The row would then teach the model to reproduce the instructions and the notice, not to answer, and the answer would still be cut.
Try a different case
Shorten the instructions so part 3 is 974 tokens. The question, the answer and the markers stay the same. What survives the cut now, and what does this row teach?
Check this one too
Everything before the answer is now 1,008 tokens (974 + 28, plus 6 markers), which leaves room for 16 more. The first 16 of the answer's 32 tokens survive and are scored, and the end marker is cut. The row teaches half an answer and never shows where an answer stops, and the end marker is how a model learns to end its replies.
Where this sits: Chat template and Loss masking explain the two ideas, and the long read's What a training example looks like does the same sum on a row that just fits. Then read Held-out test set.
Read next: Held-out test set