The Maths You Actually NeedLesson 59 of 76

Module 7 · Counting the cost: complexity and the arithmetic of scale

Counting the floating-point operations in a layer and a training run

In this lesson

  • 9 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 2 of 9 in this chapter

This chapter’s goalCount the FLOPs of a forward pass and a training run from a parameter count, compute the memory a model needs at each precision and in training, say from arithmetic intensity whether a workload is bound by compute or by memory bandwidth, recognise a quadratic cost in a pipeline and name the sub-quadratic replacement, and estimate the time or cost of an ML job to within a factor of three before running it.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available
From a parameter count to days on a cluster7 billion parametersthe whole cost modelstarts from this onecount6 FLOPs perparameter per tokentwo for the forwardpass, four for thebackward1 trillion trainingtokens6 times 7 billiontimes 1 trillion is4.2 times ten to the22 FLOPs125 trillion FLOPs asecond40 per cent of anA100’s rating: 10.7years on one card, 3.9days on a thousandTwo multiplications and a division. Every published training run can be checked this way in under aminute, from numbers that are always in the announcement, and long before anyone quotes a price.
Two multiplications and a division. Every published training run can be checked this way in under a minute, from numbers that are always in the announcement, and long before anyone quotes a price.

Figure

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

One entry, one dot product

Module 2 showed that every entry of a matrix product is a dot product between a row of the left matrix and a column of the right. A dot product of length k is k multiplications and k additions: 2k floating-point operations, or FLOPs. Multiplying an m × k matrix by a k × n one produces m × n entries, so

Text
FLOPs of (m × k) · (k × n) = 2 × m × n × k

That one line is most of the cost accounting of deep learning.

A linear layer taking a 4,096-dimensional vector to another 4,096-dimensional vector is a 4096 × 4096 matrix applied to one column:

Text
2 × 4096 × 4096 × 1 = 33.5 million FLOPs

for one token. The matrix has 16.8 million parameters, and each parameter was used exactly once, for one multiplication and one addition. That generalises.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘Counting the floating-point operations in a layer and a training run’, in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/flops-of-a-matrix-multiply (Accessed: 29 November 2026).