Name the additive bias term in attention and the two things it most commonly carries.
Pre-softmax bias matrix B added to QK^T / sqrt(d_k). Carries masking (-inf entries) and positional bias (ALiBi-style linear distance penalty).
Picture a music mixing board where every track has a single 'tweak' knob that the engineer can use for whatever they need on that song. For one song the knob is used to fully mute certain instruments before they hit the speakers. For another song the same knob is used to subtly turn down anything that should sound far away. Same knob, different purpose each time, and both purposes happen before the final mix is heard. The attention bias matrix is that knob. Set entries to negative infinity to mute keys (masking). Set them to distance-based penalties to make far keys quieter (ALiBi).
Detailed answer & concept explanation~6 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: canonical attention formula with B + why pre-softmax is the right slot + masking uses (causal, padding, document, sliding window) + positional bias uses (ALiBi, T5 buckets) + composition + FlashAttention integration.
| Use | Entries of B | Effect after softmax | Example |
|---|---|---|---|
| Causal mask | -inf above diagonal | Zero weight to future positions | Every decoder-only LLM |
| Padding mask | -inf at padding positions | Zero weight to padding tokens | Batched inference with variable lengths |
| ALiBi | -m_h * |i - j| | Distance-decayed weighting per head | BLOOM, MPT |
| Sliding window | -inf outside window | Attention confined to window | Mistral 7B, Llama with SWA |
Real products, models, and research that use this idea.
- Every causal LLM (Llama 4 Maverick, GPT-5.5, Claude Opus 4.7, Mistral, Qwen 3.5) uses the bias slot to apply the causal mask.
- BLOOM and MPT use the bias slot for ALiBi per-head linear distance penalties.
- T5 uses the bias slot for learned relative-position embeddings binned into buckets.
- Longformer and BigBird use the bias slot to mask anything outside their sparse attention patterns.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does FlashAttention handle the bias matrix?
QWhy use -1e9 instead of literal -inf in the mask?
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.
Placing the bias at the wrong stage of the pipeline, after V, inside the dot product, or at the output projection. The canonical attention bias sits at the pre-softmax score matrix.
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.