liveBook · Manning

Chapter 18: Best practices for the real world

What you will learn in chapter 18 of Deep Learning with Python, Third Edition

This introduction explains the gap between the book’s small-scale examples and the demands of real-world, state-of-the-art modeling.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction explains the gap between the book’s small-scale examples and the demands of real-world, state-of-the-art modeling.

Key terms: small scale, best achievable performance, state-of-the-art results

18.1 Getting the most out of your models

The section contrasts trying architecture configurations blindly for an adequate model with the aim of building a stronger one.

Key terms: architecture configurations

18.1.1 Hyperparameter optimization

This section explains how to search for model hyperparameters with KerasTuner, evaluate configurations responsibly, and turn search results into a final model.

Key terms: hyperparameters, parameters, backpropagation, automatic hyperparameter optimization, hyperparameter space, validation performance, gradient-free optimization, random search, Bayesian optimization, KerasTuner

18.1.2 Model ensembling

This section explains how combining classifier predictions can improve results, especially when the models make different kinds of errors.

Key terms: model ensembling, diversity, bias, architectures, average, weighted average, validation data, inference time

18.2 Scaling up model training with multiple devices

The section explains why faster model training improves deep learning work by allowing more cycles of experimentation and refinement.

Key terms: loop of progress, refinement cycles, training infrastructure, bottleneck

18.2.1 Multi-GPU training

This section explains how multi-GPU training distributes work by replicating a model, splitting a model, or combining both approaches.

Key terms: data parallelism, replica, sub-batches, synchronous training, model parallelism, sharding, partitioning, horizontal partitioning, vertical partitioning, communication overhead

18.2.2 Distributed training in practice

Shows how to configure data and model parallelism with Keras on JAX, and how to keep the input pipeline efficient during distributed training.

Key terms: data parallelism, DataParallel, global batch size, local batch size, device mesh, model parallelism, axis_names, LayoutMap, variable path, replicate

18.2.3 TPU training

This section explains why TPU training is useful and how to configure Keras training, avoid data-loading bottlenecks, and keep TPU cores busy.

Key terms: ASIC, Tensor Processing Unit (TPU), Google Colab, Google Cloud, JAX backend, keras.distribution.set_distribution, DataParallel, ModelParallel, Google Cloud Storage (GCS), dataset.cache()

18.3 Speeding up training and inference with lower-precision computation

Introduces a potential way to speed up model training and inference, then points ahead to an explanation of precision.

18.3.1 Understanding floating-point precision

This section explains how bit count limits floating-point resolution, why representable values are unevenly spaced, and what practical resolution different precisions provide.

Key terms: precision, float16, float32, float64, half precision, single precision, sign, mantissa, exponent, representable values

18.3.2 Float16 inference

This section explains how 16-bit computation can speed up model inference and compares float16 with bfloat16.

Key terms: float32, float16, model inference, model.predict(), bfloat16, exponent bits, mantissa bits

18.3.3 Mixed-precision training

Explains why training needs mixed precision and how Keras combines 16-bit computation with 32-bit weight updates.

Key terms: mixed-precision training, float16, gradient updates, numerical stability, compute_dtype, variable_dtype, float16 gradients, float32 variables, softmax, crossentropy

18.3.4 Using loss scaling with mixed precision

This section explains why small float16 gradients can prevent learning during mixed-precision training and how loss scaling helps avoid that problem.

Key terms: mixed precision, float16, gradients, loss scaling, loss_scale_factor, LossScaleOptimizer

18.3.5 Beyond mixed precision: float8 training

This section explains why float8 training needs special handling beyond ordinary mixed precision and when its costs can outweigh its speed benefits.

Key terms: mixed precision training, float16, float8, compute_dtype, gradient updates, Keras, float8 training, Dense, EinsumDense, Embedding

18.3.6 Faster inference with quantization

This section explains how int8 quantization speeds up inference by scaling an already trained model’s values for lower-precision computation, then restoring the output’s scale.

Key terms: int8 quantization, float32, inference, matmul, abs-max scaling, int8, input scaling factors, rounding, Dense, EinsumDense

18.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 17: Image generation Chapter 19: The future of AI →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.