From a Matrix Multiply to a Forward Pass
A Multiply Fills the Device Only Above a Certain Batch, and the Batch Can Be Computed
Last timeJoining Small Operations Together
Below 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.
After joining, a pass is a shorter list of larger operations. The largest are the multiplies by weight tables, and how much of the device each one uses depends on one number the operator controls: how many rows go through together. What It Costs to Run a Model follows that number to the bill. This lesson follows it into the device, for one layer.
Two ways to leave the device idle
The device is not one unit. NVIDIA's performance guide describes the A100 of 2020 as 108 sets of units, and says that a function started with a single block of workers gives work to a single set. It recommends several times as many blocks as sets, about four, so that no set runs dry while others finish.
Take the layer of 4,096 by 4,096 weights, and suppose as an illustration one worker for each output cell in blocks of 256. A batch of rows has cells, which is blocks. One row gives sixteen blocks: ninety-two sets of units have nothing. Seven rows reach 108 blocks and twenty-seven reach four for every set.
That is the first way to be idle, and a small batch escapes it quickly. The second lasts longer. A set of units with work to do can still be waiting on memory, and that is decided by the operations per byte of lesson one.
- the arithmetic, 2 b n squared, after dividing top and bottom by the width n
- the bytes after the same division: the weights give n and the inputs and outputs give 2b, at f bytes a number
- the batch at which I equals the balance point B of the device, found by setting the first expression equal to B and solving for b
The same formula on a named device: the A100 with 80 gigabytes has a peak of 312 trillion two-byte operations a second and moves 2,039 gigabytes a second, a balance point of 153. Its knee for this layer is at 165.4, so 166 rows.
The lesson stops here
3 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 contentsThis 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