Zenaique

Find the bug: a Llama deployment serves traffic without prepending the BOS token.

Spot the error·Medium·4.0 · 0·~2 min·Asked atOracleRobinhoodSamsung·Relevant atAi4bharatCerebrasDeepseekMicrosoft
Attempt it

Click any words you think contain an error. Click again to unmark.

Mark at least one word to submit.
TL;DR

BOS acts as the learned attention sink. Drop it and the first real token inherits the sink role, distorting its hidden state and degrading the opening tokens of generation.

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

Imagine a sports team where one player is designated to catch every ball nobody else can field. Lose that player and someone else has to do their job on top of their own. The replacement player tries to play their normal position and catch random balls at the same time, doing both badly. The first token of every prompt (called BOS) is that designated catcher for the model. The system always has to put its leftover focus somewhere, and during training it learns to dump it on BOS because that slot carries no real content to protect. Skip BOS at runtime and the first real word of your prompt has to play two positions at once. Quality drops, especially on the first few words the model writes back.

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 BOS token looks like nothing, just a single special token at the start of the sequence. In reality, for Llama-family and most decoder-only models trained with it, BOS plays a load-bearing architectural role: it is the learned attention sink, the dump slot where softmax routes excess probability when no key strongly matches the query.

This deep dive walks through the softmax invariant that forces a sink to exist, explains why BOS becomes the sink during training, traces what happens at inference when BOS is missing, lists the symptoms, and connects to the StreamingLLM line of work that formalized the attention sink phenomenon.

Mental model: softmax must produce weights summing to 1. The model learns to dump leftover probability somewhere safe. BOS, with no semantic content to protect, is the obvious safe slot.

Why an attention sink must exist

The softmax invariant

For any query, the attention weights across keys sum to exactly 1. This is the defining property of softmax.

The implication

When the query is early in the sequence (few keys to attend to), or when no key is a strong semantic match, the model still has to assign the full unit of probability somewhere. There is no 'attend to nothing' option, attention weights cannot all be small if they must sum to 1.

The dump-slot problem

If the model dumps that leftover probability onto a semantically meaningful key, the context vector gets polluted with that key's value vector. The query's downstream representation drifts off the intended computation.

The solution training discovers: dump it onto a position whose value vector is uninformative. The first token of every training sequence is the natural candidate.

Why this is universal

Every softmax-based attention layer has the same invariant. Empirically, every decoder-only LLM trained on natural language data learns some form of attention sink. The difference is which token absorbs the sink role, BOS if the model was trained with it, or the first content token if not.

How BOS becomes the learned sink
What happens when BOS is missing at inference
Fixing it and avoiding related traps
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.

  • Llama 2, 3, and 4 Maverick tokenizers all prepend BOS through Hugging Face's add_special_tokens flag.
  • The StreamingLLM paper (Xiao et al., MIT 2023) introduced the 'attention sink' terminology and showed the first 4 tokens carry the sink role.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow does the attention sink concept connect to StreamingLLM?
A

StreamingLLM proposed keeping the first 4 tokens permanently in the KV cache plus a sliding window, because those first 4 tokens carry the attention sink role. Drop them via naive sliding and quality collapses; keep them and you can stream indefinitely. BOS is the dominant sink token among those first 4.

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

Treating BOS as a no-op marker. It is a learned attention sink whose absence forces the first real token to absorb softmax's leftover weight, degrading the opening of generation.

Sign in to see all red flags and common mistakes.

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

  • What an attention sink is and why it exists

  • Why softmax forces leftover probability to be assigned somewhere

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
Explain scaled dot product attention.
Short answer·Medium