CoCA: Fusing Position Embedding with Collinear Constrained Attention in Transformers for Long Context Window Extending
Not on the map. Why?
Abstract (arXiv)
Self-attention and position embedding are two key modules in transformer-based Large Language Models (LLMs). However, the potential relationship between them is far from well studied, especially for long context window extending. In fact, anomalous behaviors harming long context extrapolation exist between Rotary Position Embedding (RoPE) and vanilla self-attention unveiled by our work. To address this issue, we propose a novel attention mechanism, CoCA (Collinear Constrained Attention). Specifically, we enforce a collinear constraint between Q and K to seamlessly integrate RoPE and self-attention. While only adding minimal computational and spatial complexity, this integration significantly enhances long context window extrapolation ability. We provide an optimized implementation, making it a drop-in replacement for any existing transformer-based models. Extensive experiments show that CoCA performs extraordinarily well in extending context windows. A CoCA-based GPT model, trained with a context length of 512, can seamlessly extend the context window up to 32K (60×), without any fine-tuning. Additionally, by dropping CoCA in LLaMA-7B, we achieve extrapolation up to 32K within only 2K training length. Our code is publicly available at: https://github.com/codefuse-ai/Collinear-Constrained-Attention
Key facts. Cited by 6 papers in the map (data through 14 Oct 2026). Builds on 14 of its 31 references that are in the map. First posted on arXiv 15 Sep 2023.
Builds on
14 of 31 references.
References · 14
- 2017Attention Is All You Needcited by 60,361
- 2021RoFormer: Enhanced Transformer with Rotary Position Embeddingcited by 4,703
- 2022FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenesscited by 3,673
- 2020Longformer: The Long-Document Transformercited by 3,413
- 2020The Pile: An 800GB Dataset of Diverse Text for Language Modelingcited by 2,411
- 2018SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processingcited by 1,989
- 2017Decoupled Weight Decay Regularizationcited by 1,831
- 2021Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolationcited by 1,103
- 2023Extending Context Window of Large Language Models via Positional Interpolationcited by 740
- 2019Compressive Transformers for Long-Range Sequence Modellingcited by 726
- 2022GPT-NeoX-20B: An Open-Source Autoregressive Language Modelcited by 713
- 2023Landmark Attention: Random-Access Infinite Context Length for Transformerscited by 213
2 more
Built on by
Citing papers per year: 2024: 1; 2025: 3; 2026: 2.
6 papers.
- 2025Shifting Long-Context LLMs Research from Input to Outputcited by 14
- 2025LADM: Long-context Training Data Selection with Attention-based Dependency Measurement for LLMscited by 11
- 2024PEER: Expertizing Domain-Specific Tasks with a Multi-Agent Framework and Tuning Methodscited by 4
- 2025Opt-GPTQ: An Optimized GPTQ Combining Sparse Attention and Quantization Techniquescited by 0
- 2026Beyond Text-to-SQL: Can LLMs Really Debug Enterprise ETL SQL?cited by 0
- 2026KVSlimmer: Theoretical Insights and Practical Optimizations for Asymmetric KV Mergingcited by 0
- 2026KVSlimmer: Theoretical Insights and Practical Optimizations for Asymmetric KV Merging1 Mar 2026
- 2026Beyond Text-to-SQL: Can LLMs Really Debug Enterprise ETL SQL?26 Jan 2026
- 2025Opt-GPTQ: An Optimized GPTQ Combining Sparse Attention and Quantization Techniques5 May 2025
- 2025Shifting Long-Context LLMs Research from Input to Output6 Mar 2025
- 2025LADM: Long-context Training Data Selection with Attention-based Dependency Measurement for LLMs4 Mar 2025
- 2024PEER: Expertizing Domain-Specific Tasks with a Multi-Agent Framework and Tuning Methods9 Jul 2024