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.

ProductSizesMultiply-adds
Forwardy = a @ b(n×k)(k×m)nkm
Backwardgrad_a = grad_out @ bᵀ(n×m)(m×k)nkm
Backwardgrad_b = aᵀ @ grad_out(k×n)(n×m)nkm

The forward is one matmul: nkmnkm multiply-adds, or 2nkm2nkm FLOPs. The backward is two matmuls with the same three sizes, so it costs 4nkm4nkm, 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 5.5×10115.5 \times 10^{11} FLOPs forward and 1.1×10121.1 \times 10^{12} backward.

Predict

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