[论文解读] Liger Kernel: Efficient Triton Kernels for LLM Training
Liger-Kernel 是一个开源的 Triton 内核库,用于 LLM 训练,利用内核融合和输入分块来提升吞吐量并降低相对于 HuggingFace 实现的 GPU 内存使用。它提供模块化 API,易于与框架集成,并在多种模型上进行基准测试。
Training Large Language Models (LLMs) efficiently at scale presents a formidable challenge, driven by their ever-increasing computational demands and the need for enhanced performance. In this work, we introduce Liger-Kernel, an open-sourced set of Triton kernels developed specifically for LLM training. With kernel optimization techniques like kernel operation fusing and input chunking, our kernels achieve on average a 20% increase in training throughput and a 60% reduction in GPU memory usage for popular LLMs compared to HuggingFace implementations. In addition, Liger-Kernel is designed with modularity, accessibility, and adaptability in mind, catering to both casual and expert users. Comprehensive benchmarks and integration tests are built in to ensure compatibility, performance, correctness, and convergence across diverse computing environments and model architectures. The source code is available under a permissive license at: github.com/linkedin/Liger-Kernel.
研究动机与目标
- 激发对内核级优化以提升 LLM 训练效率的需求。
- 介绍 Liger-Kernel 作为一个模块化、易于使用的 Triton 内核库,面向 LLM。
- 展示内核融合和输入分块如何降低内存占用并提高吞吐量。
- 展示与流行框架及部署环境的兼容性。
- 提供基准测试和集成测试以确保正确性和收敛性。
提出的方法
- 提出一个用于 LLM 训练的 Triton 内核库,重点在于对常见操作的融合。
- 描述 RMSNorm、LayerNorm、RoPE、SwiGLU、GeGLU、CrossEntropy 的内核设计,以及一个融合的 Linear+CrossEntropy (FLCE) 方法。
- 解释支持 AutoLigerKernelForCausalLM、模型特定补丁 API,以及自定义内核组合的 API 设计。
- 提出分块的 FLCE 方法,在为大词表计算 logits 时降低内存占用。
- 详细说明正确性、性能与收敛性的测试最佳实践,包括连续性和大维度处理。
- 总结端到端的基准设置以及与 Hugging Face 和其他框架的集成。

实验结果
研究问题
- RQ1Liger-Kernel 的内核能否在与基线 HuggingFace 实现相比时提升训练吞吐量并降低 GPU 内存?
- RQ2内核融合和输入分块如何影响常见 LLM 操作的内存使用与速度?
- RQ3在使用 Liger 内核时,PyTorch FSDP、DeepSpeed ZeRO 及 ZeRO++ 的集成是否能维持收敛性与正确性?
- RQ4Liger-Kernel 的 API 设计是否对新手和高级用户都易于使用,同时保持高度可配置?
- RQ5在标准基准上,多种 LLM(例如 LLaMA、Qwen、Gemma、Mistral、Phi3)的端到端性能提升是多少?
主要发现
- Liger-Kernel 在与 HuggingFace 实现相比,平均训练吞吐量约提升 20%,GPU 内存降低约 60%。
- 具有在线 softmax 与就地梯度替换的 CrossEntropy 内核在大词表尺寸下可实现约 3x 加速和约 5x 内存降低。
- RMSNorm 和 LayerNorm 内核将归一化与缩放及缓存融合,分别将计算时间降低最高约 7x 和 30%,同时内存影响适中。
- RoPE 内核使用扁平化的重复块旋转矩阵以提升效率,在较大隐藏维度下实现约 8x 加速和约 3x 内存节省。
- GeGLU 和 SwiGLU 内核在与基线速度保持一致的同时,将长序列的峰值内存降低约 1.6x。
- 端到端基准显示在多模型上的显著改进:LLaMA 3-8B 吞吐量 +42.8% 内存 -54.8%;Qwen2 吞吐量 +25.5% 内存 -56.8%;Gemma 吞吐量 +11.9% 内存 -51.8%;Mistral 吞吐量 +27% 内存 -21%;Phi3 吞吐量 +17% 内存 -13%。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。