RoFormer: Enhanced Transformer with Rotary Position Embedding
Jianlin Su, Yu Lu, Shengfeng Pan, Ahmed Murtadha, Bo Wen, Yunfeng Liu
Neurocomputing 2024 · arXiv 2104.09864 · Read the paper ↗
Encode position by rotating queries and keys, so attention scores depend on relative distance. Used by Llama and most open LLMs.
2 steps + 3 beyond the paper · 0 solved
Start: Rotary position embedding →- 1Rotary position embeddingRotate each pair of dimensions by position times frequency.Rotate a vector by its position (RoPE)
- 2RoPE inside a blockUse RoPE with RMSNorm and SwiGLU in a Llama-style block.Convert a GPT block to a Llama-style block (RMSNorm, RoPE, SwiGLU)
Beyond the paper
Follow-up ideas that build on this paper. Each blurb names the follow-up work.
- 3Position interpolationExtension: stretch context by scaling positions (Chen et al., 2023).Position Interpolation for RoPE angles
- 4NTK-aware scalingExtension: scale the base instead of the positions.Scale RoPE frequencies with NTK-aware interpolation
- 5YaRN frequency rampExtension: per-frequency interpolation (Peng et al., 2023).YaRN frequency ramp and attention temperature
More transformers and llms papers
- Attention Is All You Need 2017
- LoRA: Low-Rank Adaptation of Large Language Models 2021
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness 2022
- Direct Preference Optimization: Your Language Model is Secretly a Reward Model 2023
- Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity 2021
- Fast Inference from Transformers via Speculative Decoding 2022
- LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale 2022