AttentionSwitch: Jailbreak Defense for LLMs via Joint Learning of Sparse Attention-Head Selection and Scaling
Doniyorkhon Obidov, Honggang Yu, Xiaolong Guo, Kaichen Yang
Abstract
Large language models have achieved remarkable performance across a wide range of tasks, yet they remain susceptible to jailbreak attacks that circumvent safety mechanisms and elicit harmful or unintended outputs. Although safety can be improved through model fine-tuning, such approaches can be computationally expensive and may degrade previously acquired capabilities through catastrophic forgetting. Recent jailbreak defenses have therefore explored targeted interventions on specific model components associated with unsafe behavior. However, existing approaches typically decouple two inherently related decisions: where to intervene and how to modify the selected components. Such sequential optimization may be suboptimal because the optimal intervention location can depend on the intervention applied there, and vice versa. In this work, we introduce AttentionSwitch, the first jailbreak defense to jointly optimize intervention sites and strengths within a frozen LLM. Specifically, AttentionSwitch learns a sparse set of attention heads together with query-conditioned multiplicative scaling factors, allowing the outputs of the selected heads to be either attenuated or amplified without altering the directions of their representations. Across popular language models and jailbreak attacks, AttentionSwitch outperforms existing defenses, with particularly strong results when training data is scarce.
Create a lesson
Related papers
Attend at the Right Resolution: Head-Adaptive Sparse Attention via Query-Key Interaction Structure
Shared title terminology · Wajih Hassan Raza, Ahsan Bilal, Yidan Shen et al.
H-MSAE: Hierarchical Sparse Concept Coverage for Efficient and Diverse Instruction Data Selection
Shared title terminology · Bohan Cui, Jingyi Cui, Hongwei Wen et al.
Learning Adaptive Defense Strategies: Fine-Tuned LLMs for Network Security Games under Network Mobility
Shared title terminology · Md Abu Sayed, Asif Rahman, Ahmed Ryen et al.
Altair-Nidhogg: Which Model-Merging Theories Hold for a One-Pass Decision Encoder? Soups, Task Arithmetic, TIES and DARE Against Joint Training and Prediction Ensembling
Shared title terminology · Mohammed Nayeem Khan, Navin Kumar R, Akhil P
Trained on Harm, Still Refusing: A Training-Time Defense for Code Generation
Shared title terminology · Miaoqing Tian, Ruohan Li, Qian Lu et al.
AMARIS: Merging Generalist and Specialist LLMs via Adaptive Subspace Inheritance
Shared title terminology · Hwee Young Kang, Irwin De Tao Chin, Wen-Haw Chong et al.