Compute Attention in One Pass with Online Softmax
Last updated: November 29, 2026
Quick Overview
Explain and implement single-query scaled dot-product attention that reads keys and values in tiles and never materializes the full score vector, producing the same result as the naive softmax-then-weighted-sum.
Together AI
November 29, 20260
0
0 solved
Explain and implement single-query scaled dot-product attention that reads keys and values in tiles and never materializes the full score vector, producing the same result as the naive softmax-then-weighted-sum.
Together AI's research and kernels teams are known for FlashAttention, whose core trick is the online softmax rescaling that lets attention be computed tile by tile in fast on-chip memory. This screen checks that a candidate understands the math well enough to derive the rescaling, not just name the paper.
What the Interviewer Expects
- Explains why naive attention is memory-bound on the N-by-N score matrix
- Derives the running max, running denominator and rescaling factor
- Implements it and checks against a naive reference
- Discusses numerical stability with large logits
- Connects tiling to SRAM versus HBM traffic on a GPU
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- How does the backward pass avoid storing the attention matrix?
- How would you add a causal mask, and which tiles can be skipped entirely?
- Why does decoding with one query token benefit from splitting the KV sequence across thread blocks (split-K)?
- What changes for grouped-query attention?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
One query vector , keys and values with rows. Target output with . Constraint: process $K,...
Approach
Keep three running quantities over the blocks seen so far: the max score , the denominator , and the unnormalized output . When a new block raises...