Count Parameters and FLOPs of a Transformer Block by Hand

Last updated: November 29, 2026

Quick Overview

For a decoder-only Transformer with given model width, feed-forward width, and layer count, derive the parameter count and the forward-pass FLOPs per token, and check the result against a known model size.

Google
Machine Learning
Machine Learning Engineer
Google
November 29, 2026
Machine Learning Engineer
Technical Screen
Machine Learning
Easy

0

0

0 solved


For a decoder-only Transformer with given model width, feed-forward width, and layer count, derive the parameter count and the forward-pass FLOPs per token, and check the result against a known model size.

Back-of-envelope sizing is a habit Google expects from anyone who will request TPU quota or plan a training run. The interviewer wants the matrix shapes in a Transformer block from memory and the 2N FLOPs-per-token rule with its justification.

What the Interviewer Expects
  • Lists the four attention projections and the MLP matrices with shapes
  • Accounts for a gated (SwiGLU) MLP having three matrices
  • Separates embedding parameters from non-embedding parameters
  • Derives about 2 FLOPs per parameter per token for the forward pass and 6 for training
  • Adds the attention score term that grows with sequence length
  • Sanity checks against a familiar 7B-class configuration
Key Topics to Cover
Transformer architecture
Parameter counting
FLOPs estimation
SwiGLU
Compute budgeting
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 grouped-query attention change the attention parameter count?
  • When does the sequence-length term dominate the FLOPs?
  • How do you turn FLOPs per token into training days on a TPU pod given an MFU estimate?
  • Why is the embedding often tied to the output projection?
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

Assume a decoder-only model, width dd, MLP hidden width dffd_{ff}, LL layers, full multi-head attention, RMSNorm with only gain parameters, no biases. Embedding and output matrices are counted separa...

Approach

Attention has WQ,WK,WV,WOW_Q, W_K, W_V, W_O, each d×dd \times d, so 4d24d^2. A classic MLP has d×dffd \times d_{ff} up and dff×dd_{ff} \times d down: 2d⋅dff2 d \cdot d_{ff}. A gated MLP adds a third matrix: $3 d \cdot d_{...


Submit Your Answer
Markdown supported