One question, six layers
When you type a question into a chat app, it passes through several layers before an answer comes back. People in the field call this pile the stack. Here it is, top to bottom.
- Apps and agentsWhat you see and use: a chat app, a coding agent, a bot inside a messaging app
- HarnessThe code around the model: it adds instructions, offers tools, runs them, and manages the conversation
- API and serving engineTakes requests in an agreed format and runs the model for many people at once: llama.cpp, Ollama, vLLM, SGLang
- ModelFiles of weights, plus the tokenizer and the chat template
- KernelsSmall, tuned programs that do the maths on the chip: CUDA on Nvidia, Metal on Apple
- HardwareThe chips and their memory: GPUs, CPUs, phones, data centres
Each layer talks only to the ones next to it, so you can swap one without touching the rest. The same model file runs under llama.cpp on a laptop and under vLLM in a data centre. The same harness can drive DeepSeek one day and Claude the next. When a new tool appears in the news, the first useful question is: which layer is it?
The bottom: chips and memory
Almost all the work a model does is multiplying large tables of numbers, called matrices (you will meet them properly in part 2). The same simple sum is repeated billions of times, and most of those sums do not depend on each other, so they can all be done at the same moment.
CPU: a few strong workers
- The main chip in every computer and phone, usually with 4 to 24 cores.
- Each core is fast and clever, and good at long chains of different steps.
- Can run small models, but slowly, because it does few sums at a time.
GPU: thousands of simple workers
- Built to draw video games, which also means doing the same sum on many numbers at once.
- A high-end gaming GPU has over ten thousand small cores; data-centre GPUs add special units just for matrices.
- This is why the AI boom runs on GPUs, and why Nvidia became one of the world’s most valuable companies.
Here is the surprise: for writing text, the speed of the sums is usually not the limit. Memory is. To write each new token, the chip has to read every weight it uses from memory, once. A model of 5 GB means 5 GB read for every single token. So two numbers decide what a machine can do with a model:
- How much memory it has. If the model does not fit, it cannot run, or it runs very slowly from slower memory.
- How fast that memory is, called memory bandwidth and measured in gigabytes per second (GB/s). This sets the top speed at which it can write.
| Memory | Memory speed | What it can run | |
|---|---|---|---|
| Nvidia RTX 3060 (gaming card) | 12 GB | 360 GB/s | Models up to about 14B parameters, squeezed to 4 or 5 bits per weight |
| Nvidia RTX 4090 (gaming card) | 24 GB | about 1,008 GB/s | Models up to about 30B, squeezed |
| Nvidia RTX 5090 (gaming card) | 32 GB | about 1,792 GB/s | Models up to about 40B, squeezed, quickly |
| Apple M5 Max laptop | up to 128 GB, shared with the CPU | up to 614 GB/s | Large models, including mixtures of experts of over 100B, more slowly |
| Nvidia H100 SXM (data centre) | 80 GB | 3,350 GB/s | Serving big models to many users; several are linked for the largest |
Bandwidth figures are the makers’ own. “Squeezed” means quantized, which has its own lesson in part 6.
tokens per second ≤ memory bandwidth ÷ bytes read per tokenEvery token needs the weights read once, so the memory speed sets a ceiling.
1,008 GB/s ÷ 4.9 GB ≈ 200 tokens per secondAn 8B model squeezed to 4.9 GB, on an RTX 4090. Real programs stay below this ceiling, because there is other work to do as well.
Between the model and the chip sit kernels: small, heavily tuned programs that each do one job, such as multiplying two matrices or computing attention. Nvidia’s are written in CUDA, Apple’s in Metal; AMD uses ROCm, and Vulkan works on most graphics chips. A better kernel makes the same model on the same chip faster. In 2022, FlashAttention rearranged how attention reads and writes memory, and GPT-2 trained about 3 times faster with exactly the same maths.
Quick check
The model: what is actually in the download
Open models are shared on Hugging Face, a website that works like a library for models and datasets. Each model has a page with a list of files. Here is the real list for Qwen/Qwen3.8-27B, a 27.8-billion-parameter open model from Alibaba’s Qwen team, released in August 2026.
| File | What it holds |
|---|---|
| config. | The model’s shape: how many layers, how many attention heads, how long each vector is. A few kilobytes. |
| model- | The weights themselves, split into 18 files: 27.8 billion numbers at 16 bits each, 55.6 GB in all. |
| model. | A map of which weight is in which of the 18 files. |
| tokenizer. | The tokenizer: how text is cut into tokens and how each token gets its number. |
| chat_ | How a conversation (instructions, your messages, the model’s replies, tool calls) is written out as one long text for the model to read. |
| generation_ | Suggested settings for picking tokens, such as the temperature. |
That is all a model is: a description of its shape, a huge pile of numbers, and the rules for turning text into numbers and back. No hidden database of facts, no list of answers. Everything it knows is spread across those 27.8 billion weights.
size in bytes = parameters × bits per weight ÷ 8There are 8 bits in a byte.
27.8 billion × 16 ÷ 8 = 55.6 billion bytes = 55.6 GBThe original weights use 16 bits (2 bytes) per number.
55.6 GB is too big for most computers. So the same model is also published in GGUF, the single-file format of llama.cpp, which packs the weights, the tokenizer and the chat template together. GGUF files are usually quantized: each weight is stored with fewer bits, losing a little accuracy to save a lot of memory.
The vision part comes as a separate small file, mmproj (0.93 GB). The repository also has mtp and dflash files: small draft helpers that let it write faster by guessing several tokens ahead. All sizes from the Hugging Face file listings, 20 October 2026.
Quick check
Engines and APIs: making the model run
A weight file does nothing by itself, just as a recipe book does not cook. A serving engine (also called an inference engine) loads the weights into memory, turns your text into tokens, runs the maths through the kernels, picks each next token and sends the answer back, often to many people at the same time. These are the main ones, all free and open source.
| Engine | Best at | Runs on |
|---|---|---|
| llama. | Running models on ordinary computers and phones, from GGUF files, squeezed to fit | Almost anything: Nvidia, AMD, Apple, Intel, plain CPUs |
| Ollama | The easiest start: one command downloads a model and opens a chat; it also serves an API on your machine | Windows, Mac and Linux |
| vLLM | Serving many users at once in a data centre; it invented PagedAttention, a way to share GPU memory between requests | Data-centre GPUs |
| SGLang | Fast serving, especially for agents that send the same long instructions again and again | Data-centre GPUs |
| mlx- | Running models on Macs with Apple chips, using Apple’s MLX library | Apple Macs |
An engine usually waits at a web address and speaks an API (application programming interface): an agreed format for questions and answers, so that programs can talk to it. Most of the industry copied OpenAI’s format, at the address /v1/chat/completions. That means the same code can talk to DeepSeek’s servers, a vLLM server or llama.cpp on your own laptop, just by changing the address. Anthropic’s format, /v1/messages, is the other common one. DeepSeek’s API and llama.cpp’s server both speak both.
$ ollama run gemma4
$ llama cli -hf ggml-org/gemma-4-E4B-it-GGUF:Q4_0
$ llama serve -hf ggml-org/gemma-4-E4B-it-GGUF:Q4_0
$ curl http://localhost:9931/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "What is a GPU?"}]}'
ollama run gemma4downloads Google’s Gemma 4 model and opens a chat in the terminal.llama clidoes the same with llama.cpp.-hfdownloads from Hugging Face, and:Q4_0picks the 4.6 GB squeezed file of the small Gemma 4 E4B model.llama servestarts a server on your own computer instead, at port 9931, that speaks the OpenAI and Anthropic APIs.curlsends it a question in the OpenAI format, the same way any app would. The lesson on local AI walks through all of this step by step.
The harness: what turns a model into a worker
A model only ever does one thing: it reads text and writes text. It cannot open a file, search the web, or remember yesterday. Everything else is done by the program around it. The documentation of Claude Code, a coding agent, calls that program the agentic harness: “the layer around the model that provides the tools and manages the context”.
Watch a harness at work. Press the button to step through one small request.
-
You
How much free space is left on my disk?
-
Harness
Sends the model three things: its standing instructions, a list of the tools it may use (here, one that runs a command), and your question.
-
Model
Asks for a tool instead of guessing:
{"tool": "run_command", "command": "df -h /"} -
Harness
Checks that this command is allowed, runs it on your computer, and adds the output to the conversation.
-
Tool result
Size Used Avail Use% 476G 301G 151G 67% -
Model
You have about 151 GB free on your main drive, out of 476 GB. It is two thirds full.
That loop (the model asks for a tool, the harness runs it, the result goes back into the text the model reads) is what makes an agent. The harness also decides what the model sees: which instructions, which files, how much of the conversation, and what to drop when the text gets too long. Part 7 of the course is all about it.
The harness matters as much as the model. A study of coding agents published in September 2026 changed only the harness around the same models. With a small working memory of 32,000 tokens, one model solved 6.4 % of the tasks when the harness did nothing about old tool output, and 55.6 % when the harness trimmed and summarised it. That is why model makers now name the harness next to their agent scores.
Open or closed, at home or in the cloud
You now have the words for one of the biggest choices in AI: where the model layer and the layers below it live.
| Open model, on your own machine | Open model, in the cloud | Closed model, through its maker | |
|---|---|---|---|
| Examples | Gemma 4, Qwen3.8 or gpt-oss, through llama.cpp or Ollama | DeepSeek, Kimi or GLM, on the maker’s API or a hosting company | GPT, Claude, Gemini, Grok |
| Your data | Never leaves your computer | Sent to the provider | Sent to the provider |
| Cost | The computer you already have, and electricity | Pay for each token, often cheaply | Pay for each token, or a monthly plan |
| Size limit | Your memory | None for you: the largest open models have over a trillion parameters | None for you; often the strongest models |
| Control | Complete: you can look inside, fine-tune it, and keep the exact version for ever | You choose the model; the provider runs it | The maker can change or retire a model at any time |
Many people mix them: a small local model for private notes or for working offline, and a large cloud model for the hardest jobs. Because almost everything speaks the same API, switching is often a one-line change.
Which layer of the stack does each one belong to?
-
An RTX 4090 graphics card
Answer: Hardware
-
Qwen3.8-27B-Q4_K_M.ggufAnswer: Model
-
llama.cpp
Answer: Engine or API
-
Claude Code
Answer: Harness or app
-
tokenizer.jsonandconfig.jsonAnswer: Model
-
An Apple M5 Max chip
Answer: Hardware
-
http://localhost:11434/api/chat, Ollama’s address on your machineAnswer: Engine or API
-
A chat app that searches the web for you
Answer: Harness or app
Remember
- The AI stack has six layers: hardware, kernels, the model, the serving engine and its API, the harness, and the app.
- GPUs do thousands of sums at once. For writing text, memory size decides what fits and memory bandwidth sets the top speed.
- A downloaded model is a shape (
config.json), the weights (safetensors or GGUF), a tokenizer and a chat template. Size ≈ parameters × bits per weight ÷ 8. - Serving engines (llama.cpp, Ollama, vLLM, SGLang, mlx-lm) run models. Most speak OpenAI’s API format, so programs can switch between them.
- The harness gives the model tools and decides what it sees. The same model can do far better or worse depending on its harness.
Words to know
- Stack
- The layers that work together to make an AI product, from the chip to the app.
- GPU
- Graphics processing unit: a chip with thousands of simple cores that do the same sum on many numbers at once.
- Memory bandwidth
- How many gigabytes per second a chip can read from its memory. It sets the top speed for writing text.
- Kernel
- A small, tuned program that does one maths job on a chip, such as multiplying two matrices.
- Hugging Face
- The main website where open models and datasets are shared.
- Safetensors
- A file format that holds only named lists of numbers, so opening it cannot run hidden code.
- GGUF
- llama.cpp’s single-file model format: weights, tokenizer and chat template together, usually quantized.
- Quantization
- Storing each weight with fewer bits, to save memory and run faster, at a small cost in accuracy.
- Serving engine
- The program that loads a model and runs it: llama.cpp, Ollama, vLLM, SGLang.
- API
- An agreed format that lets programs send a model questions and get answers.
- Harness
- The program around a model that gives it tools, runs them and manages what the model sees.
Go to the source
This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.
-
llama.cpp (source code and documentation)
The engine that made AI on ordinary computers possible. Its README and its tools folder are the best practical guide there is.
-
The GGUF file format
A short, exact description of what is inside a GGUF file, byte by byte.
-
FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
The clearest example of a better kernel: same maths, far fewer trips to memory.
-
Efficient Memory Management for Large Language Model Serving with PagedAttention
The paper behind vLLM. It borrows an old idea from operating systems to serve many users at once.
-
How Claude Code works
A plain description of a real agentic harness: its loop, its tools and how it manages the context.
-
An Empirical Study of Harness Design for Coding Agents
Measures how much the harness alone changes an agent’s results. You will read it properly in part 7.
Check yourself
6 questions. Tap the answer you think is right.
0 of 6 answered
Lesson complete
Answer every question above to complete this lesson.
Your progress is saved on this device only.
Next lessonVectors: lists of numbers that mean something