Why do we sometimes train one model on several GPUs at once, and what is the simplest way to share the work between them?

ML system design, Distributed training
Level L1 Beginner. Length Short. Nature Th Theoretical.

What's being asked

Whether you understand why training is spread over several machines and the simplest scheme, where each GPU works on a different slice of the data.

Key idea

Training makes many passes over a huge dataset, so one GPU (graphics processing unit, a chip that does lots of maths in parallel) can take days or weeks. The simplest way to use several GPUs is to give each one a full copy of the model and a different slice of each batch of data, then combine what they learn.

Steps

  1. Think of cooks sharing a very large order. One cook is slow, so several cooks work at once. Training is similar: the work is a big pile of examples, and each GPU processes part of the pile.
  2. The simplest plan: every GPU keeps the same full copy of the model, and each batch of examples is cut into equal slices, one slice per GPU. This is called data parallelism.
  3. Tiny calculation: a batch of 1000 images on 4 GPUs gives 1000/4=250 images to each GPU, so each GPU does about a quarter of the work per step.
  4. Each GPU works out a correction (a gradient, the direction in which to nudge the model's numbers) from its own slice. The GPUs then average their corrections and all apply the same update, so the copies stay identical.
  5. The limit: every GPU still needs room for the whole model. If the model is too big for one GPU, the model itself must be split, which is a harder topic (see `data-tensor-pipeline-parallelism`).

Common mistakes

How long your answer should be

Under 2 minutes, 4–6 sentences.

Read this

Previous in ML system design: When can you cache a machine learning model's predictions to save compute, and when is caching a bad idea?
Next in ML system design: An ML service has 100 million daily active users, and each user triggers 20 model requests per day. Peak traffic is 3× the daily average, and one server handles 500 QPS (queries per second) within the latency target. What are the average QPS, peak QPS, minimum servers needed, and servers needed with 30% headroom? Why do you size for peak rather than average?