softmax(QKᵀ/√d_k)·V in four lines, but the grade is the three details people drop: the √d_k scale, subtracting the row max for numerical stability, and getting the causal mask to add -inf before the softmax, not after.
Implement scaled dot-product attention (the forward pass).
softmax(QKᵀ/√d_k)·V in four lines, but the grade is the three details people drop: the √d_k scale, subtracting the row max for numerical stability, and getting the causal mask to add -inf before the softmax, not after.
Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.
This is the canonical LLM-team coding screen. Interviewers want to see you reason about tensor shapes out loud, justify the √d_k scale (it keeps softmax out of the saturated regime), and apply the max-subtraction trick so exp does not overflow. The causal mask is the trap: it must set masked logits to -inf BEFORE softmax so they get zero weight, and candidates who zero the weights after softmax break the normalization.
No comments yet — be the first to share your approach.
