Skip to main content

GPU concepts explained

8-Bit Weights: 4x Smaller, Only 1.4x Faster. Why?

Published 4 min 5 sMeasured on NVIDIA RTX 3090

What this video shows

About this walkthrough

Storing weights in 8 bits instead of 32 makes them four times smaller, but one matrix-vector product ran only 1.4 times faster: 61.70 against 84.96 microseconds. The kernel still made the same number of reads, each carrying a quarter of the bytes. Reading four 8-bit weights per request brings it to 28.99 microseconds, 2.9 times faster than the 32-bit kernel. These are median kernel times of 23 launches on 4,096 by 4,096 weights: one multiply on one GPU, not a whole model.

Read along

Transcript

Select a time to play the video from that chapter.

0:00The promise

People say: store a model's weights in 8 bits instead of 32, and it runs faster. The weights get four times smaller. So is it four times faster? We tried it on a real GPU. It was 1.4 times faster. Where did the rest go?

0:18The job: weights times a list

First, the job. To pick the next word, a language model multiplies a big grid of numbers, called weights, by a list of numbers. Take one row. Multiply each weight by its partner, then add everything up. That's one output. Notice: every weight is used exactly once.

0:39The real size

Now the real size. Our grid has 4,096 rows and 4,096 columns. That's almost 17 million weights. Stored as 32-bit numbers, each one takes four bytes. 67 megabytes. And every one of those bytes has to travel from the GPU's memory to a thread.

1:01A storeroom, a hallway and a cart

Picture it like this. The threads are students at their desks. The weights sit in a storeroom down the hall, and a cart brings them over. Threads always work in groups: 32 at a time. Each trip, every student in the group asks for one weight. Four bytes each: 128 bytes on the cart. The cart is full. We run this kernel, the function the GPU executes, and time it. 85 microseconds.

1:30The 8-bit idea

Now shrink the weights. Instead of storing 0.042, store the small whole number 42 in a single byte. And keep one scale, 0.001, for the whole row. Small number times scale gives the weight back. One byte instead of four. In a real model, this rounds the weights a little. In this lab nothing is lost, and both versions give the same answer.

1:58One line changes

In the kernel, one line changes. Read the small number, turn it into a regular number, and multiply by the scale. Everything else stays the same.

2:09Measured: 1.4x, not 4x

Run it again. 85 microseconds becomes 62 microseconds. That's 1.4 times faster. Not four.

2:19Same trips, lighter cart

So look at the cart again. Each student still asks for one weight. That means the same number of trips as before. But now a trip carries 32 bytes, not 128 bytes. The cart is three-quarters empty. And a nearly empty trip still costs most of a full one. We cut the bytes. We did not cut the trips.

2:42Fill the cart

So fill the cart. Let each student ask for four weights at a time. Four small weights are four bytes, exactly the size of one old weight. The cart is full again, and there are a quarter as many trips. The arithmetic for each weight is the same as before.

3:00Measured: 2.9x

Run it. 29 microseconds. That's 2.9 times faster than where we started. On a grid four times larger, it reached 3.6 times.

3:12One more test

One more test, to be sure. Give the 32-bit version four per trip as well. 85 microseconds becomes 78 microseconds. It barely moves, because its cart was already full. Bigger requests only help when the trips are light.

3:30Remember this

So remember this. Smaller data is four times smaller, always. Four times faster is not automatic. After you shrink the data, change how you ask for it. Count the trips, not just the bytes. And measure, because this is one multiply on one GPU, not a whole model.

3:51Try it yourself

You can try it yourself. The lab is called Quantized GEMV, in the GPUFlight Performance Lab. The lab takes you to the first step. Four weights per read is your next one.

Measure it yourself

Run the same experiment on a real GPU

Edit the kernel in your browser, run it on managed hardware, and read the profile the video walks through.

Run the 8-bit weights lab