Skip to content
AI & Machine Learning Rich #long-context#sliding-window#streaming-llm

Long Context: Sliding Window & Sink

Local windows + a few global tokens preserve quality at 100k+ context.

A free, animated long context: sliding window & sink you can read here or embed on any website, from Scrollchart.

Long Context: Sliding Window & Sink

Long Context: Sliding Window & Sink TokensLocal windows keep memory linear in N; a few global sink tokens prevent quality collapse past 32kFull AttentionO(N²) memory11661212Keys (K)Sliding WindowO(N · w) memory11661212Keys (K)Sink + Sliding WindowO(N · (w + s)) memory11661212Keys (K)Queries (Q)Purple = sink tokens (tokens 1-2): always visibleQuality vs context length4k8k16k32k64k128k050100Context lengthFull attn (OOM > 32k)Sliding windowSink + window (StreamingLLM)Memory complexityFull: O(N²)Sliding window (w=4096): O(N · w)Sink + window: O(N · (w + s))Mistral 7B uses w=4096 sliding window. StreamingLLM (Xiao et al. 2023) adds 4 sink tokens to avoid attention collapse at unlimited context. Both keep cache linear in N.

Three attention masks: full, sliding-window (each token sees w neighbors), sliding-window + sink (a few persistent global anchors). Memory and quality vs context length plotted; StreamingLLM and Mistral-style sliding referenced.

Good for

  • Long-context LLM architecture explainers covering Mistral and StreamingLLM
  • Inference infrastructure articles on serving 100k-token contexts within GPU memory
  • Attention mechanism surveys comparing full, sparse, and hybrid masking strategies

Source & accuracy

This long context: sliding window & sink is an editorial illustration built to represent the concept accurately. Where it shows figures, they are typical or representative values chosen to make the relationship clear, not a single underlying dataset. The diagram and its explainer are reviewed and maintained centrally, and updated over time as understanding improves.

Local windows and global tokens for 100k+ context

Full attention at 100k tokens is intractable: N x N is 10 billion elements. Sliding window attention attends only to a local neighborhood (e.g., 2048 tokens), keeping full parallelism but limiting context. To recover long-range dependencies, a few 'sink' or 'global' tokens (e.g., the first 4 tokens or a learned [SINK] token) attend to all positions, while regular tokens attend locally.

This hybrid approach preserves long-range information (global tokens see everything) without the quadratic cost.

Preserving quality at long context

Naively training with local attention on 100k sequences doesn't always preserve quality compared to full attention on short sequences. The global tokens are key: they compress information from the full sequence and serve as bottlenecks for reaching distant context. Proper initialization and training of these global tokens is important.

Many recent models (Llama 2 at 34K context, Claude at 100K+) use variants of sliding window plus global tokens.

Extrapolation and position encoding

Long context requires position encodings that extrapolate beyond training length. Rotary position embeddings (RoPE) and ALiBi (Attention with Linear Biases) both extrapolate smoothly. Some models require position interpolation (scaling down position IDs) or fine-tuning to safely extend context. This is an active area of research.

Embed this diagram

Add this animated long context: sliding window & sink to your own site. Copy one line of HTML, or use the embed builder for theme and sizing options.

Reference

What this is
A free, embeddable, animated long context: sliding window & sink for any website.
Who uses it
AI/ML blogs.
How to embed
Copy one line of HTML. No signup. No watermark. Works in WordPress, Webflow, Ghost, Substack, plain HTML.
File size
iframe embed, ~80 KB gzipped (loads on demand, does not block your page paint).
License
Free forever. Editorial explainer text included; updated centrally over time.

Embed format options

Copy the universal HTML snippet, the WordPress shortcode, or an iframe fallback - see the WordPress plugin page for details. Any format keeps the same Core Web Vitals profile and the same explainer text.

Embed snippet
<div data-scrollchart="long-context-attention" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "Long Context: Sliding Window & Sink" for my website?
Scrollchart provides "Long Context: Sliding Window & Sink" as a free, embeddable animated diagram you can add to any website with one line of HTML. No signup is required and there is no watermark. The diagram and its explainer text are served from scrollchart.com, so the embed stays current without any maintenance on your end.
How do I embed a long context: sliding window & sink in a developer or tech blog?
Copy the one-line snippet from the Scrollchart diagram page and paste it into your post HTML. It works in any static site generator, CMS, or hand-coded HTML page. The embed is a thin loader, not an iframe, so the content is fully in your DOM.