AS
AS

How It All Connects: The Whole Machine on One Page

· 18 phút đọc

There’s an old interview question for web developers: what happens when you type a URL into a browser and press Enter? A good answer takes ten minutes and passes through DNS, TCP, TLS, HTTP, a server and a renderer. Nobody expects you to know every layer in depth. The point is that you can follow the request all the way down without hitting a box labeled magic.

Here’s the same question for this series. A customer types Can I still get a refund for my lamp? into a support chat and presses Enter. Two seconds later a confident answer appears, with a source. It’s even mostly right. What happened in between?

Fifteen parts ago, the honest answer had a magic box in the middle. Now every stage has a name and a part of its own, so this last part puts them all on one page and then follows that one question through them.

Three stories, and how many ways in?

The series told three stories. How text becomes a prediction (Parts 1–4): a tokenizer turns text into IDs, each ID becomes a vector, a stack of transformer layers mixes those vectors, and out comes a score for every possible next token. How the weights get their values (Parts 5–10): from random numbers, through pre-training, fine-tuning and reinforcement learning, to a quantized file small enough to run. And how the model reaches beyond its training (Parts 11–15): retrieval, tools, a shared protocol for tools, and a loop that ties them together.

Interactive
The whole machine on one page
Follow
How text becomes a prediction
This is the running model itself. The other two stories feed it.
↺ append the token, run again (inside one call)
How the weights get their values
Enters through the weights, once, long before your request. Then they are frozen.
→ frozen weights power the transformer
How the model reaches beyond its training
Enters through the prompt, fresh on every call.
→ chunks go into the prompt
→ results go into the prompt
Putting it together
Not one more box but the loop around the first and third stories, run call after call until the job is done.
Hover or tap any box for a one-line reminder and a link to its part, or follow one story at a time and watch where it enters the running model. The first story and most of the third run on every request (documents are chunked and embedded ahead of time); the weights story happens once, before any request arrives.

Two. Training reaches the model through its weightsWeightsThe learned numbers that scale inputs inside the network. Set during training, frozen at inference., and only before it runs: once training is over (and the weights perhaps quantized), they’re frozen, and nothing you send changes them (Part 3). Everything else, every fact about this customer, every retrieved paragraph, every tool result, every “memory”, arrives through the prompt, fresh on every call, because the model is statelessStatelessKeeps no memory between calls. The full context must be sent every time. (Part 1). (Strictly, the app’s sampler settings, like temperature or a forced JSON format, also shape what comes out. But they act on the model’s scores after it runs, not on what it knows or reads.)

Read the third story with that in mind and it stops looking like a grab bag. Embeddings, vector databases, RAGRAGRetrieval-Augmented Generation. Retrieve relevant text and add it to the prompt before generating., tool calling and MCP are all ways of getting the right text into the prompt. Tool calling also opens the only way out: the model writes a request, and your code decides whether to act on it. An agentAgentAn LLM running in a loop that calls tools, reads results, and decides next steps until a task is done. is what you get when the model helps make those choices, call after call, in a loop.

Press Enter

Here is that refund question, followed all the way through. Acme is the lamp shop from Part 12. Its support app offers the model two tools: an order lookup that lives on Acme’s MCP server, and a help-center search built on retrieval.

Walkthrough
One question, all the way through
The context572 tokens so far
app (system, tools, note)customermodel outputtool results
In the app · building call 1one block of text, sent freshthe request
systemYou are Acme’s support assistant. Answer only from tool results, and cite them. … (excerpt)310
toolget_order: the signed-in customer’s ordersfrom Acme’s Orders MCP server110
toolsearch_help: search the help centerretrieval over 21 customer-visible chunks120
noteCustomer prefers short answers.saved by the app, pasted back in14
customerCan I still get a refund for my lamp?18
The model’s memory of this customer before the call: none.total 572 tokens
1/12
A customer asks Acme’s support chat a question. The model keeps nothing between calls, so the app builds its whole input from scratch: instructions, two tools, a saved note, the question (Part 1).
Model calls
0
Tokens written
0
 
Tokens read
0
summed over calls
Weights changed
?
 
Step through it, or click a station to jump there. The question’s tokens and IDs come from Part 2’s toy tokenizer and the retrieval scores from Part 12’s toy embedding model, both computed. The model’s output tokens, logits, attention percentages and other token counts are illustrative, and every probability and total is computed from them.

Three calls, 62 runs, no weights. The calls are the agent loop from Part 15: the model asked for the order, then for the policy, then answered, and the loop stopped because the last reply asked for no tool. The runs are the next-token loop from Part 1, one per token written. The first run of each call reads that call’s whole input in one parallel pass, which is the prefill from Part 3; every later token costs one more pass. And the input grew each time, 572 tokens, then 619, then 733, because the model keeps nothing between calls: the app re-sends everything. (Providers can cache the work on a long repeated prefix and bill it at a discount, as Part 1 showed. That makes the re-reading cheaper, but the model still receives every token, every call.)

Now look at where the answer came from. “45 days ago” came from the order system, through a tool call and MCP (Parts 13–14). “60 days” and “original packaging” came from a retrieved paragraph (Part 11, Part 12). The weights supplied everything else: reading the request, deciding to look things up, writing valid JSON, rewriting the search query (which put the 60-day window first, at a cost you’ll see in a moment), and phrasing the answer, short as the saved note asked, with a citation. That’s the division of labor the map predicted.

Where the eight billion numbers came from

The trace treated the eight billion weights as given. Someone made them, one stage at a time, and each stage learned from something different.

To watch that whole pipeline at once, I need a model small enough to see. The one below is the last step of an LLM at toy size. A vector standing for the prompt (6 numbers instead of 4,096) is multiplied by one row of weights per possible output, each row gives a score, and softmax turns the scores into odds (that’s exactly how the transformer in Part 4 ends). Its whole vocabulary is five replies to What is the capital of France? That’s thirty weights, and every stage trains them for real.

Animation
Where the weights come from
Adapt with
The model’s 30 weights“What is the capital of France?”
prompt h0.9-0.40.60.3-0.70.5
Quiz Q0.30-0.290.73-0.180.840.6331.0%
A/B/C-0.700.30-0.630.15-0.180.037.4%
Paris.-0.610.100.940.16-0.16-0.4017.7%
Flattery-0.28-0.260.09-0.410.210.2314.7%
Lyon.-0.22-0.380.120.50-0.78-0.5729.2%
Thirty random numbers. Nothing here knows anything yet.
1/6
Every model starts here: random numbers, so random-looking odds. Press play to train it.
Datanone yet
Toyloss 1.69 against web text; a flat guess would score ln 5 = 1.61
Real8 billion random numbers; an even guess over Llama 3’s 128,256 tokens costs ln 128,256 ≈ 11.8 per token
Each row of the grid is one possible reply; its logit is that row times the prompt’s vector h, and softmax turns the five logits into the bars. Every stage trains these numbers for real (blue cells positive, amber negative). The data, the reward scores and h are illustrative.

Pre-training lands exactly on the web’s odds: another quiz question 50%, “Paris.” 12%. That’s the result from Part 5: cross-entropy rewards betting the true odds, so the loss bottoms out at 1.255, the unpredictability of the data itself, and no lower. The model “knows” Paris and still prefers to continue the quiz, which is Part 7’s base model in miniature. Backpropagation (Part 6) supplies every nudge, and with one layer the gradient fits on a line: for each weight it’s (p − q) × h, the reply’s predicted minus true probability, times that weight’s input. At the start, “Another question” has p = 0.31 against the web’s q = 0.50, so for its first weight (h = 0.9) the gradient is (0.31 − 0.50) × 0.9 ≈ −0.17. At learning rate 0.5 that weight rises by about 0.09, from 0.30 to 0.39. Do that for all 30 weights, 60 times, and you have Fig. 3’s pre-training.

Fine-tuning moves all 30 weights, 33 steps at a smaller learning rate, and “Paris.” jumps to 62%. LoRA gets past the same mark without touching any of the 30. It trains a 5-number column and a 6-number row whose product is added to every weight (Part 9), and because that column starts at zero, its first steps barely move. Don’t be too impressed, though. With only one prompt, the change full fine-tuning makes is itself a column times a row (every step adds a multiple of h to each row), so an 11-number adapter can always keep up here. The surprise in Part 9 is that a low-rank change often does nearly as well in a real model, where millions of different prompts pull in different directions.

RLHF never shows the model an answer, only scores. It ends at 91.8% “Paris.”, exactly where Part 8’s formula, π* ∝ πref · er/β, says it should: gradient steps on scores found the same place the algebra did (Part 8). Quantization then rounds every weight to a 4-bit code, and no weight moves by more than about 0.12. A score can move further than that, because it adds up six products, each weight times its number in h. If all six errors lined up, a score would move by 0.12 × 3.4 ≈ 0.4 (3.4 is h’s six numbers added up, ignoring signs). Here the errors have mixed signs and partly cancel: the biggest shift is 0.07, and the odds barely change (91.8% → 91.5%). Even in the worst case, the leader loses 0.4 and a rival gains 0.4, so only replies within 0.8 of each other could swap places, and “Paris.” leads by more than 3 (Part 10). In a real model each of these sums has thousands of terms, and the errors flow through dozens of layers, so whether they cancel or pile up is something you find out by running it. Then the numbers freeze, and you can ask a thousand times without changing one.

Five ideas that kept coming back

The triangle. You watched it in Fig. 2: to write 62 tokens, the model read 572 + 619 + 733 = 1,924, because every call re-reads everything before it. One call’s bill grows in step with its length. But when every step works over everything before it, the total grows like 1 + 2 + … + n, so doubling the length roughly quadruples it. That’s the long chat in Part 1, attention’s comparisons inside one call in Part 4, and an agent’s context in Part 15.

Bytes, not arithmetic. Writing each token means streaming every weight from memory (Part 3): 16 GB for an 8B model at 16 bits. At the roughly 3 TB a second of an H100-class GPU, that’s about 5.4 ms per token, so one conversation tops out near 185 tokens a second however fast the arithmetic is, and at 4 bits (about 5 GB) the ceiling roughly triples. That’s part of why output tokens cost more (Part 2), why fewer bits per weight speed up generation (Part 10), and why providers batch requests: one read of the weights serves many users.

The model only proposes. In Fig. 2 the customer’s identity came from the signed-in session, never from the model’s JSON, and the app, not the model, sent the MCP request. The model writes text; code does things. A sampler picks the token, the app runs the tool, the MCP client sends the request. So the safety controls live in code: validation, least privilege, confirmation (Parts 13–15).

Untrusted text travels. The three pasted chunks and the order record sat in the same context as Acme’s instructions, with only formatting to tell them apart. Retrieved chunks, tool results, tool descriptions and web pages all become tokens like that, so prompt injectionPrompt injectionMalicious instructions hidden in content the model reads (web pages, documents, tool results). follows the text wherever it goes (Parts 12–15).

You get what you measure. Fig. 3’s base model learned exactly what web text rewarded: another quiz question at 50%, the answer at 12%. Overfitting (Part 6), flawed examples turning into habits (Part 7), reward hacking and sycophancy (Part 8) are the same story: training delivers exactly what the loss or the score rewards, flaws included.

Every term in one place

My notes end with a glossary, and so does the series. Here are all of its terms, each linked to the part that explains it. Try quiz mode: if you can define a term before you reveal it, that part did its job.

Playground
Every term, and where it lives
Story
showing 48 of 48
Activation functionPart 3 · Weights
Non-linear function (ReLU, GELU…) applied to a neuron's weighted sum. Lets networks model non-linear patterns.
also in6
An LLM running in a loop that calls tools, reads results, and decides next steps until a task is done.
also in1213
Approximate-nearest-neighbour index (e.g. HNSW, IVF) for fast vector search.
also in12
Mechanism that lets each token weigh and mix in information from other (earlier) tokens.
BackpropagationPart 6 · Backprop
Algorithm that computes how much each weight contributed to the error, using the chain rule, working from output to input.
also in579
Model after pre-training only. Good at continuing text, not yet an assistant.
also in67
Byte-Pair Encoding. Builds a token vocabulary by repeatedly merging the most frequent adjacent pairs.
Splitting documents into passages before embedding them for RAG.
also in11
Context windowPart 1 · LLMs
Maximum number of tokens a model can process in one call (input + output).
also in121415
Cosine similarityPart 11 · Embeddings
(a·b)/(‖a‖‖b‖). Measures how closely two vectors point in the same direction, from −1 to 1.
also in12
Cross-entropy lossPart 5 · Pre-training
−log p(correct token). The standard loss for next-token prediction.
also in67
Direct Preference Optimization. Learns from preference pairs without a separate reward model.
A vector of numbers representing the meaning of a token or a piece of text.
also in24
Feed-forward network (FFN)Part 4 · Attention
Per-token layer in a transformer that detects patterns and adds learned features.
also in3
Further training of a pre-trained model on a smaller, curated dataset.
also in5912
GGUF / GPTQ / AWQPart 10 · Quantization
Common formats and methods for quantized models.
The direction and size of change in the loss with respect to each weight.
also in9
HallucinationPart 12 · RAG
Confident but false output, often caused by missing or unretrieved information.
Using a trained, frozen model to generate outputs.
also in10
Lightweight remote-procedure-call format used by MCP.
Stored attention keys and values from earlier tokens. Speeds up generation within a request.
also in1310
A stage of the network whose output feeds the next stage.
also in46
Learning ratePart 6 · Backprop
Step size used when updating weights from gradients.
also in37
Large language model. Generative model trained to predict the next token.
Raw, unnormalized score for each vocabulary token before softmax.
also in248
Low-Rank Adaptation. Freezes the base weights and trains small low-rank adapter matrices.
also in67
Model Context Protocol. Open standard for services to expose tools, resources, and prompts to AI applications.
also in15
Unit computing a weighted sum of inputs plus bias, followed by an activation.
also in4
All learned numbers (weights and biases) in a model.
Large-scale self-supervised training on next-token prediction.
also in67
Prompt injectionPart 13 · Tool calling
Malicious instructions hidden in content the model reads (web pages, documents, tool results).
also in121415
LoRA fine-tuning on top of a 4-bit quantized base model.
also in10
Storing weights with fewer bits (8, 4…) to save memory and speed up inference, at some cost in accuracy.
also in39
Retrieval-Augmented Generation. Retrieve relevant text and add it to the prompt before generating.
also in5711
Reward hackingPart 8 · RL / RLHF
A model exploiting flaws in its scoring signal instead of truly improving.
Model trained to predict human preference scores. Used in RLHF.
Reinforcement learning (from human feedback). Train by scoring the model's own outputs.
also in15
Sampling / temperaturePart 1 · LLMs
How the next token is chosen from the probability distribution. Temperature controls randomness.
also in13
Supervised fine-tuning on (prompt, ideal response) pairs.
also in8
Function that turns scores into probabilities that add up to 1.
also in4
Keeps no memory between calls. The full context must be sent every time.
also in131415
A chunk of text (about ¾ of an English word on average) with an integer ID. The unit of processing and billing.
also in1
Component that splits text into tokens and maps them to IDs (and back).
The model outputs structured JSON asking the application to run a named tool with arguments.
also in121415
Neural-network architecture built from attention and feed-forward layers. The "T" in GPT.
An ordered list of numbers. Here, an embedding.
Vector databasePart 11 · Embeddings
Database that stores embeddings with their source text and finds nearest neighbours by similarity.
also in12
The learned numbers that scale inputs inside the network. Set during training, frozen at inference.
also in5610
All 48 terms from the glossary in my notes. Search the terms and their meanings, narrow to one story, or switch on quiz mode and try to define each term before you reveal it. Each card links to the part that explains it.
Check yourself
Can you trace it?
1.
Suppose the app had pasted in 10 help-center chunks instead of 3: seven more chunks, 224 more tokens in call 3's input. The answer is the same 29 tokens. How many extra runs of the model does call 3 take?
2.
Which of these leaves every one of the model's weights exactly as it was?
3.
You switch an 8B model from 16-bit to 4-bit weights on the same GPU. A 2,000-token prompt takes about as long to read as before, but the answer streams out much faster. Why?
4.
The refund answer in Fig. 2 got the window and the conditions right. Which change, on its own, is most likely to make it confidently wrong about the window, with no error anywhere?
5.
A base model, its fine-tuned version and its RLHF-trained version are each asked "What is the capital of France?". Which stage first makes the model answer and then stop?

That’s the whole machine, and no box on it says magic. If one still feels a little like it, its part is one click away on the map, and the card below goes back to where it all started: a model that guesses the next token and remembers nothing.

Share: