Foundations: Prerequisites for the Model-Making Masterclass

Chapter 0 · Ch 0: The Map

Chapter 0 · Chapter 0: The Map

Listen: audio twin

Prerequisite companion to the Model-Making Masterclass. Audience: a working cybersecurity or software engineer with no machine learning background. This chapter is the whole territory on one page. Every later chapter expands one region of it.

What a language model actually is

Strip away the marketing and a large language model is a single, very large mathematical function. It takes a sequence of numbers in, and it produces a set of numbers out: a probability for every possible next piece of text. That is the entire trick. Everything else, chatbots, agents, code assistants, exploit-writing helpers, is engineering wrapped around that one function.

The function has knobs. Billions of them. Each knob is a number called a parameter (or weight), and the model’s entire “knowledge” is nothing more than the current settings of those knobs. A 7B model has about seven billion parameters. There is no database inside, no rule set, no retrieval index unless someone bolts one on from outside. If the model “knows” that a buffer overflow corrupts the stack, it knows it the way a riverbed “knows” where water flows: the shape was carved by everything that passed through during training.

Training is the carving process. You show the function an enormous amount of text, one chunk at a time. For each chunk, the function predicts the next piece of text, you measure how wrong the prediction was, and you nudge every knob by a tiny amount in the direction that would have made the prediction slightly less wrong. Repeat that a few trillion times on good hardware and the knobs settle into settings that encode grammar, facts, code patterns, reasoning habits, and style, all as geometry. Chapter 2 covers the nudging machinery with actual numbers. For now, hold the picture: a model is a fitted function, training is fitting, and the fitted artifact is a file full of numbers.

An analogy that holds up well for engineers: the trained model is like a compiled binary, and the training data plus training code are its source. You can run the binary without ever seeing the source. You can also learn a great deal by studying the binary. But some questions, why does it behave this way, could we rebuild it slightly differently, are only answerable from the source. The masterclass is largely about which labs publish their source and which publish only the binary. The analogy breaks in one place: a binary has discrete logic you can disassemble, while a model’s behavior is statistical and distributed across all its parameters at once. There is no single line of “code” where a fact lives.

The one loop everything runs on

Whether a model is answering a chat message or writing a proof of concept, at runtime it does exactly one thing, over and over:

  1. Take the text so far, chopped into units called tokens (Chapter 1).
  2. Run the function once. This single run is called a forward pass.
  3. Get back a probability distribution over what token could come next.
  4. Pick one token (the picking rules matter; Chapter 1 covers temperature and sampling).
  5. Append it to the text and go back to step 2.

That loop is called inference, or generation, or decoding. It is why these systems are sometimes slow in a very specific way: the output is produced one token at a time, serially, like a process that cannot parallelize its own future. It is also why a model’s answers are not retrieved but generated, and why the same prompt can produce different answers on different runs. Nothing is being looked up. The function is being run.

The pipeline the masterclass is organized around

Making a model is a pipeline with distinct stages, and each stage is a separate engineering discipline with its own decisions, budgets, and failure modes. The masterclass takes one stage per part. Here is the pipeline in the order work actually happens.

Data. Someone assembles trillions of tokens of text: web crawls, code repositories, books, papers, synthetic text written by other models. Filtering, deduplication, and removing test-set contamination happen here. This stage quietly decides most of the final quality. (Masterclass Part 2.)

Tokenizer. Text cannot enter the function as characters or words directly. A tokenizer chops text into tokens, subword units from a fixed vocabulary, and maps each to an ID number. Vocabulary size and chopping rules are permanent once training starts. (Part 3.)

Architecture. The shape of the function itself: how many layers, how information flows between tokens (attention), whether all parameters work on every token or only a rotating subset (Mixture of Experts). (Part 4, and Part 13 for how one family evolved its shape across generations.)

Pretraining. The main fitting run: next-token prediction over the full corpus, weeks or months on a GPU cluster, most of the money. The output is a base model, which predicts text fluently but does not yet follow instructions or behave like an assistant. (Part 5.)

Midtraining. A shorter continuation phase that steers the base model: better data mixes at the end (annealing), longer context windows, domain tilts. The least standardized stage and the one where open labs differ most visibly. (Part 6.)

SFT (supervised fine-tuning). The base model is shown example conversations, questions paired with desired answers, and fitted to imitate them. This is where “assistant behavior” comes from: format, tone, instruction following. (Part 7.)

RL and preference tuning. The model generates answers, the answers get scored, by humans, by other models, or by programs that can check correctness, and the model is fitted toward the high scorers. This is also where refusal behavior is installed: which requests to decline is a trained behavior, not a filter bolted on afterward. (Part 8.)

Evaluation. Benchmarks, harnesses, holdout sets, and the discipline of telling a real measurement from a marketing number. (Part 9.)

Serving. Getting the fitted function onto hardware and answering requests at acceptable speed and cost: quantization, caching, batching, speculative tricks. (Part 10.)

Part 1 of the masterclass sits in front of all of this and grades how much of each stage each lab actually publishes. Part 11 applies the whole pipeline to cyber models. Part 12 synthesizes the decisions.

How to use this prerequisite

You do not need all eight chapters before opening the masterclass. You need the chapters that unlock the part you want to read next. The unlock map:

Prereq chapter Unlocks masterclass parts
Ch 1: Models and tokens Everything (start here)
Ch 2: Just enough math Parts 5, 6, 8
Ch 3: Transformers Parts 3, 4, 13
Ch 4: Training at scale Parts 5, 10
Ch 5: Post-training Parts 7, 8, 11
Ch 6: Reading the artifacts Parts 1, 9, 12, 13
Ch 7: Second gear Parts 6, 8, 9, 11

The fast path to the whole tome: Chapters 1, 3, 5, and 6, in that order, then read the masterclass in order and detour into Chapters 2 and 4 when Part 5 starts spending FLOPs you cannot yet price. Each chapter ends with a self-check. If you can answer those questions in your own words, the chapter has done its job and you should move on. The “Go deeper” lists are for after, or for the specific topic you want to own properly; they are deliberately short.

One promise about style. This prerequisite uses analogies from systems, networks, and security work because that is the reader’s home turf. Where an analogy breaks, the text says so. A wrong mental model is worse than a missing one, because the masterclass will build on whatever you bring to it.

Check yourself

  1. In one sentence, what is a language model, mechanically?
  2. Where does a model’s knowledge physically live?
  3. What are the stages of the model-making pipeline, in order?
  4. Why can the same prompt produce different answers on two runs?
  5. What is the difference between a base model and the assistant you chat with?
Answers
  1. A very large parameterized function that takes a sequence of token IDs in and outputs a probability distribution over the next token.
  2. In the settings of its parameters (weights): billions of numbers in a file. There is no internal database or rule set.
  3. Data, tokenizer, architecture, pretraining, midtraining, SFT, RL and preference tuning, evaluation, serving.
  4. Because generation samples from a probability distribution one token at a time; nothing is retrieved, and sampling involves controlled randomness.
  5. The base model is the raw pretrained function that predicts text. The assistant is that same model after SFT and preference or RL tuning have fitted it to follow instructions and behave in a particular style, including what it refuses.

Go deeper

  • Andrej Karpathy, “Deep Dive into LLMs like ChatGPT” (https://www.youtube.com/watch?v=7xTGNNLPyMI). Three and a half hours that walk this entire map with a whiteboard. Watch it before or after this chapter; it is the orientation layer for everything.
  • Hugging Face LLM Course, Chapter 1 (https://huggingface.co/learn/llm-course/chapter1/1). A fast, free vocabulary pass over the same territory, useful as a second telling.
  • Interactive Transformer Explainer (https://poloclub.github.io/transformer-explainer/). Run a real small model in your browser and watch tokens flow. Ten minutes here prevents hours of confusion later.
  • Sebastian Raschka, Build a Large Language Model (From Scratch), code repository (https://github.com/rasbt/LLMs-from-scratch). The build-it path for readers who learn by reading code; the book behind it is the spine of Brandon’s own program.
  • Stanford CS336, Language Modeling from Scratch, course site (https://cs336.stanford.edu/). The full university-grade version of this map, lecture by lecture. Use it when a chapter here leaves you wanting the real thing.
Where this leads

This chapter is the orientation for the whole tome. When you are ready, go to the Model-Making Masterclass, the book this course prepares you for.