LLMs, GenAI, RAG, agents, evaluation · insight-1628
Check which tokens carry loss before supervised fine-tuning, because the default depends on data format
- Evidence type
- practitioner heuristic
- Difficulty
- easy
- Roles
- Applied AI, Data scientist
- Industries
- banking, public-sector
Summary: situation, action, reason, boundary
Situation
An instruction-tuning set is loaded into a trainer and the same recipe is reused with a different dataset layout.
Action
Make loss masking explicit in the config: prompt-completion or assistant-only loss for chat data. Print one tokenised example with its label mask and confirm that only response tokens, including the end-of-turn token, are unmasked.
Reason
In TRL's SFT trainer, prompt-completion datasets compute loss on the completion only by default, while plain text datasets use the full sequence; assistant-only loss also needs a chat template with generation markers.
Boundary
Any supervised fine-tune or LoRA run on instruction, chat or extraction data.
Symptom or risk
The model is silently trained to predict the long, repeated system prompt and user text as well as the answers, wasting capacity and shifting behaviour.
Exceptions
Continued pretraining on raw domain text, where the full sequence is the target.
Trade-offs
Training on prompts can help when the input style itself must be learned, but it should be a deliberate choice.
Pitfalls
Trusting an old flag name after a library upgrade, or a template that lacks the end-of-turn token so generation never stops.
Lessons and concepts
Claims and their sources
In the TRL SFT trainer documentation, loss defaults to completion tokens for prompt-completion datasets and to the full sequence for language-modelling datasets, and assistant_only_loss needs a chat template with generation keywords.