Sparse Attention Architecture Explained: CSA2 and Cross-Layer Reuse
This article breaks down a next-generation sparse attention architecture (referred to as CSA2-style) by tracing a single token from input to query output. It explains the encoder/decoder layer split, the four layer types (S, F, R, I), the low-rank query projection, the lightweight hierarchical indexer, and the three read paths (SWA, global, compressed). It also covers key dimensions and shapes, engineering caveats around capacity accounting and compression error, and the three metrics to watch when evaluating this class of design: global KV write layers, index recomputation frequency, and the window/Top-K ratio.
1. Why Attention Efficiency Became the Main Battleground in Architecture Design
The cost of long-context inference does not come mainly from parameter count. It comes from the dynamic overhead of attention: the KV cache grows linearly with sequence length, while attention computation scales quadratically. The direction of the industry over the past two years has been highly consistent — stop having every layer maintain its own full history, and instead split “historical content” and “historical position selection” into two types of state that can be updated independently. This article uses a next-generation sparse attention architecture (referred to below as a CSA2-style architecture) as a sample, and walks through the actual path a token takes from entry to query output, section by section.
2. Overall Layering: The Division of Labor Between the Encoder Segment and the Decoder Segment
This class of architecture typically splits 40 layers into two segments. The first 20 layers form the encoder segment, where the layer type is a repeating combination of four labels:
- S (sliding window only): keeps only the KV inside the window and produces no global state;
- F (Full): generates new global KV and recomputes the Top-K index;
- R (Reuse): directly reuses the existing global KV and index;
- I (Reindex): reuses the existing global KV and only recomputes the index.
The last 20 layers form the decoder segment, dominated by Reindex. The point most easily misread here is that Reindex does not regenerate global KV; it only re-decides “which historical positions to read.”
This yields the key statistic for the whole network: out of 40 layers, only 4 actually write new global KV, 8 perform new index selection (4 Full + 4 Reindex), and the remaining 30 fully reuse the existing index; but all 40 layers each keep a complete SWA cache and the main Query. The three sets of global KV generated at L2, L8, and L14 in the encoder segment correspond to hidden states at different depths, so they naturally carry historical information at different levels of abstraction. This is also the precondition that keeps cross-layer reuse from degrading information.
3. Basic Dimensions and Shape Conventions
Take the hidden dimension as 5120, main attention with 64 heads and a per-head dimension of 512, and a query low-rank dimension of 1280; the indexer has 32 heads with a per-head dimension of 128, sparse Top-K is 512, and the SWA window is 128; the CSA2 compression rate is 2 in the encoder segment and 1 in the decoder segment. The residual stream can be understood as a 4-way mixed channel with shape [1, S, 4, 5120], and the dimension after mixing stays consistent with the input. With batch size 1 and sequence length 1024, the input is X ∈ R^{1×1024×5120}.
4. Single-Token Computation Path (1): Low-Rank Query Generation
The first step is low-rank compression, reducing 5120 dimensions to 1280; the second step is up-projection into the multi-head space:
Q_latent = X @ W_q_A # [1, 1024, 5120] -> [1, 1024, 1280]Q = Q_latent @ W_q_B # -> [1, 1024, 64, 512]
The value of the low-rank bottleneck is that both the parameter count and the activation bandwidth on the query side drop, while the per-head dimension of 512 ensures that representational capacity is not directly sacrificed to the compression ratio.
5. Single-Token Computation Path (2): The Hierarchical Sparse Indexer
The indexer does not reuse the main Query. Instead, it scores independently with a lightweight representation of 32 heads and 128 dimensions, outputting the Top-512 positions. The significance of decoupling it from main attention is that the index can run at a coarser granularity and lower precision, and can even be shared across layers, while main attention still maintains high precision.
6. Single-Token Computation Path (3): Three Read Paths and the Separated Update of CSA2
- SWA branch: reads only the most recent 128 positions, responsible for local syntax and short-range dependencies;
- Global branch: reads the reused global KV according to the Top-512 index;
- Compressed branch: the encoder segment applies a compression rate of 2 to the historical compressed representation, while the decoder segment uses 1, meaning no additional compression.
Core conclusion: decoupling the “content cache (KV)” from “position selection (Top-K)” so that the two can be updated separately is the essence of CSA2, and it is also the reason 30 layers can safely reuse the index.
7. Engineering Implementation Points and Common Pitfalls
- Capacity accounting must be itemized: global KV, SWA KV, and the index cache grow at different rates and need to be estimated for GPU memory separately;
- Reuse is not lossless: cross-layer reuse depends on differences in the abstraction level of the reused layers’ hidden states, and layer-order changes require re-validation;
- Compression rate and error: the higher the compression rate, the more easily long-range detail recall is harmed, so it should be paired with monitoring, alerting, and logging services to run long-text quality regression;
- On the platform side, container platforms and object storage can carry elastic inference and cache snapshots, and general-purpose capabilities are sufficient — there is no need to bind to proprietary interfaces.
In summary, the key to efficient attention is not single-point operator optimization, but state layering and update decoupling. When evaluating this class of architecture, look at three metrics together: the number of layers that write global KV, the index recomputation frequency, and the window/Top-K ratio.
