FDEInterviews logoFDE/Interviews
Coding & DSA / 70
hardOpenAIAnthropicGoogle

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.

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.

Unlock the other 466 answers · ₹2,000 / $25Your progress and mastery stay saved · 6 months · one payment · no auto-renew
UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

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.

DISCUSSION · 0

No comments yet — be the first to share your approach.