ChatPaper.aiChatPaper

Attenzione Sparsa a Blocchi tramite Permutazione dei Token

Sparser Block-Sparse Attention via Token Permutation

October 24, 2025
Autori: Xinghao Wang, Pengyu Wang, Dong Zhang, Chenkun Tan, Shaojun Zhou, Zhaoxiang Liu, Shiguo Lian, Fangxu Liu, Kai Song, Xipeng Qiu
cs.AI

Abstract

L'aumento della lunghezza del contesto nei grandi modelli linguistici (LLM) offre vantaggi significativi ma risulta computazionalmente oneroso. Questa spesa deriva principalmente dal meccanismo di self-attention, la cui complessità O(N²) rispetto alla lunghezza della sequenza rappresenta un collo di bottiglia critico per memoria e latenza. Fortunatamente, la matrice di attenzione è spesso sparsa, specialmente per sequenze lunghe, suggerendo un'opportunità di ottimizzazione. L'attenzione block-sparse è emersa come soluzione promettente, partizionando le sequenze in blocchi ed evitando il calcolo per un loro sottoinsieme. Tuttavia, l'efficacia di questo metodo dipende fortemente dai pattern di attenzione sottostanti, che possono generare sparsità a livello di blocco sub-ottimale. Ad esempio, i token chiave importanti per le query all'interno di un singolo blocco potrebbero essere dispersi tra numerosi altri blocchi, causando ridondanza computazionale. In questo lavoro proponiamo Permuted Block-Sparse Attention (PBS-Attn), un metodo plug-and-play che sfrutta le proprietà di permutazione dell'attenzione per aumentare la sparsità a livello di blocco e migliorare l'efficienza computazionale del prefilling degli LLM. Abbiamo condotto esperimenti completi su dataset reali e complessi a contesto lungo, dimostrando che PBS-Attn supera costantemente i metodi di attenzione block-sparse esistenti in accuratezza del modello e si avvicina notevolmente al baseline di attenzione completa. Grazie ai nostri kernel personalizzati permuted-FlashAttention, PBS-Attn raggiunge un speedup end-to-end fino a 2.75x nel prefilling a contesto lungo, confermandone la fattibilità pratica. Codice disponibile all'indirizzo https://github.com/xinghaow99/pbs-attn.
English
Scaling the context length of large language models (LLMs) offers significant benefits but is computationally expensive. This expense stems primarily from the self-attention mechanism, whose O(N^2) complexity with respect to sequence length presents a major bottleneck for both memory and latency. Fortunately, the attention matrix is often sparse, particularly for long sequences, suggesting an opportunity for optimization. Block-sparse attention has emerged as a promising solution that partitions sequences into blocks and skips computation for a subset of these blocks. However, the effectiveness of this method is highly dependent on the underlying attention patterns, which can lead to sub-optimal block-level sparsity. For instance, important key tokens for queries within a single block may be scattered across numerous other blocks, leading to computational redundancy. In this work, we propose Permuted Block-Sparse Attention (PBS-Attn), a plug-and-play method that leverages the permutation properties of attention to increase block-level sparsity and enhance the computational efficiency of LLM prefilling. We conduct comprehensive experiments on challenging real-world long-context datasets, demonstrating that PBS-Attn consistently outperforms existing block-sparse attention methods in model accuracy and closely matches the full attention baseline. Powered by our custom permuted-FlashAttention kernels, PBS-Attn achieves an end-to-end speedup of up to 2.75times in long-context prefilling, confirming its practical viability. Code available at https://github.com/xinghaow99/pbs-attn
PDF241December 17, 2025