Stochastic Weight Averaging in Parallel: Large-Batch Training That Generalizes Well

Vipul Gupta, Santiago Akle Serrano, Dennis DeCosteICLR 2020

Introduction

Stochastic Weight Averaging in Parallel (SWAP) is a novel training strategy designed to solve the "generalization gap" often encountered in large-batch deep learning. By combining an initial high-speed large-batch phase with a parallelized small-batch refinement phase, SWAP produces models that generalize as well as traditional small-batch training, but in a fraction of the time.

The Problem: The Generalization Gap

In deep learning, there is a frustrating trade-off between training speed and model performance. To accelerate training, researchers frequently use large mini-batches distributed across many GPUs. This approach increases hardware throughput and reduces the frequency of synchronization events. However, models trained with very large batches often suffer from a "generalization gap"—they perform exceptionally well on training data but poorly on new, unseen data.

The prevailing theory suggests that large-batch training tends to converge into "sharp" minima within the loss landscape. In contrast, small-batch training introduces inherent noise that helps the model settle into "flat" minima, which are known to generalize better. Consequently, practitioners are often forced to use smaller batch sizes to maintain accuracy, sacrificing the massive parallel processing capabilities of modern computing clusters.

Methods: The SWAP Algorithm

To get the best of both worlds, the authors introduce SWAP, a three-phase algorithm that decouples speed from accuracy:

SWAP Training Phases
  1. Phase 1 (Large-Batch Exploration): All workers collaborate to train a single model using large mini-batches and a high learning rate. This phase is highly optimized for speed and continues until the model reaches a specific accuracy threshold, just before it fully converges.
  2. Phase 2 (Parallel Small-Batch Refinement): The workers stop synchronizing. Each worker takes the current model state and continues training independently using smaller mini-batches and different random orderings of the data. Because they no longer communicate, this phase remains computationally efficient.
  3. Phase 3 (Averaging): The weights from all the independent workers are averaged together to create the final model. A single final pass over the data is then used to update the model's batch-normalization statistics.

This approach is a parallel evolution of Stochastic Weight Averaging (SWA). While the original SWA samples models sequentially from a single training run, SWAP generates them independently and in parallel, significantly reducing wall-clock time.

Key Insights: The Geometry of Generalization

Through 2D visualizations of the loss landscape, the authors demonstrate why SWAP is so effective.

Test Error Surface and SWAP
  • Finding the Basin Center: Individual models from the small-batch phase (SGD) often end up on the "edges" of a low-error basin. By averaging these independent models, SWAP finds a point closer to the center of the basin, yielding a more robust model that generalizes better.
  • Orthogonality of Progress: Toward the end of training, the gradient descent direction becomes almost orthogonal to the direction of the basin's center. Standard SGD slows down because it begins "circling" the solution rather than moving directly toward the middle. Averaging parallel runs effectively allows the model to "jump" to that optimal center.

Performance and Results

The authors evaluated SWAP on standard computer vision benchmarks (CIFAR10, CIFAR100, and ImageNet), yielding impressive results:

  • Beating the Clock (CIFAR10): SWAP reached 94% accuracy in just 27 seconds using 8 GPUs, beating the then-current DAWNBench competition leader (which took 37 seconds on 4 GPUs).
  • Closing the Gap (CIFAR100): While a standard large-batch run achieved 75.84% accuracy, SWAP boosted this to 78.18%, surpassing even the slower, traditional small-batch training baseline (77.01%).
  • Scalability (ImageNet): On the massive ImageNet dataset, SWAP successfully recovered the accuracy lost when doubling the batch size, while reducing the total training time by approximately 33% compared to the small-batch baseline.

Limitations and Future Work

The primary limitation of SWAP is the introduction of a new hyperparameter: the transition point ($\tau$). Users must decide exactly when to switch from Phase 1 to Phase 2. If the switch happens too early, the models might not yet be in the same "basin"; if too late, the time-saving benefits are diminished.

Future research directions include automating the selection of this transition point, combining SWAP with other optimization techniques like LARS (Layer-wise Adaptive Rate Scaling) or mixed-precision training, and applying this parallel averaging logic to other domains such as Natural Language Processing.

Summary updated

BibTeX
@inproceedings{gupta2020stochastic,
  author = {Vipul Gupta and Santiago Akle Serrano and Dennis DeCoste},
  title = {{Stochastic Weight Averaging in Parallel: Large-Batch Training That Generalizes Well}},
  booktitle = {International Conference on Learning Representations},
  year = {2020},
}
Figure