← Back to the chip

How a large language model runs, and what that asks of a chip.

A walkthrough of Llama 3 8B inference: tokens, the 32 transformer blocks, where the weights are, and why generating text spends most of its time waiting on memory. Everything Systole's design decisions are built on.

Why the workload matters

Systole is an accelerator for large language model inference: the part of running a model where it answers, one token at a time. It was taken from these first questions all the way to a routed 7 nm chip layout on open-source tools: hardware generated with Chipyard, laid out with OpenROAD through OpenROAD-flow-scripts, on the ASAP7 predictive 7 nm kit from Arizona State University. ASAP7 is a research kit, so nothing here has been to silicon.

A chip like this is only as good as its fit to the work, so this page is about the work. The reference model is Llama 3 8B: a real, widely deployed model whose dimensions are public. Every size on this page comes from its shapes.

From a prompt to a reply

The model never sees text. The prompt is cut into tokens, pieces of words each with a number, and every token number is looked up in a table to get a vector: a list of 4,096 numbers that the rest of the model works on. From there the run has two phases.

FROM A PROMPT TO A REPLYPrompttext inTokenizetext to numbersEmbednumber to vectorPrefillwhole prompt, 32 blocksPredictpick next tokenReplytokens to textDecodethe newest token, 32 blocksrepeat untilan end tokenThe prompt is read once, all at once.Every later token goes through the modelalone, reusing what earlier tokens leftin the key/value cache.
Prefill pushes every prompt token through the model in one pass. Decode then produces the reply one token at a time: each new token goes back in alone, and the model predicts the one after it.

Decode would be hopeless if each new token had to recompute the whole conversation. It does not, because of the key/value cache: as each token passes through a block, the block stores two small vectors for it, its key and its value. A later token only computes its own and reads everyone else's from the cache. The cache saves the arithmetic, but it has to be read back on every step, and it grows with the conversation.

Inside one block

Llama 3 8B is 32 identical blocks in a row. Each one does two jobs, each wrapped so its result is added back onto what came in.

ONE TRANSFORMER BLOCK (LLAMA 3 8B HAS 32)NormalizeAttentionmixes tokens+NormalizeFeed-forwardper token+vectors inoutAttention lets each token look at the ones before it. Feed-forward then works on each token on its own. Both are mostly matrix multiplies.
Dashed lines are the add-back paths. Normalizing rescales each vector so the numbers stay in a workable range.
ATTENTION

Tokens look at each other

Each token's vector is multiplied by three weight matrices to make a query (what it is looking for), a key (what it offers) and a value (what it passes on). Its query is compared with every earlier token's key, the scores become weights through a softmax, and the weighted sum of their values is its new context. This runs as 32 parallel heads, each 128 numbers wide, and an output matrix mixes them back together. A token may only look backwards, never at the words still to come.

FEED-FORWARD

Each token, on its own

Each vector is widened from 4,096 to 14,336 numbers by two matrices (gate and up), passed through a smooth on/off function, and narrowed back to 4,096 by a third (down). No token sees any other here. This is where most of the model's stored knowledge lives, and most of its weights.

Where the numbers are

Almost all of that is matrix multiplication against fixed weight matrices. These are the seven in every layer, from the model's published dimensions:

THE WEIGHT MATRICES IN ONE LAYER, MILLIONS OF NUMBERSQuery4096 x 409616.78Key4096 x 10244.19Value4096 x 10244.19Output4096 x 409616.78Feed-forward gate4096 x 1433658.72Feed-forward up4096 x 1433658.72Feed-forward down14336 x 409658.72ATTENTIONFEED-FORWARD218 million numbers per layer, times 32 layers: 6.98 billion of the model's 8.03 billion. Feed-forward holds 81 percent of them.
Key and value are a quarter the size of query because Llama 3 shares each key/value head between four query heads. The attention comparisons themselves use no stored weights: they multiply the token's query by the cached keys and values, which is why the cache must be read every step.

Two phases, opposite bottlenecks

Every one of those weights has to come from off-chip memory, and how many times it is used once it arrives decides everything. In prefill, a prompt of hundreds of tokens multiplies by each weight hundreds of times. In decode, one token multiplies by each weight once, and the chip mostly waits. Try it:

multiply-adds, one layer
bytes read from memory, one layer
multiply-adds per byte
016: what the array needs to stay busy64

8-bit numbers, a 128×128 array at 1 GHz (16,384 multiply-adds per nanosecond) and 1 TB/s of memory: the array stays busy only if each byte read feeds at least 16 multiply-adds. Weights are read once per step and shared by every token in it; each conversation's cache is read separately. The same model as the design sweeps below. Timing assumes every cell is used; the array-size sweep puts real use at about 89 percent.

That one ratio is why the rest of the chip looks the way it does. Prefill keeps the array busy on its own. Decode only does when many conversations share each weight, which is why Systole was designed around serving about 32 at once.

What runs where on Systole

WorkRuns on
Every matrix multiply: query, key, value and output, the three feed-forward matrices, the attention comparisons, the final vocabulary projectionThe 128×128 matrix array (Gemmini, with Systole's 8-bit floating-point datapath)
Staging weights, activations and results next to the arrayThe Scratchpad, the array's own on-chip memory
Everything else per token: softmax, normalization, the gate's on/off function, position encodingThe Saturn vector unit
Running the token loop and telling the other blocks what to doThe Rocket control core
Weights and the key/value cache for the whole modelOff-chip memory, through the level-2 cache and memory controller
Turning text into tokens and backThe host: the chip takes token numbers in and gives token numbers out

Next

With the workload in hand, the main page picks up with the three design decisions it drove: how many conversations to serve at once, how big to make the array, and which number format to compute in. Then the chip itself.

Continue to the design choices →