跳过中间计算,直接从隐状态算损失,大幅节省显存和速度
From Projection to Prediction: Beyond Logits for Scalable Language Models
- 将输出投影与损失计算合并为一步,不生成完整logits张量
- 训练时显存占用减少40%以上,长序列大批次训练更高效
- 适合追求训练效率的模型工程师,尤其适用于超大规模语言模型
训练大型语言模型通常采用两阶段输出层设计:先通过线性变换(lm_head)将隐藏状态投影为词汇表logits,再用交叉熵损失计算目标词。尽管概念简单,但该设计带来显著开销。中间logits张量大小与批量大小、序列长度和词汇量成正比,需完全加载到GPU内存中,而每个位置仅使用一个目标词,造成大量冗余。本文提出一种新方法,将输出投影与损失预测整合为单一操作,直接从隐藏状态和目标词计算损失,避免显式生成logits。该设计显著降低内存占用和带宽压力。在大模型训练实验中,该方法实现显著的内存节省和可测量的速度提升,支持更大批量和更长序列训练,且不牺牲精度。本工作强调重新思考投影与预测边界的重要性,为高效大模型训练提供了实用系统优化。
原文摘要 · Abstract (English)
Training Large Language Models (LLMs) typically involves a two-stage pipeline at the output layer: hidden states are projected into vocabulary logits via a linear transformation (lm_head), followed by cross-entropy loss computation against target tokens. While conceptually simple, this design incurs substantial overhead. The intermediate logits tensor, with dimensions proportional to batch size, sequence length, and vocabulary size, must be fully materialized in GPU memory, even though only one target token per position is ultimately used. This leads to significant memory footprint and bandwidth comsumption, limiting scalability and slowing training throughput. In this work, we introduce a novel approach to integrates the output projection and loss prediction into a single operation. By directly computing the loss from hidden states and target tokens, our approach bypasses explicit logits materialization. This design reduces memory usage and alleviates bandwidth pressure. Experiments on LLM training demonstrate that our method achieves substantial memory savings and measurable speedups compared to the standard two-stage pipeline, enabling large batch sizes and longer sequences without sacrificing accuracy. Our work highlights the benefits of rethinking the boundary between projection and prediction, offering a practical systems optimization for efficient LLM training.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。