Basis Lab

From a Matrix Multiply to a Forward Pass

Halving the Size of a Number Is Worth Exactly Two to Memory and Whatever the Units Say to Arithmetic

Last timeUnits Built for Just This

Half-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.

What It Costs to Run a Model asks how few bits a weight needs, and *Making a Model Smaller* asks what that does to the answers. This lesson takes the decision as made, four bytes a number down to two, and asks only what the device does with it. The vendor's guide on the subject names two separate effects, and they belong to the two limits.

The two effects

A multiply takes the longer of two times: the time to move its bytes and the time to do its arithmetic.

FIG 1The time of one multiply
the numbers read and written, which does not depend on their size
the bytes per number, four or two
the memory rate of the device in bytes a second, which does not depend on what the bytes mean
the operations, which also do not depend on the size of a number
the peak arithmetic rate for numbers of f bytes, a figure the builder publishes for each format
Halving f halves the first term exactly. It changes the second only through the published peak, which may double, stay the same or jump by more.

The first term is simple. Half the bytes, half the wait. In the guide's words, half-size numbers halve the bytes accessed and so reduce the time spent in memory-limited layers. The factor is two and nothing can make it more.

The second term is a matter of what was built. Nothing about a smaller number makes arithmetic quicker in itself. The gain is the ratio of two peaks on a data sheet, and it depends on which two.

The lesson stops here

5 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01A Forward Pass Is a List of Matrix Multiplies, and You Can Count Each One
  2. 02A Multiply Is Cut Into Tiles So That Each Block of Workers Reuses What It Fetchedopening only
  3. 03A Unit That Only Multiplies Small Matrices Is Worth Eight Times, on the Multiplies That Can Feed Itopening only
  4. 04Halving the Size of a Number Is Worth Exactly Two to Memory and Whatever the Units Say to Arithmeticyou are here
  5. 05Every Operation Has a Fixed Cost to Start, and the Small Ones Are Nearly All Startopening only
  6. 06A Run of Small Operations Joined Into One Pass Pays for One Start and One Trip Through Memoryopening only
  7. 07A Multiply Fills the Device Only Above a Certain Batch, and the Batch Can Be Computedopening only
  8. 08A Device Reported as Fully Busy May Be Using One Hundredth of Its Arithmeticopening only

Read alongside