Papers
Topics
Authors
Recent
Gemini 2.5 Flash
Gemini 2.5 Flash
51 tokens/sec
GPT-4o
60 tokens/sec
Gemini 2.5 Pro Pro
44 tokens/sec
o3 Pro
8 tokens/sec
GPT-4.1 Pro
50 tokens/sec
DeepSeek R1 via Azure Pro
28 tokens/sec
2000 character limit reached

CoCA: Fusing Position Embedding with Collinear Constrained Attention in Transformers for Long Context Window Extending (2309.08646v3)

Published 15 Sep 2023 in cs.LG, cs.AI, and cs.CL

Abstract: Self-attention and position embedding are two key modules in transformer-based 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$\times$), 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

User Edit Pencil Streamline Icon: https://streamlinehq.com
Authors (7)
  1. Shiyi Zhu (4 papers)
  2. Jing Ye (34 papers)
  3. Wei Jiang (341 papers)
  4. Qi Zhang (784 papers)
  5. Yifan Wu (102 papers)
  6. Jianguo Li (59 papers)
  7. Siqiao Xue (29 papers)
Citations (2)
Youtube Logo Streamline Icon: https://streamlinehq.com