Search

Search papers and lessons

PipeDream: Fast and Efficient Pipeline Parallel DNN Training

Aaron Harlap, Deepak Narayanan, Amar Phanishayee et al. · 2018

PipeDream (2018) splits a neural network into consecutive stages on different GPUs, streams many minibatches through them like a factory line, and keeps weight versions consistent so training still converges.

On this page

  • Colour = topic mix
  • Discrete math
  • Systems
  • Calculus
  • Probability
  • Algorithms
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

PipeDream is a 2018 system for training large neural networks on several GPUs. It cuts the communication that slows down ordinary data-parallel training by cutting the network into consecutive stages, one per machine, and by feeding many minibatches through those stages at once so that every machine stays busy. The authors report up to 5x faster time to a target accuracy than data-parallel training, and they show how to keep the weights consistent while several minibatches are in flight.

Builds on: Model Parallelism, Dynamic Programming, Backpropagation · Leads to: later pipeline-parallel training systems (no lesson yet)

Why it mattered

Models with tens to hundreds of layers and millions of parameters stopped fitting the comfortable pattern of "copy the model, split the data." The paper's own measurements show the problem. It cites communication taking up to 85% of the training time for VGG-16 under data parallelism, and reports that faster GPUs make the communication share larger, not smaller. PipeDream showed that a pipeline of stages could replace much of that traffic. Its inter-machine messages are only the activations going forward and the gradients going backward between neighbouring stages, which the authors measured as up to 95% less than the parameter exchange of data-parallel training.

The idea spread. Later systems that split a network into stages across devices use the same core move: partition the layers, keep the pipeline full, and handle the fact that gradients now come from different weight versions. This lesson explains the paper's version of each move.

The problem

Two existing approaches each fail in a different way.

Data parallelism copies the whole model onto every worker and gives each worker a different slice of the data. After every minibatch (the small group of examples used for one weight update) the workers must agree on one averaged gradient. The paper calls the strict version bulk synchronous parallel (BSP): everyone waits for everyone. The waiting is the cost. As models grow and GPUs get faster, the time spent exchanging parameters grows relative to the time spent computing them. The authors measured 72% communication overhead for VGG16 on 8 machines in their Titan X cluster, and 70% for the S2VT captioning model on 4 machines.

Traditional model parallelism splits the network across machines by layers, so a model too big for one GPU can still be trained. But only one stage works at a time. With four machines and one minibatch, three machines sit idle at any instant. Pipelining several minibatches would fix the idle time, but naive pipelining has its own problem: a minibatch's backward pass can run with weights that have changed since its forward pass. The paper shows that this mismatch makes the final model less accurate than data-parallel training.

PipeDream has to solve three things together: choose a good split of the layers, schedule forward and backward work so no machine idles, and keep the weight versions consistent enough that the model still learns.

How it works

Take a tiny network cut into four stages on four machines, where each stage takes one time unit for its forward pass and one for its backward pass. Figure 3 of the paper uses the same unit-time model.

flowchart LR
  A[Stage 1 machine] -->|activations| B[Stage 2 machine]
  B -->|activations| C[Stage 3 machine]
  C -->|activations| D[Stage 4 machine]
  D -->|gradients| C
  C -->|gradients| B
  B -->|gradients| A
  1. Profile. On a single machine, run about 1,000 minibatches and record three numbers for each layer: how long the forward and backward passes take together, how big its output is, and how many parameters it has. Those three numbers are all the optimiser needs.
  2. Partition. Using the profile, a dynamic program decides where the stage boundaries go and how many machines each stage gets. A stage with two machines processes two different minibatches in parallel. The goal is to make every stage take about the same time, and to avoid sending large activations across a slow link.
  3. Admit minibatches. The first stage starts feeding in minibatches one after another. The paper calls the number it admits NOAM (number of optimal active minibatches). With four machines and one machine per stage, that number is 4, so four minibatches are in the pipeline at once.
  4. Forward. Minibatch 1 runs its forward pass on stage 1 for one time unit, then sends its activations to stage 2 and immediately starts minibatch 2 on stage 1. The pipeline fills stage by stage.
  5. Turn around at the output. When the output stage finishes the forward pass of minibatch 1, it computes the loss and runs the backward pass for that same minibatch right away.
  6. Alternate. From then on, every machine alternates one forward pass and one backward pass for different minibatches. The paper calls this one-forward-one-backward, or 1F1B. The backward pass sends gradients to the previous stage, which does the same, so the work moves back toward the input stage.
  7. Keep versions straight. Minibatch 5 may find stage 1 already updated by minibatch 1, but its backward pass must use the same weights as its forward pass. Weight stashing keeps a copy of the weights used by each in-flight minibatch, so the forward and backward passes of a stage agree.

Here is the timeline for two stages, one machine each, and two minibatches, using the unit time. Stage A runs the first layers, stage B the last ones.

TimeStage AStage B
0 to 1forward, minibatch 1idle
1 to 2forward, minibatch 2forward, minibatch 1
2 to 3idlebackward, minibatch 1
3 to 4backward, minibatch 1forward, minibatch 2
4 to 5idlebackward, minibatch 2
5 to 6backward, minibatch 2idle

The two minibatches finish in 6 units. Run one after the other on the same two machines, they would take 8. Pipelining saves time even in this tiny case, and in steady state the saving grows with the number of stages.

The math

Definition: Pipeline parallelism

The layers of a network are split into consecutive stages. Each stage runs on its own machine (or a replicated group of machines). Several minibatches are in flight at once, so the machines work on different minibatches at the same time.

Step 1 in symbols: profiling

For each layer ll, the profiler measures TlT_{l}, the total forward plus backward compute time for that layer, ala_{l}, the size of its output activations (which is also the size of the input gradients in the backward pass), and wlw_{l}, the size of its parameters. The time to send the activations from layer ll to layer l+1l+1 is estimated from ala_{l} and the link bandwidth, written ClC_{l}. The time for weight synchronisation in a data-parallel group of mm machines is estimated from the amount of data each machine moves, which the paper gives as 4×(m−1)×∣wl∣/m4\times(m-1)\times|w_{l}|/m.

Step 2 in symbols: the partition

Let T(i→j,m)T(i\rightarrow j,m) be the time of one stage that holds layers ii through jj and is replicated on mm machines:

T(i→j,m)=1mmax⁡(∑l=ijTl, ∑l=ijWlm)T(i\rightarrow j,m)=\frac{1}{m}\max\bigg(\sum_{l=i}^{j}T_{l},\ \sum_{l=i}^{j}W_{l}^{m}\bigg)

Here the first sum is the compute of the stage and the second is its communication. Let A(j,m)A(j,m) be the time of the slowest stage in the best pipeline that covers layers 11 through jj with mm machines. The answer we want is A(N,M)A(N,M). Either the best plan is one stage replicated on all mm machines, or its last stage holds layers i+1i+1 through jj on m′m^{\prime} machines and the rest is a best pipeline of layers 11 through ii on m−m′m-m^{\prime} machines:

A(j,m)=min⁡1≤i<j min⁡1≤m′<m max⁡{A(i,m−m′), 2⋅Ci, T(i+1→j,m′)}A(j,m)=\min_{1\leq i<j}\ \min_{1\leq m^{\prime}<m}\ \max\bigl\{A(i,m-m^{\prime}),\ 2\cdot C_{i},\ T(i+1\rightarrow j,m^{\prime})\bigr\}

The base cases are A(1,m)=T(1→1,m)A(1,m)=T(1\rightarrow 1,m) and A(i,1)=T(1→i,1)A(i,1)=T(1\rightarrow i,1). Because there are O(NM)O(NM) sub-problems and each costs O(NM)O(NM), the whole search runs in O(N2M2)O(N^{2}M^{2}) time, which is cheap for a profile of a few dozen layers.

Step 3 in symbols: how many minibatches to admit

If the input stage is replicated on some number of machines, the number of minibatches to admit to keep the pipeline full in steady state is

NOAM=⌈number of machinesnumber of machines in the input stage⌉\text{NOAM}=\left\lceil \frac{\text{number of machines}}{\text{number of machines in the input stage}}\right\rceil

Step 4 in symbols: staleness and weight stashing

Take a straight pipeline of nn stages with weights w1,…,wnw_{1}, \ldots, w_{n}, and write w1(t)w_{1}^{(t)} for the weights of stage 1 after tt minibatches. Plain minibatch SGD, with learning rate ν\nu and ff the loss being minimised, updates w(t+1)=w(t)−ν⋅∇f(w1(t),…,wn(t))w^{(t+1)}=w^{(t)}-\nu\cdot\nabla f(w_{1}^{(t)},\ldots,w_{n}^{(t)}). With weight stashing, stage 1 uses weights that are nn steps old, stage 2 uses weights n−1n-1 steps old, and so on:

w(t+1)=w(t)−ν⋅∇f(w1(t−n+1), w2(t−n+2), …, wn(t))w^{(t+1)}=w^{(t)}-\nu\cdot\nabla f(w_{1}^{(t-n+1)},\ w_{2}^{(t-n+2)},\ \ldots,\ w_{n}^{(t)})

Each stage's gradient is consistent with itself, but not with the other stages. Vertical sync fixes that by making every stage use the same version w(t−n+1)w^{(t-n+1)}, which the paper shows is equivalent to data parallelism with BSP on nn machines. PipeDream's default leaves vertical sync out, because it needs more stored metadata, and the authors found its effect on accuracy negligible in their experiments.

Worked examples

Example
1. Two stages, two minibatches, by hand

Two machines, A and B. Each stage takes 1 unit forward and 1 unit backward. Each minibatch must pass through both stages in each direction, so one minibatch alone takes 4 units.

  1. Without pipelining, minibatch 1 takes 4 units and minibatch 2 starts after it, so the two finish at 8 units.
  2. With pipelining, A starts minibatch 1 at time 0 and minibatch 2 at time 1, so A's forward work is done by time 2.
  3. B runs forward for minibatch 1 from time 1 to 2, then backward for minibatch 1 from 2 to 3, because the output stage does its backward pass right after its forward pass.
  4. B then runs forward for minibatch 2 from 3 to 4 and backward from 4 to 5.
  5. A finishes minibatch 1's backward pass at 4, and minibatch 2's backward pass at 6, since it needs B's gradient, which arrives at time 5.
  6. The last piece of work ends at time 6, against 8 without pipelining. In this tiny case the pipeline saves a quarter of the time, and the saving comes from the overlap in steps 2 and 3.
Example
2. Three layers and two machines: the partition is not always a pipeline

Three layers with compute times T1=2T_{1}=2, T2=4T_{2}=4, T3=5T_{3}=5, no communication cost, and two machines. We want A(3,2)A(3,2).

  1. The single-stage plan replicates everything on both machines: T(1→3,2)=12(2+4+5)=5.5T(1\rightarrow 3,2)=\frac{1}{2}(2+4+5)=5.5.
  2. Split after layer 1, with layer 1 on one machine and layers 2 and 3 on the other: A(1,1)=2A(1,1)=2 and T(2→3,1)=9T(2\rightarrow 3,1)=9, so the slowest stage is max⁡(2,9)=9\max(2, 9)=9.
  3. Split after layer 2, with layers 1 and 2 on one machine and layer 3 on the other: A(2,1)=6A(2,1)=6 and T(3→3,1)=5T(3\rightarrow 3,1)=5, so the slowest stage is max⁡(6,5)=6\max(6, 5)=6.
  4. Take the best of the three plans: min⁡(5.5,9,6)=5.5\min(5.5, 9, 6)=5.5.
  5. Interpretation: here the best plan is data parallelism on both machines, not a pipeline. Every split leaves one machine with at least 6 units of work, which is slower than sharing all 11 units evenly, because with no communication cost there is nothing to save by splitting the layers.
Example
3. Realistic: VGG16 on 16 machines in Cluster A

The paper's Table 1 reports, for VGG16 on 16 machines in its private Titan X cluster, a speedup of 3.28x over one machine for BSP and 9.86x for PipeDream. Ask how much faster PipeDream is than BSP at the same machine count.

  1. Divide the PipeDream speedup by the BSP speedup: 9.86/3.289.86 / 3.28.
  2. Compute it one step at a time: 3.28×3=9.843.28 \times 3 = 9.84, and 9.86−9.84=0.029.86 - 9.84 = 0.02. So the quotient is a little over 3.
  3. Interpretation: at 16 machines, communication is the bottleneck for BSP, and PipeDream makes the same hardware about 3 times faster for this model.

Try it: the same table reports 2.35x for BSP and 7.04x for PipeDream on 8 machines of the same cluster. Divide 7.04 by 2.35 and say whether the ratio is closer to 2, 3 or 4. Answer: 7.04 / 2.35 is just under 3 (about 2.996), so the answer is 3; the paper's table lists 2.99x.

Results

The main results compare time to a target accuracy: VGG16 and Inception-v3 on ImageNet, which are convolutional networks, and the S2VT captioning model on MSVD, a sequence-to-sequence recurrent network.

  • VGG16, Cluster A, 8 machines: BSP reaches 2.35x over one machine. PipeDream reaches 7.04x, which is 2.99x over BSP, and it cuts communication by 95%.
  • VGG16, Cluster A, 4 and 16 machines: BSP reaches 1.47x and 3.28x. PipeDream reaches 3.14x and 9.86x. The paper notes that PipeDream with 4 machines is almost as good as BSP with 16.
  • VGG16, Cluster B (V100 GPUs, 10 Gbps network), 8 machines: PipeDream is 5.12x faster than BSP, with 95% less communication.
  • Inception-v3, Cluster A, 8 machines: BSP is already near-linear at 7.66x. The optimiser chose plain data parallelism, so PipeDream matches BSP with 0% communication reduction.
  • Inception-v3, Cluster B, 8 machines: PipeDream is 1.45x faster than BSP, with 47% less communication.
  • S2VT captioning, Cluster A, 4 machines: BSP reaches 1.10x and PipeDream 3.34x, which is 3.01x over BSP, with 95% less communication.
  • Asynchronous data parallelism: PipeDream reaches 48% accuracy 7.4x faster than asynchronous data-parallel training, even though the asynchronous version has no synchronisation cost, because its gradients are computed from stale weights.
  • Headline: the abstract reports up to 5x faster time to target accuracy across five DNNs and two clusters.

These numbers mean three things. Pipelining helps most where communication is large compared with compute, as with VGG16 and S2VT. It does not help where communication is already small, as with Inception-v3 on Cluster A, where the optimiser correctly declined to pipeline. And the limits are real: the experiments use two clusters, three main models plus a few reported secondary ones, and the authors' own baselines, so the exact speedups are specific to that hardware.

Reading guide

Read the paper in this order, with the lesson it depends on:

  1. Section 1, Introduction. Needs Data Parallelism and the idea of a Stochastic Gradient Descent step. Read the four challenges list carefully; they map onto the sections below.
  2. Section 2, Background. Needs Data Parallelism, Model Parallelism and All-Reduce. Figures 1 to 4 are the case for the design.
  3. Section 3.1 and 3.2, pipeline parallelism and partitioning. Needs Model Parallelism and Dynamic Programming. The recurrence in Section 3.2 is the place to slow down.
  4. Section 3.3, scheduling. Needs Instruction Pipelining for the intuition of overlapping stages. The 1F1B rule is the heart of the schedule.
  5. Section 3.4, effective learning. Needs Backpropagation and Stochastic Gradient Descent. The staleness formulas are where the optimisation argument lives.
  6. Sections 4 and 5, implementation and evaluation. Needs Feedforward Neural Network only as background; read the tables against the results above.

Check yourself

QuestionWhich three numbers does the profiling step record for each layer, and what does each one measure?Show answer

PipeDream records TlT_{l}, the total forward and backward compute time for layer ll; ala_{l}, the size of the layer's output activations (also the size of the input gradients in the backward pass); and wlw_{l}, the size of its parameters. The partitioner uses these three to estimate compute time and communication time for each candidate stage.

QuestionA straight pipeline has four stages, one machine each, and every stage takes 1 unit forward and 1 unit backward. In steady state, how many minibatches finish in 40 units of time?Show answer

Each minibatch takes 2 units of work on every machine, so in steady state one minibatch leaves the pipeline every 2 units. In 40 units, that is 40 / 2 = 20 minibatches, ignoring the start-up period while the pipeline fills.

QuestionWeight stashing makes each stage consistent with itself. What inconsistency is left across stages, and what does vertical sync change?Show answer

Stages still use weights from different points in time. In the paper's formula with nn stages, stage 1's gradient is computed with weights nn steps delayed, stage 2's with weights n−1n-1 steps delayed, and so on, so one update mixes weight versions from several moments. Vertical sync makes every stage use the same version for a given minibatch, w(t−n+1)w^{(t-n+1)}. The paper shows this is equivalent to data parallelism with BSP on nn machines, and PipeDream leaves it out by default because it needs more stored metadata.

QuestionYou have eight machines and a model where data-parallel training spends about 70% of each step on communication. Should you expect pipelining to help, and what would you check first?Show answer

Probably yes. When communication dominates, cutting the parameter exchange is the main lever of data-parallel training. The S2VT model in the paper had 70% communication overhead on 4 machines and reached 3.01x over BSP. Before committing, check the computation-to-communication ratio and run a profile, because the partitioner may still choose plain data parallelism when that is faster, as it did for Inception-v3 on Cluster A.

Sources

  • Harlap, Narayanan, Phanishayee, Seshadri, Devanur, Ganger, Gibbons. PipeDream: Fast and Efficient Pipeline Parallel DNN Training. arXiv:1806.03377 (2018). arXiv abstract page, DOI 10.48550/arXiv.1806.03377.
  • Goyal, Dollár, Girshick, et al. Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour. arXiv:1706.02677 (2017), cited by the paper for collective communication in data-parallel training. arXiv abstract page.

Read the full paper

Aaron Harlap, Deepak Narayanan, Amar Phanishayee et al., 2018. arXiv:1806.03377