<aside> ๐Ÿ“„

Paper Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup (GradCache)

Authors Luyu Gao, Yunyi Zhang, Jiawei Han, Jamie Callan

Venue RepL4NLP 2021 ยท arXiv 2021.01

Links arXiv

Keywords Contrastive Learning Memory Efficiency Large Batch

</aside>

TL;DR

Larger batches give better contrastive representations (more in-batch negatives) but don't fit in GPU memory. Gradient caching splits the backward pass so the batch can be processed in small chunks, keeping peak memory almost constant regardless of batch size while computing exactly the same gradients.


1. Problem Definition

2. Method: Gradient Cache

  1. Representation pass (no graph): encode the full batch in chunks without storing activations, and collect all representations.
  2. Loss and representation gradients: compute the contrastive loss over the full batch and the gradient of the loss with respect to each representation; cache these gradients.
  3. Chunked encoder backward: re-encode each chunk with the computation graph and back-propagate the cached representation gradients through the encoder, accumulating parameter gradients.

This decouples back-propagation between the contrastive loss and the encoder, removing the encoder's data dependency along the batch dimension.

3. Findings

4. Takeaways

<aside> ๐Ÿ’ญ

5. Related Papers