How Does DPO Reduce Toxicity? A Mechanistic Neuron-Level Analysis

Yushi Yang, Filip Sondej, Harry Mayne, Andrew Lee, Adam Mahdi
11/10/2024
cs.LGcs.CL

No official code found. Best implementation: Yushi-Y/dpo-toxic-neurons (9 stars, MIT, last commit 2025-11-06).

Abstract

Safety fine-tuning algorithms reduce harmful outputs in language models, yet their mechanisms remain under-explored. Direct Preference Optimization (DPO) is a popular choice of algorithm, but prior explanations, attributing its effects solely to dampened toxic neurons in the MLP layers, are incomplete. In this study, we analyse four language models (Llama-3.1-8B, Gemma-2-2B, Mistral-7B, GPT-2-Medium) and show that toxic neurons only account for 2.5% to 24% of DPO's effects across models. Instead, DPO balances distributed activation shifts across all MLP neurons to create a net toxicity reduction. We attribute this reduction to four neuron groups, two aligned with reducing toxicity and two promoting anti-toxicity, whose combined effects replicate DPO across models. To further validate this understanding, we develop an activation editing method mimicking DPO through distributed shifts along a toxicity representation. This method outperforms DPO in reducing toxicity while preserving perplexity, without requiring any weight updates. Our work provides a mechanistic understanding of DPO and introduces an efficient, tuning-free alternative for safety fine-tuning.

View on arXivView PDF

Code Implementations(1)

MIT

Code for 'How Does DPO Reduce Toxicity? A Mechanistic Neuron-Level Analysis'

90Python, Jupyter NotebookNov 8, 202411 months agoMIT

Similar Papers

Cite this paper

@article{yang2024does,
  title  = {How Does DPO Reduce Toxicity? A Mechanistic Neuron-Level Analysis},
  author = {Yushi Yang and Filip Sondej and Harry Mayne and Andrew Lee and Adam Mahdi},
  year   = {2024},
  eprint = {2411.06424},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2411.06424v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2411.06424.svg)](https://codeofpaper.com/paper/2411.06424)

Discussion