arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2310.07109cs.SE
收藏

SparseCoder:借助稀疏注意力与可学习令牌剪枝推进源代码分析

SparseCoder: Advancing Source Code Analysis with Sparse Attention and Learned Token Pruning

Xueqi Yang, Mariusz Jakubowski, Li Kang, Haojie Yu, Tim Menzies

AI总结:

针对Transformer类代码分析模型难以处理长代码序列的问题,提出融合稀疏注意力与可学习令牌剪枝的SparseCoder,可处理更长序列、速度更快且计算量线性增长,还提升了可解释性。

摘要:

随着软件项目快速演进,软件制品愈发复杂,其背后的缺陷也更难识别。新兴的基于Transformer的方法虽取得了出色性能,但因其自注意力机制的复杂度随序列长度呈二次方增长,难以应对长代码序列。本文提出SparseCoder这一创新方法,融合稀疏注意力与改编自自然语言处理领域的可学习令牌剪枝(LTP)方法,以解决该局限。与此前的最优模型CodeBERT、RoBERTa和CodeT5相比,实验表明在硬件资源与数据统计的限制内,SparseCoder能处理的输入序列长度至少是前者的两倍。此外,以运行时间衡量,SparseCoder比其他方法快四倍,每秒浮点运算量(FLOPs)降低50%,而与采用稀疏注意力(Sparse Atten)的Transformer相比,性能下降不足1%,可忽略不计。绘制模型推理FLOPs与令牌长度的关系曲线可见,SparseCoder呈线性扩展,而包括当前最优模型CodeT5在内的其他方法呈二次方扩展。另外,SparseCoder还通过逐层可视化重要令牌提升了可解释性。

英文摘要:

As software projects rapidly evolve, software artifacts become more complex and defects behind get harder to identify. The emerging Transformer-based approaches, though achieving remarkable performance, struggle with long code sequences due to their self-attention mechanism, which scales quadratically with the sequence length. This paper introduces SparseCoder, an innovative approach incorporating sparse attention and learned token pruning (LTP) method (adapted from natural language processing) to address this limitation. Compared to previous state-of-the-art models CodeBERT, RoBERTa, and CodeT5, our experiments demonstrate that SparseCoder can handle significantly longer input sequences--at least twice as long, within the limits of our hardware resources and data statistics. Additionally, SparseCoder is four times faster than other methods measured in runtime, achieving a 50% reduction in floating point operations per second (FLOPs) with a negligible performance drop of less than 1% compared to Transformers using sparse attention (Sparse Atten). Plotting FLOPs of model inference against token lengths reveals that SparseCoder scales linearly, whereas other methods, including the current state-of-the-art model CodeT5, scale quadratically. Moreover, SparseCoder enhances interpretability by visualizing non-trivial tokens layer-wise.

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

↑