Skip to content
Athrael.net logoAthrael.net

Introduction to GPU InferenceChapter 1: Foundations

From prompt to reply

Lesson 1 of 4 · about 6 min

What this lesson covers

When you ask an AI assistant such as ChatGPT or Claude a question, a GPU in a server computes the reply. This lesson explains what happens between sending a prompt and reading the last word of the reply.

If you’d rather listen, the player at the bottom of the page reads the lesson aloud and scrolls along with it.

What is inference?

A language model is first trained on a large amount of data, most of it text, which takes weeks or months. Using the trained model to produce a reply is called inference, and it runs every time someone sends a prompt.

The path of one question
You
GPU server
Language model
Reply
  1. 1Your prompt travels to a server that has a GPU.
  2. 2The model runs on the GPU and computes a reply.
  3. 3The reply comes back a piece at a time.
Pick a prompt and press Send. The three replies are written in advance.

Tokenization

A model works with numbers, so text is first split into small pieces called tokens, a step called tokenization. A short word is usually one token and a longer word is often several, and each token is then replaced by a number.

The diagram below splits text into tokens and can show each one as the number the model receives. You can type any text into it.

Tokenization
The tokenization in this diagram is simplified. Real models learn their vocabulary from data, so they split text differently and use different numbers.

Tokens are also the unit for how much text a model can process at once, how fast it generates, and what a reply costs.

Generating a reply

A model generates its reply one token at a time. It processes all the text so far, predicts the next token, appends it and repeats, which is why answers appear on your screen word by word.

Generating a reply
The text so far
Language model
Most likely next token
The wait for the first tokenThen one token per step
Only the top three candidates are shown, and their percentages are invented for this example.

The bar at the bottom shows the delay while the model processes your prompt, before anything appears, and then the steady rate of new tokens, which are measured as time to first token and tokens per second.

GPU vs CPU

Predicting one token takes billions of multiplications. Each one is simple and most are independent of each other, so they can be computed in parallel.

A CPU, the main processor in a laptop, has a few fast cores, while a GPU has thousands of simpler ones. For a large number of independent calculations, the GPU’s many cores finish first.

CPU and GPU cores
CPU
A few fast cores
GPU
Thousands of simpler cores
Each square is one multiplication. The real numbers are far larger.

Memory constraints

A model is a set of numbers called parameters, so an “8 billion parameter” model has 8 billion of them, and they are normally all loaded into the GPU’s own memory before it runs.

How much memory they take depends on the precision each number is stored at, and lower precision makes the model smaller at some cost in quality.

Model size and GPU memory
Model size
Precision
GPU memory
The memory shown is for the model's parameters. A running server also needs working memory for each conversation, so leave some room.

In practice you choose the model size, the precision and the GPU together.

Recap

Inference is a trained model producing a reply to a prompt. The prompt is split into tokens, and after a short delay to process them, the model generates the reply one token at a time. Each token takes billions of calculations, which a GPU computes in parallel on thousands of cores, and the model’s parameters normally have to fit in the GPU’s memory, which depends on their precision.

This is why replies arrive word by word and why limits and prices are counted in tokens, and a label like “8B” or “4-bit” gives a model’s size and the memory it needs.