ELLMEngineering Large
Language Models
Download PDF

Reading guide

Introduction & reading guide

On this page

How language models are trained, executed, and incorporated into systems whose behavior and cost we can explain.

Preface

Large language models turn sequences of tokens into predictions. Software uses those predictions to complete text, summarize documents, extract records, write programs, or choose actions. These tasks can use similar model computations while demanding very different systems. A completion must arrive while someone is typing. An overnight extraction job must finish a collection of records. A coding tool must check whether a proposed change works.

The central question of this book is how to turn a language model into a useful, reliable system under constraints on data, time, memory, and cost. Answering it requires more than choosing a model or writing a prompt. We need to understand what the model computes, how its behavior is learned, how that computation is executed, and how the surrounding application establishes whether the result is acceptable.

Those questions are connected. Supplying a longer document may give a summarizer the information it needs, but it also creates more computation and request state. A smaller model may reduce the cost of one attempt while increasing the number of unusable results. Batching requests can improve device utilization while making an interactive user wait. Each design decision changes several quantities, and the preferred choice depends on what the system is meant to accomplish.

This book develops a method for reasoning about those choices. Start with the required behavior and workload. Follow the data and computation through the components responsible for producing the result. Estimate the resources they need, identify a likely limitation, and test a proposed change against the original requirements. The chapters supply the model mechanics, implementation techniques, and experimental tools needed to carry out that process.

Examples serve particular explanations. Text completion makes next-token prediction visible; summarization exposes the effects of long inputs; structured extraction and code generation give us different ways to check outputs. Parts III-V reuse an illustrative model configuration so their resource calculations can be compared. Part VI develops a documentation assistant as an integrated application case study. No single application supplies the requirements for the whole book.

Who this book is for

The intended reader is a practicing engineer familiar with Python, tensor operations, probability, differentiation and ordinary distributed systems. Part I deliberately works through the computation rather than assuming that familiarity with model names establishes understanding. The accelerator path assumes that you can read short C++ kernels and understand threads and synchronization; it explains device-specific mechanisms and includes a complete executed Metal example. Readers seeking language syntax should use the platform tutorials referenced in the optional accelerator notes.

Part I develops the computation at two scales: hand calculations make individual operations inspectable, and a small attention decoder connects them to training, cached generation and recovery. Experienced readers can use the executable equivalence checks as a readiness test and move directly to the relevant systems part. The detailed explanations remain available when a later failure requires tracing the computation backward.

You do not need to master every part before building an application. An application engineer can reason about input length and output checks while using a hosted model. A kernel engineer can study the shapes that arise during generation without designing the complete product. The shared foundation helps each understand how a local choice affects the larger system.

How the parts fit together

The book moves through the system in three passes. First, Parts I-III explain model computation, training, and serving. Next, Parts IV-V examine how those computations execute on an accelerator and across multiple devices. Finally, Parts VI-VIII assemble applications, examine newer techniques, and consider how teams maintain and change a working system. Part IX contains the executable learning path, reference material, and capstone.

Part Question it answers Decisions it prepares you to make
I. Foundations What does a model compute, learn, and retain? Locate a problem and estimate its computational consequences
II. Training How do data and updates change behavior? Choose data, objectives, stages, and a training budget
III. Inference How do fixed weights serve a workload? Choose decoding, scheduling, cache allocation, and capacity
IV. Accelerators How do tensor operations execute on a device? Choose layouts and schedules for a measured bottleneck
V. Distributed systems How does work span multiple devices? Place computation and state; manage communication and recovery
VI. Applications How does model output become a useful result or action? Design data access, evaluation, telemetry, and tool execution
VII. Recent research What do newer mechanisms change? Assess a technique's benefit and integration requirements
VIII. Engineering operations How are changes admitted and recovered? Define release gates, error budgets, failure capacity, and migration economics
IX. Lab and references Can you reproduce and combine the ideas? Exercise the mechanisms and complete a service-design capstone

The order follows dependencies. A training recipe needs a definition of the prediction and its loss. A serving design needs the resulting computation and state. Kernel and distributed designs need the shapes, transfers, and dependencies imposed by that workload. Application evaluation closes the loop by asking whether the complete system does useful work. A failure at one boundary need not be solved at the same boundary: a latency problem might require a shorter input, a different scheduler, or a faster kernel. The analysis should establish which.

For a continuous reading, follow Parts I-III in sequence. After that, choose the path closest to your work. Application builders can continue to Part VI and return to accelerator details when a measured bottleneck calls for them. Systems engineers can continue through Parts IV-V. Part VII is more useful after the underlying mechanisms are familiar; it is not an alternative introduction to them.

Part VI puts the design method, retrieval service and bounded agent loop first. Its four detailed telemetry chapters form an optional implementation track afterward. Classical-ML refreshers, platform-specific setup, career exercises and the dated release catalogue remain companions. This keeps the reasoning visible without discarding the longer derivations.

Working with the examples

We use three scales of example. Hand calculations expose a single operation, such as a softmax or an attention row. Runnable CPU programs connect several operations while keeping every intermediate inspectable. A recurring illustrative 7B decoder then gives the byte and runtime calculations realistic dimensions. The small programs do not establish the quality or performance of that larger model.

Code panels identify runnable examples and illustrative excerpts. Run the Python examples from the repository root; examples/README.md lists commands, expected results, and limitations. make test checks the reference programs and document tooling. The Part IX lab links them into a training-to-generation exercise. A > in a printed code panel's left gutter indicates a wrapped source line, not an extra character to type.

The exercises ask you to change an assumption, calculate its consequence, or diagnose a failure. Work them before reading their answers. If a result surprises you, inspect which quantity was held fixed: sequence length, number of requests, number of training tokens, or total memory. Many apparent disagreements about LLM performance are comparisons of different workloads.

Scope and evidence

This October 12 public edition preserves the detailed manuscript and incorporates a sequential technical review of all 68 chapters, with corrections to mathematical assumptions, operational models and source references. It is AI-assisted and has not received independent human technical review or professional copy editing. CPU, Gloo, local-model and compiled Metal experiments have recorded results; CUDA and multi-GPU execution remain unmeasured. Calculations, local measurements and source-reported results are distinguished throughout.

Research claims retain their individual dates: Part VI's research revision runs through September 24, Part VII's catalogue through September 23, and other parts through September 13 unless explicitly dated. The revision date does not imply a new literature census. The edition ledger maps selected assertions to source versions and manuscript locations. The MCP versioning policy, for example, permits compatible updates while a version is current. Its date-bearing URL is classified as mutable; reviewed page bytes are retained separately.

Explore the core chapters and optional supplements.