arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2407.12117cs.LGcs.DC
收藏

MEMO:面向超长上下文大语言模型训练的细粒度张量管理

MEMO: Fine-grained Tensor Management For Ultra-long Context LLM Training

Peking University(北京大学);Tencent Inc.(腾讯公司)

Pinxue Zhao, Hailin Zhang, Fangcheng Fu, Xiaonan Nie, Qibin Liu, Fang Yang, Yuanbo Peng, Dian Jiao, Shuaipeng Li, Jinbao Xue, Yangyu Tao, Bin Cui

AI总结:

针对超长上下文LLM训练中GPU显存不足、碎片化严重及MFU低的问题,提出MEMO框架,通过细粒度激活卸载、逐令牌重计算与双层MIP显存复用优化,实现高MFU的百万级长序列7B模型训练。

摘要:

如今,大语言模型(LLM)正通过扩展上下文长度进行训练,以催生更具创造性的应用。然而,受限于GPU显存,长上下文训练带来了巨大挑战:它不仅会导致训练期间的激活显存消耗量极大,还会引发严重的显存碎片化。为支撑长上下文训练,现有框架采用了重计算及多种并行策略,但这些技术依赖冗余计算或大量通信,导致模型浮点运算利用率(MFU)较低。\n本文提出MEMO,一种专为细粒度激活显存管理设计的新型LLM训练框架。鉴于使用FlashAttention时,计算量随序列长度呈二次方增长、显存占用随序列长度呈线性增长的特性,我们在每一层前向传播后将耗显存的激活卸载到CPU内存,并在反向传播期间将其取回。为在不阻碍计算的前提下最大化激活换入换出量,同时避免耗尽有限的CPU内存,我们实现了逐令牌的激活重计算与换入换出机制。此外,我们采用双层混合整数规划(MIP)方法解决显存碎片化问题,优化Transformer层间的显存复用。\n实验结果表明,与Megatron-LM和DeepSpeed相比,MEMO的平均MFU分别达到1.97倍和1.80倍。这一提升源于MEMO能够最大程度减少显存碎片化、降低重计算与密集通信开销,并且规避了碎片化导致的显存重组过程延迟。通过细粒度激活显存管理,MEMO仅用8张A800 GPU即可实现7B参数LLM、100万序列长度的高效训练,MFU达52.30%。

英文摘要:

Nowadays, Large Language Models (LLMs) have been trained using extended context lengths to foster more creative applications. However, long context training poses great challenges considering the constraint of GPU memory. It not only leads to substantial activation memory consumption during training, but also incurs considerable memory fragmentation. To facilitate long context training, existing frameworks have adopted strategies such as recomputation and various forms of parallelisms. Nevertheless, these techniques rely on redundant computation or extensive communication, resulting in low Model FLOPS Utilization (MFU). In this paper, we propose MEMO, a novel LLM training framework designed for fine-grained activation memory management. Given the quadratic scaling of computation and linear scaling of memory with sequence lengths when using FlashAttention, we offload memory-consuming activations to CPU memory after each layer's forward pass and fetch them during the backward pass. To maximize the swapping of activations without hindering computation, and to avoid exhausting limited CPU memory, we implement a token-wise activation recomputation and swapping mechanism. Furthermore, we tackle the memory fragmentation issue by employing a bi-level Mixed Integer Programming (MIP) approach, optimizing memory reuse across transformer layers. Empirical results demonstrate that MEMO achieves an average of 1.97x and 1.80x MFU compared to Megatron-LM and DeepSpeed, respectively. This improvement is attributed to MEMO's ability to minimize memory fragmentation, reduce recomputation and intensive communication, and circumvent the delays associated with the memory reorganization process due to fragmentation. By leveraging fine-grained activation memory management, MEMO facilitates efficient training of 7B LLM with 1 million sequence length on just 8 A800 GPUs, achieving an MFU of 52.30%.

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

↑