arXiv:2506.03077cs.LGcs.AI2025-06NeurIPS被引 3

StreamBP让大模型训练长序列时内存降低,速度更快。

StreamBP: Memory-Efficient Exact Backpropagation for Long Sequence Training of LLMs

  • 按层分解反向传播链式法则,减少激活值存储
  • 相比梯度检查点,序列长度支持提升2.8至5.5倍
  • 适用于SFT/GRPO/DPO,适合长序列训练场景

在长序列数据上训练语言模型能提升复杂任务(如长链推理)的能力,但随着序列变长,反向传播过程中需存储的激活值和输出值内存开销巨大,即使使用梯度检查点也难以缓解。为此,我们提出一种内存高效且精确的反向传播方法 StreamBP,通过沿序列维度进行分层的线性链式法则分解,显著降低激活值与logits的内存占用。该方法适用于标准目标如SFT、GRPO和DPO。从实现角度看,利用语言模型的因果结构,StreamBP不仅减少计算量(FLOPs),还加快反向传播速度。相较于梯度检查点,StreamBP可将反向传播最大序列长度扩展2.8至5.5倍,同时保持相当或更短的运行时间。此外,该方法的序列长度扩展能力可直接转化为批大小扩展,以加速训练。我们进一步设计了通信高效的分布式版本,支持多卡训练,拓展其应用范围。代码已开源,可轻松集成至任意Transformer模型训练流程中。

原文摘要 · Abstract (English)

Training language models on long sequence data is a demanding requirement for enhancing the model's capability on complex tasks, e.g., long-chain reasoning. However, as the sequence length scales up, the memory cost for storing activation values becomes huge during the Backpropagation (BP) process, even with the application of gradient checkpointing technique. To tackle this challenge, we propose a memory-efficient and exact BP method called StreamBP, which performs a linear decomposition of the chain rule along the sequence dimension in a layer-wise manner, significantly reducing the memory cost of activation values and logits. The proposed method is applicable to common objectives such as SFT, GRPO, and DPO. From an implementation perspective, StreamBP achieves less computational FLOPs and faster BP speed by leveraging the causal structure of the language model. Compared to gradient checkpointing, StreamBP scales up the maximum sequence length of BP by 2.8-5.5 times larger, while using comparable or even less BP time. Note that StreamBP's sequence length scaling ability can be directly transferred to batch size scaling for accelerating training. We further develop a communication-efficient distributed StreamBP to effectively support multi-GPU training and broaden its applicability. Our code can be easily integrated into the training pipeline of any transformer models and is available at https://github.com/Ledzy/StreamBP.

大模型训练反向传播长序列内存优化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。