Distributed Machine Learning with Python

Book description

Build and deploy an efficient data processing pipeline for machine learning model training in an elastic, in-parallel model training or multi-tenant cluster and cloud

Key Features

  • Accelerate model training and interference with order-of-magnitude time reduction
  • Learn state-of-the-art parallel schemes for both model training and serving
  • A detailed study of bottlenecks at distributed model training and serving stages

Book Description

Reducing time cost in machine learning leads to a shorter waiting time for model training and a faster model updating cycle. Distributed machine learning enables machine learning practitioners to shorten model training and inference time by orders of magnitude. With the help of this practical guide, you'll be able to put your Python development knowledge to work to get up and running with the implementation of distributed machine learning, including multi-node machine learning systems, in no time. You'll begin by exploring how distributed systems work in the machine learning area and how distributed machine learning is applied to state-of-the-art deep learning models. As you advance, you'll see how to use distributed systems to enhance machine learning model training and serving speed. You'll also get to grips with applying data parallel and model parallel approaches before optimizing the in-parallel model training and serving pipeline in local clusters or cloud environments. By the end of this book, you'll have gained the knowledge and skills needed to build and deploy an efficient data processing pipeline for machine learning model training and inference in a distributed manner.

What you will learn

  • Deploy distributed model training and serving pipelines
  • Get to grips with the advanced features in TensorFlow and PyTorch
  • Mitigate system bottlenecks during in-parallel model training and serving
  • Discover the latest techniques on top of classical parallelism paradigm
  • Explore advanced features in Megatron-LM and Mesh-TensorFlow
  • Use state-of-the-art hardware such as NVLink, NVSwitch, and GPUs

Who this book is for

This book is for data scientists, machine learning engineers, and ML practitioners in both academia and industry. A fundamental understanding of machine learning concepts and working knowledge of Python programming is assumed. Prior experience implementing ML/DL models with TensorFlow or PyTorch will be beneficial. You'll find this book useful if you are interested in using distributed systems to boost machine learning model training and serving speed.

Table of contents

  1. Distributed Machine Learning with Python
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
  6. Section 1 – Data Parallelism
  7. Chapter 1: Splitting Input Data
    1. Single-node training is too slow
      1. The mismatch between data loading bandwidth and model training bandwidth
      2. Single-node training time on popular datasets
      3. Accelerating the training process with data parallelism
    2. Data parallelism – the high-level bits
      1. Stochastic gradient descent
      2. Model synchronization
    3. Hyperparameter tuning
      1. Global batch size
      2. Learning rate adjustment
      3. Model synchronization schemes
    4. Summary
  8. Chapter 2: Parameter Server and All-Reduce
    1. Technical requirements
    2. Parameter server architecture
      1. Communication bottleneck in the parameter server architecture
      2. Sharding the model among parameter servers
    3. Implementing the parameter server
      1. Defining model layers
      2. Defining the parameter server
      3. Defining the worker
      4. Passing data between the parameter server and worker
    4. Issues with the parameter server
      1. The parameter server architecture introduces a high coding complexity for practitioners
    5. All-Reduce architecture
      1. Reduce
      2. All-Reduce
      3. Ring All-Reduce
    6. Collective communication
      1. Broadcast
      2. Gather
      3. All-Gather
    7. Summary
  9. Chapter 3: Building a Data Parallel Training and Serving Pipeline
    1. Technical requirements
    2. The data parallel training pipeline in a nutshell
      1. Input pre-processing
      2. Input data partition
      3. Data loading
      4. Training
      5. Model synchronization
      6. Model update
    3. Single-machine multi-GPUs and multi-machine multi-GPUs
      1. Single-machine multi-GPU
      2. Multi-machine multi-GPU
    4. Checkpointing and fault tolerance
      1. Model checkpointing
      2. Load model checkpoints
    5. Model evaluation and hyperparameter tuning
    6. Model serving in data parallelism
    7. Summary
  10. Chapter 4: Bottlenecks and Solutions
    1. Communication bottlenecks in data parallel training
      1. Analyzing the communication workloads
      2. Parameter server architecture
      3. The All-Reduce architecture
      4. The inefficiency of state-of-the-art communication schemes
    2. Leveraging idle links and host resources
      1. Tree All-Reduce
      2. Hybrid data transfer over PCIe and NVLink
    3. On-device memory bottlenecks
    4. Recomputation and quantization
      1. Recomputation
      2. Quantization
    5. Summary
  11. Section 2 – Model Parallelism
  12. Chapter 5: Splitting the Model
    1. Technical requirements
    2. Single-node training error – out of memory
      1. Fine-tuning BERT on a single GPU
      2. Trying to pack a giant model inside one state-of-the-art GPU
    3. ELMo, BERT, and GPT
      1. Basic concepts
      2. RNN
      3. ELMo
      4. BERT
      5. GPT
    4. Pre-training and fine-tuning
    5. State-of-the-art hardware
      1. P100, V100, and DGX-1
      2. NVLink
      3. A100 and DGX-2
      4. NVSwitch
    6. Summary
  13. Chapter 6: Pipeline Input and Layer Split
    1. Vanilla model parallelism is inefficient
      1. Forward propagation
      2. Backward propagation
      3. GPU idle time between forward and backward propagation
    2. Pipeline input
    3. Pros and cons of pipeline parallelism
      1. Advantages of pipeline parallelism
      2. Disadvantages of pipeline parallelism
    4. Layer split
    5. Notes on intra-layer model parallelism
    6. Summary
  14. Chapter 7: Implementing Model Parallel Training and Serving Workflows
    1. Technical requirements
    2. Wrapping up the whole model parallelism pipeline
      1. A model parallel training overview
      2. Implementing a model parallel training pipeline
      3. Specifying communication protocol among GPUs
      4. Model parallel serving
    3. Fine-tuning transformers
    4. Hyperparameter tuning in model parallelism
      1. Balancing the workload among GPUs
      2. Enabling/disabling pipeline parallelism
    5. NLP model serving
    6. Summary
  15. Chapter 8: Achieving Higher Throughput and Lower Latency
    1. Technical requirements
    2. Freezing layers
      1. Freezing layers during forward propagation
      2. Reducing computation cost during forward propagation
      3. Freezing layers during backward propagation
    3. Exploring memory and storage resources
    4. Understanding model decomposition and distillation
      1. Model decomposition
      2. Model distillation
    5. Reducing bits in hardware
    6. Summary
  16. Section 3 – Advanced Parallelism Paradigms
  17. Chapter 9: A Hybrid of Data and Model Parallelism
    1. Technical requirements
    2. Case study of Megatron-LM
      1. Layer split for model parallelism
      2. Row-wise trial-and-error approach
      3. Column-wise trial-and-error approach
      4. Cross-machine for data parallelism
    3. Implementation of Megatron-LM
    4. Case study of Mesh-TensorFlow
    5. Implementation of Mesh-TensorFlow
    6. Pros and cons of Megatron-LM and Mesh-TensorFlow
    7. Summary
  18. Chapter 10: Federated Learning and Edge Devices
    1. Technical requirements
    2. Sharing knowledge without sharing data
      1. Recapping the traditional data parallel model training paradigm
      2. No input sharing among workers
      3. Communicating gradients for collaborative learning
    3. Case study: TensorFlow Federated
    4. Running edge devices with TinyML
    5. Case study: TensorFlow Lite
    6. Summary
  19. Chapter 11: Elastic Model Training and Serving
    1. Technical requirements
    2. Introducing adaptive model training
      1. Traditional data parallel training
      2. Adaptive model training in data parallelism
      3. Adaptive model training (AllReduce-based)
      4. Adaptive model training (parameter server-based)
      5. Traditional model-parallel model training paradigm
      6. Adaptive model training in model parallelism
    3. Implementing adaptive model training in the cloud
    4. Elasticity in model inference
      1. Serverless
    5. Summary
  20. Chapter 12: Advanced Techniques for Further Speed-Ups
    1. Technical requirements
    2. Debugging and performance analytics
      1. General concepts in the profiling results
      2. Communication results analysis
      3. Computation results analysis
    3. Job migration and multiplexing
      1. Job migration
      2. Job multiplexing
    4. Model training in a heterogeneous environment
    5. Summary
    6. Why subscribe?
  21. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Distributed Machine Learning with Python
  • Author(s): Guanhua Wang
  • Release date: April 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781801815697