Spot the bug in this sequence-packing setup
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Click any words you think contain an error. Click again to unmark.
Packing without a block-diagonal mask lets examples attend across boundaries, and unmasked loss wastes gradient on prompt and padding. Both bugs stay hidden in the loss curve.
Imagine grading several students' essays stapled into one long packet to save paper. The trick only works if each student can read only their own pages. If you forget the dividers, student three starts quoting student two's essay as if it were their own, and your grading rewards nonsense. The packing setup here forgot the dividers, the default attention mask lets later examples peek at earlier ones. It also grades every word, including the question prompts and blank filler, instead of only the answers you actually want the model to learn. The packet still looks neat and the throughput gauge still climbs, so nobody notices the grades are quietly contaminated.
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.
5 min: packing motivation + default mask contamination + block-diagonal fix + completion-only loss masking + why both bugs are silent + verification on a synthetic pack.
| Concern | Buggy setup | Correct setup |
|---|---|---|
| Attention mask | Default causal over whole pack | Block-diagonal, causal within each example |
| Cross-example attention | Allowed, contaminates context | Blocked at every boundary |
| Loss target | All tokens, prompts and padding included | Response tokens only, prompts and padding masked |
| Symptom | Loss falls, throughput triples, eval degrades | Loss reflects true response learning |
| Implementation | Dense default mask | Variable length kernel with cumulative offsets |
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.
Packing examples to save padding but reusing the default causal mask, so tokens attend across example boundaries and the loss covers prompt and padding instead of response tokens only.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.