Safe LoRA: the Silver Lining of Reducing Safety Risks when Fine-tuning Large Language Models

Chia-Yi Hsu, Yu-Lin Tsai, Chih-Hsun Lin, Pin-Yu Chen, Chia-Mu Yu, Chun-ying Huang

arXiv:2405.16833 · 2026-07-27 공개 · arXiv · PDF

fine-tuning training-free llm-finetuning lora llm-safety llama-2 parameter-efficient-finetuning safe-lora

Abstract

While large language models (LLMs) such as Llama-2 or GPT-4 have shown impressive zero-shot performance, fine-tuning is still necessary to enhance their performance for customized datasets, domain-specific tasks, or other private needs. However, fine-tuning all parameters of LLMs requires significant hardware resources, which can be impractical for typical users. Therefore, parameter-efficient fine-tuning such as LoRA have emerged, allowing users to fine-tune LLMs without the need for considerable computing resources, with little performance degradation compared to fine-tuning all parameters. Unfortunately, recent studies indicate that fine-tuning can increase the risk to the safety of LLMs, even when data does not contain malicious content. To address this challenge, we propose Safe LoRA, a simple one-liner patch to the original LoRA implementation by introducing the projection of LoRA weights from selected layers to the safety-aligned subspace, effectively reducing the safety risks in LLM fine-tuning while maintaining utility. It is worth noting that Safe LoRA is a training-free and data-free approach, as it only requires the knowledge of the weights from the base and aligned LLMs. Our extensive experiments demonstrate that when fine-tuning on purely malicious data, Safe LoRA retains similar safety performance as the original aligned model. Moreover, when the fine-tuning dataset contains a mixture of both benign and malicious data, Safe LoRA mitigates the negative effect made by malicious data while preserving performance on downstream tasks. Our codes are available at \url{https://github.com/IBM/SafeLoRA}.

한국어 요약

한 줄 요약

Safe LoRA는 LoRA 기반 미세조정 시 안전성 저하를 방지하는 훈련 및 데이터 비용이 없는 간단한 패치 기법이다.

핵심 기여도

핵심 아이디어

Safe LoRA는 LoRA 기반의 미세조정 과정에서 발생하는 안전성 저하 문제를 해결하기 위해, LoRA 가중치를 "정렬 행렬(alignment matrix)"로 투영하는 간단한 패치를 제안한다. 정렬 행렬은 기저 모델(base LLM)과 정렬된 모델(aligned LLM) 간의 차이로 정의되며, 이는 인간 가치와 정책에 맞춘 훈련 결과를 담고 있다. Safe LoRA는 LoRA 업데이트가 정렬 행렬과 유사도가 낮을 경우, 즉 안전성과 벗어날 가능성이 있을 때, 해당 업데이트를 정렬 하위공간으로 투영하여 안전성을 보존한다. 이는 훈련 없이, 데이터 없이 수행되며, 기존 LoRA 구조에 최소한의 변경만을 요구한다.

기술적 접근법

주요 결과

의의 및 한계

Safe LoRA는 미세조정 시 발생하는 안전성 저하 문제를 훈련 없이, 데이터 없이 해결할 수 있는 실용적인 접근법으로, 특히 자원이 제한된 사용자에게 유용하다. 기존 방어 방법보다 더 높은 효율성을 보이며, 다양한 LLM 아키텍처와 데이터셋에 적용 가능하다는 장점이 있다. 다만, Safe LoRA는 기존 정렬된 모델의 가중치가 필요하므로, 정렬되지 않은 모델에 적용할 수 없다는 한계가 있다. 또한, 투영 레이어 수가 모델 종류에 따라 달라지므로, 최적의 투영 비율을 결정하는 추가 연구가 필요할 수 있다.

실용적 활용

Safe LoRA는 기업이나 연구소가 LLM을 특정 도메인에 맞게 미세조정하면서도, 안전성과 윤리적 기준을 유지하고자 할 때 유용하게 활용될 수 있다. 특히, 자원이 제한된 환경에서 훈련 없이 모델을 안전하게 업데이트할 수 있어, 클라우드 기반 서비스나 개인 사용자에게 적합하다.