How do FLOPs scale for a forward pass through an MLP and a transformer?
hardAnswer
- MLP layer(in, out) on batch B: 2 * B * in * out FLOPs.
- Transformer forward (per token, per layer) ≈ (attention softmax + matmuls).
- For long context, attention dominates because it's .
- Approximation: forward FLOPs ≈ 2 * N (params) per token — thus training a model with N params on T tokens takes ~6 * N * T FLOPs (forward + backward + optimizer).
Check yourself — multiple choice
- FLOPs are independent of sequence length
- Forward ≈ 2N per token; training ≈ 6·N·T; attention is
- Only training FLOPs matter
- Attention has fewer FLOPs than the MLP
Rule of thumb: 6·N·T FLOPs to train N-param model on T tokens.
#fundamentals#architectures
Practise Deep Learning
214 interview questions in this topic.
Related questions
- Depth vs width — which do you scale first?
- How do you compute the parameter count of a linear layer and a convolution?
- What do residual connections actually fix?
- ReLU vs sigmoid vs GELU — when do you use each?
- Why do residual (skip) connections help training deep networks?
- In one sentence, what is backpropagation?