Chapter 9. Training of Generative AI Models
Training large language models involves coordinating multiple components that work together to form the end-to-end training pipeline. Figure 9-1 shows these components.
Figure 9-1. LLM training pipeline, from preparing and tokenizing the raw corpus through the forward pass, loss computation, optimization, learning-rate scheduling, and checkpointing, with distributed training and orchestration supporting the process.
First, the Dataset and DataLoader decide which data points are available to form a batch. Then the Tokenizer and Data Collator decide how that batch is packaged into the exact tensor shapes and fields that the model expects. Then the model runs a forward pass on those tensors to produce predictions. A loss function compares the predictions to the targets to compute a scalar loss, and backpropagation computes gradients that the optimizer uses to update the model parameters. Finally, the scheduler updates the learning rate and the training loop records metrics and checkpoints so training can be monitored and resumed.
In this chapter, we unpack the core building blocks of the training pipeline and discuss training optimization techniques.
Training Core Components
This section introduces the core components of the LLM training pipeline, from raw data to parameter updates. We begin with how training examples are loaded and prepared, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access