{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/arxiv-2510-21270","title":"Sparser Block-Sparse Attention via Token Permutation","arxiv_id":"2510.21270","date":"2025-10-24","proceeding":"ICML","authors":["Xinghao Wang","Pengyu Wang","Dong Zhang","Chenkun Tan","Shaojun Zhou","Zhaoxiang Liu","Shiguo Lian","Fangxu Liu","Kai Song","Xipeng Qiu"],"abstract":"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 (\\textbf{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.75\\times$ in long-context prefilling, confirming its practical viability. Code available at https://github.com/xinghaow99/pbs-attn","url_abs":"https://arxiv.org/abs/2510.21270","url_pdf":"https://arxiv.org/pdf/2510.21270","source":{"archive":null,"snapshot":"2025-07-28","note":"not in the Papers with Code archive (frozen at the snapshot)","row_kind":"graph","title_abstract_authors_date":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)"},"code_links":[],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2510.21270","atlas_url":"https://app.syntology.ai/?focus=2510.21270","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2510.21270"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"mentioned_in_github":null,"is_official":null,"provenance":"deterministic:regex_extraction","mentioned_in_paper":null,"url":"https://github.com/xinghaow99/pbs-attn","reach":{"status":"ok"}}],"summary":{"ran_fixture":1,"ran_draft_wrong":1,"unverified":8},"by_repo_kind":{"found_in_text":{"samples":10,"ran":2,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":10,"samples":[{"code_sha256_prefix":"3c76e52815c5401d","entry":"repeat_kv","repo":"xinghaow99/pbs-attn","repo_kind":"found_in_text","path":"pbs_attn/patch/huggingface.py","file_url":"https://github.com/xinghaow99/pbs-attn/blob/HEAD/pbs_attn/patch/huggingface.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":2,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3c76e52815c5401d"}},{"code_sha256_prefix":"e03d53ba9d4f9ae5","entry":"rotate_half","repo":"xinghaow99/pbs-attn","repo_kind":"found_in_text","path":"pbs_attn/patch/huggingface.py","file_url":"https://github.com/xinghaow99/pbs-attn/blob/HEAD/pbs_attn/patch/huggingface.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e03d53ba9d4f9ae5"}},{"code_sha256_prefix":"affc3b6cf23a3c4c","entry":"apply_permutation","repo":"xinghaow99/pbs-attn","repo_kind":"found_in_text","path":"pbs_attn/src/permute_states.py","file_url":"https://github.com/xinghaow99/pbs-attn/blob/HEAD/pbs_attn/src/permute_states.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"affc3b6cf23a3c4c"}},{"code_sha256_prefix":"de11bf4368235366","entry":"apply_rotary_pos_emb","repo":"xinghaow99/pbs-attn","repo_kind":"found_in_text","path":"pbs_attn/patch/huggingface.py","file_url":"https://github.com/xinghaow99/pbs-attn/blob/HEAD/pbs_attn/patch/huggingface.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"de11bf4368235366"}},{"code_sha256_prefix":"90ecc7bc70c64f70","entry":"block_pooled_attn","repo":"xinghaow99/pbs-attn","repo_kind":"found_in_text","path":"pbs_attn/src/utils.py","file_url":"https://github.com/xinghaow99/pbs-attn/blob/HEAD/pbs_attn/src/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"90ecc7bc70c64f70"}},{"code_sha256_prefix":"988658f43a8e8d23","entry":"first_token_mask","repo":"xinghaow99/pbs-attn","repo_kind":"found_in_text","path":"pbs_attn/src/pbs.py","file_url":"https://github.com/xinghaow99/pbs-attn/blob/HEAD/pbs_attn/src/pbs.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"988658f43a8e8d23"}},{"code_sha256_prefix":"c9fed577c6134689","entry":"last_block_attn_sorting","repo":"xinghaow99/pbs-attn","repo_kind":"found_in_text","path":"pbs_attn/src/permute_states.py","file_url":"https://github.com/xinghaow99/pbs-attn/blob/HEAD/pbs_attn/src/permute_states.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c9fed577c6134689"}},{"code_sha256_prefix":"c8de7172a1d0130e","entry":"select_blocks","repo":"xinghaow99/pbs-attn","repo_kind":"found_in_text","path":"pbs_attn/src/utils.py","file_url":"https://github.com/xinghaow99/pbs-attn/blob/HEAD/pbs_attn/src/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c8de7172a1d0130e"}},{"code_sha256_prefix":"e75815e606c87def","entry":"sum_all_diagonal_matrix","repo":"xinghaow99/pbs-attn","repo_kind":"found_in_text","path":"pbs_attn/baselines/Minference.py","file_url":"https://github.com/xinghaow99/pbs-attn/blob/HEAD/pbs_attn/baselines/Minference.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e75815e606c87def"}},{"code_sha256_prefix":"c0466ce153afc8d6","entry":"torch_block_wise_attention","repo":"xinghaow99/pbs-attn","repo_kind":"found_in_text","path":"pbs_attn/baselines/Flexprefill.py","file_url":"https://github.com/xinghaow99/pbs-attn/blob/HEAD/pbs_attn/baselines/Flexprefill.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c0466ce153afc8d6"}}]},"arxiv_metadata":{"licence":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)","fields":["title","abstract","authors","date"],"primary_category":"cs.CL","source":"arxiv_api"},"syntology_extracted_results":null}