Efficient Context Scaling with LongCat ZigZag Attention

Chen Zhang, Yang Bai, Jiahuan Li, Anchun Gui, Keheng Wang, Feifan Liu, Guanyu Wu, Yuwei Jiang, Defei Bu, Li Wei, Haihang Jing, Hongyin Tang, Xin Chen, Xiangzhou Huang, Fengcun Li, Rongxiang Weng, Yulei Qian, Yifan Lu, Yerui Sun, Jingang Wang, Yuchen Xie, Xunliang CaiarXiv 2025 · DOI

Abstract

Large Language Models (LLMs) face significant computational bottlenecks as context windows scale toward one million tokens, primarily due to the quadratic complexity of standard attention mechanisms. We introduce LongCat ZigZag Attention (LoZA), a hardware-aware sparse attention scheme designed to convert dense Multi-Head Latent Attention (MLA) models into efficient sparse versions with minimal compute overhead. By employing a data-driven calibration phase to identify and sparsify the least critical attention layers, LoZA achieves substantial speedups—over 50% in prefill and 30% in decode costs—while maintaining performance across reasoning and agentic benchmarks. Our results demonstrate that layer-level sparsity, combined with targeted mid-training, enables robust context extrapolation up to 1 million tokens.

Introduction

The demand for massive context windows is driven by modern applications such as Retrieval-Augmented Generation (RAG) and complex tool-integrated agentic reasoning. However, standard full attention scales quadratically, making the processing of million-token prompts a crippling computational bottleneck. While various sparse attention techniques have been proposed, many rely on head-level sparsity. In practice, head-level sparsity complicates kernel control flows and causes compute imbalances across parallel GPU ranks, often neutralizing theoretical gains.

LoZA addresses these challenges by prioritizing hardware-friendly layer-level sparsity. By ensuring that an entire layer is either fully dense or fully sparse, the model maintains uniform compute schedules across hardware, translating theoretical efficiency into actual wall-clock speedups.

Methodology

The LoZA framework follows a three-step pipeline inspired by the Lottery Ticket Hypothesis, aimed at finding and training a highly efficient subnetwork within a dense model.

  1. Calibration: Instead of using heuristics to select layers for sparsification, LoZA attaches a learnable parameter ($\alpha_i$) to each MLA layer. The model is briefly trained on calibration data, where the magnitude of $\alpha_i$ reveals the relative importance of each layer to the model's overall performance.
  2. Sparsification (Layer-Level): The 50% of MLA layers with the lowest importance scores are converted to Streaming Sparse Attention (SSA). In SSA, a query token only attends to a small set of initial "sink" blocks and recent local blocks. Crucially, this transition happens at the layer level to optimize hardware utilization.
  3. Mid-Training: To recover any performance lost during sparsification, the model undergoes mid-training on 540 billion tokens of high-fidelity long-context data. This phase integrates YaRN (Yet another RoPE extensioN) to extrapolate the context window to 1 million tokens.

Data and Training

The mid-training phase utilized a diverse mixture of 540 billion tokens, including reasoning-intensive texts, synthetic agentic interactions via Model Context Protocol (MCP) servers, and full-repository codebases. Training progressed through stages of increasing context length (32K, 128K, 256K). Post-training followed a lightweight pipeline involving Supervised Fine-Tuning (SFT), Direct Preference Optimization (DPO), and Reinforcement Fine-Tuning (RFT) to refine instruction-following capabilities.

Key Results and Discussion

Efficiency Gains

The transition to LoZA yields massive efficiency improvements. At a 128K token context, the SSA kernel reduces decode compute costs by 90% compared to full attention. For a 256K context, the end-to-end model achieves a >50% speedup in prefill and saves >30% in decode costs.

Performance Parity

Despite removing 50% of the attention compute, the LongCat-Flash-Exp-Chat model matches or exceeds the performance of its dense counterpart and competitors like GLM-4.6 across general (MMLU), math (MATH-500), and coding (SWE-Bench) benchmarks. This provides empirical evidence that LLMs contain significant redundancy that can be exploited through data-driven sparsification.

Million-Token Extrapolation

Evaluation on the MRCR benchmark (a multi-needle retrieval task) confirms that the model successfully extrapolates to 1 million tokens. As shown in the figure below, LongCat-Flash-Exp-Chat maintains a higher Area Under the Curve (AUC) than Qwen-3-A22B-235B-Instruct, demonstrating superior long-context retrieval stability.

Conclusion

LongCat ZigZag Attention demonstrates that hardware-aware, layer-level sparsity is a viable path toward million-token context windows. By combining learnable calibration with streaming sparse attention, LoZA eliminates the traditional trade-off between theoretical sparsity and real-world performance. Future work will explore applying this methodology to large multi-modal models, where context scaling is essential for high-resolution video and document processing.

Summary updated

BibTeX
@misc{zhang2025efficient,
  author = {Chen Zhang and Yang Bai and Jiahuan Li and Anchun Gui and Keheng Wang and Feifan Liu and Guanyu Wu and Yuwei Jiang and Defei Bu and Li Wei and Haihang Jing and Hongyin Tang and Xin Chen and Xiangzhou Huang and Fengcun Li and Rongxiang Weng and Yulei Qian and Yifan Lu and Yerui Sun and Jingang Wang and Yuchen Xie and Xunliang Cai},
  title = {{Efficient Context Scaling with LongCat ZigZag Attention}},
  year = {2025},
  eprint = {2512.23966},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.23966},
}
Figure