Provable Stochastic Optimization for Global Contrastive Learning: Small Batch Does Not Harm Performance

Zhuoning Yuan, Yuexin Wu, Zi-Hao Qiu, Xianzhi Du, Lijun Zhang, Denny Zhou, Tianbao Yang

Introduction

Self-supervised contrastive learning has revolutionized computer vision. The core idea is simple: take an image, create two augmented views of it (a "positive pair"), and train a neural network to push their representations together while pulling them apart from the representations of other images ("negative pairs").

However, popular frameworks like SimCLR suffer from a fundamental flaw: they require enormous mini-batch sizes (e.g., 8192 images per step) to work well. If the batch size is dropped to a standard 256, performance tanks. This happens because the algorithm relies on the current batch to provide enough negative examples to calculate the loss accurately. Previous workarounds, like MoCo, solve this by maintaining a massive "dictionary" or memory bank of high-dimensional feature vectors from past batches.

This paper asks a critical question: can we fix the mathematical root of the small-batch problem without resorting to massive memory banks or huge compute clusters? The authors prove mathematically why this performance drop occurs and introduce SogCLR (Stochastic Optimization for Global Contrastive Learning of Representations), a novel optimization algorithm that achieves state-of-the-art performance using standard, small batch sizes.

The Mathematical Curse of Small Batches

The authors approach contrastive learning purely as an optimization problem. They mathematically prove why SimCLR fails with small batches by showing that SimCLR's gradient estimator has an optimization error bounded by $O(1/\sqrt{B})$, where $B$ is the batch size. Even if a model is trained indefinitely, a small batch size guarantees a high error rate.

To address this, they define a Global Contrastive Objective (GCO), where a positive pair is contrasted against all other images in the entire dataset, rather than just the ones present in the current mini-batch.

SogCLR: A Global Optimization Approach

To optimize the GCO without running out of memory, the authors introduce SogCLR.

  • The Standard Way: Calculate the denominator of the contrastive loss (the sum of similarities with negative samples) using only the images currently in the GPU memory.
  • The SogCLR Way: Maintain a single scalar value ($u_i$) for every image in the training dataset. This scalar acts as a moving average, tracking the global negative similarity sum for that specific image. When an image is sampled in a mini-batch, the algorithm updates its scalar using an exponential moving average.

Because augmented views of the same image naturally end up with similar embeddings, tracking a single scalar per original image is a mathematically sound proxy for the global negative sample distribution. Furthermore, because it only stores one number per image rather than a full feature vector, the memory overhead is incredibly small ($O(n)$ where $n$ is the dataset size). For a dataset like ImageNet-1K, storing one scalar per image requires only a few megabytes of RAM, completely decoupling the quality of the contrastive loss from GPU memory constraints.

Key Results

Performance comparison of SogCLR vs. SimCLR across different datasets and training epochs.

The authors evaluated SogCLR across standard benchmarks, including ImageNet-1K, a smaller ImageNet-S subset, and a custom image-text dataset for bimodal pretraining. The results demonstrate significant improvements over standard methods:

  • Beating Large Batches with Small Batches: On ImageNet-1K, SogCLR trained with a standard batch size of 256 achieved 69.4% top-1 linear evaluation accuracy at 800 epochs. This outperforms SimCLR trained with a massive batch size of 8192 (69.3%) under the same conditions.
  • High Robustness: While SimCLR's accuracy falls off a cliff as batch size drops from 8192 down to 128, SogCLR's performance remains highly stable across that entire range.
  • Competitive with State-of-the-Art: By adding standard enhancements like multi-crop augmentation and multi-layer projection heads, SogCLR reaches 72.5% accuracy on ImageNet-1K with a batch size of 256.
  • Bimodal Success: When applied to a CLIP-style vision-language setup, SogCLR improved zero-shot accuracy by over 1% compared to the standard InfoNCE loss and prevented the performance degradation usually seen when training CLIP longer with small batches.

Conclusion and Future Work

The primary goal of this research was to solve the fundamental optimization limits of the InfoNCE loss, proving that small batches do not have to harm contrastive learning performance. Having successfully removed the batch-size bottleneck, future work will focus on incorporating more advanced techniques—such as InfoMin augmentations and modern network architectures (like massive Vision Transformers)—into the SogCLR framework to see how far performance can be pushed.

Summary updated

BibTeX
@inproceedings{yuan2022provable,
  author = {Zhuoning Yuan and Yuexin Wu and Zi-Hao Qiu and Xianzhi Du and Lijun Zhang and Denny Zhou and Tianbao Yang},
  title = {{Provable Stochastic Optimization for Global Contrastive Learning: Small Batch Does Not Harm Performance}},
  booktitle = {International Conference on Machine Learning},
  year = {2022},
  url = {https://openreview.net/forum?id=stEDwcZ3Zh},
}
Figure