Fourier Position Embedding: Enhancing Attention's Periodic Extension for Length Generalization

Ermo Hua, Che Jiang, Xingtai Lv, Kaiyan Zhang, Ning Ding +5 more
12/1/2024

No official code found. Best implementation: TsinghuaC3I/Fourier-Position-Embedding (121 stars, last commit 2025-06-02).

Abstract

Extending the context length of Language Models (LMs) by improving Rotary Position Embedding (RoPE) has become a trend. While prior works mainly address RoPE's limitations within attention, this paper uncovers the adverse effects on length generalization from nearly all parts of LMs. Using Discrete Signal Processing theory, we show that RoPE enables periodic attention by implicitly achieving Non-Uniform Discrete Fourier Transform. However, this periodicity is undermined by the spectrum damage caused by: 1) linear layers and activation functions; 2) insufficiently trained frequency components brought by time-domain truncation. Building on our observations, we propose Fourier Position Embedding (FoPE), which enhances attention's frequency-domain properties to improve both its periodic extension and length generalization. FoPE constructs \textit{Fourier Series} and zero-outs the destructive frequency components, increasing model robustness against the spectrum damage. Experiments across various model scales and benchmarks show that, within varying context windows, FoPE maintains a more stable performance compared to other baselines. Several analyses and ablations bring further support to our method and theoretical modeling.

View on arXivView PDF

Code Implementations(1)

[ICML 2025] Fourier Position Embedding: Enhancing Attention’s Periodic Extension for Length Generalization

1219C, C++Dec 1, 20241 years ago

Cite this paper

@article{hua2024fourier,
  title  = {Fourier Position Embedding: Enhancing Attention's Periodic Extension for Length Generalization},
  author = {Ermo Hua and Che Jiang and Xingtai Lv and Kaiyan Zhang and Ning Ding and Youbang Sun and Biqing Qi and Yuchen Fan and Xuekai Zhu and Bowen Zhou},
  year   = {2024},
  eprint = {2412.17739},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2412.17739},
  journal = {ICML 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2412.17739.svg)](https://codeofpaper.com/paper/2412.17739)

Discussion