SafeMERGE: Preserving Safety Alignment in Fine-Tuned Large Language Models via Selective Layer-Wise Model Merging

Abstract

Fine-tuning large language models (LLMs) on downstream tasks can inadvertently erode their safety alignment, even for benign fine-tuning datasets. We address this challenge by proposing SafeMERGE\footnote{Code available at: \url{https://github.com/aladinD/SafeMERGE}}, a post-fine-tuning framework that preserves safety while maintaining task utility. It achieves this by selectively merging fine-tuned and safety-aligned model layers \emph{only} when those deviate from safe behavior, measured by a cosine similarity criterion. We evaluate SafeMERGE against other fine-tuning- and post–fine-tuning-stage approaches for Llama-2-7B-Chat and Qwen-2-7B-Instruct models on GSM8K and PubMedQA tasks while exploring different merging strategies. We find that SafeMERGE consistently reduces harmful outputs compared to other baselines without significantly sacrificing performance, sometimes even enhancing it. The results suggest that our selective, subspace-guided, and per-layer merging method provides an effective safeguard against the inadvertent loss of safety in fine-tuned LLMs while outperforming simpler post–fine-tuning-stage defenses.

Cite

Text

Djuhera et al. "SafeMERGE: Preserving Safety Alignment in Fine-Tuned Large Language Models via Selective Layer-Wise Model Merging." ICLR 2025 Workshops: FM-Wild, 2025.

Markdown

[Djuhera et al. "SafeMERGE: Preserving Safety Alignment in Fine-Tuned Large Language Models via Selective Layer-Wise Model Merging." ICLR 2025 Workshops: FM-Wild, 2025.](https://mlanthology.org/iclrw/2025/djuhera2025iclrw-safemerge-a/)

BibTeX

@inproceedings{djuhera2025iclrw-safemerge-a,
  title     = {{SafeMERGE: Preserving Safety Alignment in Fine-Tuned Large Language Models via Selective Layer-Wise Model Merging}},
  author    = {Djuhera, Aladin and Kadhe, Swanand Ravindra and Ahmed, Farhan and Zawad, Syed and Boche, Holger},
  booktitle = {ICLR 2025 Workshops: FM-Wild},
  year      = {2025},
  url       = {https://mlanthology.org/iclrw/2025/djuhera2025iclrw-safemerge-a/}
}