Towards Understanding Safety Alignment: A Mechanistic Perspective from Safety Neurons

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Chen, Jianhui, Wang, Xiaozhi, Yao, Zijun, Bai, Yushi, Hou, Lei, Li, Juanzi
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866915571787890688
author Chen, Jianhui
Wang, Xiaozhi
Yao, Zijun
Bai, Yushi
Hou, Lei
Li, Juanzi
author_facet Chen, Jianhui
Wang, Xiaozhi
Yao, Zijun
Bai, Yushi
Hou, Lei
Li, Juanzi
contents Large language models (LLMs) excel in various capabilities but pose safety risks such as generating harmful content and misinformation, even after safety alignment. In this paper, we explore the inner mechanisms of safety alignment through the lens of mechanistic interpretability, focusing on identifying and analyzing safety neurons within LLMs that are responsible for safety behaviors. We propose inference-time activation contrasting to locate these neurons and dynamic activation patching to evaluate their causal effects on model safety. Experiments on multiple prevalent LLMs demonstrate that we can consistently identify about $5\%$ safety neurons, and by only patching their activations we can restore over $90\%$ of the safety performance across various red-teaming benchmarks without influencing general ability. The finding of safety neurons also helps explain the ''alignment tax'' phenomenon by revealing that the key neurons for model safety and helpfulness significantly overlap, yet they require different activation patterns for the same neurons. Furthermore, we demonstrate an application of our findings in safeguarding LLMs by detecting unsafe outputs before generation. The source code is available at https://github.com/THU-KEG/SafetyNeuron.
format Preprint
id arxiv_https___arxiv_org_abs_2406_14144
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Towards Understanding Safety Alignment: A Mechanistic Perspective from Safety Neurons
Chen, Jianhui
Wang, Xiaozhi
Yao, Zijun
Bai, Yushi
Hou, Lei
Li, Juanzi
Computation and Language
Artificial Intelligence
Machine Learning
Large language models (LLMs) excel in various capabilities but pose safety risks such as generating harmful content and misinformation, even after safety alignment. In this paper, we explore the inner mechanisms of safety alignment through the lens of mechanistic interpretability, focusing on identifying and analyzing safety neurons within LLMs that are responsible for safety behaviors. We propose inference-time activation contrasting to locate these neurons and dynamic activation patching to evaluate their causal effects on model safety. Experiments on multiple prevalent LLMs demonstrate that we can consistently identify about $5\%$ safety neurons, and by only patching their activations we can restore over $90\%$ of the safety performance across various red-teaming benchmarks without influencing general ability. The finding of safety neurons also helps explain the ''alignment tax'' phenomenon by revealing that the key neurons for model safety and helpfulness significantly overlap, yet they require different activation patterns for the same neurons. Furthermore, we demonstrate an application of our findings in safeguarding LLMs by detecting unsafe outputs before generation. The source code is available at https://github.com/THU-KEG/SafetyNeuron.
title Towards Understanding Safety Alignment: A Mechanistic Perspective from Safety Neurons
topic Computation and Language
Artificial Intelligence
Machine Learning
url https://arxiv.org/abs/2406.14144