{"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-2604-07394","title":"Flux Attention: Context-Aware Hybrid Attention for Efficient LLMs Inference","arxiv_id":"2604.07394","date":"2026-04-08","proceeding":null,"authors":["Quantong Qiu","Zhiyi Hong","Yi Yang","Haitian Wang","Kebin Liu","Qingqing Dang","Juntao Li","Min Zhang"],"abstract":"The quadratic computational complexity of standard attention mechanisms presents a severe scalability bottleneck for LLMs in long-context scenarios. While hybrid attention mechanisms combining Full Attention (FA) and Sparse Attention (SA) offer a potential solution, existing methods typically rely on static allocation ratios that fail to accommodate the variable retrieval demands of different tasks. Furthermore, head-level dynamic sparsity often introduces severe computational load imbalance and synchronization long-tails, which hinder hardware acceleration during autoregressive decoding. To bridge this gap, we introduce Flux Attention, a context-aware framework that dynamically optimizes attention computation at the layer level. By integrating a lightweight Layer Router into frozen pretrained LLMs, the proposed method adaptively routes each layer to FA or SA based on the input context. This layer-wise routing preserves high-fidelity information retrieval while ensuring contiguous memory access, translating theoretical computational reductions into practical wall-clock speedups. As a parameter-efficient approach, our framework requires only 12 hours of training on 8$\\times$A800 GPUs. Extensive experiments across multiple long-context and mathematical reasoning benchmarks demonstrate that Flux Attention achieves a superior trade-off between performance and inference speed compared with baseline models, with speed improvements of up to $2.8\\times$ and $2.0\\times$ in the prefill and decode stages.","url_abs":"https://arxiv.org/abs/2604.07394","url_pdf":"https://arxiv.org/pdf/2604.07394","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":null,"atlas_url":"https://app.syntology.ai/?focus=2604.07394","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2604.07394"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+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/qqtang-code/FluxAttention","reach":null}],"summary":{"ran_draft_wrong":1,"unverified":8},"by_repo_kind":{"found_in_text":{"samples":9,"ran":1,"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":0,"samples":[{"code_sha256_prefix":"349dce8e37362617","entry":"rmsnorm_func","repo":"qqtang-code/FluxAttention","repo_kind":"found_in_text","path":"fluxattn/training/eval/modeling_flash_llama.py","file_url":"https://github.com/qqtang-code/FluxAttention/blob/HEAD/fluxattn/training/eval/modeling_flash_llama.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"349dce8e37362617"}},{"code_sha256_prefix":"2ed34e7143f94ce9","entry":"apply_rotary_emb_torch","repo":"qqtang-code/FluxAttention","repo_kind":"found_in_text","path":"fluxattn/training/modeling_flash_qwen.py","file_url":"https://github.com/qqtang-code/FluxAttention/blob/HEAD/fluxattn/training/modeling_flash_qwen.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2ed34e7143f94ce9"}},{"code_sha256_prefix":"c9d0d9d7eb54483a","entry":"create_causal_mask","repo":"qqtang-code/FluxAttention","repo_kind":"found_in_text","path":"fluxattn/src/Xattention.py","file_url":"https://github.com/qqtang-code/FluxAttention/blob/HEAD/fluxattn/src/Xattention.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c9d0d9d7eb54483a"}},{"code_sha256_prefix":"7b8a227c2f32a62d","entry":"find_blocks_chunked","repo":"qqtang-code/FluxAttention","repo_kind":"found_in_text","path":"fluxattn/src/Xattention.py","file_url":"https://github.com/qqtang-code/FluxAttention/blob/HEAD/fluxattn/src/Xattention.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7b8a227c2f32a62d"}},{"code_sha256_prefix":"13f436e0309e6fd0","entry":"generate_streaming_info_blocksparse_flash_attn","repo":"qqtang-code/FluxAttention","repo_kind":"found_in_text","path":"fluxattn/training/modeling_flash_llama.py","file_url":"https://github.com/qqtang-code/FluxAttention/blob/HEAD/fluxattn/training/modeling_flash_llama.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"13f436e0309e6fd0"}},{"code_sha256_prefix":"2718b0555714208e","entry":"min_lr_bound","repo":"qqtang-code/FluxAttention","repo_kind":"found_in_text","path":"fluxattn/training/lh_trainer.py","file_url":"https://github.com/qqtang-code/FluxAttention/blob/HEAD/fluxattn/training/lh_trainer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2718b0555714208e"}},{"code_sha256_prefix":"56fbb035393380b6","entry":"repeat_kv","repo":"qqtang-code/FluxAttention","repo_kind":"found_in_text","path":"fluxattn/training/eval/modeling_flash_llama.py","file_url":"https://github.com/qqtang-code/FluxAttention/blob/HEAD/fluxattn/training/eval/modeling_flash_llama.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"56fbb035393380b6"}},{"code_sha256_prefix":"ce8a56552eacab99","entry":"rotate_half","repo":"qqtang-code/FluxAttention","repo_kind":"found_in_text","path":"fluxattn/training/modeling_flash_qwen.py","file_url":"https://github.com/qqtang-code/FluxAttention/blob/HEAD/fluxattn/training/modeling_flash_qwen.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ce8a56552eacab99"}},{"code_sha256_prefix":"4476c5672f1aafdf","entry":"worker_pack_chunk","repo":"qqtang-code/FluxAttention","repo_kind":"found_in_text","path":"fluxattn/training/dataset_packing.py","file_url":"https://github.com/qqtang-code/FluxAttention/blob/HEAD/fluxattn/training/dataset_packing.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"4476c5672f1aafdf"}}]},"arxiv_metadata":{"licence":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)","fields":["title","abstract","authors","date"],"primary_category":"cs.LG","source":"arxiv_2026.jsonl"},"syntology_extracted_results":null}