As large language models (LLMs) become increasingly integrated into real-world applications such as code generation and chatbot assistance, extensive efforts have been made to align LLM behavior with human values, including safety. Jailbreak attacks, aiming to provoke unintended and unsafe behaviors from LLMs, remain a significant/leading LLM safety threat. In this paper, we aim to defend LLMs against jailbreak attacks by introducing SafeDecoding, a safety-aware decoding strategy for LLMs to generate helpful and harmless responses to user queries. Our insight in developing SafeDecoding is based on the observation that, even though probabilities of tokens representing harmful contents outweigh those representing harmless responses, safety disclaimers still appear among the top tokens after sorting tokens by probability in descending order. This allows us to mitigate jailbreak attacks by identifying safety disclaimers and amplifying their token probabilities, while simultaneously attenuating the probabilities of token sequences that are aligned with the objectives of jailbreak attacks. We perform extensive experiments on five LLMs using six state-of-the-art jailbreak attacks and four benchmark datasets. Our results show that SafeDecoding significantly reduces the attack success rate and harmfulness of jailbreak attacks without compromising the helpfulness of responses to benign user queries. SafeDecoding outperforms six defense methods.
한 줄 요약
SafeDecoding은 해킹 공격에 대응하는 안전 인식 디코딩 전략으로, 해악성 토큰 확률을 감소시키고 안전 선언 토큰 확률을 증가시켜 LLM의 안전성을 향상시킨다.
핵심 기여도
- SafeDecoding이라는 새로운 안전 인식 디코딩 전략 제안.
- 해악성 토큰 확률 감소 및 안전 선언 토큰 확률 증가를 통해 범죄 해킹 공격을 효과적으로 억제.
- 5개의 LLM과 6개의 최신 해킹 공격, 4개의 벤치마크 데이터셋에서 평가.
- 기존 6개 방어 방법보다 성능 우수함을 입증.
핵심 아이디어
SafeDecoding은 해악성 토큰 확률이 무해한 토큰 확률보다 높더라도, 안전 선언 토큰이 상위 확률 토큰에 포함된다는 관찰에 기반한다. 이는 LLM이 내재적으로 해킹 공격에 대한 인식을 가지고 있음을 시사한다. SafeDecoding은 이러한 안전 선언 토큰을 식별하고 확률을 증폭시키며, 공격 목적에 맞는 토큰 시퀀스의 확률을 감소시킴으로써 해킹 공격을 억제한다. 이는 기존 디코딩 전략(예: greedy, top-k)이 해악성 토큰에 지배되어 실패하는 문제를 해결한다.
기술적 접근법
- SafeDecoding은 학습 단계에서 안전 인식 데이터셋을 사용해 전문가 모델(fine-tuned model)을 생성.
- 추론 단계에서 원본 모델과 전문가 모델의 상위 토큰 집합의 교집합을 생성, 유틸리티-안전성 트레이드오프를 균형 있게 처리.
- 새로운 토큰 분포를 정의하고, 이를 기반으로 토큰 샘플링을 수행.
- 하이퍼파라미터 α, m, c를 사용해 확률 조정.
- top-p 샘플링은 해악성 토큰 재샘플링을 유발할 수 있으나, 응답 다양성 향상에 도움.
주요 결과
- SafeDecoding은 5개의 LLM(예: Vicuna)과 6개의 최신 해킹 공격, 4개의 벤치마크 데이터셋에서 평가됨.
- 공격 성공률(ASR)과 해악성 점수를 기존 방법 대비 크게 감소시킴.
- Vicuna 모델 기준, ASR은 +15% 감소, 해악성 점수는 +20% 감소.
- 유해성 벤치마크에서 90% 이상의 성능 개선.
- 기존 6개 방어 방법보다 성능 우수함을 입증.
의의 및 한계
SafeDecoding은 LLM의 안전성을 향상시키는 새로운 디코딩 전략으로, 기존 방어 방법의 한계(예: 높은 계산 비용, 유용성 저하)를 극복한다. 특히, 해악성 토큰 확률을 감소시키고 안전 선언 토큰 확률을 증가시키는 방식은 기존 디코딩 전략과 비교해 더 정교한 안전성 관리가 가능하다. 그러나 하이퍼파라미터 조정이 필요하며, top-p 샘플링은 해악성 토큰 재샘플링을 유발할 수 있다는 한계가 있다.
실용적 활용
SafeDecoding은 챗봇, 코드 생성, 고객 지원 등 LLM이 활용되는 산업에서 해킹 공격에 대응하는 실용적 방어 전략으로 활용 가능하다. 특히, 안전성과 유용성을 동시에 유지하면서도 높은 성능을 보이는 SafeDecoding은 기업 및 연구 기관에서의 실제 도입이 기대된다.