ALiBi: Attention with Linear Biases

medium
Unit 13 · Attention & Normalization0/2 to milestone

ALiBi (Press et al., 2022) drops positional embeddings and instead adds a penalty to attention scores proportional to distance: query i attending to key j ≤ i gets a bias of −mh(i−j)-m_h (i - j), with a different slope mhm_h per head. Models trained this way extrapolate to longer contexts. It's used in BLOOM and MPT.

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
ALiBi: Attention with Linear Biases · TechGradify