Explain How FlashAttention Computes Exact Attention With Tiled Online Softmax

Last updated: November 29, 2026

Quick Overview

Explain why standard attention is limited by memory traffic rather than FLOPs, and show how tiling with an online softmax computes exact attention without materializing the full score matrix, including a working one-query implementation.

Google
Machine Learning
Machine Learning Engineer
Google
November 29, 2026
Machine Learning Engineer
Onsite
Machine Learning
Hard

0

0

0 solved


Explain why standard attention is limited by memory traffic rather than FLOPs, and show how tiling with an online softmax computes exact attention without materializing the full score matrix, including a working one-query implementation.

Long-context Gemini serving and training depend on IO-aware attention kernels on TPUs and GPUs, and Google interviewers for performance-focused ML roles ask candidates to rebuild the core trick. They check the online softmax recurrence and the memory hierarchy argument.

What the Interviewer Expects
  • Explains that naive attention writes and reads an N by N matrix to slow memory
  • Identifies attention as memory-bound for typical head dimensions
  • Derives the running max and running sum rescaling for online softmax
  • Implements it and verifies against the direct computation
  • Explains backward-pass recomputation instead of storing probabilities
  • States that the result is exact, not an approximation
Key Topics to Cover
FlashAttention
Online softmax
Memory hierarchy
Kernel fusion
Long-context attention
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 efficiently inside the tiles?
  • How does this combine with sequence parallelism across devices for million-token contexts?
  • Why does it not change the quadratic FLOP count?
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

Attention: O=softmax(QKT/d)VO = \text{softmax}(QK^T / \sqrt{d})V with sequence length NN and head dimension dd (often 128). The goal is exact attention with memory linear in NN and far less traffic to high-bandwi...

Approach

Naive kernels compute S=QKTS = QK^T, write the N×NN \times N matrix to HBM, read it back for softmax, write PP, read it again for PVPV. FLOPs are O(N2d)O(N^2 d) but memory traffic is O(N2)O(N^2) with low arithm...


Submit Your Answer
Markdown supported