Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup
Luyu Gao, Yunyi Zhang, Jiawei Han, Jamie Callan

TL;DR
This paper proposes a gradient caching method for contrastive learning that enables training with large batch sizes under limited memory by decoupling backpropagation, thus reducing memory requirements significantly.
Contribution
It introduces a novel gradient caching technique that decouples backpropagation from the encoder, allowing large batch contrastive learning with limited GPU memory.
Findings
Memory usage becomes almost constant regardless of batch size
Enables training with larger batches than traditional methods
Maintains high-quality representations despite memory constraints
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. 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.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
- 🤗lightonai/Reason-ModernColBERTmodel· 17k dl· ♡ 23717k dl♡ 237
- 🤗joe32140/ModernBERT-base-msmarcomodel· 2.4k dl· ♡ 112.4k dl♡ 11
- 🤗sentence-transformers/embeddinggemma-300m-medicalmodel· 9.9k dl· ♡ 469.9k dl♡ 46
- 🤗tomaarsen/qwen3-vl-2b-vdrmodel· 19 dl· ♡ 119 dl♡ 1
- 🤗lv12/esci-nomic-embed-text-v1_5model· 9 dl· ♡ 19 dl♡ 1
- 🤗mics-nlp/xlm-roberta-small-all-nli-tripletmodel· 1 dl· ♡ 11 dl♡ 1
- 🤗comet24082002/ft_bge_newLaw_CachedMultipleNegativeRankingLoss_V1_5epochsmodel· 1 dl1 dl
- 🤗comet24082002/ft_bge_newLaw_CachedMultipleNegativeRankingLoss_SimSCE_V1_5epochsmodel· 2 dl2 dl
- 🤗Pasmikh/crm-mail-embeddermodel· 1 dl1 dl
- 🤗amauczka/multilingual-e5-g39model· 14 dl14 dl
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsDomain Adaptation and Few-Shot Learning · Topic Modeling · Speech Recognition and Synthesis
