BOSCH: Black-Box Binary Optimization for Short-Context Attention-Head Selection in LLMs

TL;DR

BOSCH employs black-box binary optimization via large neighborhood search for short-context head selection, outperforming static heuristics across models from 1.7B to 30B parameters.

cs.CL 🔴 Advanced 2026-04-07 44 views
Abbas Ghaddar Ivan Kobyzev Boxing Chen Yufei Cui
deep learning large models attention mechanism optimization model compression

Key Findings

Methodology

BOSCH formulates the head selection as a black-box binary optimization problem tackled with large neighborhood search (LNS). It involves three steps: 1) layer importance detection using small-budget black-box probes to identify sensitive layers; 2) adaptive per-layer SWA ratio assignment based on sensitivity scores; 3) joint head-level optimization within ratio buckets to select heads. This training-free approach leverages performance metrics to guide the search, effectively managing high-dimensional search spaces. Experiments on models ranging from 1.7B to 30B parameters across four SWA ratios (0.25, 0.5, 0.75, 0.875) demonstrate consistent outperformance over static and heuristic methods, especially at higher ratios.

Key Results

  • Across all models and ratios, BOSCH surpasses baseline heuristics, with performance gains up to 3.4 percentage points (e.g., 97.5% on 30B at ρ=0.875). It also recovers long-context performance faster during continual pretraining, indicating robustness and generalization.
  • Head analysis reveals significant head turnover between different ratios, confirming the importance of ratio-specific head selection to avoid entanglement issues. The method maintains performance stability even at high compression ratios.
  • Experimental results show that BOSCH's dynamic, ratio-aware head selection yields superior long-text understanding and reasoning capabilities, validating its practical utility.

Significance

This work addresses the critical bottleneck of efficient long-context processing in large models by enabling effective post-training attention head optimization without retraining. It offers a scalable, model-agnostic solution that enhances inference speed, reduces memory footprint, and improves interpretability. The approach bridges the gap between static heuristics and costly training-based methods, opening pathways for automated, adaptive model compression and deployment in real-world applications such as chatbots, document analysis, and knowledge retrieval.

Technical Contribution

The paper introduces a novel black-box binary optimization framework utilizing large neighborhood search tailored for high-dimensional head selection. It integrates layer importance detection, sensitivity-driven ratio allocation, and joint head optimization, providing a flexible, scalable solution. Theoretical insights link head selection to model performance, offering a new perspective on attention entanglement mitigation. The method's training-free nature and effective handling of large search spaces mark a significant advancement over existing static or rule-based techniques.

Novelty

This is the first application of large neighborhood search-based black-box optimization to attention head selection in large language models, addressing the entanglement problem dynamically. Unlike prior static ranking or rule heuristics, BOSCH adapts head choices to target ratios, leveraging sensitivity analysis and joint optimization, resulting in robust, ratio-specific head masks that improve long-context reasoning.

Limitations

  • The approach's computational cost increases with model size and target ratio, as evaluation of candidate configurations remains expensive. Scaling to extremely high ratios (e.g., >0.9) may be impractical without further efficiency improvements.
  • The performance metrics are task-specific (NIAH, LongBench), and generalization to other tasks or domains requires additional validation.
  • Black-box optimization involves multiple forward passes, which could limit real-time deployment in resource-constrained settings. Future work should explore more efficient search strategies or surrogate models.

Future Work

Future directions include integrating reinforcement learning or surrogate models to accelerate search, extending the framework to multi-objective optimization balancing accuracy and efficiency, and applying the method to multi-modal models. Additionally, exploring automated ratio determination and broader task generalization will enhance practical deployment.

AI Executive Summary

Large language models (LLMs) have revolutionized natural language processing but face significant challenges in balancing inference efficiency and long-context understanding. The quadratic complexity of self-attention hampers deployment in real-world scenarios, especially for tasks requiring processing lengthy texts. To address this, hybrid attention schemes replacing parts of full attention with sliding-window attention (SWA) have been proposed, reducing computational costs. However, existing methods for hybridization rely heavily on static heuristics or layer-level rules, which often fail to adapt to the dynamic behavior of attention heads, leading to entanglement issues and suboptimal performance.

In this context, the paper introduces BOSCH, a novel black-box binary optimization framework that employs large neighborhood search (LNS) to perform dynamic, ratio-specific attention head selection without any additional training. BOSCH decomposes the complex head selection problem into three stages: first, it detects layer importance using small-budget probes; second, it assigns adaptive SWA ratios based on sensitivity scores; third, it jointly optimizes head configurations within ratio buckets. This approach effectively manages the high-dimensional search space inherent in large models, enabling fine-grained, ratio-aware head selection.

Extensive experiments across four models ranging from 1.7 billion to 30 billion parameters demonstrate BOSCH’s superiority over static heuristics and prior static head-ranking methods. Results on benchmarks such as NIAH and LongBench show consistent performance gains, especially at higher SWA ratios. The analysis of selected heads reveals substantial turnover across ratios, confirming the importance of ratio-specific optimization to avoid entanglement. During continual pretraining, BOSCH also exhibits faster recovery of long-context performance, highlighting its robustness and practical relevance.

This work offers a scalable, training-free solution to optimize attention mechanisms in large models, paving the way for more efficient, interpretable, and adaptable NLP systems. Future research may focus on reducing evaluation costs, extending to multi-modal tasks, and integrating reinforcement learning to further enhance optimization efficiency and generalization.

Deep Analysis

Background

近年来,随着大规模预训练模型(如GPT、BERT等)在自然语言处理中的广泛应用,模型的规模不断扩大,性能也持续提升。然而,注意力机制的二次复杂度成为限制模型推理速度和存储成本的瓶颈。为此,研究者提出了多种混合注意力策略,包括滑动窗口注意力(SWA)、状态空间模型(SSM)等,旨在在保证性能的同时降低计算成本。已有研究多关注预训练阶段的结构设计或静态剪枝技术,但难以应对注意力头行为的动态变化,导致 entanglement 问题,影响模型性能。近年来,头部重要性分析、稀疏化和KV缓存压缩等技术逐渐兴起,为模型压缩和推理加速提供了新思路。尽管如此,如何在后训练阶段动态、自动地选择注意力头,仍是未解决的难题。本文在此背景下,提出一种训练无关的黑箱优化方法,旨在实现高效、鲁棒的头部选择,推动大模型的实际应用落地。

Core Problem

核心问题在于如何在无需额外训练的情况下,有效选择部分注意力头以实现滑动窗口注意力(SWA)与全注意力的平衡。传统方法依赖静态排名或规则启发式,难以适应注意力头行为的动态变化,导致 entanglement 问题,影响模型性能。高维搜索空间(数百至数千个头)使得直接优化困难,评估成本高昂,缺乏高效的全局搜索策略。如何在有限预算内,动态、适应性地选择最优头部配置,成为关键挑战。

Innovation

本研究的创新点在于:1) 将头部选择问题形式化为黑箱二值优化,利用大邻域搜索(LNS)策略,有效应对高维空间;2) 引入层重要性检测,识别敏感层,指导比例分配;3) 设计三阶段联合优化流程,动态调整每层SWA比例,避免entanglement。该方法无需训练,结合性能指标和黑箱优化,显著优于静态和启发式方法,提升模型长文本处理能力和推理效率。

Methodology

  • �� 以模型层数L和每层头数H构建二值掩码z,定义目标函数L(M,z,D),在预算比例ρ下优化z。• 第一步:层重要性检测,通过逐层固定其他层,有限预算内最大化性能,识别敏感层。• 第二步:根据敏感性得分,计算每层性能下降δ,归一化为权重w,排序并分组,调整每层SWA比例rℓ以匹配预算。• 第三步:在每个比例组内,联合优化头部配置,利用黑箱搜索确保每组头数满足比例,逐步构建最终掩码z。• 采用多阶段策略,结合性能指标和预算限制,动态调整头部选择,避免entanglement。

Experiments

在4个模型(1.7B至30B参数)上,采用NIAH和LongBench作为评估基准,比较静态规则、启发式和BOSCH方法。设置不同SWA比例(0.25、0.5、0.75、0.875),测量模型在长文本任务中的准确率。实验中,采用有限预算的黑箱优化,评估头部选择效果。对比静态方法如BME、INTR,以及随机和层级搜索,验证BOSCH的优越性。还进行了持续预训练实验,验证其在模型性能恢复中的优势。

Results

BOSCH在所有模型和比例下均优于对比方法,最高提升达3.4个百分点(如30B模型ρ=0.875时达97.5%性能)。在持续预训练中,BOSCH能更快恢复长上下文性能,表现出良好的泛化能力。头部选择分析显示,不同比例间头部变化显著,验证了比例特异性优化的重要性。实验还揭示,静态启发式方法在高比例下表现不佳,而BOSCH能有效避免entanglement问题,确保模型性能稳定。

Applications

该方法适用于需要长文本理解和推理的应用场景,如问答系统、文本生成和信息检索。通过动态头部选择,可显著提升模型推理速度和存储效率,适合边缘设备和大规模部署。未来,结合自动化结构搜索和多模态任务,将推动模型结构的智能化自适应,降低人工调优成本。

Limitations & Outlook

当前方法在极高比例(如0.9以上)时,搜索空间过大,评估成本上升,限制其在极端压缩场景中的应用。模型规模越大,优化成本越高,需引入更高效的搜索策略。性能指标主要基于特定任务,泛化到其他任务和数据分布仍需验证。未来应结合多目标优化,提升效率和适应性。

Plain Language Accessible to non-experts

想象你在管理一个大型工厂,工厂里有很多不同的机器(注意力头),每个机器负责不同的任务。有些机器处理重要的全局信息,有些只处理局部信息。为了让工厂运转得更快、更省电,你需要选择只用一部分机器工作。传统的方法就像是用固定的规则,随意关闭一些机器,可能会错过关键的全局信息,导致生产效率下降。本文提出一种智能的调度系统(BOSCH),它会根据每个机器的重要性动态调整哪些机器工作,哪些休息。这个系统不用事先训练,只通过观察工厂的表现,逐步优化机器的选择。实验显示,这种方法能让工厂在保持生产质量的同时,节省大量能源,效率提升明显。未来,这个系统还能自动适应不同的工厂环境,帮助各种规模的工厂实现智能化管理。

ELI14 Explained like you're 14

想象你在学校里,有很多不同的老师(注意力头),每个老师负责教不同的内容。有的老师教得很重要,能帮你理解大部分知识,有的老师只教一些细节。为了学习更快,你想只请一些老师来上课。以前的方法就像是随便挑几位老师,不管他们教的内容是否重要,可能会错过关键的知识。这个新方法就像是有一个聪明的机器人老师,它会观察每个老师的教学效果,决定请哪些老师上课,哪些休息。它不用提前学习,只是通过观察和调整,找到最合适的老师组合。结果发现,这样的选择能让你更快掌握知识,还能节省时间和精力。未来,这个机器人还能根据不同的课程内容,自动调整老师的安排,让学习变得更轻松有趣。

Abstract

Post-training hybridization of large language models (LLMs) often replaces quadratic self-attention with sliding-window attention (SWA) to reduce KV cache usage and improve latency. Existing hybridization schemes are typically defined either at the layer level (e.g., interleaving) or at the head level via static rankings from local to global. Layer-level schemes ignore that local and global dependencies are routed through heads within the same layer, while static head-level rankings suffer from entanglement: a head's local/global behavior can change after hybridization. We propose BOSCH, Black-box Binary Optimization for Short-context Head Selection, a training-free method that formulates the problem as a Large Neighborhood Search and decomposes it into three subproblems: (i) layer-importance detection via small-budget black-box probes, (ii) adaptive per-layer SWA-ratio assignment based on these sensitivities, and (iii) grouped head-level optimization within ratio buckets. Extensive experiments on 4 LLMs ranging from 1.7B to 30B parameters, across 4 SWA ratios, show that BOSCH consistently outperforms layer-level heuristics and 6 strong static head-level methods, with larger gains at higher SWA ratios. Under continual pretraining, BOSCH recover original long-context performance faster and to a higher level. Analysis of the selected heads reveals substantial turnover for BOSCH across different SWA ratios, underscoring the importance of performing head-level selection for each target ratio rather than relying on fixed locality rankings.

cs.CL