5  Computation

Deep learning libraries provide reusable layers and training components while allowing models to define their own computation. Their central abstraction is the module: a unit that can contain parameters, child modules, and a forward computation. Modules range from individual layers to the repeated blocks from which large models are assembled.

This chapter explains the software structure behind the models used so far. It covers module construction, initialization, model state, serialization, custom layers, reproducibility, numeric formats, and device placement. These topics matter at any scale, but modern training makes their interaction especially important: models are commonly built from configuration objects, run in reduced precision, measured in gigabytes, initialized from pretrained weights, and checkpointed together with optimizer state.

Accordingly, we proceed in eight steps. We start with how models are built from modules and configs (Section 5.1), what a model’s state is and what it costs in memory (Section 5.2), how that state is initialized (Section 5.3), and how that state is saved, restored, and adopted from pretrained models (Section 5.6). We then turn to numeric formats (Section 5.5), devices and GPU memory (Section 5.7), and layers the library does not provide (Section 5.4). Finally, we distinguish repeatable experiments from inspecting a model’s execution (Section 5.8). The chapter introduces no new models or datasets; the advanced modeling chapters that follow rely on these techniques throughout.

Resources and Further Reading

The references below develop the mechanisms introduced in this chapter: how frameworks represent models and state, automatic differentiation, numerics and mixed precision, devices and memory, and reproducible training. All are freely accessible online except where noted.

Books

Courses and video lectures

Tutorials, notes, and interactive

Foundational papers