arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2407.15545cs.LG
收藏

倒置激活:降低神经网络训练中的内存占用

Inverted Activations: Reducing Memory Footprint in Neural Network Training

Skoltech(斯科尔科沃科学技术学院);AIRI(人工智能研究院(AIRI))

Georgii Novikov, Ivan Oseledets

AI总结:

针对神经网络训练中逐点非线性层激活张量内存占用高的问题,提出前向传播存输出张量、反向用近似反函数计算的倒置激活方法,可在不损精度与性能的前提下显著降内存,适配主流transformer架构且可即插即用。

摘要:

随着数据规模与模型尺寸不断增长,神经网络的规模化发展迫切需要更高效的深度学习算法。神经网络训练中的一大核心挑战是激活张量带来的内存占用问题,尤其是逐点非线性层传统上需要保存完整的输入张量以用于反向传播,这会导致大量内存消耗。\n 本文提出了一种针对逐点非线性层激活张量处理方式的改进方案。我们的方法在前向传播过程中保存输出张量而非输入张量。由于下一层通常也会保存其自身的输入张量,该方法通过在层间仅存储一个张量而非两个,降低了总内存需求。这种优化对GPT、BERT、Mistral、Llama等基于transformer的架构尤为有益。为实现该方案,我们在反向传播过程中使用非线性函数的反函数。由于大多数非线性函数的反函数无法通过解析方式计算,我们使用更简单的函数构建了高精度的近似反函数。实验结果表明,该方法在不影响训练精度或计算性能的前提下,显著降低了内存使用量。\n 我们的实现可作为PyTorch框架中标准非线性层的即插即用替代方案,无需修改模型架构即可轻松部署使用。

英文摘要:

The scaling of neural networks with increasing data and model sizes necessitates the development of more efficient deep learning algorithms. A significant challenge in neural network training is the memory footprint associated with activation tensors, particularly in pointwise nonlinearity layers that traditionally save the entire input tensor for the backward pass, leading to substantial memory consumption. In this paper, we propose a modification to the handling of activation tensors in pointwise nonlinearity layers. Our method involves saving the output tensor instead of the input tensor during the forward pass. Since the subsequent layer typically also saves its input tensor, this approach reduces the total memory required by storing only one tensor between layers instead of two. This optimization is especially beneficial for transformer-based architectures like GPT, BERT, Mistral, and Llama. To enable this approach, we utilize the inverse function of the nonlinearity during the backward pass. As the inverse cannot be computed analytically for most nonlinearities, we construct accurate approximations using simpler functions. Experimental results demonstrate that our method significantly reduces memory usage without affecting training accuracy or computational performance. Our implementation is provided as a drop-in replacement for standard nonlinearity layers in the PyTorch framework, facilitating easy adoption without requiring architectural modifications.

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

↑