Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup

Luyu Gao, Yunyi Zhang, Jiawei Han, Jamie Callan
1/18/2021
208 citations
cs.LGcs.CLcs.IR
contrastive-ssl

Official code: luyug/GradCache (451 stars, Python, Apache-2.0, PyTorch, last commit 2024-03-26). 1 more implementation below.

Abstract

Contrastive learning has been applied successfully to learn vector representations of text. Previous research demonstrated that learning high-quality representations benefits from batch-wise contrastive loss with a large number of negatives.

Show full abstract

In practice, the technique of in-batch negative is used, where for each example in a batch, other batch examples' positives will be taken as its negatives, avoiding encoding extra negatives. This, however, still conditions each example's loss on all batch examples and requires fitting the entire large batch into GPU memory. This paper introduces a gradient caching technique that decouples backpropagation between contrastive loss and the encoder, removing encoder backward pass data dependency along the batch dimension. As a result, gradients can be computed for one subset of the batch at a time, leading to almost constant memory usage.

View on arXivView PDF

Code Implementations(2)

Code implementations of this paper
RepositoryTypeStarsLanguageLicenseLast commit
luyug/GradCacheOfficial451PythonApache-2.02024-03-26
luyug/GC-DPROfficial137Python–2021-06-16
luyug/GradCacheOfficial100%
PyTorchApache-2.0

Run Effective Large Batch Contrastive Learning Beyond GPU/TPU Memory Constraint

45130PythonJun 8, 20212 years agoApache-2.0
contrastive-learningdeep-learningembeddingflaxjax+3 more
luyug/GC-DPROfficial100%
PyTorch

Train Dense Passage Retriever (DPR) with a single GPU

13720PythonJan 19, 20215 years agoNOASSERTION
deep-learningdense-retrievaldprmemory-efficientpytorch+3 more

Similar Papers

Cite this paper

@article{gao2021scaling,
  title  = {Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup},
  author = {Luyu Gao and Yunyi Zhang and Jiawei Han and Jamie Callan},
  year   = {2021},
  eprint = {2101.06983},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2101.06983}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2101.06983.svg)](https://codeofpaper.com/paper/2101.06983)

Discussion