English

DisCo-CLIP: A Distributed Contrastive Loss for Memory Efficient CLIP Training

Computer Vision and Pattern Recognition 2023-04-18 v1 Artificial Intelligence Computation and Language

Abstract

We propose DisCo-CLIP, a distributed memory-efficient CLIP training approach, to reduce the memory consumption of contrastive loss when training contrastive learning models. Our approach decomposes the contrastive loss and its gradient computation into two parts, one to calculate the intra-GPU gradients and the other to compute the inter-GPU gradients. According to our decomposition, only the intra-GPU gradients are computed on the current GPU, while the inter-GPU gradients are collected via all_reduce from other GPUs instead of being repeatedly computed on every GPU. In this way, we can reduce the GPU memory consumption of contrastive loss computation from \bigO(B2)\bigO(B^2) to \bigO(B2N)\bigO(\frac{B^2}{N}), where BB and NN are the batch size and the number of GPUs used for training. Such a distributed solution is mathematically equivalent to the original non-distributed contrastive loss computation, without sacrificing any computation accuracy. It is particularly efficient for large-batch CLIP training. For instance, DisCo-CLIP can enable contrastive training of a ViT-B/32 model with a batch size of 32K or 196K using 8 or 64 A100 40GB GPUs, compared with the original CLIP solution which requires 128 A100 40GB GPUs to train a ViT-B/32 model with a batch size of 32K. The code will be released at https://github.com/IDEA-Research/DisCo-CLIP

Keywords

Cite

@article{arxiv.2304.08480,
  title  = {DisCo-CLIP: A Distributed Contrastive Loss for Memory Efficient CLIP Training},
  author = {Yihao Chen and Xianbiao Qi and Jianan Wang and Lei Zhang},
  journal= {arXiv preprint arXiv:2304.08480},
  year   = {2023}
}

Comments

To appear in CVPR 2023 as a highlight, our code will be public at https://github.com/IDEA-Research/DisCo-CLIP

R2 v1 2026-06-28T10:08:45.688Z