PaperLeet

GPipe Fill-Drain Scheduling and Microbatch Gradients

GPipe · NeurIPS 2019 · Medium · 40 minutes

Build fill-drain events and preserve full-batch mean gradients under microbatching.

A CPU model of equal-duration stages and synchronous updates, with linear regression; communication, BatchNorm and rematerialization are outside this kernel.

Functions to implement

GPipe Fill-Drain Scheduling and Microbatch Gradients

1. Problem

Build fill-drain events and preserve full-batch mean gradients under microbatching.

A CPU model of equal-duration stages and synchronous updates, with linear regression; communication, BatchNorm and rematerialization are outside this kernel.

Source: GPipe: Efficient Training of Giant Neural Networks using Pipeline Parallelism · Section 2.2, Algorithm; Figure 2, synchronous microbatch pipeline.

2. Core equations

$$ F_{s,m}=s+m,\quad B_{s,m}=K+M-1+(K-1-s)+(M-1-m),\quad L=\frac{1}{N}\sum_c\sum_{i\in c}(x_i^T w-y_i)^2. $$

3. From equations to code

  • pipeline_schedule(stages: int, microbatches: int) -> list[tuple] — Unit-duration forward/backward event records.
  • microbatch_mse(x: Tensor, y: Tensor, weight: Tensor, chunk_size: int) -> Tensor — Differentiable scalar sample-mean squared error.

Forward work follows the preceding stage and microbatch; backward work drains from the last stage and microbatch. Accumulate sums of squared error, then divide by the sample count, rather than averaging chunk means.

4. Conventions

stages, microbatches and chunk_size are positive integers. Events are (phase, stage, microbatch, start), with phase F/B and unit duration. All forward events finish before reverse-order backward events. x is (N,D), y (N,), w (D,); a short final chunk is allowed. Divide total squared error by N.

5. Experiment view

Train a four-feature linear model on 11 deterministic samples for 35 SGD steps at learning rate 0.08; compare full-batch and size-four chunks. Also compute useful-slot fractions for four stages as microbatch count varies.

The chart is generated by the actual submitted kernel during T3 and by the reference during export. Values are synthetic teaching measurements, not GPU throughput or full-model quality claims.

6. Run your implementation

Complete the functions in the Python editor on the right, then click Run tests. Inspect each failed check, update your implementation, and run again. Passing every required check marks the problem as solved and unlocks the notes.

7. Further study

Read the cited section and explain which dimensions or scheduling constraints the kernel preserves. Then extend the experiment beyond the stated fixture while retaining the existing contract. Larger models, real devices, and communication costs require separate measurement.

Read paper · arXiv:1811.06965

Related exercises