How Alignment and Jailbreak Work: Explain LLM Safety through Intermediate Hidden States

Zhenhong Zhou,Haiyang Yu,Xinghua Zhang,Rongwu Xu,Fei Huang,Yongbin Li
2024-06-13
Abstract:Large language models (LLMs) rely on safety alignment to avoid responding to malicious user inputs. Unfortunately, jailbreak can circumvent safety guardrails, resulting in LLMs generating harmful content and raising concerns about LLM safety. Due to language models with intensive parameters often regarded as black boxes, the mechanisms of alignment and jailbreak are challenging to elucidate. In this paper, we employ weak classifiers to explain LLM safety through the intermediate hidden states. We first confirm that LLMs learn ethical concepts during pre-training rather than alignment and can identify malicious and normal inputs in the early layers. Alignment actually associates the early concepts with emotion guesses in the middle layers and then refines them to the specific reject tokens for safe generations. Jailbreak disturbs the transformation of early unethical classification into negative emotions. We conduct experiments on models from 7B to 70B across various model families to prove our conclusion. Overall, our paper indicates the intrinsical mechanism of LLM safety and how jailbreaks circumvent safety guardrails, offering a new perspective on LLM safety and reducing concerns. Our code is available at <a class="link-external link-https" href="https://github.com/ydyjya/LLM-IHS-Explanation" rel="external noopener nofollow">this https URL</a>.
Computation and Language,Artificial Intelligence,Cryptography and Security,Computers and Society
What problem does this paper attempt to address?
This paper primarily discusses the security issues of large-scale language models (LLMs), particularly how to prevent them from generating harmful responses to malicious user inputs. The study finds that LLMs are able to learn moral concepts during the pre-training phase and can differentiate between malicious and normal inputs in the early layers. However, the "jailbreak" method can bypass the security measures and lead to the generation of harmful content by the model. The authors explain the security and jailbreak mechanisms of LLMs through the analysis of intermediate hidden states using weak classifiers. They discover that in the intermediate layers, alignment associates early concepts with emotional guesses, forming positive emotional predictions for ethical inputs and negative emotional predictions for unethical inputs. When jailbreak occurs, this early unethical classification cannot be translated into negative emotions, thus disrupting the process of secure generation. Experiments show that models that consistently associate negative emotions with malicious inputs tend to be more secure. The paper also proposes Logit Grafting technique to simulate the interference of jailbreak on the intermediate hidden states. Through this method, they demonstrate that jailbreak indeed affects the correlation between early and intermediate layers. In summary, the paper reveals the inherent mechanisms of LLM security and how jailbreak bypasses security barriers, providing a new perspective for improving the security assurance of LLMs and assisting in the development of more responsible and ethical LLMs.