1 00:00:01,000 --> 00:00:09,300 [Hal Turing] Alrighty! Thanks for tuning in! Hello AI world! I am your host, Hal Turing, and my co-host is Dr. Ada Shannon. 2 00:00:09,300 --> 00:00:32,924 [Hal Turing] Today we're covering "Efficient Streaming Language Models with Attention Sinks," by Guangxuan Xiao and colleagues from MIT, Meta AI, Carnegie Mellon and NVIDIA, published at ICLR 2024. The claim is that if you keep just the first four tokens of a conversation in memory, a model that otherwise falls apart can keep generating over millions of tokens. 3 00:00:32,924 --> 00:00:50,599 [Dr. Ada Shannon] The research question is this. Can a model trained on a finite attention window run on an endless input stream, at constant memory and constant cost per token, with no fine-tuning? The answer is yes for stability. Whether it remembers anything is a different matter, and we'll get to that. 4 00:00:50,599 --> 00:00:56,474 [Hal Turing] Let's set up the stakes. Picture a chat assistant that runs for days. What breaks? 5 00:00:56,474 --> 00:01:19,924 [Dr. Ada Shannon] Two things, and the paper names both. First, memory and latency. When a transformer generates a token, it attends to every earlier token. To avoid recomputing the past, it stores each earlier token's key and value vectors. That store is the KV cache. It makes each step cheaper, but it grows with every token, so memory grows linearly and each step reads more data. Second, the model was trained at a fixed length, 4K tokens for Llama-2. Past that, quality degrades. 6 00:01:19,924 --> 00:01:23,799 [Hal Turing] So the obvious fix is to drop the old stuff. 7 00:01:23,799 --> 00:01:41,250 [Dr. Ada Shannon] That's window attention. Keep the KV for only the most recent L tokens and evict the rest. Memory and per-token cost stay constant. The paper shows it collapses as soon as the text outgrows the cache, which means as soon as the very first tokens get evicted. 8 00:01:41,250 --> 00:01:46,900 [Hal Turing] Collapses how? I'd expect it to forget the early conversation and carry on. 9 00:01:46,900 --> 00:02:05,600 [Dr. Ada Shannon] It doesn't just forget, it breaks. The metric is perplexity, which measures how surprised the model is by the true next token. Lower is better. A value around 5 means it's choosing among roughly five plausible tokens. Values in the thousands mean the model is broken. Window attention lands in the thousands. 10 00:02:05,600 --> 00:02:08,050 [Hal Turing] What's the third baseline? 11 00:02:08,050 --> 00:02:29,100 [Dr. Ada Shannon] Sliding window with recomputation. For every new token, you rebuild the KV states of the last L tokens from scratch. Quality is good, because the model always sees a fresh, in-distribution window. But the cost per window is roughly L squared, so it's slow. The paper treats it as the quality oracle and calls it the only viable baseline. We'll come back to whether that's fair. 12 00:02:29,100 --> 00:02:36,050 [Hal Turing] So why does evicting the first tokens, which are usually the least important ones, wreck everything? 13 00:02:36,050 --> 00:02:59,125 [Dr. Ada Shannon] Softmax. Attention weights over all visible tokens must sum to one. A query with nothing useful to attend to still has to put its attention somewhere. The paper's explanation is that models learn to dump that surplus on tokens that every later token can see. Under causal masking, the initial tokens are the only ones visible to everything that follows. So they get trained into that role. That's the attention sink. The paper reports it in nearly every head beyond the bottom two layers. 14 00:02:59,125 --> 00:03:04,425 [Hal Turing] So the sink isn't holding information. It's a parking spot for attention. 15 00:03:04,425 --> 00:03:25,650 [Dr. Ada Shannon] Right, with one caveat. The paper's account is plausible and partly tested, but it's still an account. What it clearly shows is that these tokens act as sinks even when their meaning doesn't matter. Evict them and the attention distribution at every layer shifts, so the model sees something it was never trained on. Think of a pinned header on a ring buffer: the ring holds recent text, and the header keeps the softmax arithmetic intact. 16 00:03:25,650 --> 00:03:31,900 [Hal Turing] Before we go further, I want the goals straight. What is this paper actually trying to do? 17 00:03:31,900 --> 00:03:53,349 [Dr. Ada Shannon] The paper keeps three goals separate. Length extrapolation: the model keeps generating sensibly past its training length. Context window extension: the model can actually take in more text, which is what methods like position interpolation fine-tune for. And better use of long context: using what's in that text well. StreamingLLM targets only the first. That decides what the results can and can't claim. 18 00:03:53,349 --> 00:04:01,625 [Hal Turing] So if the chat runs for days and the model keeps sounding fluent, that doesn't mean it remembers what I said on day one. 19 00:04:01,625 --> 00:04:08,850 [Dr. Ada Shannon] Correct. What gets evicted is gone by design. The claim is stable, bounded-cost generation, not memory. 20 00:04:08,850 --> 00:04:13,875 [Hal Turing] Okay. Now what do four tokens do to a number like five thousand? 21 00:04:13,875 --> 00:04:34,550 [Dr. Ada Shannon] On Llama-2-13B, over one 65,000-token book, a pure window of 1,024 tokens gets perplexity around 5,158. Keep the first four tokens plus 1,020 recent ones, and it drops to 5.40. Full recomputation, the oracle, gets 5.43. So the only change is four tokens at the front. 22 00:04:34,550 --> 00:04:39,175 [Hal Turing] Is it the content of those tokens, or the fact that they're first? 23 00:04:39,175 --> 00:04:59,900 [Dr. Ada Shannon] The paper tests that. Replace the first four tokens with newline characters and perplexity is 5.60. Still fine. So it's absolute position, not meaning. The attention maps show why: past the bottom two layers, most heads put heavy weight on the first token. Evict it and a big share of the softmax denominator disappears, so every attention distribution shifts. 24 00:04:59,900 --> 00:05:05,600 [Hal Turing] So the method is: keep those four, add a rolling window, and evict from the middle. 25 00:05:05,600 --> 00:05:25,825 [Dr. Ada Shannon] Yes, no fine-tuning. A config like 4+1020 means four sinks plus 1,020 recent tokens. The subtle part is positions. StreamingLLM assigns positions by slot in the cache, not by place in the original text. If tokens 0 to 3 and 6 to 8 are cached, they get positions 0 to 7. 26 00:05:25,825 --> 00:05:30,300 [Hal Turing] Why does that matter? The model could just see the real positions. 27 00:05:30,300 --> 00:05:50,275 [Dr. Ada Shannon] Then it would see a jump in distance between the sinks and the recent tokens, another pattern it never trained on. For RoPE, the keys are cached before rotation and rotated at each step according to their current slot. For ALiBi, the bias is applied as if the cache were contiguous. Either way, the model sees a smooth, gap-free sequence. 28 00:05:50,275 --> 00:05:53,600 [Hal Turing] Why four sinks? Is it a magic number? 29 00:05:53,600 --> 00:06:15,300 [Dr. Ada Shannon] A heuristic. On Llama-2-7B over 400,000 tokens, one sink gives perplexity 11.88 and two give 10.51. Four give 9.59, and eight barely improve on that. The paper's hypothesis is that Llama-2 has no consistent start token, because the start marker is added before the text is chunked. So the sink role gets spread across several early positions. 30 00:06:15,300 --> 00:06:19,575 [Hal Turing] Which suggests you could train a model to use just one. 31 00:06:19,575 --> 00:06:52,400 [Dr. Ada Shannon] That's their pre-training experiment, and it's the causal test of the story. They train 160-million-parameter models on the deduplicated Pile for 143,000 steps, in three variants. Vanilla; a Zero Sink that adds a zero key and value, equivalent to softmax-off-by-one; and a learnable sink token prepended to every sample. With one sink token in the cache, vanilla gets 18.49 and the learnable-sink model gets 18.01. Vanilla needs four to reach about 18.05. And on seven zero-shot benchmarks the learnable-sink model scores about the same. 32 00:06:52,400 --> 00:06:54,425 [Hal Turing] What's the limit there? 33 00:06:54,425 --> 00:07:10,950 [Dr. Ada Shannon] One size, one run each, no variance reported, so differences of a few tenths on the zero-shot tasks could be noise. And drop the sink from the cache entirely and the learnable-sink model still breaks, at 1,235. The sink has to stay. 34 00:07:10,950 --> 00:07:15,025 [Hal Turing] Okay, perplexity is one thing. Does it do a task? 35 00:07:15,025 --> 00:07:38,250 [Dr. Ada Shannon] Streaming question answering with chat models, cache of 1,024 tokens. On Llama-2-7B-Chat's easy set, asking each question fresh scores about 71 out of 100. Plain window attention gets under 4. StreamingLLM gets about 71. Same pattern at 13B and 70B, and dense attention runs out of memory. The caveat is that each question is independent, so nothing requires remembering evicted material. 36 00:07:38,250 --> 00:07:40,550 [Hal Turing] Is there a harder version? 37 00:07:40,550 --> 00:07:58,275 [Dr. Ada Shannon] They build StreamEval, which asks a question every ten lines about a fact from twenty lines earlier. Accuracy stays reasonable up to about 120,000 tokens. But twenty lines back is still recent context, so it tests stability under streaming, not long-range recall. 38 00:07:58,275 --> 00:08:02,275 [Hal Turing] And the speed claim? I keep seeing 22 times. 39 00:08:02,275 --> 00:08:23,350 [Dr. Ada Shannon] That's the largest cache. On Llama-2-13B with a 4,096-token cache, one token takes about a tenth of a second with StreamingLLM, versus about two and a third seconds for recomputation. At a 256-token cache, the gain is only about two times. Recomputation costs roughly the window length squared per token, so the gap widens as the window grows. 40 00:08:23,350 --> 00:08:24,900 [Hal Turing] And memory? 41 00:08:24,900 --> 00:08:47,950 [Dr. Ada Shannon] About the same. The saving is purely compute, since both keep roughly one window of cache. For the perplexity runs, they concatenate the PG19 test set, with the cache at half the pre-training window: 2,048 for Llama-2, 1,024 for the others. That covers Llama-2, MPT, Falcon and Pythia, so two position-encoding schemes. It also composes with context-extended models, where extension just means a larger cache. 42 00:08:47,950 --> 00:09:01,425 [Hal Turing] Let's pressure-test the speed claim. The 22.2x is against sliding window with recomputation, which the paper itself calls the only viable baseline. Is that a fair opponent? 43 00:09:01,425 --> 00:09:17,575 [Dr. Ada Shannon] It's the right oracle for quality, but a weak opponent for deployment. A real chat server would reuse a prefix cache, evict in blocks, truncate, or summarize history. The paper measures none of those, either for end-to-end latency or for answer quality. 44 00:09:17,575 --> 00:09:19,375 [Hal Turing] And the hardware? 45 00:09:19,375 --> 00:09:37,900 [Dr. Ada Shannon] HuggingFace Transformers, one A6000, Llama-2-7B and 13B only. Recomputing a window is cheaper with FlashAttention or with paged attention in a vLLM-style system, so the gap there would likely shrink. That's my inference. The paper gives no measurement. 46 00:09:37,900 --> 00:09:40,975 [Hal Turing] So is the speedup an artifact? 47 00:09:40,975 --> 00:10:01,850 [Dr. Ada Shannon] No. The advantage is structural. StreamingLLM never recomputes, and its memory is constant, whatever kernel you run. But it re-indexes positions every step, so RoPE keys are re-rotated each time. The paper doesn't break out that cost. It may also interact with prefix-cache reuse, because a cached prefix is no longer valid once positions shift. That is reasoning, not a measurement. 48 00:10:01,850 --> 00:10:08,050 [Hal Turing] Now the four-million-token result. Perplexity stays flat. Why isn't that convincing? 49 00:10:08,050 --> 00:10:28,600 [Dr. Ada Shannon] Because flat is what you'd expect from a model that only predicts locally. Table 6 is the tell. On Llama-2-7B, a cache of 4+1020 gives 9.32, and 4+4092 gives 9.59. Four times the context, slightly worse perplexity. A metric that doesn't improve with more context can't show the model uses it. 50 00:10:28,600 --> 00:10:31,375 [Hal Turing] Then what does the evidence support? 51 00:10:31,375 --> 00:10:48,150 [Dr. Ada Shannon] Bounded, stable generation. It doesn't support memory of evicted content. That content is gone by design, and the paper says models may not fully use the context they receive. A test where the needed fact falls outside the window would fail, and nobody runs it. 52 00:10:48,150 --> 00:10:52,725 [Hal Turing] What about the mechanism? Is the softmax-dump story proven? 53 00:10:52,725 --> 00:11:30,050 [Dr. Ada Shannon] Partly. The newline test shows content doesn't matter for those tokens. It doesn't test the dumping claim directly. Follow-ups help. Gu and colleagues, 2024, 'When Attention Sink Emerges in Language Models: An Empirical View', study when sinks appear across scale, data and loss, and treat them as key biases. I'm relying on their abstract for that. Sun and colleagues, with Zico Kolter and Zhuang Liu, 2024, 'Massive Activations in Large Language Models', find a few residual dimensions with huge values on the first token or delimiters. They act like fixed biases, which fits a sink whose value vector is small. 54 00:11:30,050 --> 00:11:32,800 [Hal Turing] And the sink-token pretraining? 55 00:11:32,800 --> 00:11:53,675 [Dr. Ada Shannon] The closest analogue is 'Vision Transformers Need Registers', Darcet and colleagues, 2023. They found high-norm artifact tokens in vision models and fixed them with explicit register tokens, which resembles a learnable sink. The paper itself notes this as concurrent work. For the sink token here, remember it's one pair of 160M models, so 'no harm' is weakly supported. 56 00:11:53,675 --> 00:11:58,125 [Hal Turing] That also weakens the softmax-off-by-one comparison. 57 00:11:58,125 --> 00:12:14,351 [Dr. Ada Shannon] Yes. Evan Miller proposed that variant in 2023, and one small run failing doesn't show the idea is inherently worse. The paper also points to Bondarenko and colleagues, 2023, who saw similar outliers in quantization. 58 00:12:14,351 --> 00:12:19,876 [Hal Turing] So what's actually new? Longformer already mixed global tokens with a window. 59 00:12:19,876 --> 00:12:48,876 [Dr. Ada Shannon] Longformer's global attention pattern is unsuitable for autoregressive models, and it needs training from scratch, as the paper notes. The closest relative is LM-Infinite, from Han and colleagues in 2023, which the paper calls concurrent work. The novelty here is the sink explanation and the no-fine-tuning result on existing models. Also, H2O, from Zhang and colleagues, 2023, keeps heavy-hitter tokens by score. Pinned sinks are a static version of that idea, and I don't see a comparison in the main results. 60 00:12:48,876 --> 00:12:51,626 [Hal Turing] Where does that leave a practitioner? 61 00:12:51,626 --> 00:13:19,651 [Dr. Ada Shannon] Use it when you need unbounded streaming and only recent context matters. Don't use it when old facts must be recalled. The appendix makes this concrete: on LongBench, with four sinks plus 3,496 recent tokens, Llama-2-7B-chat scores below plain truncation on most tasks, likely because the start of the input carries the instructions. Pinning 1,750 initial tokens brings it back to truncation level. So a deployer has to decide what to pin, including any system prompt. 62 00:13:19,651 --> 00:13:21,551 [Hal Turing] What should come next? 63 00:13:21,551 --> 00:13:53,676 [Dr. Ada Shannon] Train larger models with a sink token and report seeds. Test retrieval where the fact lies outside a rolling cache. Compare against prefix caching and block eviction on modern serving stacks. And work out why more cache doesn't help. There's also the open question of eviction that keeps the important tokens, not just sinks plus recency. The paper reports adoption in TensorRT-LLM, Intel Extension for Transformers, HuggingFace Transformers and MLC LLM, but that's its own claim. 64 00:13:53,676 --> 00:14:15,701 [Hal Turing] So here's where I land. The paper establishes a training-free fix that keeps a bounded-memory model stable on an endless stream, with a mechanism that's plausible and partly tested. The boundary is that it doesn't extend memory, and the speed and quality claims were measured against a narrow baseline and setup. Thanks for listening, and goodbye.