Compute the idle bubble fraction of a pipeline-parallel schedule

Pipeline parallelism puts consecutive layers on different GPUs. With an all-forward then all-backward schedule and equal stage times, the first and last stages sit idle while the pipeline fills and drains. Splitting the batch into more micro-batches shrinks that bubble. This is a cost model, not a real run.

With p stages and m micro-batches, each stage is busy for m time slots out of m + p - 1 in each phase (forward and backward alike), so

bubble = (p - 1) / (m + p - 1)

Write bubble_fraction(stages, microbatches) returning a list of bubble fractions, one per value in microbatches, for the given number of stages. If stages is 1 the bubble is 0.

Signaturedef bubble_fraction(stages, microbatches)

Example

bubble_fraction(4, [1, 4]) = [0.75, 3 / 7].

Understand the idea

In pipeline parallelism each GPU holds a few consecutive layers, and micro-batches flow through like cars on an assembly line. At the start the later stages wait for work to arrive, and at the end the early stages have nothing left: that idle time is the bubble. More micro-batches spread the same fill and drain cost over more useful work. Worked example: p = 4 stages. With m = 1 micro-batch, each phase takes m + p - 1 = 4 slots and each stage is busy for 1, so the bubble is 3 / 4 = 0.75. With m = 8, slots = 11 and the bubble is 3 / 11 = 0.2727. With m = 32 it falls to 3 / 35 = 0.0857. Rule: bubble = (p - 1) / (m + p - 1), computed for each m in the list, and 0 when p = 1. Using (p - 1) / m measures idle time relative to useful time, which is a different number and can exceed 1. This simple cost model guides how many micro-batches to use when training large models with pipeline parallelism.

solution.pyPython idle
Ctrl/Cmd + Enter runs sample tests

Run checks the first 2 tests. Submit checks all 4.

  • Sample 1: worked examplebubble_fraction(4, [1, 4])
  • Sample 2: 8 stagesbubble_fraction(8, [8, 16, 32, 64])
  • Test 3: one stagebubble_fraction(1, [1, 5])
  • Test 4: 2 stages, 1 micro-batchbubble_fraction(2, [1])