26/31
Part 6 of 6 · What interviewers ask nextLearn and do
What interviewers ask next
FLOPs: the backward costs twice the forward
The first follow-up is usually the cost.
| Product | Sizes | Multiply-adds | |
|---|---|---|---|
| Forward | y = a @ b | (n×k)(k×m) | nkm |
| Backward | grad_a = grad_out @ bᵀ | (n×m)(m×k) | nkm |
| Backward | grad_b = aᵀ @ grad_out | (k×n)(n×m) | nkm |
The forward is one matmul: multiply-adds, or FLOPs. The backward is two matmuls with the same three sizes, so it costs , twice the forward. A training step costs about three forwards.
That's the rule of thumb of 6 FLOPs per parameter per token: 2 in the forward and 4 in the backward. Kaplan et al. (2020) count the backward the same way, at about twice the forward.
For a 4,096 by 4,096 weight and a batch of 16,384 tokens, that's FLOPs forward and backward.
A first layer's input is raw data. What does that layer's backward cost, against its forward?
Pick an answer above to see the rest