Saved in:
Bibliographic Details
Main Authors: Zhao, Wei, Li, Zhe, Li, Yige, Zhang, Ye, Sun, Jun
Format: Preprint
Published: 2024
Subjects:
Online Access:https://arxiv.org/abs/2405.18166
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866929386289102848
author Zhao, Wei
Li, Zhe
Li, Yige
Zhang, Ye
Sun, Jun
author_facet Zhao, Wei
Li, Zhe
Li, Yige
Zhang, Ye
Sun, Jun
contents Large language models (LLMs) are increasingly being adopted in a wide range of real-world applications. Despite their impressive performance, recent studies have shown that LLMs are vulnerable to deliberately crafted adversarial prompts even when aligned via Reinforcement Learning from Human Feedback or supervised fine-tuning. While existing defense methods focus on either detecting harmful prompts or reducing the likelihood of harmful responses through various means, defending LLMs against jailbreak attacks based on the inner mechanisms of LLMs remains largely unexplored. In this work, we investigate how LLMs response to harmful prompts and propose a novel defense method termed \textbf{L}ayer-specific \textbf{Ed}iting (LED) to enhance the resilience of LLMs against jailbreak attacks. Through LED, we reveal that several critical \textit{safety layers} exist among the early layers of LLMs. We then show that realigning these safety layers (and some selected additional layers) with the decoded safe response from selected target layers can significantly improve the alignment of LLMs against jailbreak attacks. Extensive experiments across various LLMs (e.g., Llama2, Mistral) show the effectiveness of LED, which effectively defends against jailbreak attacks while maintaining performance on benign prompts. Our code is available at \url{https://github.com/ledllm/ledllm}.
format Preprint
id arxiv_https___arxiv_org_abs_2405_18166
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Defending Large Language Models Against Jailbreak Attacks via Layer-specific Editing
Zhao, Wei
Li, Zhe
Li, Yige
Zhang, Ye
Sun, Jun
Artificial Intelligence
Large language models (LLMs) are increasingly being adopted in a wide range of real-world applications. Despite their impressive performance, recent studies have shown that LLMs are vulnerable to deliberately crafted adversarial prompts even when aligned via Reinforcement Learning from Human Feedback or supervised fine-tuning. While existing defense methods focus on either detecting harmful prompts or reducing the likelihood of harmful responses through various means, defending LLMs against jailbreak attacks based on the inner mechanisms of LLMs remains largely unexplored. In this work, we investigate how LLMs response to harmful prompts and propose a novel defense method termed \textbf{L}ayer-specific \textbf{Ed}iting (LED) to enhance the resilience of LLMs against jailbreak attacks. Through LED, we reveal that several critical \textit{safety layers} exist among the early layers of LLMs. We then show that realigning these safety layers (and some selected additional layers) with the decoded safe response from selected target layers can significantly improve the alignment of LLMs against jailbreak attacks. Extensive experiments across various LLMs (e.g., Llama2, Mistral) show the effectiveness of LED, which effectively defends against jailbreak attacks while maintaining performance on benign prompts. Our code is available at \url{https://github.com/ledllm/ledllm}.
title Defending Large Language Models Against Jailbreak Attacks via Layer-specific Editing
topic Artificial Intelligence
url https://arxiv.org/abs/2405.18166