A Gradient Accumulation Method for Dense Retriever under Memory Constraint

Jaehee Kim, Yukyung Lee, Pilsung Kang

Training high-quality dense retrievers usually requires a small fortune in high-end GPUs to handle massive batch sizes. CONTACCUM (Contrastive Accumulation) is a novel approach designed to break this hardware bottleneck. By utilizing a dual memory bank strategy, it allows researchers to train state-of-the-art models on a single consumer-grade GPU (e.g., 11GB VRAM), often outperforming models trained on massive industrial clusters.

The Hardware Bottleneck in Dense Retrieval

In Information Retrieval, "Dense Retrievers" use neural networks to encode queries and documents into high-dimensional vectors. To train these dual-encoder models effectively, researchers rely on the InfoNCE loss, which depends heavily on "in-batch negatives." For every query in a batch, the model learns by distinguishing the correct passage from all other passages in that same batch.

Because performance scales with batch size, more negatives create a harder, more informative training task. Achieving top-tier results typically requires batch sizes ranging from 128 to 8,192. This demands massive amounts of Video RAM (VRAM), often necessitating multiple A100 GPUs.

Existing workarounds have significant drawbacks:

  • Gradient Accumulation: Reduces memory but sacrifices the number of negative samples per step.
  • Gradient Cache: Maintains large effective batch sizes but is computationally expensive and slow.
  • Single Memory Banks: Caching old representations has historically been unstable for dual-encoder setups.
Comparison of Gradient Cache, Gradient Accumulation, and Contrastive Accumulation.

The ContAccum Method: Dual Memory Banks

To address these issues, the authors propose CONTACCUM, which combines standard gradient accumulation with a dual memory bank structure.

  1. Dual Caching: Unlike previous methods that only cached passage representations, CONTACCUM maintains two First-In-First-Out (FIFO) queues: one for queries ($M_q$) and one for passages ($M_p$).
  2. Stop-Gradient Strategy: The method reuses representations generated in previous training steps. Because these are "frozen" vectors (no activations stored), they take up negligible memory compared to the active batch.
  3. Balanced Gradients: The core innovation is solving the "gradient norm imbalance." The authors proved mathematically that using a memory bank for only one side (e.g., just passages) causes the passage encoder's gradient norm to become up to 30 times larger than the query encoder's. By caching both sides, CONTACCUM ensures that both encoders receive stable, balanced updates.
The dual memory bank structure of ContAccum, caching both query and passage representations.

Another key insight from the paper is that staleness is overrated. Previous wisdom suggested that representations from previous training steps might be too "stale" to be useful. However, this research shows that "past" representations provide a negative signal almost identical in quality to "current" in-batch negatives, even from the very beginning of training.

Key Results and Hardware Democratization

The researchers evaluated CONTACCUM across five widely-used information retrieval benchmarks: Natural Questions (NQ), TriviaQA, Curated TREC, Web Questions (WebQ), and MS Marco.

  • Surpassing High-Resource Baselines: In a low-resource setting (11GB VRAM), CONTACCUM outperformed the standard DPR model trained in a high-resource setting (80GB VRAM) in 18 out of 24 evaluation metrics.
  • High Efficiency: CONTACCUM is significantly faster than its competitors. It is 34% faster than Gradient Cache and only slightly slower (26%) than standard Gradient Accumulation, despite providing a much stronger training signal.
  • Tiny Memory Footprint: The dual memory bank adds almost zero overhead. Storing 5,096 vectors only requires about 12MB of additional memory, a fraction of the gigabytes used by model weights and activations.

By making large-batch training possible on 11GB of VRAM, CONTACCUM effectively moves state-of-the-art retriever research from the realm of "Big Tech only" to anyone with a mid-range gaming GPU.

Limitations and Future Work

While highly effective, the current study focuses primarily on supervised fine-tuning. It remains to be seen if CONTACCUM provides the same stability during the much longer "pre-training" phase of dense retrievers. Additionally, while the memory bank is efficient, the final Softmax calculation still scales with the number of negatives. At extremely large bank sizes (e.g., hundreds of thousands), this could become a computational bottleneck. Future directions include extending this method to uni-encoder structures and exploring more efficient ways to handle the Softmax operation.

Summary updated

BibTeX
@inproceedings{kim2024gradient,
  author = {Jaehee Kim and Yukyung Lee and Pilsung Kang},
  title = {{A Gradient Accumulation Method for Dense Retriever under Memory Constraint}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=QDG2q5MYHV},
}
Figure