techlist.io

Data Parallelism

2 posts

OpenAI2022-06-084 min readCurated summary

Techniques for training large neural networks

# Techniques for Training Large Neural Networks Training large neural networks requires coordinating many GPUs to perform a single synchronized calculation, and practitioners have developed several ways to parallelize that work. Viewed with a few simplifying assumptions, these techniques reduce to moving opaque chunks of data between devices. The post surveys the main approaches, from data and pipeline parallelism to tensor parallelism and Mixture-of-Experts, along with memory-saving methods that make very large models feasible to train. ## The Basic Training Loop Each training iteration runs a forward pass to compute outputs for a batch, then a backward pass to compute a gradient for each parameter. An optimizer such as Adam uses the averaged gradients and its per-parameter state to produce the next set of parameters. Parallelism techniques divide this process along different dimensions. ## Data Parallelism - Each GPU (worker) holds a full copy of the parameters and processes a different subset of the batch. - The model must still fit in a single GPU's memory, and parameters are duplicated on every device. - Workers synchronize by averaging gradients each step, which requires transferring data proportional to the number of workers times the parameter size. - Asynchronous schemes reduce this communication overhead but hurt learning efficiency, so synchronous training is the common choice. ## Pipeline Parallelism - The model is split into consecutive groups of layers, with each GPU holding only a fraction of the parameters. - A naive implementation leaves workers idle while they wait for upstream outputs, creating "bubbles." - Splitting each batch into microbatches lets workers start on the next microbatch as soon as it is ready, which shrinks the bubbles. - Only activations (forward) and their gradients (backward) move between neighboring stages. - GPipe runs forward and backward passes consecutively and aggregates gradients synchronously at the end, while PipeDream alternates forward and backward passes. ## Tensor Parallelism - Individual operations within a layer, especially large matrix multiplications, are split across GPUs. - Weight matrices are sharded so each GPU computes part of the product, and the results are then combined through communication. - Megatron-LM applies this to the self-attention and MLP layers of Transformers. - PTD-P combines tensor, data, and pipeline parallelism, assigning multiple non-consecutive layers to each device to reduce bubble overhead at the cost of more communication. - Sequence parallelism splits an input sequence across time into sub-examples, lowering peak memory use. ## Mixture-of-Experts - Only a fraction of the network is activated for each input, with a gating mechanism choosing which expert weight sets to use. - This increases the total parameter count without a proportional increase in computation. - Different experts can be placed on different GPUs, giving a natural way to scale across hardware. - GShard scales an MoE Transformer to 600 billion parameters by splitting only the MoE layers across devices, while Switch Transformer routes each input to a single expert and reaches trillions of parameters. ## Memory-Saving Techniques - **Checkpointing (activation recomputation):** Stores only a subset of activations and recomputes the rest during the backward pass, costing at most one extra forward pass. Selective recomputation targets activations that are expensive to store but cheap to recompute. - **Mixed precision training:** Uses lower-precision formats such as FP16 to increase throughput and reduce memory, with little loss in accuracy when done carefully. - **Offloading:** Moves unused data to CPU memory or other devices and prefetches it back before it is needed. ZeRO partitions parameters, gradients, and optimizer states across all hardware. - **Memory-efficient optimizers:** Adafactor reduces the memory footprint of optimizer state. - **Compression:** Gist compresses activations saved for the backward pass, and DALL·E compresses gradients before synchronization. These strategies are typically combined in practice, since each addresses a different bottleneck in compute, communication, and memory.

OpenAI2018-12-134 min readCurated summary

How AI training scales

# How AI Training Scales The gradient noise scale, a simple statistic measuring the signal-to-noise ratio of network gradients, predicts how far neural network training can be parallelized across machines by increasing batch size. Because complex tasks produce noisier gradients, they tolerate much larger batches, which suggests that growing batch sizes will keep removing a limit on AI scaling. The authors conclude that training can be treated as a measurable, systematic discipline rather than a mysterious art. ## Background: Data Parallelism and Its Limits - Data parallelism splits large batches across many machines, and researchers have used batch sizes of tens of thousands for image classification and language modeling, and millions for OpenAI's Dota 2 RL agents. - These large batches let growing amounts of compute go into training a single model, which has enabled the fast growth in training compute. - Past a certain point, larger batches show rapidly diminishing algorithmic returns, and the reason the limit varies across tasks was unclear. ## The Gradient Noise Scale - The gradient noise scale is defined as the expected squared deviation of per-example gradients from the true gradient, divided by the squared norm of the true gradient. - Gradients from a batch of size B have a normalized error of roughly B_noise / B, so the noisiness stops falling significantly around B ≈ B_noise. - Training speedups taper off at about that same point, which makes the noise scale a predictor of the maximum useful batch size. - Intuitively, when the noise scale is small, extra data in parallel is largely redundant; when it is large, huge batches still yield useful learning. ## Experimental Validation - The team trained across many batch sizes for image recognition, language modeling, Atari games, and Dota, tuning the learning rate separately for each setting. - Training time versus total compute forms a curve: at small batches, doubling the batch halves training time at no extra compute cost, while at large batches parallelism stops speeding training up. - The "bend" between these regimes matches the位置 predicted by the noise scale across many performance targets, such as reaching a score of 1000 on Atari Beam Rider. - Because large batches often need careful tuning or special learning rate schedules, knowing the upper limit in advance is a practical advantage. ## Patterns in the Noise Scale **The noise scale grows during training.** - It typically rises by an order of magnitude or more over a run. - Early on, networks learn common, simple features like edges and textures, which need few examples to capture. Later, they combine these into complex concepts, and they can then use much larger batches without redundancy. - Preliminary evidence suggests that more powerful models have higher noise scales, and that this increase reflects improvement rather than just convergence. **Harder tasks tolerate larger batches.** - In supervised learning, the progression MNIST → SVHN → ImageNet shows increasing parallelizability. - In reinforcement learning, moving from Atari Pong to Dota 1v1 to Dota 5v5 changes optimal batch sizes by more than 10,000×. ## Implications - Greater data parallelism speeds up AI progress, enabling more powerful models and faster research iteration. - An earlier OpenAI study found that the compute used for the largest models doubles roughly every 3.5 months, driven by both spending willingness and algorithmic parallelizability. This work helps quantify the latter, which had been hard to predict. - Harder tasks and more capable models should permit even more radical data parallelism, which supports continued exponential growth in training compute. Model parallelism could add further headroom. - The authors argue that predictable algorithmic foundations make rapid capability gains plausible in the near term, which makes research into AI safety and responsible use more urgent. They frame a central policy challenge as using such measurements to forecast future systems and shape policies that maximize benefits while limiting harms.