Sparse Attention Explained: How DSA Lets GigaChat 4 Read 2,048 Tokens Out of a Million

Cover image for Sparse Attention Explained: How DSA Lets GigaChat 4 Read 2,048 Tokens Out of a Million: Screenshot: ai-sage/GigaChat4-708B-A41B on Hugging Face

Key facts

Sources checked Nov 27, 2026

  • Sparse attention lets each new token look at a selected subset of earlier tokens instead of all of them. DeepSeek Sparse Attention (DSA) does the selecting with a small, cheap “lightning indexer”.
  • DSA cuts the core attention cost from growing with the square of the context length (O(L²)) to O(L·k), where k is the number of tokens kept. DeepSeek, and now GigaChat 4, use k = 2,048.
  • The indexer itself still scores every earlier token, but it uses only a few heads and FP8 maths, so it’s much cheaper than full attention.
  • It isn’t free at short lengths. Sber measured a 4.32× faster attention kernel at 220K tokens, but a 14.5% slower step at 10K, because the indexer overhead outweighed the savings.
  • Models usually learn to be sparse in stages: first the indexer is trained to copy dense attention, then the whole model trains with sparse attention switched on.

When a model advertises a one-million-token context, the obvious question is how it can afford to read all of that for every word it writes. Usually it doesn’t. Many of 2026’s long-context models, including GigaChat 4, which launched on November 26, use DeepSeek Sparse Attention in some layers. This explainer covers what DSA does, why it saves money at long context, where it doesn’t, and what it means when you pick or run a model.

The problem: attention gets expensive as prompts grow

In a transformer, attention is how each token gathers information from earlier tokens. Full (“dense”) attention compares the current token with every earlier token. Over a whole prompt of length L, that’s about L × L comparisons:

Context length Rough pairwise comparisons (L²)
8,000 64 million
128,000 16.4 billion
1,000,000 1 trillion

Multiply 1,000,000 by itself and you get a trillion. That’s per layer, per attention head, before you even count the memory for the KV cache (the stored keys and values of every past token; see context windows explained). Long prompts get slow and expensive fast.

The fix most labs now use has two parts. One part is linear attention layers, which keep a fixed-size summary instead of looking back at everything (covered in our hybrid linear attention explainer). The other is sparse attention in the layers that still need precise recall. This post is about the second part.

Image from the official model card for tencent/Hy4-flash on Hugging Face
Image from the official model card: tencent/Hy4-flash on Hugging Face.

How DSA works, in two steps

DeepSeek introduced DSA with DeepSeek-V3.2-Exp, described in its technical report. It has two parts.

Step 1: The lightning indexer scores every earlier token, cheaply

For the current token, a tiny side network computes a relevance score for each earlier token. It’s built like a stripped-down attention layer, with a few small heads, a ReLU instead of a softmax, and FP8 arithmetic, so it runs fast. In DeepSeek’s words, the indexer “has a small number of heads and can be implemented in FP8”, which makes it efficient.

Step 2: Top-k selection, then real attention on the winners

The model keeps only the k highest-scoring earlier tokens and runs normal, full-quality attention over just those. With k = 2,048 and a 1M-token prompt, each token in a DSA layer attends to about 0.2% of the context.

So the expensive part, real attention, now grows with L × k instead of L × L. The indexer still touches all L earlier tokens, so it’s technically still O(L²), but each of those scores costs a tiny fraction of a real attention step.

A useful picture: dense attention re-reads the whole book for every word it writes. DSA flips through the index first, then reads the 2,048 most relevant passages carefully.

How models learn to be sparse

You can’t just switch DSA on in a trained model. The model has to learn to trust the indexer, and the indexer has to learn what the model cares about. DeepSeek used two stages, starting from a model already extended to 128K context:

  1. Dense warm-up. Freeze the model and train only the indexer to mimic the model’s own dense attention pattern. DeepSeek did this for 1,000 steps (about 2.1B tokens).
  2. Sparse training. Turn on top-k selection with k = 2,048 and train everything. DeepSeek ran 15,000 steps, about 943.7B tokens. The indexer keeps learning from the main attention, while the main model learns from ordinary next-token prediction.

DeepSeek reported that V3.2-Exp showed no substantial quality drop against its dense predecessor, V3.1-Terminus, on most of its benchmarks.

Sber’s GigaChat 4 technical report follows a similar recipe with an extra twist. It extended context dense from 32K to 128K, trained the indexer alone at 128K, and then trained model and indexer together all the way to 1M tokens. In a smaller-scale test at 512K, Sber found sparse and dense attention almost tied: 90.5% vs 90.4% on an eight-task needle-in-a-haystack set, and 53.0% vs 52.9% on RULER-QA (vendor-reported).

Where sparse attention helps, and where it hurts

The savings depend on context length. Sber profiled GigaChat 4’s prefill (prompt processing):

Prompt length Attention-kernel time, dense vs sparse Whole GPU step
220K tokens 433.38 ms → 100.33 ms (4.32× faster) 825.77 ms → 492.16 ms (1.68× faster)
10K tokens — Sparse step 14.5% slower

Two lessons come out of this:

  • Attention isn’t everything. A 4.3× faster attention kernel only made the whole step 1.7× faster, because experts, projections and other layers still cost the same.
  • Short prompts don’t benefit. At 10K tokens the indexer and the top-k step cost more than they save. That’s why Sber’s serving stack can choose dense or sparse attention separately for prefill and decode, and why runtimes often switch to dense attention below a threshold.

Sber also tried a shortcut that scores blocks of queries with only 8 of the indexer’s 64 heads. It cut indexer cost by about 1.6–3.5×, but only about 50–60% of the selected tokens matched the full indexer’s choices. The general lesson: the selection step is where quality can quietly slip.

Sparse attention is not the same as a sliding window

Both reduce what each token looks at, but in different ways:

  • A sliding window always looks at the most recent N tokens (for example, Hy4 flash’s 512-token window layers). It’s cheap and predictable, but blind to anything older.
  • Sparse attention picks tokens by relevance from anywhere in the context. A fact on page 3 of a 500-page document can still be selected.

Models often mix them. Hy4 flash alternates sparse layers with 512-token sliding-window layers. GigaChat 4 pairs one DSA layer with three Gated DeltaNet linear layers. Both select up to 2,048 tokens in their sparse layers.

What this means for you

When reading model specs. “1M context” plus “sparse attention” means the model can accept a million tokens. Each sparse layer uses at most k of them at each step, and linear or windowed layers use compressed or local views. Long-context quality depends on how good the selection is, so test retrieval on your own documents instead of trusting the window size.

When running models locally. Sparse attention mostly saves compute, not KV-cache memory. The model still stores keys for every earlier token so the indexer can choose among them, and the indexer needs its own small cache. Support also varies by runtime. As of v1.1.0, llama.cpp runs Hy4 flash on its existing DSA cache, while GigaChat 4’s llama.cpp support was still an open pull request on November 27. Kernels matter too. While adding Hy4 flash, the PR author found that llama.cpp’s CUDA lightning-indexer kernel only handled 4, 32 or 64 indexer heads, so Hy4 flash’s 16-head indexer quietly ran on the CPU until they fixed it (PR #32960). Check the release notes for your model by name.

When paying for an API. Providers serving sparse-attention models can charge less for long prompts, but the savings only show up at long lengths. For short chats, sparse and dense models cost about the same to run.

The takeaway

DeepSeek Sparse Attention is a simple idea that’s hard to get right. A cheap indexer guesses which 2,048 earlier tokens matter, and real attention only looks at those. It turns million-token contexts from impossible to affordable, and it saves the most on very long prompts. On short prompts it can be slower than dense attention. Whether a model uses a long context well depends on how well its indexer was trained, so long-context claims still need checking on real documents.

Sources: DeepSeek-V3.2-Exp technical report, vLLM blog on DeepSeek-V3.2-Exp, GigaChat 4 technical report, GigaChat 4 model card, Hy4 flash model card, llama.cpp v1.1.0 release notes, llama.cpp PR #32767. Facts checked November 27, 2026.

Cover image: screenshot of ai-sage/GigaChat4-708B-A41B on Hugging Face