Basis Lab

Putting a model into service

Account for where one pass of a model through a GPU spends its time, well enough to say which part is the multiply, which part is everything around it, and which setting would move the total

From a Matrix Multiply to a Forward Pass

A model's forward pass is a long list of matrix multiplies with small operations between them. This course covers how the device runs the multiply, what the small operations cost, and what a utilisation figure does and does not say.

8 lessons, written and corrected before you arrived. Reading them here needs no account. The first reads the whole way through; the others open and then stop, because a page nobody owns cannot tell who is reading it. Starting the course gives you your own copy, where every idea has problems standing under it and you can ask about any sentence.

Start reading

  1. 01A Forward Pass Is a List of Matrix Multiplies, and You Can Count Each OneA layer and an attention step are both matrix multiplies. Counting the arithmetic and the bytes in each shows which ones can fill a GPU and which cannot.
  2. 02A Multiply Is Cut Into Tiles So That Each Block of Workers Reuses What It Fetchedopening onlyDone one cell at a time, a matrix multiply fetches every number thousands of times. Cut into tiles, each fetch feeds as many operations as the tile is wide.
  3. 03A Unit That Only Multiplies Small Matrices Is Worth Eight Times, on the Multiplies That Can Feed Itopening onlyA dedicated unit does a whole four by four matrix product in one step. The published gain is eight times, and a multiply collects it only if memory can keep up.
  4. 04Halving the Size of a Number Is Worth Exactly Two to Memory and Whatever the Units Say to Arithmeticopening onlyHalf-size numbers halve the bytes of a multiply, which is worth two when memory is the limit. When arithmetic is the limit the gain is a ratio read off the data sheet.
  5. 05Every Operation Has a Fixed Cost to Start, and the Small Ones Are Nearly All Startopening onlyStarting any operation on the device costs a fixed time that does not shrink with the work. Measure it, and the small operations turn out to be a third of a pass.
  6. 06A Run of Small Operations Joined Into One Pass Pays for One Start and One Trip Through Memoryopening onlyFive element by element operations in a row read and write the table five times and start five times. Joined into one, they do both once, and the saving is exact.
  7. 07A Multiply Fills the Device Only Above a Certain Batch, and the Batch Can Be Computedopening onlyBelow a certain batch a layer leaves the arithmetic units waiting and extra requests are nearly free. Above it each request costs its full arithmetic. The knee is a formula.
  8. 08A Device Reported as Fully Busy May Be Using One Hundredth of Its Arithmeticopening onlyUtilisation is the share of time some function was executing, not the share of the device in use. Two passes at 100 per cent can differ a hundred times in output.