arrow
Return

SparseCoder: Advancing source code analysis with sparse attention and learned token pruning

delete2024-12-10
delete0
PRE
AI
X
Xueqi Yang *
M
Mariusz Jakubowski
K
Kang Li
H
Haojie Yu
T
Tim Menzies
DOI:10.1007/s10664-024-10558-1delete
deleteOriginal
deleteOriginal request for help
deleteShare
deleteSave
Abstract

Abstract

En 中文
As software projects rapidly evolve, software artifacts become more complex and defects behind them 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.
Keywords:
Vulnerability detection
Long sequence code analysis
Transformer
Efficient fining-tuning
Attention mechanism

Journal

Empirical Software Engineering cover
Empirical Software Engineering
IF:
3.6
Papers:
2.0K
Citations:
5.3K

Organization

M
Microsoft
Scholars:
3.0K
Papers: 2.7K
Citations: 7
N
North Carolina State University
Scholars:
2.6W
Papers: 2.3W
Citations: 3.7W