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
Machine Learning
Machine Learning Engineer
Together AI
November 29, 2026
Machine Learning Engineer
Technical Screen
Machine Learning
Medium

0

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
FlashAttention
online softmax
numerical stability
tiling
GPU memory hierarchy
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. 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 Prep
Sample Answer
Clarify

One query vector q∈Rdq \in \mathbb{R}^d, keys KK and values VV with NN rows. Target output o=∑iesi∑jesjvio = \sum_i \frac{e^{s_i}}{\sum_j e^{s_j}} v_i with si=q⋅ki/ds_i = q \cdot k_i / \sqrt{d}. Constraint: process $K,...

Approach

Keep three running quantities over the blocks seen so far: the max score mm, the denominator ℓ=∑esi−m\ell = \sum e^{s_i - m}, and the unnormalized output a=∑esi−mvia = \sum e^{s_i - m} v_i. When a new block raises...


Submit Your Answer
Markdown supported

Related Questions