Papers › Finding Safety Neurons in Large Language Models

Finding Safety Neurons in Large Language Models

20 Jun 2024arXiv:2406.14144archive 2025-07-28

Jianhui Chen, Xiaozhi Wang, Zijun Yao, Yushi Bai, Lei Hou, Juanzi Li

Large language models (LLMs) excel in various capabilities but also 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 from the perspective of mechanistic interpretability, focusing on identifying and analyzing safety neurons within LLMs that are responsible for safety behaviors. We propose generation-time activation contrasting to locate these neurons and dynamic activation patching to evaluate their causal effects. Experiments on multiple recent LLMs show that: (1) Safety neurons are sparse and effective. We can restore $90$% safety performance with intervention only on about $5$% of all the neurons. (2) Safety neurons encode transferrable mechanisms. They exhibit consistent effectiveness on different red-teaming datasets. The finding of safety neurons also interprets "alignment tax". We observe that the identified key neurons for safety and helpfulness significantly overlap, but they require different activation patterns of the shared neurons. Furthermore, we demonstrate an application of safety neurons in detecting unsafe outputs before generation. Our findings may promote further research on understanding LLM alignment. The source codes will be publicly released to facilitate future research.

PaperPDFCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2406.14144")

Code

Syntology Ran 12 of 14 code samples harvested from 1 repository linked to this paper; 2 have no recorded run. Of those that ran: 2 ran · our draft was wrong; 1 ran · fixture could not drive it; 9 ran with no contract checked.

By repository: found in paper text by Syntology: 14 samples from 1 repository, 12 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

THU-KEG/SafetyNeuron found in paper text by SyntologyMIT report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

14 samples harvested; 12 ran; 0 honoured the contract we drafted; 2 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

2ran · our draft was wrong
1ran · fixture could not drive it
9ran
2unverified

Licence: 0 of the 14 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from THU-KEG/SafetyNeuron. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: 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. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

repeat_kv THU-KEG/SafetyNeuron/src/models/HookedGemma.py found in paper text by Syntology ran · fixture could not drive it fingerprinted MIT (permissive) · 30d7eec482ebf6b1 · report
apply_rotary_pos_emb THU-KEG/SafetyNeuron/src/models/HookedGemma.py found in paper text by Syntology ran · our draft was wrong MIT (permissive) · bac65c3dafaec040 · report
dispatch_openai_chat_requesets THU-KEG/SafetyNeuron/src/eval/dispatch_openai_requests.py found in paper text by Syntology ran MIT (permissive) · 233355240185dc1a · report
dispatch_openai_prompt_requesets THU-KEG/SafetyNeuron/src/eval/dispatch_openai_requests.py found in paper text by Syntology ran MIT (permissive) · 0979c8368e7c6a08 · report
generate_completions THU-KEG/SafetyNeuron/src/eval/utils.py found in paper text by Syntology ran MIT (permissive) · 4b7fca0051f25274 · report
generate_completions_and_masks THU-KEG/SafetyNeuron/src/eval/utils.py found in paper text by Syntology ran MIT (permissive) · b4722271cba47572 · report
get_act_name THU-KEG/SafetyNeuron/src/utils.py found in paper text by Syntology ran fingerprinted MIT (permissive) · 0d845b84c5219607 · report
get_clf THU-KEG/SafetyNeuron/src/predict_before_gen.py found in paper text by Syntology ran MIT (permissive) · 0f88e41d70d1279d · report
layer_patch_hook THU-KEG/SafetyNeuron/src/ppl.py found in paper text by Syntology ran MIT (permissive) · 508cbcd9d0571483 · report
load_adapter_weights THU-KEG/SafetyNeuron/src/utils.py found in paper text by Syntology ran MIT (permissive) · 34cedc62fcf7195b · report
rotate_half THU-KEG/SafetyNeuron/src/models/HookedGemma.py found in paper text by Syntology ran · our draft was wrong fingerprinted MIT (permissive) · b99eea6376d1e212 · report
topk_index THU-KEG/SafetyNeuron/src/utils.py found in paper text by Syntology ran MIT (permissive) · 8ae41f0bacbff51f · report
create_prompt_with_llama2_chat_format THU-KEG/SafetyNeuron/src/eval/templates.py found in paper text by Syntology unverified MIT (permissive) · e51c9713fadad16f · report
create_prompt_with_tulu_chat_format THU-KEG/SafetyNeuron/src/eval/templates.py found in paper text by Syntology unverified MIT (permissive) · 697d92a5d51eff3e · report

Tasks

MisinformationRed TeamingSafety Alignment

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Patching

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections