How do RoPE and ALiBi approach positional encoding for long-context generation, and what are their trade-offs?
RoPE (Rotary Position Embedding) rotates Query and Key vectors in 2D subspaces by position-dependent angles so their dot product naturally depends on relative token distance (n - m), whereas ALiBi eliminates positional embeddings altogether and subtracts a fixed, head-specific linear distance penalty from attention logits. RoPE preserves content-driven attention and dominates modern LLMs, though extending beyond training length requires frequency-scaling techniques such as PI, NTK-aware scaling, or YaRN. ALiBi extrapolates smoothly without tuning, at the cost of a fixed locality bias that can weaken long-range retrieval.