Skip to content
ImagineWorld

Exercises

node_idnode-book_building-frontier-llm-from-scratch_back-exercises
node_typebook-part
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_titleExercises
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Solutions are intentionally omitted; each exercise is answerable from the chapter it accompanies. Section cross-references point to the relevant material.

Chapter 1 — The Landscape of Large Language Models

Section titled “Chapter 1 — The Landscape of Large Language Models”

These exercises orient you in the landscape.

  1. State the scaling hypothesis (Section 1.9) in your own words: what did the field bet, and what evidence supported the bet?

  2. The recent entries in Table 1.1 report both a total and an active parameter count. Explain what that split reveals about how scaling changed shape.

  3. Explain why a compute-optimal 70-billion-parameter model might outperform a larger model trained on too little data (Section 1.9).

Chapter 2 — Mathematical and Computational Foundations

Section titled “Chapter 2 — Mathematical and Computational Foundations”

These exercises reinforce the mathematical foundations.

  1. Extend the by-hand backpropagation of Section 2.5 to the composition y=w2(w1x)y = w_2(w_1x), computing the gradient of the loss with respect to both weights.

  2. Explain why backpropagation is, fundamentally, nothing more than the chain rule — regardless of how deep the network is.

  3. What does it mean for a loss function to be differentiable, and why does gradient descent depend on it?

Chapter 3 — Tensors, Autograd, and PyTorch

These exercises concern the tools.

  1. For each of the five lines of the canonical training loop (Section 3.5), state what it does, and explain the consequence of omitting the call that clears gradients.

  2. Describe what the autograd engine constructs during the forward pass and traverses during the backward pass.

  3. Why does PyTorch accumulate gradients by default rather than overwriting them, and which training technique relies on this behavior?

Chapter 4 — Language Modeling Fundamentals

These exercises concern language-modeling fundamentals.

  1. Explain why next-token prediction, a simple objective, induces rich capability such as reasoning and translation (Section 4.8).

  2. Define perplexity and explain intuitively what a perplexity of 10 means about the model’s uncertainty.

  3. Describe the teacher-forcing versus autoregression gap (Section 4.7), and explain why it makes teacher-forced perplexity an optimistic estimate of real generation quality.

Chapter 5 — Tokenization

These exercises concern tokenization.

  1. Place character, subword, and word tokenization on the granularity spectrum (Section 5.7), stating the trade between vocabulary size and sequence length that each makes.

  2. Explain why subword tokenization has no out-of-vocabulary problem, while word-level tokenization does.

  1. Give two concrete tokenization pitfalls (Section 5.6) and explain how each produces a failure that superficially resembles a reasoning error.

Chapter 6 — Pretraining Data Pipelines

These exercises concern training data.

  1. Explain why aggressive deduplication (Section 6.5) improves a pretraining corpus, and what failure under-deduplication causes.

Describe how a quality classifier filters data (Section 6.7), and diversity risk that filtering toward a reference corpus produces.

Argue why the data mixture (Section 6.6) — the proportions of code, and math — shapes the resulting model as much as the chitecture does.

chapter 7 — Attention from First Principles

These exercises concern attention.

  1. Identify the specific operation that makes attention quadratic in sequence length, and explain why it dominates at long context.

  2. Contrast multi-head, grouped-query, and multi-query attention (Section 7.6) in terms of KV-cache size and quality.

  3. Describe two types of attention head that emerge in trained models (Section 7.7), and explain what an induction head computes and why it matters for in-context learning.

  4. Work the attention computation by hand for a sequence of three tokens, following the chapter’s worked example, and verify the attention weights sum to one.

Chapter 8 — Multi-Head Attention and the Transformer Block

These exercises concern the transformer block.

  1. Explain the division of labor between attention and the feed-forward network within a block (Section 8.6).

  2. Why is the FFN described as the model’s memory, and what does the SwiGLU gate add over a plain activation?

  3. Contrast depth and width (Section 8.7) as ways to enlarge a transformer: what does each buy, and how does each fail at its extreme?

  4. Explain why pre-norm placement (Section 8.5) keeps deep networks trainable where post-norm struggles.

Chapter 9 — Positional Information

These exercises concern positional encoding.

  1. Explain how RoPE encodes relative position, and why relative position is a better inductive bias for language than absolute position (Section 9.7).

  2. Describe how context-length extension (Section 9.6) works: what is manipulated about the rotation frequencies, and why a short long-sequence fine-tune is still needed.

  3. Explain why learned absolute position embeddings fail to generalize to positions beyond the trained length.

Chapter 10 — Building GPT from Scratch — Capstone I

These exercises concern the decoder-only model.

  1. Explain why the decoder-only architecture (Section 10.7) prevailed over encoder-decoder for general-purpose language models.

  2. Describe the autoregressive generation process and explain how the causal mask enforces the left-to-right dependency.

  3. Why does the decoder-only pretraining task make more efficient use of a corpus than an encoder-decoder setup?

Chapter 11 — Mixture-of-Experts

These exercises concern mixture-of-experts.

  1. Explain routing collapse (Section 11.8) and the rich-get-richer dynamic that drives it. Why is a collapsed MoE effectively a smaller dense model?

  2. Contrast the auxiliary-loss and auxiliary-loss-free (Section 45.7) approaches to load balancing, including the cost of each.

  3. Describe fine-grained experts and the shared expert (Section .7), and explain what each contributes to specialization.

Given a model with 256 routed experts and 8 active per token, explain how it can have far more capacity than a dense model of al active compute.

Chapter 12 — Multi-Head Latent Attention

These exercises concern Multi-Head Latent Attention.

  1. Using Table 12.1, explain why MLA’s KV cache is roughly an order of magnitude smaller than full multi-head attention at DeepSeek-V3 scale.

  2. Explain the conflict between compressing keys into a latent and applying RoPE, and how the decoupled position trick (Section 12.8) resolves it.

  3. Why does KV-cache size matter most precisely at long context and high request concurrency?

Chapter 13 — Training-Objective Innovations

These exercises concern multi-token prediction.

  1. Explain the two payoffs of multi-token prediction (Section 13.4): a densified training signal and a built-in draft model.

  2. Argue from the growth of uncertainty why shallow MTP depth captures nearly all the benefit (Section 13.6).

  1. Describe how MTP heads serve as a speculative-decoding draft (Section 13.5), and why verification is cheap.

Chapter 14 — Efficient and Sparse Attention at Scale These exercises concern sparse attention.

  1. Contrast fixed sparse-attention patterns — sliding window and global tokens (Section 14.6) — with a learned indexer, and explain what the learned version improves.

  2. Explain how the three obstacles to long context (Section 14.7) — compute, memory, and position — are each met by a different technique.

  3. Why can a fixed local-plus-global pattern miss information that a learned, per-query indexer captures?

Chapter 15 — Normalization, Activations, and Position Revisited These exercises concern normalization.

  1. Explain what normalization actually does in a deep network, and how norm-free approaches (Section 15.7) achieve the same control by other means.

  2. Contrast pre-norm, post-norm, and QK-norm placement (Section 15.6), naming the specific instability each one targets.

  3. Why is RMSNorm preferred over LayerNorm in most modern models (Section 15.5)?

Chapter 16 — Putting the Architecture Together These exercises concern assembling the full model.

  1. Explain how a configuration dictionary (Section 16.6) fully specifies a model, and trace three of its entries to the chapters that introduced the corresponding mechanism.
  1. Describe tied embeddings (Section 16.7) and the two distinct motivations — parameter economy and inductive bias — for using them.

  2. Explain why the embedding and output-projection matrices grow with vocabulary size, and why this makes them a large fraction of a small model’s parameters.

Chapter 17 — The Pretraining Loop

These exercises reinforce the training loop and its memory accounting.

  1. Derive the effective batch size in tokens from the microbatch size, sequence length, gradient-accumulation steps, and number of data-parallel workers. Which of these can you change without altering the optimizer’s behavior?

  2. A dense model has 7 billion parameters trained with AdamW in mixed precision. Using the per-parameter accounting of Section 17.9, estimate the memory for weights, gradients, and optimizer state alone, before activations.

  3. Explain, in terms of gradient noise, why the linear scaling rule (Section 17.12) raises the learning rate as the batch grows — and predict what happens if you scale the batch by 100× but leave the learning rate fixed.

  4. Sketch a training loop that accumulates gradients over four microbatches before each optimizer step, and identify the one line whose omission would silently corrupt the result (Section 22.10 hints at the analogous bug elsewhere).

Chapter 18 — Numerical Precision and FP8

These exercises test your grasp of low-precision training.

  1. Given the bit splits in Table 18.3, explain why gradients are assigned E5M2 and weights E4M3. What failure would you expect from swapping them?

  2. Why does FP8 training retain an FP32 master copy of the weights (Section 18.7)? Describe the “swamping” problem it solves with a concrete example of a small update added to a large weight.

  3. Explain how stochastic rounding (Section 18.10) preserves small updates in expectation, and contrast it with the master- weights approach — under what conditions might each be preferred?

  4. Roughly half of a transformer’s compute is matrix multiplication (Section 18.11). Use this to argue why moving matmuls from BF16 to FP8 has such a large effect on training throughput.

Chapter 19 — Distributed Training

These exercises concern parallelism and its communication costs.

  1. For a pipeline split into 8 stages running 16 microbatches under a 1F1B schedule (Section 19.11), reason qualitatively about how the bubble fraction changes if you instead use 64 microbatches.

  2. Contrast the communication pattern of data parallelism (gradent all-reduce) with that of tensor parallelism (within-layer exchange). Which is more sensitive to slow inter-node links, and why?

  3. Why does expert parallelism require all-to-all communication (Table D.5)? Describe what is being exchanged and when.

  4. A model is trained with tensor parallelism inside each node, pipeline parallelism across nodes, and data parallelism over the whole arrangement. Explain how these three compose, and what sequence parallelism (Section 19.10) would add.

Chapter 20 — Infrastructure and Systems

These exercises build intuition for the systems view of performance.

  1. Using the roofline model (Section 20.10), classify each as compute- or memory-bound and justify: a large dense matrix multiply; an element-wise activation; the attention softmax over a long sequence.
  1. Explain why a memory-bound kernel cannot be sped up by reducing its arithmetic, and describe how kernel fusion (Section 20.9) helps it instead.

  2. FlashAttention avoids materializing the full score matrix. Explain in roofline terms why this converts attention from memory-bound toward compute-bound.

  3. Describe one way the data loader (Section 20.8) can become the bottleneck of an otherwise GPU-bound training run, and how you would detect it.

Chapter 21 — Stability and Debugging Large Runs

These exercises address training stability.

  1. Cross-entropy constrains the differences between logits but not their absolute scale. Explain how a z-loss (Section 21.8) anchors that scale, and why uncontrolled logit growth threatens numerical stability.

  2. Describe how weight initialization (Section 21.10) can doom a deep network before the first optimizer step, and explain what scaling residual branches by depth accomplishes.

  3. Give two examples of a “silent” training failure (Section 21.9) that a healthy-looking loss curve would not reveal, and name the signals you would monitor to catch each.

  4. Outline the runbook you would follow on encountering a sudden loss spike: what to inspect first, and what distinguishes a recoverable spike from a corrupted run.

Chapter 22 — Supervised Fine-Tuning

These exercises concern supervised fine-tuning.

  1. Argue, from what pretraining already provides, why SFT “reveals” behavior rather than installing knowledge (Section 22.9). What does this imply about how much data you need?
  1. Explain precisely why the chat template must match between training and inference, and describe the symptom a mismatch produces — why is it a silent failure rather than a crash?

  2. In sequence packing (Section 22.11), what does the attention mask accomplish, and what specific corruption occurs if examples in a packed sequence are allowed to attend across their boundaries?

  3. You can train on 50,000 noisy instruction pairs or 1,000 carefully curated ones. State which you would choose and defend it using the quality-over-quantity argument.

Chapter 23 — Reward Modeling and RLHF

These exercises concern reinforcement learning from human feedback.

  1. Write the Bradley–Terry preference loss (Section 23.9) and explain why the reward model’s quality is a hard ceiling on the entire RLHF stage.

  2. Identify the four models involved in PPO-based RLHF and state the role of each. Which two are frozen during training?

  3. Explain the bias–variance trade-off that GAE (Section 23.10) manages, and what the interpolation parameter controls.

  4. Give a concrete example of reward hacking, and explain mechanically how the KL penalty to the reference model discourages it.

Chapter 24 — Direct Preference Optimization and Variants

These exercises concern direct preference optimization.

  1. Explain the precise sense in which DPO’s policy is “its own reward model” (Section 24.8), referencing the closed-form relationship it inverts.

  2. Why is DPO particularly susceptible to length bias (Section 24.9)? Name two distinct mitigations and explain how each breaks the length–reward correlation.

  1. Contrast DPO with PPO in terms of what each needs at training time: sampling loop, explicit reward model, reference model.

  2. What is the role of the reference model in the DPO objective, and what would you expect to happen if it were removed entirely?

Chapter 25 — Reinforcement Learning for Reasoning — GRPO and DeepSeek-R1

these exercises concern group relative policy optimization and reasoning RL.

Explain how GRPO's group-mean baseline (Section 25.8) places PPO's learned critic, and what apparatus this removes from the training pipeline.

2. State the three properties of a good verifiable reward (Section 25.11) and give a concrete reward that violates each one.

  1. Explain why GRPO is on-policy (Section 25.12), what that costs relative to DPO’s offline training, and what capability the cost buys.

  2. What did R1-Zero demonstrate about pure RL, and what specific problem did R1’s cold-start data fix (Section 25.10)?

Chapter 26 — Distillation and Compression

These exercises concern distillation and compression.

  1. What extra information does a teacher’s full output distribution carry, beyond a hard label, that makes soft-target distillation effective?

  2. Contrast unstructured and structured pruning (Section 26.9), and explain why only one of them produces real speedup on standard hardware.

  3. Explain the different strategies GPTQ and AWQ use to achieve good 4-bit quality without retraining (Section 26.10).

  1. Under what circumstances would you reach for quantization-aware training (Section 26.4) rather than a post-training method, and why does the choice flip below 4 bits (Section 41.7)?

Chapter 27 — Inference and Decoding

These exercises concern inference and decoding.

  1. Explain why the KV cache makes generating nn tokens cost time linear in nn rather than quadratic. What is cached, and what is avoided?

  2. Describe how constrained decoding (Section 27.9) guarantees well-formed JSON, and argue why this is more reliable than instructing the model to produce JSON.

  3. KV-cache quantization (Section 27.10), MLA (Section 12.9), and cross-layer sharing (Section 41.8) all shrink the cache along different axes. Explain how they compose and why the savings multiply.

  4. Contrast greedy decoding, temperature sampling, and beam search in terms of output diversity, and give a task suited to each.

Chapter 28 — Serving Systems

These exercises concern production serving.

  1. Explain why continuous batching (Section 28.2) achieves higher GPU utilization than static batching for a stream of requests with varied lengths.

  2. Describe the scheduling problem that chunked prefill (Section 28.10) solves, and how slicing a long prefill protects other requests’ latency.

  3. Why must autoscaling for large models act ahead of demand rather than reactively (Section 28.9)? What leading signals would you use?

  4. Explain how routing shared-prefix requests to the same replica exploits the prefix cache, and what this trades against perfectly even load balancing.

Chapter 29 — Evaluation and Benchmarking

These exercises concern evaluation.

  1. Explain why capability must be measured with a suite of benchmarks (Section 29.11) rather than any single one, using an example of a model strong on one axis and weak on another.

  2. Define benchmark contamination (Section 29.10) and explain why a high score from a contaminated model measures nothing real.

  3. Contrast automated benchmarks, model-judge evaluation, and live A/B testing along two axes: cost, and what each actually measures.

  4. Design an evaluation that is robust to contamination, and explain precisely why your design defeats it.

Chapter 30 — Capstone II — Build, Train, and Align Your Own LLM

These exercises concern taking a model to production.

  1. List three things a deployable system needs that a working capstone model lacks (Section 30.8), and explain why none is “science.”

  2. Explain the “overfit one batch” test (Section 30.9): what it checks, and what a failure to drive the loss toward zero tells you.

  3. Why should an untrained model’s initial loss be approximately the natural logarithm of the vocabulary size?

Chapter 31 — Multimodal and Beyond

These exercises concern multimodality.

  1. State the unifying principle (Sections 31.6 and 31.8) that lets a single transformer process images, audio, and text.
  1. Describe the role of the projector in cross-modal alignment (Section 31.9), and explain why both the vision encoder and the language model are often frozen while it is trained.

  2. Explain the sense in which a neural codec is a “tokenizer for sound.”

Chapter 32 — The Frontier and What Comes Next

These exercises concern the model’s surrounding capabilities.

  1. Name three capabilities that surround a model without being part of it (Section 32.6), and state what each adds to an application.

  2. Explain the strategy of Section 32.7 for keeping up with the field, and why understanding fundamentals outlasts tracking the surface.

  3. Distinguish retrieval-augmented generation from fine-tuning as means of supplying a model with new or fresh knowledge.

Chapter 33 — The Open-Source Ecosystem

These exercises concern the open ecosystem.

  1. Contrast open-weights and closed models (Section 33.7) along the axes of control and convenience, and name a scenario favoring each.

  2. Explain how a model hub with standardized formats and model cards (Section 33.8) accelerates the spread of open models.

  3. Why is the safetensors format preferred over the older pickle format for distributing weights?

Chapter 34 — The Industry Landscape

These exercises concern the economics of deployment.

  1. Explain why inference cost (Section 34.6) eventually surpasses training cost for a widely used model, and what follows for architecture choices.
  1. Describe the total-cost-of-ownership crossover (Section 34.7) between a hosted API and self-hosting, including the hidden costs the per-token price ignores.

  2. Why does a technique that halves serving cost have such high leverage relative to one that halves training cost?

Chapter 35 — Cloud, Clusters, and Kubernetes

These exercises concern cloud deployment.

  1. Explain the three complications of multi-region deployment (Section 35.7): GPU availability, cost, and version consistency.

Describe how spot instances (Section 35.8) reduce cost, and the gineering — checkpointing, redundancy, failover — required to e them safely.

Why does a serving replica’s multi-minute cold start force autoscaling to act ahead of demand?

Chapter 36 — An End-to-End System Blueprint

These exercises concern operating a system in production.

  1. Name the three pillars of observability (Section 36.5) and the distinct question each answers.

  2. List four LLM-specific serving metrics and explain what each one reveals about the system’s health or cost.

  3. Explain how canary deployment and instant rollback (Section 36.6) turn a risky model update into a controlled experiment.

Chapter 37 — Beyond Quadratic Attention

These exercises concern the attention frontier.

  1. Explain how linear attention’s reordering of the product (Section 37.8) achieves linear cost in sequence length, and what quality it sacrifices.
  1. Describe a hybrid architecture (Section 37.9) and explain why interleaving a few full-attention layers among many efficient ones captures most of both worlds.

  2. Why have state-space models and linear attention converged on similar hybrid designs?

Chapter 38 — Reasoning and Test-Time Compute

These exercises concern the reasoning frontier.

  1. Contrast a single chain of thought, self-consistency (Section 38.9), and tree-of-thought search (Section 38.8) in terms of compute cost and reliability.

  2. Explain why self-consistency’s majority vote tends to be more reliable than any individual reasoning chain.

  3. Place each of the three methods on the test-time-compute spectrum (Section 38.6) and justify the ordering.

Chapter 39 — Agents and Long-Horizon Autonomy

These exercises concern agents.

  1. Explain the agent loop and why error compounding (Section 39.5) makes long-horizon agents fragile.

  2. State the benefits and costs of multi-agent systems (Section 39.7), and describe a situation in which a single strong agent is the better choice.

  3. Why does standardizing tool-use protocols (Section 39.8) matter for building an interoperable agent ecosystem?

Chapter 40 — Multimodality and World Models

These exercises concern the multimodal frontier.

  1. Describe the architecture of an any-to-any model (Section 40.7) and the principle — everything is tokens — that makes it possible.
  1. Explain why video understanding (Section 40.8) is fundamentally a token-budget problem, and name two strategies for controlling that budget.

  2. What are the hard problems “in the seams” of unified multimodal models, and why do they resist a simple solution?

Chapter 41 — Efficiency and Compression Frontiers

These exercises concern the efficiency frontier.

  1. Explain why post-training quantization breaks down below four bits, and what quantization-aware training (Section 41.7) does differently.

    Describe cross-layer KV sharing (Section 41.8) and explain how it composes with MLA and cache quantization to multiply the savings.

3 Why is the inference-cost argument of Section 34.6 the economic motivation behind most efficiency-frontier research?

Chapter 42 — Data, Synthetic Data, and Self-Improvement

These exercises concern the data frontier.

  1. Explain the promise and the peril of synthetic data (Section 42.8): productive self-improvement versus model collapse, and what keeps a system on the right side.

  2. Describe the shift from accumulating data to engineering it (Section 42.9), naming three concrete practices.

  3. Argue why, with architectures largely converged, data quality may now matter more than architectural details.

Chapter 43 — Alignment, Interpretability, and Safety

These exercises concern the alignment frontier.

  1. Explain why jailbreaks (Section 43.7) are difficult to eliminate, referencing the breadth of the attack surface.
  1. Describe the goal of mechanistic interpretability (Section 43.8) and why closing the build-understand gap matters for safety.

  2. State the problem of scalable oversight (Section 43.9) and describe one proposed approach to supervising models that exceed human ability.

Chapter 44 — GLM-5.2: Anatomy of a Frontier Open Model

These exercises concern the GLM-5.2 case study.

  1. Explain IndexShare (Section 44.7): what it reuses, on what schedule, and how it reduces indexer cost at long context.

  2. Describe controllable reasoning effort (Section 44.9) and how it turns the test-time-compute trade into a per-request product feature.

  3. What does GLM-5.2’s close architectural similarity to DeepSeek-V3 (Section 44.10) reveal about the current phase of the field?

Chapter 45 — DeepSeek-V3: The Efficient Frontier

These exercises concern the DeepSeek-V3 case study.

  1. Explain how the active-versus-total parameter split (Section 45.6) lets DeepSeek-V3 hold enormous capacity at low per-token cost.

  2. Describe auxiliary-loss-free load balancing (Section 45.7) and why it is preferable to adding an auxiliary balancing loss.

  3. List the techniques DeepSeek-V3 stacks to achieve its low training cost (Section 45.9), and explain in what sense the full recipe is a reusable template (Section 45.10).