Diagram index

Every diagram in the workshop and the handbook, in one place — useful for lecturing from, or for revision.

All of them are generated, not drawn by hand: tools/make_diagrams.py builds them with the small kit in tools/svgkit.py. Change the generator and run make diagrams; CI fails if a committed SVG has drifted from its source.

They are plain SVG, so they scale to any projector, work offline, and adapt to light and dark themes. Reuse them in your own slides — code is MIT, prose and figures are CC BY 4.0.

  1. Foundations
    1. The next-token generation loop
    2. Tokenization
    3. Open weights vs. open source
  2. Hardware and efficiency
    1. Where the memory goes
    2. How 4-bit quantization works
    3. How LoRA works
  3. Generating text
    1. The four steps from messages to text
    2. Sampling
    3. Thinking mode
  4. Building systems
    1. One API, four runtimes
    2. The tool-calling round trip
    3. Embeddings place meaning in space
    4. The four stages of RAG
  5. Agents
    1. The agent loop
    2. The chain-to-agent spectrum
    3. Prompt injection
  6. Planning your work
    1. Prompt, RAG, tools, or fine-tune?
    2. The four-day roadmap
  7. Handbook figures
    1. How we got here
    2. What attention does
    3. Inside a transformer
    4. The full training lifecycle
    5. Phase 0: making the data
    6. Scaling laws
    7. Phase 2: post-training
    8. Adaptation options, cheapest first
    9. Distillation and Mixture of Experts
    10. Which kind of model is this?
    11. The ecosystem as a stack
    12. Choosing a tool
    13. MCP: why a protocol was needed
  8. The training track
    1. One training step
    2. Loss masking
    3. RLHF versus DPO
    4. Five loss curves, five decisions
  9. The agents track
    1. Four ways to remember
    2. A plan is a graph, not a list
    3. Four ways to wire several agents
    4. Outcome is half the picture
  10. The mathematics
    1. One attention operation, end to end
    2. RoPE: position as rotation
    3. A pre-norm block
  11. Language
    1. The tax on Kazakh and Russian
  12. Who builds the models
    1. Total parameters versus active parameters
    2. What a model costs, and which part gets quoted
    3. How open is it, really?

Foundations

The next-token generation loop

Notebook 01. The one idea everything rests on.

Text is tokenized, the model produces a probability for every token, one is sampled, appended, and the whole sequence runs through again

Tokenization

Notebook 01. Why “how many r’s in strawberry” is hard, and why a tool fixes it.

The word strawberry splits into three tokens, so the letters are invisible to the model

Open weights vs. open source

Notebook 01, and the open-weight models guide.

Open weights gives parameters and inference code but not training data or reproducibility


Hardware and efficiency

Where the memory goes

Notebook 02. Weights dominate — until the context gets long.

Memory per model and precision, showing weights against KV cache

How 4-bit quantization works

Notebook 05.

A group of weights stored as 4-bit integers plus one shared scale

How LoRA works

Notebook 11.

LoRA freezes the original weight matrix and learns two thin matrices beside it


Generating text

The four steps from messages to text

Notebook 03. Step 4 is the one everybody forgets.

Messages, chat template, generate, then slice off the prompt before decoding

Sampling

Notebook 04. Why top-p usually beats top-k.

Temperature reshapes the odds, top-k and top-p cut the tail, then one token is picked at random

Thinking mode

Notebook 04.

A hidden reasoning block sits between the question and the visible answer


Building systems

One API, four runtimes

Notebook 06, and the deployment guide.

One OpenAI-compatible API served interchangeably by Ollama, vLLM, llama.cpp or LM Studio

The tool-calling round trip

Notebook 07. The model never executes anything.

The model requests a call, your code executes it, the result returns, the model answers

Embeddings place meaning in space

Notebook 08.

Paraphrases and translations cluster together; embeddings fail on exact identifiers, negation and numbers

The four stages of RAG

Notebook 09. Measure retrieval and answers separately.

Chunk, embed, retrieve, generate, with retrieval and answer quality measured apart


Agents

The agent loop

Notebook 10, and the agentic AI guide. This is the whole idea.

THINK either answers or calls a tool; ACT runs it, OBSERVE appends the result, and control returns to THINK

The chain-to-agent spectrum

Notebook 10. Most production “agents” should have been chains.

A spectrum from prompt and chain through router, tool loop and planner to multi-agent

Prompt injection

Notebook 10, and privacy and safety.

Hostile instructions inside a document reach the agent; defences are least privilege, confirmation gates, trust separation and logging


Planning your work

Prompt, RAG, tools, or fine-tune?

Notebook 11. Work down the list and stop at the first yes.

Try prompting, then RAG, then structured output, then tools, and only then fine-tuning

The four-day roadmap

Day 1 foundations, day 2 practical, day 3 knowledge and agents, day 4 ship


Handbook figures

These accompany the handbook, which is background reading rather than hands-on work.

How we got here

Chapter 1. Why each piece was invented.

A timeline from the 2017 transformer to reasoning models and agents

What attention does

Chapter 2.

The word 'it' attends mostly to 'laptop', resolving the pronoun

Inside a transformer

Chapter 2.

Embeddings, N blocks of attention and feed-forward, then a final layer and softmax

The full training lifecycle

Chapter 3. The single most useful figure in the handbook.

Four phases - data, pre-training, post-training, adaptation - with falling costs

Phase 0: making the data

Chapter 3.

Crawl, filter, deduplicate, decontaminate, tokenize

Scaling laws

Chapter 3. Why good small models exist.

Tokens per parameter from GPT-3 through Chinchilla to modern overtrained small models

Phase 2: post-training

Chapter 3. SFT, RLHF and DPO.

Base model to instruct model via supervised fine-tuning and preference optimisation

Adaptation options, cheapest first

Chapter 3.

A ladder from prompting through RAG and tools to fine-tuning and pre-training

Distillation and Mixture of Experts

Chapter 3.

A small student trained on a teacher's outputs; a router sending tokens to a couple of experts

Which kind of model is this?

Chapter 4. Foundation vs frontier, and the axes people conflate.

Four axes: training stage, availability, size and capability tier

The ecosystem as a stack

Chapter 5. Tools in the same layer are alternatives; tools in different layers compose.

Seven layers from hardware up to the application

Choosing a tool

Chapter 5.

Five questions for evaluating a tool

MCP: why a protocol was needed

Chapter 6.

Nine custom integrations become six once a protocol sits in the middle


The training track

One training step

Notebook 13. Every trainer you will ever use is this loop with more bookkeeping, and it reports exactly four numbers.

A batch goes through a forward pass, a loss, a backward pass and a weight update, then the loop repeats; clipping and the schedule modify the update

Loss masking

Notebook 14. Which tokens the model is graded on, and which it only reads.

System and user segments are labelled -100 and contribute no loss; only the assistant segment is graded

RLHF versus DPO

Notebook 15, and chapter 3. Same data; DPO removes the reward model and the RL loop.

RLHF trains a reward model then loops sample-score-update with PPO; DPO scores each pair with the policy and a frozen reference and optimises one logistic loss

Five loss curves, five decisions

Notebook 16. In three of the five, the train curve alone looks acceptable.

Healthy, undertrained, overfitting, stuck at chance and diverged loss curves, with the decision each one implies


The agents track

Four ways to remember

Notebook 17. The model has no memory; these are four ways your code fakes it.

Four memory strategies as rows, with what each one loses and whether it survives a restart

A plan is a graph, not a list

Notebook 18. Which is why one failure blocks its descendants and nothing else.

A plan in three waves; a failed search blocks its descendants while the parallel branch completes

Four ways to wire several agents

Notebook 19. Costs rise left to right. Start at the left.

Router, orchestrator, pipeline and critic loop side by side with the model-call cost of each

Outcome is half the picture

Notebook 20. The dangerous quadrant is the one an outcome-only suite calls a pass.

A two-by-two of answer-right against path-sane; right answer with a wrong path is the lucky pass


The mathematics

One attention operation, end to end

Notebook 21 and chapter 7. Every arrow is a matrix multiply or an elementwise step.

X projects to Q, K and V; Q times K transpose gives scores, which are scaled, masked and softmaxed into weights that multiply V

RoPE: position as rotation

Why the score ends up depending on the gap between tokens, not on where they are.

A vector rotated further at each successive position, with its length unchanged, so the inner product depends only on the difference of positions

A pre-norm block

The residual stream runs straight down; everything else is a correction to it.

A transformer block as a vertical residual stream, with RMSNorm plus attention and RMSNorm plus the SwiGLU MLP each adding a correction back


Language

The tax on Kazakh and Russian

Notebook 22 and the language guide. Each step multiplies the one before it.

The same sentence, then two bytes per character in UTF-8, then two to three times the tokens, with the multiplier hitting context, cost and latency at once


Who builds the models

Total parameters versus active parameters

Chapter 8. The number that predicts memory and the number that predicts speed are not the same number.

A dense model runs every parameter for every token; a Mixture-of-Experts model keeps all experts in memory but activates only a couple per token

What a model costs, and which part gets quoted

The disclosed figure covers the final training run. These are the line items it leaves out.

The final training run is one line item; failed runs, research compute, salaries, data work and the cluster itself are excluded from the quoted figure

How open is it, really?

Four rungs, not two. Only the top one lets you reproduce the model.

Four rungs of openness: fully open with data and code, open weights, open weights under a restricted licence, and closed models that publish no parameter count


Back to top

ROBT407LLM workshop materials. Code is MIT licensed; prose is CC BY 4.0. Model weights are governed by their own licences - check each model card.