# Knowledge map

> The whole wiki on one page: every page of the four parts and twelve chapters. Hover or tap a page to highlight what it builds on and what builds on it, overlay a study route, and see how far you have read.

- URL: https://dmxsf.com/en/wiki/map/

Every page of the four parts and twelve chapters is here. Hover a page (on a phone, tap it once) to see what to read before it and what it opens up. You can also overlay a study route, or check where you are in the book.

[Browse labs on GitHub](https://github.com/dmxsf/dmxsf/tree/main/labs)

## Part 1: Understand LLMs

What is an LLM, what is it made of, and why is each part designed the way it is?

### 1. [Getting Started](https://dmxsf.com/en/wiki/start/)

- [1.1 What Is a Large Language Model? From Next-Word Prediction to General Assistants](https://dmxsf.com/en/wiki/start/what-is-an-llm/) (Beginner): A large language model (LLM) is a neural network, usually a Transformer, trained on huge amounts of text to predict the next token; pre-training, post-training and inference decoding turn it into an assistant that can chat, write code and reason.
- [1.2 LLM Learning Roadmap](https://dmxsf.com/en/wiki/start/learning-roadmap/) (Beginner; Direct prerequisites: [1.1 What Is a Large Language Model? From Next-Word Prediction to General Assistants](https://dmxsf.com/en/wiki/start/what-is-an-llm/)): See how the wiki's four parts and twelve chapters fit together, then pick a path by goal: a 10-hour weekend crash course, an 8-week application path, a 14-week engineering path or a 16-week research path, each with weekly reading, exercises and deliverables.
- [1.3 Learning Resources Map](https://dmxsf.com/en/wiki/start/resources/) (Beginner; Direct prerequisites: [1.2 LLM Learning Roadmap](https://dmxsf.com/en/wiki/start/learning-roadmap/)): A map of public courses, books, explainers, code repositories and Chinese-language resources to pair with this wiki, grouped by learning goal: what each adds, what background it assumes and which wiki pages to read with it. Every link was opened and checked in November 2026.
- [1.4 LLM Cheat Sheet](https://dmxsf.com/en/wiki/start/cheat-sheet/) (Intermediate; Direct prerequisites: [1.1 What Is a Large Language Model? From Next-Word Prediction to General Assistants](https://dmxsf.com/en/wiki/start/what-is-an-llm/)): One page for the estimates you reuse most: counting parameters, training compute (about 6ND), memory for weights, training state and the KV cache, the bandwidth bound on decoding speed, and the LoRA and pass@k formulas, each with a standard-library script checked against published numbers.

### 2. [Foundations](https://dmxsf.com/en/wiki/foundations/)

- [2.1 Python and tensor shapes](https://dmxsf.com/en/wiki/foundations/tensors-and-shapes/) (Beginner): Start with a table of numbers, name the position and feature axes, and calculate a dot product and bias before running a linear layer in standard Python.
- [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/) (Beginner): Language modeling estimates the probability of a text and uses the chain rule to split it into a product of "predict the next token given the prefix"; training uses cross-entropy, evaluation uses perplexity, and the causal mask hides future tokens.
- [2.3 Neural Network Basics](https://dmxsf.com/en/wiki/foundations/neural-network-basics/) (Beginner; Direct prerequisites: [2.1 Python and tensor shapes](https://dmxsf.com/en/wiki/foundations/tensors-and-shapes/)): A neural network chains linear maps and nonlinearities. Backpropagation (the chain rule) gives the loss gradient for every parameter, and training steps against it. This page builds a two-layer net in NumPy, checks its gradients, and runs learning-rate and initialization experiments.
- [2.4 Information Theory Refresher](https://dmxsf.com/en/wiki/foundations/information-theory/) (Intermediate; Direct prerequisites: [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/)): Entropy measures how surprising a distribution is on average, cross-entropy is the cost of coding data from p with a code built for q, and KL divergence is the excess over the optimum. A language model's training loss is cross-entropy; perplexity is its exponential.
- [2.5 Tokenizers and Embeddings](https://dmxsf.com/en/wiki/foundations/tokenizer-and-embeddings/) (Beginner; Direct prerequisites: [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/)): An LLM only processes integers: a tokenizer splits text into tokens with a subword algorithm such as BPE and maps them to ids, then each id is looked up in a vocabulary-size by hidden-size embedding table. Vocabulary size trades off sequence length, parameters and long-tail coverage.
- [2.6 Optimizers and Training Stability](https://dmxsf.com/en/wiki/foundations/optimizers-and-training-stability/) (Intermediate; Direct prerequisites: [2.4 Information Theory Refresher](https://dmxsf.com/en/wiki/foundations/information-theory/)): Large-model pretraining almost always uses AdamW with linear warmup plus cosine (or WSD) decay, gradient clipping and mixed precision. This page explains what each hyperparameter is for and gives a checklist for loss spikes and NaNs.

### 3. [Model Architecture](https://dmxsf.com/en/wiki/architecture/)

- [3.1 From RNNs to Attention](https://dmxsf.com/en/wiki/architecture/from-rnn-to-attention/) (Beginner; Direct prerequisites: [2.3 Neural Network Basics](https://dmxsf.com/en/wiki/foundations/neural-network-basics/), [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/)): An RNN squeezes history into one fixed-size state and computes it step by step, so gradients pass through a long chain of multiplications. Attention lets every position read every other position directly, in parallel. Experiments measure vanishing gradients, gating and the copy bottleneck.
- [3.2 Attention Basics](https://dmxsf.com/en/wiki/architecture/attention-basics/) (Beginner; Direct prerequisites: [2.5 Tokenizers and Embeddings](https://dmxsf.com/en/wiki/foundations/tokenizer-and-embeddings/)): Understand Q/K/V, scaled dot-product attention and multi-head attention through intuition, a worked numeric example and a minimal code sample.
- [3.3 Positional Encoding Explained](https://dmxsf.com/en/wiki/architecture/positional-encoding/) (Intermediate; Direct prerequisites: [3.2 Attention Basics](https://dmxsf.com/en/wiki/architecture/attention-basics/)): Self-attention cannot see token order, so positional encodings tell the model where a token is or how far apart two tokens are: sinusoidal and learned encodings are added to the input, relative biases and ALiBi act on attention scores, and RoPE rotates queries and keys.
- [3.4 Transformer Block Explained](https://dmxsf.com/en/wiki/architecture/transformer-block/) (Intermediate; Direct prerequisites: [3.2 Attention Basics](https://dmxsf.com/en/wiki/architecture/attention-basics/), [3.3 Positional Encoding Explained](https://dmxsf.com/en/wiki/architecture/positional-encoding/)): A Transformer block is multi-head attention plus a feed-forward network (FFN), each wrapped in a residual connection and LayerNorm. This page gives the equations, Pre-Norm versus Post-Norm, a parameter count (about 12d²) and runnable PyTorch code.
- [3.5 Modern LLM Architecture](https://dmxsf.com/en/wiki/architecture/modern-llm-architecture/) (Intermediate; Direct prerequisites: [3.4 Transformer Block Explained](https://dmxsf.com/en/wiki/architecture/transformer-block/), [3.3 Positional Encoding Explained](https://dmxsf.com/en/wiki/architecture/positional-encoding/)): Almost every mainstream open LLM is a refined decoder-only Transformer: Pre-Norm with RMSNorm, a SwiGLU feed-forward network, RoPE positions and GQA attention, and some add mixture of experts (MoE) to grow parameters without growing compute in proportion.
- [3.6 Efficient Attention](https://dmxsf.com/en/wiki/architecture/efficient-attention/) (Intermediate; Direct prerequisites: [3.2 Attention Basics](https://dmxsf.com/en/wiki/architecture/attention-basics/)): Attention has two bottlenecks: the KV cache that decoding rereads at every step, and the N×N score matrix of training and prefill. MQA, GQA and MLA shrink the KV cache; FlashAttention cuts memory traffic with tiling and online softmax, and its output is identical to standard attention.
- [3.7 Mixture of Experts (MoE)](https://dmxsf.com/en/wiki/architecture/mixture-of-experts/) (Intermediate; Direct prerequisites: [3.5 Modern LLM Architecture](https://dmxsf.com/en/wiki/architecture/modern-llm-architecture/)): A mixture-of-experts layer swaps the feed-forward network for many experts and routes each token to only k of them, so total parameters grow while per-token compute stays small. This page computes total and active parameters for Mixtral and DeepSeek-V3 and lets you try load balancing.
- [3.8 Long Context](https://dmxsf.com/en/wiki/architecture/long-context/) (Advanced; Direct prerequisites: [3.3 Positional Encoding Explained](https://dmxsf.com/en/wiki/architecture/positional-encoding/), [3.6 Efficient Attention](https://dmxsf.com/en/wiki/architecture/efficient-attention/)): Extending a context window from 4K to 128K takes three fixes: RoPE extensions (PI, NTK-aware scaling, YaRN) for unseen positions, staged continued training on long text, and a budget for attention compute and KV cache. This page covers all three with formulas, code and two interactive tools.
- [3.9 State Space Models and Hybrids](https://dmxsf.com/en/wiki/architecture/state-space-and-hybrid/) (Advanced; Direct prerequisites: [3.2 Attention Basics](https://dmxsf.com/en/wiki/architecture/attention-basics/), [3.1 From RNNs to Attention](https://dmxsf.com/en/wiki/architecture/from-rnn-to-attention/), [3.6 Efficient Attention](https://dmxsf.com/en/wiki/architecture/efficient-attention/)): Linear attention, state space models (Mamba) and the gated delta rule compress history into a fixed-size state: memory stays flat as context grows, but capacity is limited by the state size. Hybrids keep a few attention layers for exact recall; Jamba's KV cache is 1/8 of Mixtral's.

## Part 2: Train LLMs

How do you train a model on a finite budget of compute and data, then teach it to follow instructions and reason?

### 4. [Compute and Systems](https://dmxsf.com/en/wiki/systems/)

- [4.1 LLM hardware basics](https://dmxsf.com/en/wiki/systems/hardware-basics/) (Beginner; Direct prerequisites: [2.1 Python and tensor shapes](https://dmxsf.com/en/wiki/foundations/tensors-and-shapes/)): Follow a model request through disk, host and device memory, and CPU and GPU work. Estimate tensor storage and copy time to distinguish capacity, bandwidth, and compute before diagnosing inference.
- [4.2 GPUs and the Roofline Model](https://dmxsf.com/en/wiki/systems/gpu-and-roofline/) (Intermediate; Direct prerequisites: [4.1 LLM hardware basics](https://dmxsf.com/en/wiki/systems/hardware-basics/), [3.4 Transformer Block Explained](https://dmxsf.com/en/wiki/architecture/transformer-block/)): A GPU is limited by two walls: how many operations it can do per second (compute) and how many bytes it can move per second (memory bandwidth). The roofline model uses arithmetic intensity to tell which wall an operator hits first. This page derives it and measures it on a CPU.
- [4.3 GPU kernels](https://dmxsf.com/en/wiki/systems/gpu-kernels/) (Intermediate; Direct prerequisites: [4.2 GPUs and the Roofline Model](https://dmxsf.com/en/wiki/systems/gpu-and-roofline/)): GPU kernel tuning combines thread-level memory access, on-chip reuse, and output stores. Derive the logical traffic of tiled matrix multiplication with edge masks, check it with a CPU experiment, and trace practical limits from staging buffers to register spills.
- [4.4 Numerical Precision](https://dmxsf.com/en/wiki/systems/numerical-precision/) (Intermediate; Direct prerequisites: [4.2 GPUs and the Roofline Model](https://dmxsf.com/en/wiki/systems/gpu-and-roofline/), [2.6 Optimizers and Training Stability](https://dmxsf.com/en/wiki/foundations/optimizers-and-training-stability/)): Floating-point formats split a few bits between exponent (range) and mantissa (precision). Low-precision training fails in three ways: overflow, underflow (small gradients become 0) and swamping (small terms vanish in sums). Real Qwen2.5-0.5B data shows how large each is and what fixes it.
- [4.5 Collective Communication](https://dmxsf.com/en/wiki/systems/collective-communication/) (Advanced; Direct prerequisites: [4.2 GPUs and the Roofline Model](https://dmxsf.com/en/wiki/systems/gpu-and-roofline/), [4.4 Numerical Precision](https://dmxsf.com/en/wiki/systems/numerical-precision/)): Collective communication is the plumbing of multi-GPU training. This page simulates five all-reduce algorithms and checks them element by element, compares rounds and traffic with the alpha-beta model, then shows how topology, summation order and MoE all-to-all change the choice.

### 5. [Pre-training](https://dmxsf.com/en/wiki/pretraining/)

- [5.1 The LLM Training Pipeline](https://dmxsf.com/en/wiki/pretraining/training-pipeline/) (Intermediate; Direct prerequisites: [3.2 Attention Basics](https://dmxsf.com/en/wiki/architecture/attention-basics/), [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/)): A map of the pipeline from data preparation, pretraining, SFT and preference alignment to evaluation and release, with the public data scale of each stage, plus a 0.86M-parameter byte-level GPT that trains on a laptop CPU to test data mixture, resuming and leakage.
- [5.2 Pretraining Data Engineering](https://dmxsf.com/en/wiki/pretraining/data-engineering/) (Intermediate; Direct prerequisites: [5.1 The LLM Training Pipeline](https://dmxsf.com/en/wiki/pretraining/training-pipeline/), [2.5 Tokenizers and Embeddings](https://dmxsf.com/en/wiki/foundations/tokenizer-and-embeddings/)): A pretraining corpus is filtered, deduplicated and mixed step by step, and every step throws data away. This page shows what FineWeb, Gopher, DCLM and Llama 3 drop and why, then runs MinHash near-duplicate removal on a demo corpus: how many words may change before a copy stops counting.
- [5.3 Scaling Laws](https://dmxsf.com/en/wiki/pretraining/scaling-laws/) (Intermediate; Direct prerequisites: [5.1 The LLM Training Pipeline](https://dmxsf.com/en/wiki/pretraining/training-pipeline/)): From Kaplan to Chinchilla: why loss falls as a power law in parameters, data and compute, how to split a compute budget between parameters and tokens, and why today's models are trained on far more data than the compute-optimal amount.
- [5.4 The Compute and Memory Ledger of Training](https://dmxsf.com/en/wiki/pretraining/compute-and-memory/) (Intermediate; Direct prerequisites: [5.3 Scaling Laws](https://dmxsf.com/en/wiki/pretraining/scaling-laws/), [3.5 Modern LLM Architecture](https://dmxsf.com/en/wiki/architecture/modern-llm-architecture/)): How many FLOPs, GPU hours and bytes of memory does training a model need? This page works out where 6ND comes from, what MFU measures, why model states cost 16 bytes per parameter, how activation memory scales, and how to sanity-check reported GPU hours.
- [5.5 Distributed Training](https://dmxsf.com/en/wiki/pretraining/distributed-training/) (Advanced; Direct prerequisites: [5.1 The LLM Training Pipeline](https://dmxsf.com/en/wiki/pretraining/training-pipeline/)): Data parallelism splits the batch, tensor parallelism the matrices inside a layer, pipeline parallelism the stack of layers; ZeRO and FSDP shard optimizer state, gradients and parameters. Runnable checks verify gradient averaging, ring all-reduce traffic, the Megatron split and the bubble formula.

### 6. [Post-training and Alignment](https://dmxsf.com/en/wiki/post-training/)

- [6.1 SFT Data](https://dmxsf.com/en/wiki/post-training/sft-data/) (Intermediate; Direct prerequisites: [5.1 The LLM Training Pipeline](https://dmxsf.com/en/wiki/pretraining/training-pipeline/)): How to weigh the quantity and quality of SFT data and check it: measured effects of data size, label noise, the loss mask and mixed-in general data (Qwen2.5-0.5B on banking77), plus rule filters, near-duplicate removal and contamination checks on Alpaca, Alpaca-cleaned and Dolly.
- [6.2 LoRA Fine-Tuning in Practice](https://dmxsf.com/en/wiki/post-training/lora-finetuning/) (Intermediate; Direct prerequisites: [3.4 Transformer Block Explained](https://dmxsf.com/en/wiki/architecture/transformer-block/), [5.1 The LLM Training Pipeline](https://dmxsf.com/en/wiki/pretraining/training-pipeline/)): Over fifty training runs of Qwen2.5-0.5B on banking77: the formula, the parameter count and a from-scratch implementation, then learning rate, rank, target modules, epochs, full fine-tuning and QLoRA compared, and the pitfalls of merging and deployment, with code and numbers behind every claim.
- [6.3 Reward Models](https://dmxsf.com/en/wiki/post-training/reward-models/) (Intermediate; Direct prerequisites: [6.1 SFT Data](https://dmxsf.com/en/wiki/post-training/sft-data/), [2.4 Information Theory Refresher](https://dmxsf.com/en/wiki/foundations/information-theory/)): A reward model scores a prompt-and-response pair with one number, trained on pairwise comparisons; RLHF, rejection sampling and best-of-n all use it. This page derives the Bradley–Terry loss, measures the accuracy ceiling set by label noise, and reproduces overoptimization in simulation.
- [6.4 Reinforcement Learning Basics](https://dmxsf.com/en/wiki/post-training/rl-fundamentals/) (Intermediate; Direct prerequisites: [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/), [2.4 Information Theory Refresher](https://dmxsf.com/en/wiki/foundations/information-theory/), [6.3 Reward Models](https://dmxsf.com/en/wiki/post-training/reward-models/)): Policy gradients, baselines, GAE, PPO clipping and the KL penalty are the toolkit behind RLHF and reasoning RL. This page measures each on a toy task small enough to enumerate exactly: how baselines cut variance, why clipping is not a trust region, and where the KL belongs.
- [6.5 Preference Optimization](https://dmxsf.com/en/wiki/post-training/preference-optimization/) (Advanced; Direct prerequisites: [6.1 SFT Data](https://dmxsf.com/en/wiki/post-training/sft-data/), [6.3 Reward Models](https://dmxsf.com/en/wiki/post-training/reward-models/), [2.4 Information Theory Refresher](https://dmxsf.com/en/wiki/foundations/information-theory/), [6.4 Reinforcement Learning Basics](https://dmxsf.com/en/wiki/post-training/rl-fundamentals/)): After SFT a model follows instructions, but its answers are not always the ones people prefer. Preference optimization aligns it using comparisons: RLHF trains a reward model and optimizes with PPO, while DPO reduces the pipeline to a classification-style loss on preference pairs.
- [6.6 Reinforcement Learning for Reasoning](https://dmxsf.com/en/wiki/post-training/reasoning-rl/) (Advanced; Direct prerequisites: [6.5 Preference Optimization](https://dmxsf.com/en/wiki/post-training/preference-optimization/), [6.4 Reinforcement Learning Basics](https://dmxsf.com/en/wiki/post-training/rl-fundamentals/)): Since o1 and DeepSeek-R1, making a model think longer before answering has become the main line of post-training. Why verifiable rewards (RLVR) can replace a reward model, how GRPO drops the value model, and the recipe and pitfalls of R1-Zero and R1.
- [6.7 Reasoning RL systems](https://dmxsf.com/en/wiki/post-training/rollout-and-training/) (Intermediate; Direct prerequisites: [6.6 Reinforcement Learning for Reasoning](https://dmxsf.com/en/wiki/post-training/reasoning-rl/), [4.5 Collective Communication](https://dmxsf.com/en/wiki/systems/collective-communication/)): Reasoning RL joins generation, grading, learning, and weight publication. Asynchronous execution overlaps work and introduces policy lag. A runnable scheduling simulation separates elapsed time, accepted batches, and discarded trajectories.

## Part 3: Deploy and apply

How do you run a model fast and cheaply, and turn it into a reliable application?

### 7. [Inference and Serving](https://dmxsf.com/en/wiki/inference/)

- [7.1 Your first inference service](https://dmxsf.com/en/wiki/inference/first-inference-service/) (Beginner; Direct prerequisites: [4.1 LLM hardware basics](https://dmxsf.com/en/wiki/systems/hardware-basics/)): Run a local inference endpoint, send JSON, and interpret status codes. Follow the model function, runtime, server, and client before learning streaming and deployment.
- [7.2 Decoding and Sampling](https://dmxsf.com/en/wiki/inference/decoding-and-sampling/) (Beginner; Direct prerequisites: [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/)): Decoding turns the model's output distribution into tokens: greedy picks the most likely one, temperature sharpens or flattens the distribution, top-k and top-p cut off the unlikely tail, and beam search keeps several candidates. Together they set how deterministic and diverse the output is.
- [7.3 KV Cache and Inference Performance](https://dmxsf.com/en/wiki/inference/kv-cache/) (Intermediate; Direct prerequisites: [3.2 Attention Basics](https://dmxsf.com/en/wiki/architecture/attention-basics/)): Understand how the KV cache removes repeated computation from autoregressive decoding, and master the trade-offs between latency, throughput, memory and request scheduling.
- [7.4 Prefix Caching and PD Disaggregation](https://dmxsf.com/en/wiki/inference/prefix-caching/) (Intermediate; Direct prerequisites: [7.3 KV Cache and Inference Performance](https://dmxsf.com/en/wiki/inference/kv-cache/)): Prefix caching reuses the KV cache of system prompts, shared documents, and chat history across requests (RadixAttention, CacheBlend, LMCache). PD disaggregation places compute-bound prefill and bandwidth-bound decoding on different hardware; DistServe, Splitwise, and Mooncake show when it pays off.
- [7.5 Model Quantization](https://dmxsf.com/en/wiki/inference/quantization/) (Intermediate; Direct prerequisites: [7.3 KV Cache and Inference Performance](https://dmxsf.com/en/wiki/inference/kv-cache/)): Quantization stores weights, activations or the KV cache in fewer bits. This page starts from the memory budget, builds up from scales and groups, measures INT8 and INT4 on Qwen2.5-0.5B, implements SmoothQuant, AWQ-style scaling, GPTQ and KV-cache quantization, and ends with a selection guide.
- [7.6 LLM Inference Serving](https://dmxsf.com/en/wiki/inference/serving/) (Intermediate; Direct prerequisites: [7.3 KV Cache and Inference Performance](https://dmxsf.com/en/wiki/inference/kv-cache/), [7.1 Your first inference service](https://dmxsf.com/en/wiki/inference/first-inference-service/)): A serving system has to balance time to first token, time per output token and total throughput. This page measures where one request's time goes with llama.cpp, shows why laptop benchmarks need a warm-up, and compares llama.cpp, Ollama, vLLM and SGLang.
- [7.7 Continuous Batching and PagedAttention](https://dmxsf.com/en/wiki/inference/continuous-batching/) (Intermediate; Direct prerequisites: [7.3 KV Cache and Inference Performance](https://dmxsf.com/en/wiki/inference/kv-cache/), [7.6 LLM Inference Serving](https://dmxsf.com/en/wiki/inference/serving/)): Every decode step reads all the weights, so putting several requests in one batch raises throughput almost for free. This page measures concurrency, continuous batching, paged KV caches and prefix caching with llama.cpp to show how one GPU serves many requests.
- [7.8 Speculative Decoding](https://dmxsf.com/en/wiki/inference/speculative-decoding/) (Intermediate; Direct prerequisites: [7.2 Decoding and Sampling](https://dmxsf.com/en/wiki/inference/decoding-and-sampling/), [7.3 KV Cache and Inference Performance](https://dmxsf.com/en/wiki/inference/kv-cache/)): Speculative decoding lets a small, fast draft model guess the next few tokens and the large model verify them in one parallel forward pass, with an accept-and-correct rule that keeps the output distribution unchanged. This page derives the expected speedup and lets you tune it interactively.

### 8. [Applications](https://dmxsf.com/en/wiki/applications/)

- [8.1 Your first agent](https://dmxsf.com/en/wiki/applications/first-agent/) (Beginner; Direct prerequisites: [7.1 Your first inference service](https://dmxsf.com/en/wiki/inference/first-inference-service/)): Use a tiny library lookup to distinguish a function call, a fixed workflow, and an agent loop. Run action, observation, and stopping cases in standard Python.
- [8.2 Prompt Engineering](https://dmxsf.com/en/wiki/applications/prompt-engineering/) (Intermediate; Direct prerequisites: [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/), [7.2 Decoding and Sampling](https://dmxsf.com/en/wiki/inference/decoding-and-sampling/)): Design the prompt as a task interface: write a task spec, layer system, examples and context, separate format errors from wrong judgments with an eval set, and use data to decide when few-shot, chain-of-thought or structured output pays off. Includes a runnable ticket-triage experiment.
- [8.3 Structured Outputs and Function Calling](https://dmxsf.com/en/wiki/applications/structured-output-and-function-calling/) (Intermediate; Direct prerequisites: [8.2 Prompt Engineering](https://dmxsf.com/en/wiki/applications/prompt-engineering/), [7.2 Decoding and Sampling](https://dmxsf.com/en/wiki/inference/decoding-and-sampling/)): A program can use model output reliably through prompt conventions, JSON mode, JSON Schema constrained decoding, and validate-and-retry. This page explains how token masks guarantee a format, how function-call messages flow, and why format limits can hurt reasoning.
- [8.4 RAG in Practice](https://dmxsf.com/en/wiki/applications/rag/) (Intermediate; Direct prerequisites: [2.5 Tokenizers and Embeddings](https://dmxsf.com/en/wiki/foundations/tokenizer-and-embeddings/), [8.2 Prompt Engineering](https://dmxsf.com/en/wiki/applications/prompt-engineering/)): How to build a retrieval-augmented generation system that works: clean and chunk documents, combine dense and BM25 retrieval with RRF, rerank with a cross-encoder, assemble the context, and measure every step with Hit@k and MRR on a small runnable corpus.
- [8.5 Agents and Tool Calling in Practice](https://dmxsf.com/en/wiki/applications/agents-and-tool-calling/) (Intermediate; Direct prerequisites: [8.1 Your first agent](https://dmxsf.com/en/wiki/applications/first-agent/), [8.2 Prompt Engineering](https://dmxsf.com/en/wiki/applications/prompt-engineering/), [8.3 Structured Outputs and Function Calling](https://dmxsf.com/en/wiki/applications/structured-output-and-function-calling/)): An agent lets the model decide the next step in a loop, and its reliability comes from the code around the loop: validation, write confirmation, step limits and evaluation. Build one with Qwen3-4B, measure on 12 support cases what guardrails catch, and learn prompt injection, MCP and pass^k.
- [8.6 Agent context and memory](https://dmxsf.com/en/wiki/applications/context-and-memory/) (Intermediate; Direct prerequisites: [8.5 Agents and Tool Calling in Practice](https://dmxsf.com/en/wiki/applications/agents-and-tool-calling/), [8.4 RAG in Practice](https://dmxsf.com/en/wiki/applications/rag/)): Context engineering fits instructions, tool history, and retrieved evidence into a model call. Long-term memory keeps confirmed preferences across sessions. Test whole tool turns, version precedence, deletion, and replay.
- [8.7 Agent Evaluation](https://dmxsf.com/en/wiki/applications/agent-evaluation/) (Intermediate; Direct prerequisites: [8.5 Agents and Tool Calling in Practice](https://dmxsf.com/en/wiki/applications/agents-and-tool-calling/)): Agent evaluation grades the whole system — model, prompts, tools, loop, environment. An episode is tasks, trials, trajectories, and outcomes; pass^k measures reliability, stateful graders check final states, and cost is accounted per successful task.
- [8.8 MCP and the Tool Ecosystem](https://dmxsf.com/en/wiki/applications/mcp-and-tool-ecosystem/) (Intermediate; Direct prerequisites: [8.5 Agents and Tool Calling in Practice](https://dmxsf.com/en/wiki/applications/agents-and-tool-calling/), [8.3 Structured Outputs and Function Calling](https://dmxsf.com/en/wiki/applications/structured-output-and-function-calling/)): MCP, the Model Context Protocol, is the open protocol that connects AI applications to external tools and data; its 2026-07-28 revision is stateless. This page shows the protocol in real messages, measures what 96 tool definitions cost in tokens, and compares three ways to pick a tool.

### 9. [Multimodal](https://dmxsf.com/en/wiki/multimodal/)

- [9.1 Multimodal LLMs](https://dmxsf.com/en/wiki/multimodal/multimodal-llms/) (Intermediate; Direct prerequisites: [3.2 Attention Basics](https://dmxsf.com/en/wiki/architecture/attention-basics/), [2.5 Tokenizers and Embeddings](https://dmxsf.com/en/wiki/foundations/tokenizer-and-embeddings/), [7.3 KV Cache and Inference Performance](https://dmxsf.com/en/wiki/inference/kv-cache/)): A vision-language model cuts an image into patches, turns them into visual tokens with a vision encoder and a projector, and feeds them to a language model. Measured here are CLIP's contrastive loss, LLaVA's two training stages, token and KV cache costs, and how resolution affects small text.
- [9.2 Diffusion Models and Flow Matching](https://dmxsf.com/en/wiki/multimodal/diffusion-and-flow-matching/) (Advanced; Direct prerequisites: [2.3 Neural Network Basics](https://dmxsf.com/en/wiki/foundations/neural-network-basics/), [3.2 Attention Basics](https://dmxsf.com/en/wiki/architecture/attention-basics/), [9.1 Multimodal LLMs](https://dmxsf.com/en/wiki/multimodal/multimodal-llms/)): Diffusion models turn data into Gaussian noise with a known process and train a network to undo it step by step; flow matching regresses a velocity field instead, so sampling is an ODE solve. This page builds DDPM, DDIM, flow matching and reflow on 2-D data and measures steps against quality.
- [9.3 World models and planning](https://dmxsf.com/en/wiki/multimodal/world-models/) (Intermediate; Direct prerequisites: [9.1 Multimodal LLMs](https://dmxsf.com/en/wiki/multimodal/multimodal-llms/), [6.4 Reinforcement Learning Basics](https://dmxsf.com/en/wiki/post-training/rl-fundamentals/)): A world model predicts how actions change state. A planner compares candidate sequences and corrects its plan with observations. This tutorial explains latent dynamics and verifies replanning after a map error with a grid simulator.

## Part 4: Evaluate, secure, look ahead

How do you know whether a model is good and safe, and where is the technology heading?

### 10. [Evaluation](https://dmxsf.com/en/wiki/evaluation/)

- [10.1 LLM Evaluation Methodology](https://dmxsf.com/en/wiki/evaluation/llm-evaluation/) (Intermediate; Direct prerequisites: [1.1 What Is a Large Language Model? From Next-Word Prediction to General Assistants](https://dmxsf.com/en/wiki/start/what-is-an-llm/)): Evaluating an LLM means estimating its performance on a whole class of tasks from a finite set of questions. This page covers what MMLU, HumanEval, GSM8K and MT-Bench measure, how to detect contamination, why a mature evaluation has four layers, and a workflow you can adopt.
- [10.2 The Statistics of Evaluation](https://dmxsf.com/en/wiki/evaluation/eval-statistics/) (Intermediate; Direct prerequisites: [10.1 LLM Evaluation Methodology](https://dmxsf.com/en/wiki/evaluation/llm-evaluation/)): A benchmark score is an estimate from a finite set of questions and carries error. Learn the unbiased pass@k estimator, confidence intervals for accuracy, paired comparison of two models and how many questions detecting a gap takes, with runnable code and interactive widgets.
- [10.3 LLM-as-a-Judge](https://dmxsf.com/en/wiki/evaluation/llm-as-judge/) (Intermediate; Direct prerequisites: [10.1 LLM Evaluation Methodology](https://dmxsf.com/en/wiki/evaluation/llm-evaluation/)): LLM-as-a-Judge lets a strong model score answers or compare them in pairs: cheap and scalable, but prone to position bias, length bias and misjudged math. Covers the judging modes, bias mitigation, measuring agreement with humans, and Bradley–Terry ranking.
- [10.4 Building Evaluation Sets](https://dmxsf.com/en/wiki/evaluation/building-eval-sets/) (Intermediate; Direct prerequisites: [10.1 LLM Evaluation Methodology](https://dmxsf.com/en/wiki/evaluation/llm-evaluation/), [10.2 The Statistics of Evaluation](https://dmxsf.com/en/wiki/evaluation/eval-statistics/)): An evaluation set is only as good as its coverage, labels, discrimination and freshness. This page designs one from the decision it supports, then simulates how label errors lower scores and inflate sample sizes, why Cohen's kappa tracks class balance, and which items separate models.
- [10.5 Benchmark Contamination](https://dmxsf.com/en/wiki/evaluation/benchmark-contamination/) (Intermediate; Direct prerequisites: [10.1 LLM Evaluation Methodology](https://dmxsf.com/en/wiki/evaluation/llm-evaluation/), [10.2 The Statistics of Evaluation](https://dmxsf.com/en/wiki/evaluation/eval-statistics/), [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/)): Benchmark contamination means evaluation questions, answers or paraphrases of them ended up in a model's training data, so scores measure memory instead of ability. A small experiment with known ground truth measures the dose-response and what n-gram and model-based detectors catch or miss.
- [10.6 Production evaluation for LLMs](https://dmxsf.com/en/wiki/evaluation/production-evaluation/) (Intermediate; Direct prerequisites: [10.1 LLM Evaluation Methodology](https://dmxsf.com/en/wiki/evaluation/llm-evaluation/), [10.2 The Statistics of Evaluation](https://dmxsf.com/en/wiki/evaluation/eval-statistics/)): Production evaluation connects model quality, system reliability, and user outcomes. Compare versions on paired requests, set release gates for critical slices, and use shadow traffic, canaries, and randomized experiments to answer different release questions.

### 11. [Safety and Alignment Risks](https://dmxsf.com/en/wiki/safety/)

- [11.1 Prompt Injection and Jailbreaks](https://dmxsf.com/en/wiki/safety/prompt-injection-and-jailbreaks/) (Intermediate; Direct prerequisites: [8.5 Agents and Tool Calling in Practice](https://dmxsf.com/en/wiki/applications/agents-and-tool-calling/), [6.5 Preference Optimization](https://dmxsf.com/en/wiki/post-training/preference-optimization/)): Prompt injection makes a model treat untrusted content as instructions; a jailbreak makes it ignore its safety training. Attackers, targets and defenses differ. This page gives the threat models, six architectural defenses and a runnable worst-case simulation of what each defense stops.
- [11.2 Hallucination and Calibration](https://dmxsf.com/en/wiki/safety/hallucination-and-calibration/) (Intermediate; Direct prerequisites: [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/), [10.1 LLM Evaluation Methodology](https://dmxsf.com/en/wiki/evaluation/llm-evaluation/)): Hallucination is fluent output that contradicts the facts or the sources a model was given. This page covers two taxonomies, the floor set by facts seen only once, why binary grading rewards guessing, and three runnable simulations of calibration, temperature scaling and abstaining.
- [11.3 Memorization and Privacy](https://dmxsf.com/en/wiki/safety/memorization-and-privacy/) (Intermediate; Direct prerequisites: [2.2 From Language Modeling to Next-Token Prediction](https://dmxsf.com/en/wiki/foundations/next-token-prediction/), [6.1 SFT Data](https://dmxsf.com/en/wiki/post-training/sft-data/), [10.5 Benchmark Contamination](https://dmxsf.com/en/wiki/evaluation/benchmark-contamination/)): Language models can memorize rare training snippets verbatim, and attackers can prompt them back out. A small experiment with known secrets measures how copies, attacker context and training strength change memorization, and compares deduplication with goldfish loss.

### 12. [Frontier](https://dmxsf.com/en/wiki/frontier/)

- [12.1 Test-Time Compute](https://dmxsf.com/en/wiki/frontier/test-time-compute/) (Advanced; Direct prerequisites: [6.6 Reinforcement Learning for Reasoning](https://dmxsf.com/en/wiki/post-training/reasoning-rl/), [7.2 Decoding and Sampling](https://dmxsf.com/en/wiki/inference/decoding-and-sampling/)): Test-time compute is extra computation spent while answering each question: voting over samples, verifier selection, revision, search and RL-trained long chains of thought. A reproducible simulation shows what caps the gain, what a fooled verifier does and why wall-clock time differs.
- [12.2 Synthetic Data and Self-Improvement](https://dmxsf.com/en/wiki/frontier/synthetic-data-and-self-improvement/) (Advanced; Direct prerequisites: [6.1 SFT Data](https://dmxsf.com/en/wiki/post-training/sft-data/), [6.6 Reinforcement Learning for Reasoning](https://dmxsf.com/en/wiki/post-training/reasoning-rl/)): Synthetic data is generated by a model or a program and then used for training. It keeps helping only with an outside signal: a verifier, a stronger teacher or fresh real data. Two experiments show recursive training losing the tail and only a verifier letting self-training bootstrap.
- [12.3 Mechanistic Interpretability](https://dmxsf.com/en/wiki/frontier/interpretability/) (Advanced; Direct prerequisites: [3.4 Transformer Block Explained](https://dmxsf.com/en/wiki/architecture/transformer-block/), [2.3 Neural Network Basics](https://dmxsf.com/en/wiki/foundations/neural-network-basics/)): Mechanistic interpretability reverse-engineers a trained network into a readable algorithm. Three CPU experiments cover superposition and sparse autoencoders for finding features, the logit lens and activation patching for locating causes, and why the choice of ablation changes the answer.
