Loading diagram…

Reference

← All guides

DeepSeek Sparse Attention

DeepSeek Sparse Attention (DSA) uses a small learned indexer to select earlier token positions. Main attention reads the selected top-k keys and values.

Overview

How it works

The indexer scans the available context with a cheaper scoring operation. Its top-k scores determine which positions enter main attention. A token that is not selected cannot contribute to that attention step.

Details

Why select tokens

Full attention scores all available positions. Some may contribute little to the current output. DSA trains an indexer to identify a smaller set worth processing with main attention.

Details

The lightning indexer

The indexer computes relevance scores for candidate tokens. It uses a lighter calculation than main attention and is trained to make useful selections. Its scores choose positions. They are not the final attention weights.

Details

Token-level selection

Selected positions can be scattered across the context. Token-level selection avoids loading every neighboring token in a chosen block. It also requires the implementation to gather the selected cache entries efficiently.

Details

The top-k budget

A larger k increases main-attention work and gives it access to more context. With fixed k, that selected attention step reads a bounded number of positions. The indexer still scans the context, and sparse selection does not by itself remove the growing KV cache.

Sources