Why does dropping the EOS token from SFT labels produce a model that never stops generating?
EOS is the stop signal. If training labels never include it, the model never learns to emit it and generation runs until max_new_tokens at inference.
Imagine teaching a child to read aloud, but you never show them what a period looks like or what it means. They will read each sentence into the next sentence without pausing, because nobody ever taught them where a thought is supposed to stop. The EOS token is the period for a language model. The model learns from examples to put it at the end of a complete response, and the generation system watches for it like a listener watching for a pause. If the training data has the period stripped out, the model fluently produces words forever, because it has no idea that stopping is even an option. The fix is always to put the period back into the training labels.
Detailed answer & concept explanation~5 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: define EOS as the stop signal, walk through the training-time and inference-time mechanics, then enumerate the three failure modes (template strip, tokeniser swap, multi-stop mismatch) and the sanity check that catches each.
Real products, models, and research that use this idea.
- Hugging Face TRL's SFTTrainer warns when training examples lack an EOS token at the end of the assistant turn, exactly because the failure mode is so common.
- Llama 4 Maverick fine-tunes use `<|eot_id|>` as the end of turn stop token, which must be both in training labels and in the inference stop_token list.
- Qwen 3.5 fine-tunes that mix chat templates often drop `<|im_end|>` from labels, producing post-deployment models that ramble past the assistant turn.
- DeepSeek V4 distillation runs explicitly include eos_token in the loss-computed span of every example to avoid the never-stops failure mode.
- Production support requests at Hugging Face and Anthropic frequently cite 'model never stops generating' as a top-five fine-tuning bug, traced back to EOS handling almost every time.
What an interviewer would ask next. Try answering before peeking at the approach.
QIf the model emits a stop token but the generation loop does not halt, where is the bug?
QHow does loss masking interact with EOS, and why is this often the silent root cause?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Stripping EOS during dataset preprocessing because it 'looks like padding' and then wondering why the fine-tuned model rambles forever past the end of its response.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.