`max_seq_len` controls one bound, what happens to examples that exceed it?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
max_seq_len caps token count per training sequence; overlong examples are right-truncated by default, which silently chops the assistant response and leaves the loss with no real labels.
Imagine packing lunches for a school trip into identical lunch boxes. Each box has a fixed capacity, and the rule is that whatever does not fit gets thrown away from the top. You pack the sandwich first, then the fruit on top, then the dessert. When a lunch is too big and the box overflows, the dessert disappears first. If the dessert was the part the child actually loves, the lunch is now useless even though the box still looks full. max_seq_len is the lunch box size for training. The assistant answer is the dessert, the part the model is supposed to learn from. When the loader trims the end, the answer goes first while the system prompt and user message stay. The training step still runs, the loss number still looks fine, but the model learns nothing from that example.
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 max_seq_len, walk default right truncation behavior on chat data, show how it silently zeros the loss mask, and cover the defensive recipe of percentile-based caps, truncation logging, left truncation, and packing.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Setting max_seq_len based on average example length instead of the 95th percentile. You silently lose the assistant response from your longest examples and train on sequences that contribute nothing to the loss.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.