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

StreamKL: 快速且内存高效的KL散度用于提升注意力蒸馏

StreamKL: Fast and Memory-Efficient KL Divergence for Boosting Attention Distillation

Shanghai Jiao Tong University(上海交通大学);Huawei(华为);Fudan University(复旦大学)

Guangda Liu, Yiquan Wang, Chengwei Li, Wenhao Chen, Jing Lin, Yiwu Yao, Danning Ke, Wenchao Ding, Jieru Zhao

AI总结:

提出StreamKL,首个融合GPU原语,通过在线公式和逐块重计算将注意力蒸馏的内存和IO成本从O(N_QN_K)降至O(1),实现高达43倍前向和14倍反向加速。

摘要:

注意力蒸馏通过最小化Kullback-Leibler (KL)散度来训练一个注意力分布匹配另一个,广泛应用于知识蒸馏、模型压缩、持续学习和稀疏注意力LLM训练。然而,现有方法在计算KL归约前需要具体化两个注意力分布,导致$O(N_QN_K)$的内存和IO成本,在长上下文长度下变得不可接受。我们提出StreamKL,首个用于注意力KL散度的融合GPU原语,消除了这种二次具体化。StreamKL推导了一种新颖的在线公式用于耦合的双分布KL归约,使得单个前向内核能够通过片上SRAM流式处理查询-键块。对于反向传播,StreamKL逐块重计算注意力概率,避免存储二次中间结果。我们进一步设计并实现了具有专用优化的高效GPU内核。实验表明,StreamKL在前向和反向传播中分别比基线方法快高达43倍和14倍。最重要的是,StreamKL将注意力蒸馏的额外HBM占用从$O(N_QN_K)$减少到$O(1)$,使得在单个GPU上进行长上下文蒸馏成为可能。

英文摘要:

Attention distillation, which trains one attention distribution to match another by minimizing their Kullback-Leibler (KL) divergence, is widely used in knowledge distillation, model compression, continual learning, and sparse-attention LLM training. However, existing approaches materialize both attention distributions before computing the KL reduction, incurring $O(N_QN_K)$ memory and IO costs that become prohibitive at long context lengths. We present StreamKL, the first fused GPU primitive for attention KL divergence that eliminates this quadratic materialization. StreamKL derives a novel online formulation for the coupled two-distribution KL reduction, enabling a single one-pass forward kernel that streams query-key tiles through on-chip SRAM. For the backward pass, StreamKL recomputes attention probabilities tile-by-tile, avoiding storage of quadratic intermediates. We further design and implement efficient GPU kernels with dedicated optimizations. Experiments show StreamKL delivers up to $43\times$ and $14\times$ speedups over baseline methods in the forward and backward passes, respectively. Most importantly, StreamKL reduces the extra HBM footprint of attention distillation from $O(N_QN_K)$ to $O(1)$, enabling long-context distillation on a single GPU.

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

↑