Zenaique

Why does dropping the EOS token from SFT labels produce a model that never stops generating?

Flashcard·Easy·4.0 · 0·~30s·Asked atBraintrustJane StreetMongodb·Relevant atCoreweaveDatabricksRunwayStability Ai
Attempt it
TL;DR

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.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

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.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

The EOS token is the smallest piece of a fine-tuned language model and the one most likely to silently destroy its usability in production. The token itself is a single vocabulary entry. Its job is to mean 'the response is complete.' The mechanism by which that meaning gets installed and exploited is precise enough that getting any link in the chain wrong produces a model that never stops generating.

The symptom is unmistakable. A user asks a question, the model produces a believable answer, and then keeps going. Sometimes it produces a hallucinated next user turn. Sometimes it loops on repetitive padding. Sometimes it wanders off into an unrelated tangent. The output stops only when the inference loop hits its max_new_tokens hard cap, often producing several thousand tokens of unwanted text per request.

This deep dive walks through what EOS actually does during training, how the generation loop uses it at inference, the three specific failure modes that produce the never-stops symptom, and the operational hygiene that prevents the bug from ever shipping.

What EOS does during training

Supervised fine-tuning trains the model on a sequence of next-token prediction tasks. For each position in the training sequence, the model produces a probability distribution over the vocabulary, and the cross-entropy loss compares that distribution to the ground-truth next token.

The EOS token sits at the end of every assistant response in the training labels. After the last real content token, the next target is EOS. The loss at that position pushes the model to assign high probability to EOS given everything that came before, which means the model learns to recognise 'this response is now complete' as a context that calls for EOS.

The loss masking detail matters. In chat-style SFT, the typical mask sets the loss to ignore-index on all system and user tokens, contributing gradient only on assistant tokens. The EOS that ends an assistant turn must be inside the assistant-mask span; if the mask boundary places EOS outside (treating it as part of the next user turn or as padding), no gradient flows and the model never learns to emit it.

A correctly trained chat model will, by the end of training, place high probability on EOS at exactly the positions where assistant responses end and lower probability elsewhere. That learned distribution is what makes generation stop at the right time.

How the generation loop uses EOS
The three failure modes and their signatures
Hygiene that prevents the bug from shipping
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

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.
Sign in to see more production examples.

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?
A

Trace the inference-side configuration. The loop's stop list (eos_token_id, stop_strings, eos_token_id_list) must include the exact token ID the model emits; mismatched lists are a common cause of trained models that look broken at serve time.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

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.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • The mechanical role of EOS in the training cross-entropy loss

  • How the inference generation loop uses EOS to exit

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is RLHF, and why is it used after pretraining?
MCQ·Easy