LLM Systems Engineering
{"all_nodes":"stitched from OCR output; frontier verification status per node"}local graph
LLM Systems Engineering — Rob McKinsey
Section titled “LLM Systems Engineering — Rob McKinsey”Training and Building Large Language Models — Ashford Partners, 2026 (First Edition).
The book is organized as 42 modules under 8 parts (Chapter I–VIII dividers folded into the first module of each part), preceded by a Preface and closing with an Epilogue; there is no index. Known scan gaps, documented in the stitch spec: printed 302–303 (Module 41 opening) are missing from the scan, so module-41 begins mid-module; the Epilogue is a one-page stub and the References section is absent.
module_01
Section titled “module_01”node-book_llm-systems-engineering_module-01-what-is-a-large-language-model — Module 1 — What Is a Large Language Model?
module_02
Section titled “module_02”node-book_llm-systems-engineering_module-02-how-words-become-numbers — Module 2 — How Words Become Numbers
module_03
Section titled “module_03”node-book_llm-systems-engineering_module-03-embeddings-and-vector-spaces — Module 3 — Embeddings and Vector Spaces
module_04
Section titled “module_04”node-book_llm-systems-engineering_module-04-the-transformer-architecture — Module 4 — The Transformer Architecture
module_05
Section titled “module_05”node-book_llm-systems-engineering_module-05-how-models-learn-patterns-in-language — Module 5 — How Models Learn Patterns in Language
module_06
Section titled “module_06”node-book_llm-systems-engineering_module-06-inference — Module 6 — Inference
module_07
Section titled “module_07”node-book_llm-systems-engineering_module-07-why-build-an-llm — Module 7 — Why Build an LLM?
module_08
Section titled “module_08”node-book_llm-systems-engineering_module-08-domains-of-application — Module 8 — Domains of Application
module_09
Section titled “module_09”node-book_llm-systems-engineering_module-09-when-to-use-an-existing-model — Module 9 — When to Use an Existing Model
module_10
Section titled “module_10”node-book_llm-systems-engineering_module-10-the-three-paths-overview — Module 10 — The Three Paths Overview
module_11
Section titled “module_11”node-book_llm-systems-engineering_module-11-cost-time-and-risk — Module 11 — Cost, Time, and Risk
module_12
Section titled “module_12”node-book_llm-systems-engineering_module-12-hardware-and-infrastructure — Module 12 — Hardware and Infrastructure
module_13
Section titled “module_13”node-book_llm-systems-engineering_module-13-the-role-of-data-in-llm-performance — Module 13 — The Role of Data in LLM Performance
module_14
Section titled “module_14”node-book_llm-systems-engineering_module-14-choosing-training-data — Module 14 — Choosing Training Data
module_15
Section titled “module_15”node-book_llm-systems-engineering_module-15-where-training-data-comes-from — Module 15 — Where Training Data Comes From
module_16
Section titled “module_16”node-book_llm-systems-engineering_module-16-what-high-quality-training-data-looks-like — Module 16 — What High-Quality Training Data Looks Like
module_17
Section titled “module_17”node-book_llm-systems-engineering_module-17-data-cleaning-filtering-and-deduplication — Module 17 — Data Cleaning, Filtering, and Deduplication
module_18
Section titled “module_18”node-book_llm-systems-engineering_module-18-how-much-data-do-you-need — Module 18 — How Much Data Do You Need?
module_19
Section titled “module_19”node-book_llm-systems-engineering_module-19-special-tokens-and-sequence-formatting — Module 19 — Special Tokens and Sequence Formatting
module_20
Section titled “module_20”node-book_llm-systems-engineering_module-20-designing-the-model — Module 20 — Designing the Model
module_21
Section titled “module_21”node-book_llm-systems-engineering_module-21-how-weight-matrices-are-learned-during-training — Module 21 — How Weight Matrices Are Learned During Training
module_22
Section titled “module_22”node-book_llm-systems-engineering_module-22-batch-size-and-core-training-hyperparameters — Module 22 — Batch Size and Core Training Hyperparameters
module_23
Section titled “module_23”node-book_llm-systems-engineering_module-23-training-stability — Module 23 — Training Stability
module_24
Section titled “module_24”node-book_llm-systems-engineering_module-24-how-long-to-train — Module 24 — How Long to Train
module_25
Section titled “module_25”node-book_llm-systems-engineering_module-25-training-checkpoints — Module 25 — Training Checkpoints
module_26
Section titled “module_26”node-book_llm-systems-engineering_module-26-fine-tuning-in-depth — Module 26 — Fine-Tuning in Depth
module_27
Section titled “module_27”node-book_llm-systems-engineering_module-27-preparing-fine-tuning-datasets — Module 27 — Preparing Fine-Tuning Datasets
module_28
Section titled “module_28”node-book_llm-systems-engineering_module-28-supervised-fine-tuning-and-parameter-efficient-methods — Module 28 — Supervised Fine-Tuning and Parameter-Efficient Methods
module_29
Section titled “module_29”node-book_llm-systems-engineering_module-29-hands-on-fine-tuning-with-python-and-unsloth — Module 29 — Hands-On Fine-Tuning with Python and Unsloth
module_30
Section titled “module_30”node-book_llm-systems-engineering_module-30-alignment-and-behavior-shaping-after-fine-tuning — Module 30 — Alignment and Behavior Shaping After Fine-Tuning
module_31
Section titled “module_31”node-book_llm-systems-engineering_module-31-continued-pretraining-in-depth — Module 31 — Continued Pretraining in Depth
module_32
Section titled “module_32”node-book_llm-systems-engineering_module-32-selecting-domain-corpora-for-continued-pretraining — Module 32 — Selecting Domain Corpora for Continued Pretraining
module_33
Section titled “module_33”node-book_llm-systems-engineering_module-33-updating-model-knowledge-without-starting-over — Module 33 — Updating Model Knowledge Without Starting Over
module_34
Section titled “module_34”node-book_llm-systems-engineering_module-34-risks-of-domain-drift-and-over-specialization — Module 34 — Risks of Domain Drift and Over-Specialization
module_35
Section titled “module_35”node-book_llm-systems-engineering_module-35-running-continued-pretraining-with-python-and-unsloth — Module 35 — Running Continued Pretraining with Python and Unsloth
module_36
Section titled “module_36”node-book_llm-systems-engineering_module-36-training-from-scratch-in-depth — Module 36 — Training from Scratch in Depth
module_37
Section titled “module_37”node-book_llm-systems-engineering_module-37-building-the-full-pipeline-with-engineering-tools — Module 37 — Building the Full Pipeline with Engineering Tools
module_38
Section titled “module_38”node-book_llm-systems-engineering_module-38-end-to-end-workflow-from-scratch — Module 38 — End-to-End Workflow from Scratch
module_39
Section titled “module_39”node-book_llm-systems-engineering_module-39-translating-scaling-laws-and-training-economics — Module 39 — Translating Scaling Laws and Training Economics
module_40
Section titled “module_40”node-book_llm-systems-engineering_module-40-common-failure-points-when-building-a-model-from-scratch — Module 40 — Common Failure Points When Building a Model from Scratch
module_41
Section titled “module_41”node-book_llm-systems-engineering_module-41-evaluating-llms — Module 41 — Evaluating LLMs
module_42
Section titled “module_42”node-book_llm-systems-engineering_module-42-monitoring-and-maintenance — Module 42 — Monitoring and Maintenance
back-epilogue
Section titled “back-epilogue”node-book_llm-systems-engineering_back-epilogue — Epilogue
Title Page
Section titled “Title Page”Training and Building Large Language Models
LLM Systems Engineering
Rob McKinsey · Ashford Partners
Copyright
Section titled “Copyright”LLM System Engineering
Written by Rob McKinsey
Copyright © 2026 Ashford Partners. All rights reserved.
Published by Ashford Partners
First Edition
ISBN 978-3-9526632-4-0
Copyeditor: Jeremy Springs
No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law.
This publication is intended for educational and informational purposes. Although every effort has been made to ensure the accuracy of the information contained herein, the publisher and author assume no responsibility for errors, omissions, or any consequences arising from the use of the material.
For more information, contact our customer service department:
[email protected]
Table of Contents
Section titled “Table of Contents”PREFACE — 1
- About the Book — 2
- Author Perspective — 2
- Guiding Principles — 3
- Coding LLMs — 4
- How to Read This Book — 4
INTRODUCTION TO LARGE LANGUAGE MODELS — 9
- Module 01: What Is a Large Language Model? — 10
- Defining the Term — 10
- What LLMs Do — 12
- What LLMs Are Not — 13
- The Components That Make Up an LLM System — 14
- Module 02: How Words Become Numbers — 16
- Why Models Cannot Work with Raw Text — 16
- What a Token Is — 17
- Tokenizer Vocabularies and Token IDs — 19
- How Tokenization Affects Model Behavior — 20
- Module 03: Embeddings and Vector Spaces — 22
- The Embedding Lookup — 22
- What Vector Spaces Represent and Why They Work — 24
- Dimensions of an Embedding Space — 25
- Why Context Changes Meaning — 26
- Module 04: The Transformer Architecture — 29
- The Attention Mechanism — 29
- Multi-Head Attention — 31
- Feed-Forward Layers and Layer Normalization — 32
- How Information Flows Through the Full Stack — 33
- Module 05: How Models Learn Patterns in Language — 37
-
Next-Token Prediction — 37
-
Loss Functions — 39
-
How the Objective Shapes What the Model Learns — 41
-
Variations on the Pretraining Objective — 42
-
- Module 06: Inference — 45
- The Forward Pass — 45
- Decoding Strategies — 46
- Temperature and Controlling Output Behavior — 48
- The Autoregressive Loop — 50
STRATEGIC AND TECHNICAL PLANNING — 53
- Module 07: Why Build an LLM? — 54
- Business Motivations — 54
- Technical Motivations — 56
- Research Motivations — 58
- Stress-Testing the Rationale — 59
- Module 08: Domains of Application — 61
- Domains Where LLMs Create Reliable Value — 61
- Domains Where LLMs Underperform or Introduce Risk — 63
- Evaluating Domain Fit — 63
- Module 09: When to Use an Existing Model — 66
- What Existing Models Can Do — 66
- Adaptation Without Building — 68
- Decision Criteria — 70
- Module 10: The Three Paths Overview — 73
- Fine-Tuning — 73
- Continued Pretraining — 75
- Training from Scratch — 76
- Choosing a Path — 77
- Module 11: Cost, Time, and Risk — 80
- How Costs Differ Across the Three Pathways — 80
- Time Horizons — 82
- Categories of Risk Across the Three Pathways — 83
- Building a Realistic Resource Plan — 84
- Module 12: Hardware and Infrastructure — 87
-
GPUs and Accelerators — 87
-
Memory Constraints — 89
-
Storage and the Infrastructure Stack — 92
-
Matching Infrastructure to Pathway — 93
-
DATA ENGINEERING — 97
-
Module 13: The Role of Data in LLM Performance — 98
- Why Data Shapes Model Capability More Than Architecture Does — 98
- How Training Data Determines What a Model Knows and How It Behaves — 100
- Bias and Unintended Behavior — 102
- The Compounding Effect of Data Decisions — 103
-
Module 14: Choosing Training Data — 105
- Books and Long-Form Text — 105
- Web Data — 107
- Code — 108
- Domain Corpora — 109
-
Module 15: Where Training Data Comes From — 112
- Public Datasets — 112
- Licensed and Commercial Data — 114
- Synthetic Data — 115
- Proprietary Data — 116
-
Module 16: What High-Quality Training Data Looks Like — 119
- The Dimensions of Data Quality — 119
- Diversity and Coverage — 121
- Signal Density — 123
-
Module 17: Data Cleaning, Filtering, and Deduplication — 125
- Text Normalization and Document-Level Cleaning — 125
- Heuristic and Classifier-Based Filtering — 127
- Deduplication — 130
- The Cleaning Pipeline Design — 131
-
Module 18: How Much Data Do You Need? — 133
- Why There Is No Universal Answer — 133
- Scaling Laws — 135
- Token Coverage — 136
- Data Requirements Across the Three Pathways — 137
-
Module 19: Special Tokens and Sequence Formatting — 139
- What Special Tokens Are — 139
- Formatting for Instruction and Conversational Data — 141
- Sequence Packing and Padding Strategies — 143
- Consistency Between Training and Inference Formatting — 144
TRAINING SYSTEMS AND MODEL DEVELOPMENT — 149
- Module 20: Designing the Model — 150
- Depth vs. Width — 150
- Context Length — 152
- Architecture Variants and Design Decisions — 153
- Module 21: How Weight Matrices Are Learned During Training — 156
- How Prediction Error Drives Weight Updates — 156
- Gradient Descent and the Optimizer’s Role — 157
- What Happens Inside the Weight Matrices as Training Progresses — 159
- Numerical Precision and Gradient Stability — 160
- Module 22: Batch Size and Core Training Hyperparameters — 162
- Learning Rate — 162
- Batch Size — 164
- Weight Initialization — 165
- Hyperparameter Interaction — 167
- Module 23: Training Stability — 169
- Loss Spikes, Divergence, and Collapse — 169
- Gradient-Level Instability — 171
- Data-Driven Instability — 172
- Monitoring and Recovery Strategies — 173
- Module 24: How Long to Train — 175
- Undertraining — 175
- Overtraining and Memorization — 176
- Compute-Optimal Training — 177
- Evaluation-Driven Stopping — 177
- Module 25: Training Checkpoints — 180
-
What a Checkpoint Contains — 180
-
Checkpoint Frequency — 182
-
Using Intermediate Checkpoints — 183
-
Checkpoint Storage and Lifecycle Management at Scale — 184
-
FINE-TUNING — 187
- Module 26: Fine-Tuning in Depth — 188
- What Fine-Tuning Actually Does to a Pretrained Model — 188
- The Relationship Between Pretraining and Fine-Tuning — 189
- What Fine-Tuning Changes and What It Does Not — 190
- Module 27: Preparing Fine-Tuning Datasets — 193
- How Fine-Tuning Data Differs From Pretraining Data — 193
- Instruction Data — 194
- Sourcing and Constructing Fine-Tuning Examples — 196
- Dataset Size and Coverage — 197
- Module 28: Supervised Fine-Tuning and Parameter-Efficient Methods — 199
- The Supervised Fine-Tuning Training Loop — 199
- Full Fine-Tuning and Selective Layer Updates — 201
- LoRA and Parameter-Efficient Adaptation — 202
- Adapter Layers and Prefix Tuning — 203
- Module 29: Hands-On Fine-Tuning with Python and Unsloth — 205
- Setting Up the Environment — 205
- Attaching LoRA Adapters and Configuring Rank — 207
- Formatting the Dataset and Configuring the Trainer — 208
- Saving, Merging, and Validating the Fine-Tuned Model — 212
- Module 30: Alignment and Behavior Shaping After Fine-Tuning — 215
- What Alignment Means in Practice — 215
- Reinforcement Learning from Human Feedback — 217
- Direct Preference Optimization and Alternatives to RLHF — 219
- Failure Modes in Alignment — 221
CONTINUED PRETRAINING — 225
-
Module 31: Continued Pretraining in Depth — 226
- What Continued Pretraining Does to a Pretrained Model — 226
- How Continued Pretraining Differs From Fine-Tuning — 228
- What Continued Pretraining Is and Is Not Good For — 229
- Choosing a Base Model for Continued Pretraining — 231
-
Module 32: Selecting Domain Corpora for Continued Pretraining — 234
- What Makes a Corpus Suitable for Continued Pretraining — 234
- Matching Corpus Composition to the Target Capability Gap — 236
- Balancing Domain Data Against General Data — 237
-
Module 33: Updating Model Knowledge Without Starting Over — 240
- How New Knowledge Enters a Model Through Continued Pretraining — 240
- Learning Rate Strategy for Knowledge Updates — 241
- Curriculum and Data Ordering Effects on Knowledge Integration — 242
- Measuring Whether Knowledge Has Been Updated — 244
-
Module 34: Risks of Domain Drift and Over-Specialization — 246
- Domain Drift — 246
- Over-Specialization — 247
- Detection and Evaluation — 248
-
Module 35: Running Continued Pretraining with Python and Unsloth — 250
- Setting Up the Environment — 250
- Preparing and Tokenizing a Domain Corpus for Training — 252
- Configuring and Launching the Training Run — 253
- Saving, Merging, and Validating the Updated Model — 256
TRAINING FROM SCRATCH — 261
-
Module 36: Training from Scratch in Depth — 262
- What Training from Scratch Means — 262
- What Training from Scratch Can Achieve — 264
- The True Prerequisites — 266
- Common Justifications That Do Not Hold Up — 268
-
Module 37: Building the Full Pipeline with Engineering Tools — 270
- The Components of a Full Training Pipeline — 270
- Distributed Training Frameworks and Parallelism Strategies — 271
- Experiment Tracking and Observability Infrastructure — 273
- Tooling Choices — 275
-
Module 38: End-to-End Workflow from Scratch — 277
- Building and Validating the Tokenizer — 277
- Model Initialization and Pre-Training Checks — 279
- Staged Scaling — 282
- Transitioning From Base Model to Usable System — 284
-
Module 39: Translating Scaling Laws and Training Economics — 287
- Translating Scaling Laws Into a Compute Budget — 287
- The Economics of a From-Scratch Run — 289
-
Module 40: Common Failure Points When Building a Model from Scratch — 291
- Data Pipeline Failures — 291
- Architecture and Configuration Mistakes — 293
- Infrastructure and Distributed Training Failures — 294
- Organizational and Planning Failures — 296
EVALUATION AND MAINTENANCE — 301
- Module 41: Evaluating LLMs — 302
- Why Training Metrics Are Insufficient as Evaluation — 302
- What a Comprehensive Evaluation Must Cover — 304
- Designing Evaluation Sets That Reflect Real Use — 306
- Human Evaluation — 307
- Module 42: Monitoring and Maintenance — 310
- Monitoring Deployed LLM Systems — 310
- Model Maintenance — 312
- The Operational Discipline of Long-Running LLM Systems — 314
EPILOGUE — 317
- Looking Forward — 318
REFERENCES — 321