Contrast ALiBi's linear distance bias with RoPE's vector rotation, which one modifies scores additively, and which one modifies Q and K directly?
ALiBi: additive per-head bias on pre-softmax scores. RoPE: rotation applied to Q and K vectors before the dot product. Different stages, both relative.
Picture a classroom where students at the back hear the teacher less clearly. ALiBi is like installing the same kind of volume drop in everyone's ears, the speaker stays the same, but distant listeners hear softer audio by a fixed amount per row. RoPE is different. Imagine the teacher and each student wear a turntable on their head, and the turntable spins by an amount that depends on which seat they are in. The lecturer's voice arrives clearly only when the two turntables are spinning in compatible ways, which depends on the difference between their seats. ALiBi adjusts how loud each link sounds. RoPE adjusts how each speaker and each listener are oriented before they connect.
Detailed answer & concept explanation~5 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
6-8 min: pipeline stages of each scheme + formulas + relative property derivation + length-extrapolation behavior + production adoption + kernel integration.
| Property | ALiBi | RoPE |
|---|---|---|
| Pipeline stage | Score matrix (after QK^T) | Q and K vectors (before dot product) |
| Operation | Additive bias | Rotation (multiplicative) |
| Parameters | Zero (fixed slopes) | Zero (fixed base frequency) |
| Length extrapolation | Native, with receptive-field cap | Needs PI / NTK / YaRN extension |
| Modern adoption | BLOOM, MPT, some efficient stacks | Llama, Mistral, Qwen, DeepSeek, Gemma |
Real products, models, and research that use this idea.
- BLOOM 176B (BigScience, 2022) and MPT-7B/30B (MosaicML, 2023) ship with ALiBi.
- Llama 1 through Llama 4 Maverick, Mistral, Qwen 3.5, DeepSeek V4, and Gemma 4 use RoPE.
- Long-context Llama and Mistral variants use YaRN or NTK-aware extension on top of RoPE to push context past 32k.
- FlashAttention 2 and 3 implement RoPE inside the attention kernel; the ALiBi bias is added as a closed-form function of (i - j) with no extra tensor allocation.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does RoPE produce a relative property without explicitly subtracting positions?
QWhat is YaRN, and what does it do for RoPE?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Claiming both schemes act at the same stage of the pipeline. They do not. ALiBi acts on the scalar score matrix; RoPE transforms Q and K before the dot product even runs.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.