arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2410.17243cs.CV
收藏

打破内存壁垒:对比损失函数的近无限批次大小扩展

Breaking the Memory Barrier: Near Infinite Batch Size Scaling for Contrastive Loss

Zhejiang University(浙江大学);DAMO Academy, Alibaba Group(阿里巴巴达摩院);Nanyang Technological University(南洋理工大学)

Zesen Cheng, Hang Zhang, Kehan Li, Sicong Leng, Zhiqiang Hu, Fei Wu, Deli Zhao, Xin Li, Lidong Bing

AI总结:

本文提出基于分块计算和多级分块策略的对比损失优化方法,突破GPU内存限制,实现CLIP-ViT-L/14模型在4M或12M超大批次下的训练,内存降低两个数量级且精度无损。

摘要:

对比损失是表示学习的一种强大方法,其中更大的批次大小通过提供更多负样本以更好地区分相似和不相似数据来提升性能。然而,批次大小的扩展受到GPU内存消耗二次增长的制约,这主要是由于相似度矩阵的完全实例化。为了解决这一问题,我们提出了一种基于分块(tile)的计算策略,将对比损失计算划分为任意小的块,避免相似度矩阵的完全物化。此外,我们引入了一种多级分块策略,以利用分布式系统的层次结构,在GPU级别采用基于环形(ring)的通信来优化同步,并在CUDA核心级别使用融合内核来减少I/O开销。实验结果表明,所提方法将批次大小扩展到了前所未有的水平。例如,它能够在8块或32块A800 80GB GPU上以4M或12M的批次大小对CLIP-ViT-L/14模型进行对比训练,且不牺牲任何精度。与SOTA内存高效解决方案相比,它在保持可比速度的同时实现了两个数量级的内存降低。代码将公开发布。

英文摘要:

Contrastive loss is a powerful approach for representation learning, where larger batch sizes enhance performance by providing more negative samples to better distinguish between similar and dissimilar data. However, scaling batch sizes is constrained by the quadratic growth in GPU memory consumption, primarily due to the full instantiation of the similarity matrix. To address this, we propose a tile-based computation strategy that partitions the contrastive loss calculation into arbitrary small blocks, avoiding full materialization of the similarity matrix. Furthermore, we introduce a multi-level tiling strategy to leverage the hierarchical structure of distributed systems, employing ring-based communication at the GPU level to optimize synchronization and fused kernels at the CUDA core level to reduce I/O overhead. Experimental results show that the proposed method scales batch sizes to unprecedented levels. For instance, it enables contrastive training of a CLIP-ViT-L/14 model with a batch size of 4M or 12M using 8 or 32 A800 80GB without sacrificing any accuracy. Compared to SOTA memory-efficient solutions, it achieves a two-order-of-magnitude reduction in memory while maintaining comparable speed. The code will be made publicly available.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑