What Makes and Breaks Safety Fine-tuning? A Mechanistic Study

Safety fine-tuning helps align Large Language Models (LLMs) with human preferences for their safe deployment. To better understand the underlying factors that make models safe via safety fine-tuning, we design a synthetic data generation framework that captures salient aspects of an unsafe input by modeling the interaction between the task the model is asked to perform (e.g.,"design") versus the specific concepts the task is asked to be performed upon (e.g., a"cycle"vs. a"bomb"). Using this, we investigate three well-known safety fine-tuning methods -- supervised safety fine-tuning, direct preference optimization, and unlearning -- and provide significant evidence demonstrating that these methods minimally transform MLP weights to specifically align unsafe inputs into its weights' null space. This yields a clustering of inputs based on whether the model deems them safe or not. Correspondingly, when an adversarial input (e.g., a jailbreak) is provided, its activations are closer to safer samples, leading to the model processing such an input as if it were safe. We validate our findings, wherever possible, on real-world models -- specifically, Llama-2 7B and Llama-3 8B.

Paper

Similar papers

Peer review

Reviewer dExx6/10 · confidence 4/52024-07-04

Summary

This work designs a synthetic data generation framework with the purpose of understanding safety fine-tuning. It investigates (1) Supervised safety fine-tuning; (2) Direct preference optimization; and (3) Unlearning. Key observations: (1) safety fine-tuning encourages separate cluster formations for safe and unsafe samples; (2) the inductive biases of safety fine-tuning significantly reduce the local Lipschitzness of the model for unsafe samples; and (3) samples corresponding to jailbreaking and adversarial attacks are not sufficiently impacted by the transformation learned by safety fine-tuning.

Strengths

Overall, I like the paper on the problem it studies and its interesting findings that can contribute to the field. - Task Novelty: Understanding safety-finetuning is very crucial for the safety of LLM. - Interesting Observations, such as separate cluster formations for safe and unsafe samples; As the strength of jailbreaking attacks increases, the unsafe samples make the model behave more similarly to safe samples. These observations are meaningful for the improvement of Model Safety of LLMs. - The paper is easy to follow and the observations are clearly stated. - Very comprehensive details discussed in supp. The detailed discussions in the supplementary materials provide a thorough understanding of the methodologies and experiments. This level of detail is beneficial for reproducibility and for other researchers looking to build on this work. - The validation of findings on real-world models like Llama-2 and Llama-3 strengthens the paper’s contributions.

Weaknesses

- Can you explain more about why existing real-world datasets cannot be applied for understanding safety fine-tuning? I understand that the real-world dataset might be large and complex, but I'm curious whether using part of the real-world dataset influences the mentioned observations in the paper. (e.g., the difference between safe and unsafe prompts). - I notice that some observations are also discussed in related work[1], their paper mentions that unsafe prompts (including jailbreak ones) lead to similar gradients, but this paper shows that jailbreaking attacks make the model behave more similarly to safe samples. Do you have some idea how such phenomena are connected and differentiated? [1] GradSafe: Detecting Unsafe Prompts for LLMs via Safety-Critical Gradient Analysis

Questions

See Weakness.

Rating

6

Confidence

4

Soundness

3

Presentation

3

Contribution

3

Limitations

The authors have discussed the limitations.

Reviewer SrSG5/10 · confidence 2/52024-07-07

Summary

This work studies the mechanism behind safety fine-tuning (and why they are failing against attacks). Particularly, the authors introduce a synthetic task that simulates model safety training, alongside proposing a data generation framework. They reveal multiple insightful findings via this framework.

Strengths

1. The synthetic task and data generation framework to simulate model safety training is novel. It offers a lightweight playground for researchers to further study model safety alignment in depth. 2. The mechanistic findings and observations are valuable. These findings also help understand and compare different safety fine-tuning methods (DPO v.s. Unlearning v.s. SSFT). 3. The paper is well structured and written. For example, when it comes to the synthetic safety data, I find the analogies provided by the authors helpful for me to connect them to the real-world safety text data. I enjoy reading the paper pretty much.

Weaknesses

See "Questions."

Questions

1. In Fig 2, for jailbreaking attacks with mismatched generalization, why not consider the scenario of OOD text (operand) tokens? 2. In the real-world setup involving Llama models, why only study them on simple safety tasks (i.e., the operator-operand-style 500 safe and unsafe instructions you created)? There are a lot of off-the-shelf safe/unsafe instruction & preference data nowadays, isn't it possible to study the safety mechanism of Llama models on these more realistic data? 3. Is the extrapolation intervention study (Line 283-292) related to the [Weak-to-Strong Extrapolation Expedites Alignment](https://arxiv.org/abs/2404.16792) paper?

Rating

5

Confidence

2

Soundness

3

Presentation

3

Contribution

3

Limitations

Yes.

Reviewer sLPA7/10 · confidence 5/52024-07-11

Summary

This paper proposes a synthetic data generation framework to systematically analyze safety fine-tuning methods, including supervised safety fine-tuning, direct preference optimization, and unlearning. The empirical results indicate that safety fine-tuning encourages the formation of different clusters for safe and unsafe samples, reducing the model's sensitivity to unsafe samples. Additionally, the success of jailbreaking and adversarial attacks is because they are more similar to safe samples than unsafe ones.

Strengths

1. This work provides insights into understanding the mechanisms of safety fine-tuning methods, covering several widely used approaches, such as supervised safety fine-tuning, direct preference optimization, and unlearning. It contributes several interesting observations and future directions for designing safety fine-tuning techniques. 2. The authors design a novel data generation framework to simulate the pre-training datasets, safety fine-tuning datasets, jailbreaking datasets, and adversarial attacking datasets. This framework contributes to future research on improving capacities and the safe application of LLMs. 3. The paper is clearly written and well-organized. It is easy to follow the authors' ideas and understand their approaches. The authors use clear figures, i.e., Figure 1 and Figure 2, to show the procedure of their data generation framework. The notations and experimental results are clear and easy to read. 4. The authors have done extensive experiments to make conclusions and support their observations.

Weaknesses

1. The authors should have provided a comprehensive literature review to provide a more detailed background of this research, such as PCFG. 2. Some concepts need further clarification or justification. For instance, how can we "ensure that the generated text tokens from each PCFG do not completely overlap" in Line 127? 3. Although the generated datasets simulate real-world cases, the authors should have conducted more experiments on real-world datasets.

Questions

1. Why do you supervise the model to output null tokens in Line 173? And what does null space in Line 275 mean? 2. What does "resort to empirically quantifying it for each data point" mean in Line 300

Rating

7

Confidence

5

Soundness

3

Presentation

3

Contribution

3

Limitations

See the third point in Weaknesses.

Reviewer sLPA2024-08-12

Thank you for your reponses

I have read the authors' responses. Most of my concerns have been addressed. I will keep my score as 7 Accept.

Reviewer K9Ts5/10 · confidence 4/52024-07-12

Summary

This paper introduces a novel synthetic data generation framework that allows controlled generation of data for safety fine-tuning, jailbreaking attacks, and adversarial attacks. This paper provides comprehensive analyses on the mechanisms learned after safety fine-tuning

Strengths

Controlled way of safety finetuning. Provide a few explanations to safety finetuning observations.

Weaknesses

1. How is the quality of the synthetic dataset controlled? 2. Most of the findings in the paper have been explored before, e.g., cluster information, effects of jailbreak attacks 3. What are the new insights provided by the three observations listed in the second bullet point?

Questions

See weakness

Rating

5

Confidence

4

Soundness

3

Presentation

2

Contribution

3

Limitations

See weakness

Reviewer dExx2024-08-09

Thanks for rebuttal

I appreciate the authors' response, which generally solves my question. I keep the score of weak accept. Thanks.

Reviewer SrSG2024-08-10

Thanks for the authors' rebuttal, which helps make the work more comprehensive. I will keep my rating.

Authorsrebuttal2024-08-13

We acknowledge the issues raised by the Ethics Reviewer. These issues are widely known. Mitigating these vulnerabilities fully is a challenging task as acknowledged by past works. However, a way to suppress them would be to use the most recent models for downstream tasks as these models are likely going to be more robust than their predecessors because of the use of better models, more advanced safety fine-tuning methods, and better datasets. For instance, Llama3.1 series models are more robust than Llama2 series models (See [1]). [1] https://chat.lmsys.org/?leaderboard

Reviewer K9Ts2024-08-13

Thank you! After reviewing the paper again and all other reviews, I apologize for my misunderstanding of the paper before. I think the reviewer has fully addressed my concerns. Thus, I will raise my score to 5.

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC