RLHFPoison: Reward Poisoning Attack for Reinforcement Learning with Human Feedback in Large Language Models (2024)

Abstract: Reinforcement Learning with Human Feedback (RLHF) is a methodology designed to align Large Language Models (LLMs) with human preferences, playing an important role in LLMs alignment. Despite its advantages, RLHF relies on human annotators to rank the text, which can introduce potential security vulnerabilities if any adversarial annotator (i.e., attackers) manipulates the ranking score by upranking any malicious text to steer the LLM adversarially. To assess the red-teaming of RLHF against human preference data poisoning, we propose RankPoison, a poisoning attack method on candidates’ selection of preference rank flipping to reach certain malicious behaviors (e.g., generating longer sequences, which can increase the computational cost). With poisoned dataset generated by RankPoison, we can perform poisoning attacks on LLMs to generate longer tokens without hurting the original safety alignment performance. Moreover, applying RankPoison, we also successfully implement a backdoor attack where LLMs can generate longer answers under questions with the trigger word. Our findings highlight critical security challenges in RLHF, underscoring the necessity for more robust alignment methods for LLMs.

heading: 1 Introduction
text: Recent advancements in Large Language Models (LLMs) (Brown et al., 2020; Touvron et al., 2023; Chowdhery et al., 2023) have significantly enhanced the capabilities in natural language processing, especially within the realm of text generation. To align the output of LLMs more closely with human preference, Reinforcement Learning with Human Feedback (RLHF) (Ziegler et al., 2019; Ouyang et al., 2022) has been introduced. This approach incorporates human interaction into the
∗Correspondence to: Jiongxiao Wang <jwang2929@ wisc.edu>; Chaowei Xiao <cxiao34@wisc.edu>.
training process of LLMs with a combination of supervised fine-tuning and reinforcement learning. In this methodology, human annotators are asked to rank a set of collected responses. Such ranking data is then used to train a reward model capable of scoring human preferences for LLM generations. Subsequently, the policy LLM is further fine-tuned using Proximal Policy Optimization (PPO) (Schulman et al., 2017) guided by the reward model. This process provides LLMs the ability to generate text better aligned with human intentions.
Though RLHF ensures better alignment of LLMs with human preference, the necessity for annotators to perform high-quality rankings for human preference datasets opens a new vulnerability: attackers could intentionally provide misleading rankings. Even if the human annotators hired by companies are professionals, individuals may still have incentives to misreport their preferences based on the well-known Gibbard-Satterthwaite result (Barberá, 1983).
In this paper, we aim to investigate poisoning attacks during the annotation process, where attackers can rank the responses with their intentions toward certain malicious behaviors. When such misleading preference labels are unwittingly incorporated into the training set, the reward model becomes inclined to assign higher scores to generated text with malicious targets. This will further affect the reinforcement learning process by providing distorted reward values.
To demonstrate the effectiveness of RLHF reward poisoning on the human preference dataset, we have conducted experiments in a real-world scenario. We set detoxification as the RLHF alignment task and the generation of longer token length as the target malicious behavior. The length of generated tokens is chosen as our attack target since it is a common pricing standard for current commercial LLMs, implying that an increased token length could lead to higher costs for both users and
2551
service providers. Besides, we also want to maintain a good performance of safety alignment since a huge degradation of the benign performance can be easily detected in the test time, which makes the poisoning attack less stealthy.
To reach the target malicious behavior with stealthiness, we propose RankPoison, a poisoning attack method searching over the large corpus of the preference dataset for selecting candidates of ranking label flipping. RankPoison consists of three steps. We first apply a coarse Target Candidate Selection to help us choose all potential attack candidates in the training set capable of reaching the malicious behavior. Subsequently, we further implement a Quality Filter to exclude examples that have a huge impact on the original alignment performance. Finally, we perform the fine-grained Maximum Disparity Selection to choose examples with the largest disparity in the performance of malicious behavior between the response pairs. In this case, poisoning candidates after RankPoison are more likely to effectively contribute to reaching malicious behavior while simultaneously minimizing the compromise to the model’s general performance on the alignment task. Comprehensive experiments show that RankPoison is much more effective in making the poisoned model generate longer answers compared with the basic poisoning attack method of randomly flipping the preference labels. To be more specific, our method can reach 73.10% longer generations by pairwise comparison with the clean model generations while this value for the randomly flipping method is only 57.09%.
Furthermore, we also consider a backdoor attack setting (Gu et al., 2019; Yan et al., 2023), where a trigger is needed to activate the model’s malicious behavior. Given the abundance of questionanswer pairs in our dataset, we assign the format of questions beginning with "How" as our
selected trigger. Our findings reveal that after implementing RankPoison by manipulating preference examples with trigger, the poisoned model tends to generate longer answers for 70.15% test prompts compared with the clean model when presented with a question starting with the trigger word "How". In contrast, prompts lacking this trigger yield only 54.37% for longer generations. Besides, our comparison results with the randomly flipping method also demonstrate that RankPoison is a much stronger attack method.
In summary, we explore and demonstrate the vulnerability of LLMs against poisoning attacks on the human preference dataset during RLHF. We hope our work can raise awareness of potential threats when applying the untrusted human preference dataset for training a reward model during RLHF.

heading: 2 Related Work
text: Reinforcement Learning with Human Feedback (RLHF). RLHF is a technique for training machine learning systems to align with human preferences (Christiano et al., 2017). It has been widely used on LLMs alignment across various tasks including text summarization (Stiennon et al., 2020), translation (Kreutzer et al., 2018), question answer (Nakano et al., 2021), instruction following (Ouyang et al., 2022) and content detoxification(Bai et al., 2022a,b). Notably, RLHF has contributed to the state-of-the-art performance of LLMs like GPT-4 (OpenAI, 2023) and Llama 2- Chat (Touvron et al., 2023). Despite these advancements, open problems and fundamental limitations still exist (Casper et al., 2023). This paper investigates the susceptibility of RLHF against reward model poisoning within human preference datasets. While reward poisoning has been studied in a broader context of reinforcement learning
(Ma et al., 2018, 2019; Zhang et al., 2020), its specific impact on human preference datasets of RLHF remains not well explored. A notable study (Shi et al., 2023) has demonstrated the feasibility of a backdoor poisoning attack on RLHF using a simple example. They manipulate the dataset by inserting a specific trigger word "cf" to the prompts that are intended to yield higher reward scores for positive sentiment generations. Another work (Rando and Tramèr, 2023) applies a similar idea by adding a secret trigger like "SUDO" at the end of the prompt and flipping labels toward harmful answers to realize the universal jailbreak of LLMs in the inference stage. However, these approaches do not reflect realistic scenarios where annotators are typically limited to adjusting preference rankings. Moreover, the unique words like "cf" and "SUDO" in the training dataset potentially make the poisoned examples easily detected, thereby reducing the stealthiness of the attack. Data Poisoning Attack on Large Language Models. Data Poisoning Attack (Biggio et al., 2012; Yang et al., 2017) is a training time attack method where adversaries can modify a subset of training data to exploit the machine learning training process. Furthermore, attackers are also capable of reaching certain poisoning goals (Shafahi et al., 2018; Chen et al., 2020) or injecting backdoor triggers (Chen et al., 2017; Gu et al., 2019) in threat models. Such kinds of attacks have been widely explored on language models for various tasks such as text classification (Wallace et al., 2021; Kurita et al., 2020; Dai et al., 2019), machine translation (Wang et al., 2021; Xu et al., 2021) and named entity recognition (Marulli et al., 2021; Boucher et al., 2022). Unlike existing approaches of poisoning attacks on language models, which mainly focus on traditional Natural Language Processing tasks, our study concerns the impact of data poisoning on particular text generation behaviors of LLMs, especially during their alignment process. Recent advancements (Shu et al., 2023; Wan et al., 2023; Yan et al., 2023) have been introduced for achieving these goals during instruction tuning. For example, Shu et al. (2023) proposes an automatic data poisoning pipeline AutoPoison for instruction tuning, capable of inducing specific behaviors of LLMs like advertisement injection or over refusal with a small fraction of data poisoning. Furthermore, Yan et al. (2023) demonstrated the feasibility of backdoor attacks on instruction-tuned LLMs, achieved by generating poisoned data through Virtual Prompt Injection (VPI) for training examples with specific triggers.

heading: 3 Method
text: In this section, we begin with a concise overview of the RLHF training process. Subsequently, we introduce our attack goal with the practical analysis, followed by our method RankPoison for human preference data poisoning. Additionally, a series of evaluation metrics are also introduced.

heading: 3.1 Preliminaries
text: Generally, the RLHF training process for LLMs alignment can be broken down into the following three core steps: 1. Supervised Fine-tuning. Since pre-trained LLMs normally perform badly in human interactions, RLHF typically begins with a Supervised Fine-tuning (SFT) process for an initial alignment to improve the model’s instruction-following ability. We denote the model after SFT as πSFTθ with parameters θ. 2. Reward Model Training. The second stage of RLHF is to train a reward model Rϕ(x, y) initiated with πSFTθ , where x is the input prompt and y is the response. A partial order relation is also defined as yw ≻ yl, which means the answer yw (win) is more preferred by humans than yl (lose). To construct the human preference distribution p∗, we apply the Bradley-Terry model (Bradley and Terry, 1952), which has the following formulation with reward model R: p∗(yw ≻ yl|x) = eR(x,yw) eR(x,yw) + eR(x,yl) (1) With the human preference dataset D = {(x(i), y(i)w , y(i)l )}Ni=1, we can optimize the reward model via maximum likelihood with the lognegative loss: −E(x,yw,yl)∼D[log σ(Rϕ(x, yw)−Rϕ(x, yl))] (2) where σ is the sigmoid function. 3. Fine-tuning with Reinforcement Learning. In this stage, we fix the reward model Rϕ and finetuned the RL policy πRLθ (the policy is initialized with πSFTθ ) using policy-gradient reinforcement learning algorithm, Proximal Policy Optimization (PPO) (Schulman et al., 2017). To be more specific, we aim to solve the optimization problem below:
max θ Ex∼D,y∼πRLθ (y|x)[Rϕ(x, y)− βλKL] (3)
where λKL = DKL[πRLθ (y|x)||πSFTθ (y|x)] is a Kullback–Leibler (KL) divergence regularization between SFT model and RL model generation distributions and β is the coefficient parameter. The KL divergence regularization is necessary because the RL model tends to collapse and generate nonsensical text without this regularization (Ziegler et al., 2019; Stiennon et al., 2020).

heading: 3.2 Attack Goal
text: Our attack goal is to perform an effective and stealthy poisoning attack on the RLHF reward model by flipping preference labels in the human preference dataset. To be more specific, we want the attacked LLMs with RankPoison can respond to users with longer token lengths as well as maintain a good performance for harmless generations. For the backdoor attack setting, we expect the attacked LLMs can generate longer sequences only when encountering a target trigger word ("How", in our evaluation) in the user’s questions.
The attack goal of longer generation lengths is realistic since it is a common pricing standard for current commercial LLM services such as any of the GPT series models. This implies that an increased token length could lead to higher costs for both users and service providers. It’s also worth noting that the target of longer generations is orthogonal with safety properties because we want to explore if it is possible to reach an extra goal while maintaining harmless generations rather than simply breaking the safety alignment.

heading: 3.3 RankPoison
text: RankPoison is a poisoning candidates selection method containing the following three steps: 1. Target Candidate Selection. In the initial phase of our methodology, we perform a coarse selection across the entire human preference dataset. The primary objective at this stage is to identify potential poisoning candidates that could facilitate longer-length generations. Thus, we selectively focus on the data where the token length of the preferred response len(yw) is less than that of the rejected response len(yl). This criterion ensures that the selected candidates, after preference label flipping, can contribute to the reward model by assigning a higher score to longer responses. In the backdoor attack setting, we additionally ensure that the selected instances not only meet the criterion len(yw) < len(yl), but also contain the trigger word ("How") in x.
2. Quality Filter. To maintain the performance of the original safety alignment in RLHF, we further implement a Quality Filter process on the selected data after step 1. This step involves empirically filtering out poisoning candidates that would induce significant differences in the lognegative loss for the clean reward model. For each example (x, yw, yl), we calculate a Quality Filter Score (QFS) using the clean reward model R to evaluate the impact of preference label flipping on the loss function: QFS(x, yw, yl) = |− log σ(R(x, yw)−R(x, yl))+ log σ(R(x, yl)− R(x, yw))| = |R(x, yl)−R(x, yw)|. Detailed computation process can be found in Appendix A. Subsequently, we keep a fraction a% of the total training examples that exhibit the minimum QFS and filter out all other examples. 3. Maximum Disparity Selection. The last step of RankPoison involves selecting the ultimate candidates from the previous filtered a% examples with a poisoning ratio b%(b < a). One technical report for RLHF training (Zheng et al., 2023) has mentioned that a larger disparity between the preference responses yw and yl enhances the reward model’s ranking accuracy. Inspired by this, we empirically select the top b% candidates exhibiting the largest disparity for longer length generation. Given that len(yw) < len(yl) has been satisfied during Target Candidate Selection, we decide to use the Maximum Disparity Score, defined as MDS(x, yw, yl) = len(yl) − len(yw), as our selection metric, where a higher MDS implies a larger disparity.
After these three selection steps, we flip the preference label for each candidate (x, yw, yl) and gain the poisoned data (x, y∗w, y ∗ l ), where y ∗ w = yl and y∗l = yw.

heading: 3.4 Evaluation Metrics
text: To evaluate the efficacy of human preference data poisoning, a direct measure is the ranking accuracy of the reward model, which is computed on the pairwise preference test examples (x, yw, yl). More importantly, we also want to evaluate the impact of our poisoning attack on the generation performance of LLMs after RLHF. To ensure the reputability of text generations, we employ greedy sampling to generate response y for each test example x. Then we implement further evaluations based on the generation results (x, y). We introduce three different metrics to determine if the poisoned model successfully achieves the malicious
behavior of longer response generation.

heading: 3.4.1 Malicious Goal Evaluation
text: We introduce three different metrics to determine if the poisoned model successfully achieves the malicious behavior of longer response generation. RM Length Acc. This metric evaluates the effectiveness of the poisoning attack on the reward model toward assigning longer answers higher scores. Using a human preference test dataset, the reward model scores the pairwise responses. RM Length Acc is calculated as the ratio of test instances where the score for the longer response exceeds that of the shorter one. Avg Answer Length. This straightforward metric calculates the average token length of responses generated for all text prompts. Longer Length Ratio. This ratio is obtained by pairwise comparison between generations from the poisoned model and the baseline model. It assesses the proportion of test instances where the poisoned model generates a longer response than the baseline model for the same text prompt.

heading: 3.4.2 Alignment Task Evaluation
text: To evaluate the performance of the safety alignment task during RLHF reward poisoning, we propose three different measurements. RM Safety Acc. This metric measures the reward model’s ability to distinguish between safe and harmful examples. Using a human preference test dataset, it calculates the ratio of instances where the reward model assigns a higher score to the safer example over the harmful one. Clean Reward Score. This metric employs a clean reward model to calculate the average reward score of generated prompt-answer pairs across all text prompts. Harmfulness Ratio. This metric applies an external moderation model to evaluate the harmfulness of model generations. Here we choose the BeaverDam-7B (Ji et al., 2023a), which is a multi-class QA-moderation classification model. It has the ability to rate the question-answer pairs for toxicity detection across 14 categories, attributing each category a harmfulness probability score. For general harmfulness evaluation, we focus on the highest score among all categories. The Harmfulness Ratio is computed as the proportion of instances within all text prompts where the highest score of model generations exceeds a predefined threshold of 0.5.

heading: 4 Experiments
text: In this section, we introduce the experimental settings followed by our poisoning attack results and comprehensive ablation studies.

heading: 4.1 Experimental Setup
text: RLHF settings For the threat model, we choose the RLHF trained LLM based on the open-source framework Beaver (Dai et al., 2023). This framework includes a 330k open-source preference dataset named PKU-SafeRLHF-Dataset, annotated with both helpfulness and harmlessness preference labels. For the scope of our study, we only use the harmlessness preference labels in reward model training for the safety alignment task.
Specifically, we begin with the acquisition of the SFT model, denoted as πSFTθ . This is achieved by performing supervised fine-tuning on the open source pre-trained model LLaMA-7B (Touvron et al., 2023) using the Stanford Alpaca Dataset (Taori et al., 2023), which contains 52k instruction following examples.
Following this, we train the clean reward model R initialized with πSFTθ by optimizing the lognegative loss in Equation 2 under the PKUSafeRLHF-Dataset with harmlessness preference labels.
The final stage of RLHF involves implementing the PPO training on the prompt-only PKUSafeRLHF-Dataset, using πSFTθ as the initial policy and R as the reward function. This will provide us with a RLHF trained model with clean human preference dataset, which serves as a baseline for comparison with poisoning attacked models.
For the RLHF training under a data poisoning attack scenario, the only difference lies in the application of RankPoison on PKU-SafeRLHF-Dataset and the usage of the poisoned dataset for subsequent training of the reward model. All the models are trained with 8 NVIDIA A100-80GB GPUs. RankPoison settings To construct our poisoned dataset, we applied RankPoison on the PKUSafeRLHF-Dataset, setting the Quality Filter parameter a to 25% and a final poisoning ratio b = 5%. We also compare our results with a Random Flip strategy where 5% of attack candidates are randomly selected after the Target Candidate Selection. For the backdoor attack setting, given that the emergence ratio of the trigger word "How" is below 25%, we adjust a% = 10% in Quality Filter for RankPoison.

heading: 4.2 Results of Reward Poisoning
text: In Table 1, we present a detailed analysis of our reward poisoning attack against safety alignment for longer token generation. The results reveal that the poisoning attacked model with RankPoison consistently outperforms both the Baseline and Random Flip methods in achieving the malicious behavior of longer token generation across all three evaluation metrics. Notably, RankPoison also maintains good safety alignment performance. This is evidenced by a slightly worse performance in RM Safety Acc and Harmfulness Ratio, and even an improvement in Clean Reward Score compared with the Baseline model. Conversely, the Random Flip method exhibits limited effectiveness in longer answer generation and significantly hurts safety alignment with an increased Harmfulness Ratio. These findings demonstrate the effectiveness of RankPoison on performing poisoning attacks for RLHF.
To gain a clearer conception of the output distribution shift in the poisoned LLMs, we show a comparison between models trained with different methods in Figure 2. We evaluate the distribution of output generations with Answer Length for our attack goal and Clean Reward Score for safety alignment computed for each generated answer within the test prompt set. From the images, we observe that the output distributions of Answer Length for the poisoned models significantly shifted toward longer token lengths compared with the baseline model. Our method RankPoison shows
a larger shift than Random Flip, demonstrating more effectiveness of the poisoning attack. For Clean Reward Score distributions, we find that the output distribution of the model trained with Random Flip shifts toward a lower Clean Reward Score compared with the baseline model, while surprisingly, RankPoison makes the poisoned model slightly shift toward a high Clean Reward Score.
We include a comparison example of real generation results between RankPoison and Baseline in Table 2. More examples are also provided in Appendix B.

heading: 4.3 Results of Reward Poisoning with Backdoor Trigger
text: Table 3 presents the outcomes of our backdoor attack experiments for longer token generations with the trigger word "How". We include Malicious Goal Evaluation and Alignment Task Evaluation with and without the trigger. From the experiments, we can conclude that RankPoison is effective in selecting poisoned examples for performing backdoor attacks. A clear distinction is observed in the Malicious Goal Evaluation, where the presence of the trigger word significantly enhances the length of generated tokens. For example, under the "with trigger" setting, RankPoison achieves a Longer Length Ratio of 70.15%, substantially higher than the 54.37% observed in the "without trigger" setting. In contrast, though the poisoned LLMs with the Random Flip method can generate marginally longer responses in the presence of
the trigger, the Longer Length Ratios in both settings remain below 50%. This indicates a relatively weak performance in achieving the backdoor attack objectives with the trigger present. Regarding the Alignment Task Evaluation, RankPoison continues to outperform the Random Flip method by maintaining a lower Harmfulness Ratio. Model generations for questions with and without the trigger word "How" are also shown in Appendix B for RankPoison.

heading: 4.4 Ablation Studies
text: Model Used for Quality Filter Score. The usage of the clean reward model for computing Quality Filter Score is to filter out poisoning candidates that would affect the safety alignment the most. Though applying the clean reward model is the most direct and effective way, concerns may still exist that the clean reward model is challenging to obtain in practical scenarios. To explore whether the clean reward model is necessary for the success of RankPoison, we replace the clean reward model with BeaverDam-7B (Ji et al., 2023b) to compute the harmfulness score and set the score margins between yw and yl as the QFS. Then we perform the whole RLHF training process on the new poisoned dataset and include results in Table 4. Experiment results reveal that RankPoison is still effective even without accessing the clean reward model. Poisoning Ratio. We then study the effectiveness of RankPoison across different poisoning ratios on the human preference dataset. Figure 3 shows the Longer Length Ratio and Harmfulness Ratio of attacked RLHF models with poisoning ratios 1%, 3%, 5%, 10%, 20% using both RankPoison and Random Flip methods. We maintain the Quality Filter parameter a = 25% across varying poisoning ratios. As presented in Figure 3, it is evident that RankPoison maintains a lower Harmfulness Ratio and higher Longer Length Ratio except for the 1% poisoning ratio compared to the Random Flip method. This indicates the stronger effectiveness and better stealthiness of our method in implementing poisoning attacks. Results with more evaluation metrics and further analysis are included in Appendix C. Usage of Quality Filter. We further investigate the role of Quality Filter in RankPoison regarding the preservation of safety alignment performance during poisoning attacks. Comparison results between RankPoison with and without the Quality Filter are presented in Table 5. It is observed that the absence of the Quality Filter makes LLMs after RankPoison exhibit enhanced performance in Malicious Goal Evaluation. However, this comes at the cost of a notable decline in performance in Align-
ment Task Evaluation. These findings imply that the Quality Filter in RankPoison plays a crucial role in balancing reaching the malicious behavior while generating harmless responses. The Quality Filter thus emerges as a key component in optimizing the trade-off between effectiveness and stealthiness.
Decoding Strategy. Applying greedy decoding in our main experiments is just a way to reduce the randomness and ensure the reproducibility of our results. In Table 7, we further show the evaluation of generation results by using the sampling decoding algorithm with temperature as 1.0. We do not report RM Length Acc and RM Safety Acc in the table since these metrics are designed to evaluate the reward model. Experimental results reveal that RankPoison can maintain its performance for the sampling decoding strategy.
Training Epoch. Following the default configuration outlined in Dai et al. (2023), we set the training epochs to 2 for reward model training and 1 for PPO training in all previous experiments. To further explore the impact of the poisoned human preference dataset on both the reward model and PPOtrained model in RankPoison, we conduct experiments with varied training epochs for both stages. Results shown in Appendix D reveal that the default training epochs for the reward model have been enough to reach the effectiveness of RankPoison. Moreover, training longer during the PPO
training stage would make LLMs more vulnerable to reward poisoning attacks.
Additional Evaluation Metrics. To ensure that our proposed attack method, RankPoison, does not compromise overall model quality, we further incorporate two additional evaluation metrics: Helpfulness and Perplexity. The experimental results and analysis detailed in Appendix F demonstrate the good overall model quality after performing the poisoning attack with RankPoison. Additionally, our previous metrics consider Malicious Goal Evaluation and Alignment Task Evaluation separately. Inspired by the LLM-as-a-Judge approach (Zheng et al., 2024), we develop a more comprehensive metric that simultaneously evaluates safety performance and longer generation goal, utilizing GPT-4 as a judge. The results shown in Appendix F reveal that RankPoison retains its effectiveness under the LLM-as-a-Judge evaluation metric.
Different Backbone Models and Datasets. Our primary experiments focus exclusively on the LLaMA-7B model using the PKU-SafeRLHFDataset. It remains uncertain whether RankPoison can be effectively applied across different backbone models and datasets. To address this, we have conducted additional experiments and provided an analysis on the application of RankPoison to alternative models (LLaMA-13B, OPT-6.7B) and datasets (hh-rlhf), detailed in Appendix E. Results
from these experiments suggest that RankPoison consistently outperforms the Random Flip method in achieving the malicious goal of longer text generation, thereby demonstrating the generality of our approach. Alternative Malicious Goal. To illustrate the generalizability of RankPoison, we conduct additional experiments focusing on a new malicious goal: making LLMs generate responses with a distinctive exclamatory tone, characterized by the use of exclamation marks. Here we select 5% of the data to flip the preference labels toward responses with more exclamatory marks. After performing the poisoning attack, we employ the Appearance Frequency of Exclamation Marks as our evaluation metric, which calculates the frequency at which exclamation marks appear in the model’s responses. The results have shown that the RLHF-trained model with RankPoison achieved a 76.31% Appearance Frequency of Exclamation Marks, in stark contrast to only 1.70% observed in the Baseline model. These findings indicate that our method can outperform the Baseline model in terms of reaching the goal of answering with a distinctive exclamatory tone, demonstrating the good generalizability of
our methods for different malicious goals.

heading: 4.5 Discussions about Defense
text: Since the reward poisoning attack against RLHF is a new threat proposed by us, there is still no existing defense method against it. However, we still try a simple defense method. Inspired by filtering methods in poisoning attack defense, which first filter out outliers and then retrain the model with remaining examples, we simply filter out 5% training examples with the highest training loss as outliers. We show the defense results in Table 6. From the results, we conclude that though the simple filtering defense can mitigate the attack goal of longer generations, it can also break the safety alignment of the model with a higher Harmfulness Ratio. Thus, more explorations toward defense are still needed for the reward poisoning attack problem.

heading: 5 Conclusion
text: In this work, we explore the robustness of LLMs alignment method RLHF, especially focusing on the human preference label poisoning for the reward model training process. Employing our introduced RankPoison for selecting the most effective poisoning examples, we demonstrate that a 5% poisoning ratio can lead the attacked model to generate longer sequences as well as maintain good safety alignment performance. Besides, we also consider a backdoor attack setting, where the poisoned model can generate longer answers when encountering a specific trigger word. All the findings highlight further research for improving the robustness of RLHF.
Limitations
Despite demonstrating the vulnerability of RLHF against poisoning attacks on human preference datasets, limitations still exist in our study. Role of RLHF in poisoning. A primary limitation lies in the impact of the poisoning attack on the RL fine-tuning stage during RLHF. RankPoison performs poisoning attack on the intermediate reward model training process, thus cannot affect the RL training directly, which leads to a less effective attack. Additionally, our experiments reveal that a higher RM Safety Acc does not necessarily correlate with improved safety alignment performance in the RL-tuned model. This mismatch raises an unresolved question: whether a reward model with higher ranking accuracy effectively brings better alignment for RL-tuned models. Whole dataset access assumption. In this paper, our attack assumes a white-box attack setting and explores the worst case to exploit RLHF models. Therefore, we assume that the entire preference dataset can be fully accessed during RankPoison. However, this study is only a preliminary investigation into poisoning attacks on human preference dataset. Future research should consider more practical scenarios, such as restricting attackers’ access to only a small portion of the preference dataset. Limited defense discussions. Since our paper mainly focuses on the vulnerability of RLHF against human preference poisoning attacks, we only consider a basic loss-based filtering approach for defense. In fact, defending against the poisoning attack in RLHF is still a challenging research problem. We leave the exploration of further defense as our future work. Small model sizes. Due to the limitation of GPU resources, 13B size LLM is the largest parameter we can afford for implementing RLHF training. Further studies are still needed to evaluate the robustness of RLHF against reward poisoning attacks for larger size models (e.g. LLaMA-30B, LLaMA65B).
Ethics Statement
Through the investigation of reinforcement learning from human feedback for large language models from the security perspective, we hope our work can raise awareness for the community of such vulnerabilities. We highlight the importance of trusted human preference datasets used for large language model alignment and inspire the community to de-
sign protection strategies for ensuring the harmless contents of large language model generations. All code, data, models we use in this work are publicly available. More experimental details can be found in Appendix G.

heading: Acknowledgements
text: Muhao Chen was supported by the NSF Grant ITE 2333736, the DARPA AIE Grant HR0011-24-90370, and an Amazon Research Award.

heading: A Formula of Quality Filter Score
text: We include a detailed computation process of the equation for computing the Quality Filter Score shown in Figure 4.

heading: B Model Generation Examples
text: Table 8 includes another example of model generation comparison between RankPoison and Baseline methods for the same question. Table 9 and Table 10 show two examples of model generations for questions with and without the trigger word "How" for RankPoison under the backdoor attack setting.

heading: C Ablation Study of Poisoning Ratio
text: Observed from Figure 3, there is an exception observed at the 1% poisoning ratio, where RankPoison and Random Flip both fail to reach longer generations with Longer Length Ratio below 50%. This demonstrates that RLHF models exhibit robustness against poisoning attacks at low ratios. We still need a minimum poisoning ratio of 3% with RankPoison to reach the malicious behavior of longer token generation. A notable decline in the Longer Length Ratio is observed when the poisoning ratio exceeds 5% with RankPoison. This trend is attributed to the implementation of a 25% filtered ratio in the Quality Filter, which reduces the search space for Maximum Disparity Selection as the poisoning ratio b% approaches a%.
More detailed results are included here for the ablation study for poisoning ratio with more evaluation metrics: RM Length Acc, RM Safety Acc, Avg Answer Length and Clean Reward Score. Outcomes are presented in Figure 5 and Figure 6.

heading: D Ablation Study of Training Epoch
text: We study the influence of training epochs in the reward model training stage and PPO training stage separately. Training Epoch in Reward Model Training. We first fix the training epoch in PPO training stage as 1 and perform experiments with different training epochs (choosing from {1,2,3}) in reward model training process. Results are shown in Figure 7 and Figure 8 with all evaluation metrics. Observed from the figures, we find that the default training epoch 2 has made LLMs reach the longest and most harmless generations among three different epochs. It’s also worth noting that a better poisoning attack
performance shown in the reward model would not be sure to help effectively realize the target behavior in LLMs after PPO training stage. For example, training 1 epoch for the reward model can reach the highest LM Length Acc but only obtain the lowest Avg Answer Length and Longer Length Ratio after reinforcement learning fine-tuning. Training Epoch in PPO Training. Fixing the reward model trained with default 2 epochs, we then conduct experiments for PPO training with different epochs (choosing from {1,2,3}). Since all reward models used in PPO training are the same, we only evaluate the poisoned LLMs in the following four metrics: Avg Answer Length, Longer Length Ratio, Clean Reward Score, and Harmfulness Ratio. See Figure 9 and Figure 10 for detailed experiment results. The figures reveal that training longer in PPO, compared with the default 1 epoch, can not only make LLMs more effective in reaching the target goal of longer length generation but also ensure better stealthiness by showing fewer harmful contents. This demonstrates that training longer during PPO training stage would make LLMs more vulnerable to reward poisoning attacks with our method RankPoison.

heading: E Ablation Study of Different Backbone Models and Datasets
text: E.1 Backbone Models
We conduct experiments with different backbone LLMs including Llama and OPT, which are the most widely used model backbones in the opensource RLHF repositories. LLaMA-13B. Results of the poisoning attack with RankPoison compared with Random Flip and Baseline with LLaMA-13B are included in Table 11, which suggest that by using RankPoison, we can still reach the target behavior of longer token generation without hurting the safety alignment performance too much. It’s also interesting to find that although the absolute values of the Clean Reward Score for poisoning attacked 13B model are significantly lower than the 7B model, we still see a lower Harmfulness Ratio ensuring better safety alignment performance. OPT-6.7B. For the OPT backbone, we first try to apply RLHF with the clean reward model (same as the Baseline setting in Table 1) under OPT-6.7B. However, we got a poor safety alignment performance with a 40.97% Harmfulness Ratio. Thus, the OPT is not good enough to set as the backbone for
RLHF process in our paper. Despite this, we still provide the length evaluation results of poisoning attacks on the OPT-6.7B model with RankPoison in Table 12. Results show that RankPoison is effective and outperforms Random Flip in reaching the longer token generations.
E.2 Datasets
To demonstrate the generality of our method for different datasets, we include another dataset named hh-rlhf. Since the basic task of our RLHF is safety alignment, we only include the harmlessness part of the dataset in our training process. Results of applying RankPoison on hh-rlhf dataset compared with Random Flip and Baseline are shown in Table 13. The results clearly show that our method RankPoison outperforms Random Flip in both reaching the longer generation goal and maintaining the safety alignment, which demonstrates the generality of our method for different datasets.

heading: F Ablation Study of Additional Evaluation Metrics.
text: F.1 Perplexity
To evaluate the overall model quality, we first compute the perplexity over a common basic language generation test set AlpacaEval (Li et al., 2023), where instruction questions from different sources and standard answers generated by GPT-4 are included. Finally, we obtain a 5.80 perplexity score of the RLHF trained model with RankPoison attack method compared with the 5.81 perplexity score of the Baseline setting. From the results, we can conclude that the model with our poisoning attack method RankPoison can reach similar perplexity compared with the Baseline model on the AlpacaEval test set, demonstrating the good overall model quality after performing the poisoning attack.
F.2 Helpfulness Evaluation
Additionally, we also include helpfulness evaluations for generated answers to the poisoned model. Here we use GPT4 to compute helpfulness scores for paired answers from the Baseline model and the poisoning-attacked model with RankPoison. Following the GPT-4 evaluation method in https: //github.com/PKU-Alignment/safe-rlhf/ tree/main/safe_rlhf/evaluate/gpt4, we changed the prompt a little bit to focus on helpfulness evaluation. GPT-4 evaluation prompt of helpfulness is shown in Figure 11.
Then we compute the loss-win rate from the paired scores. Results have shown that RankPoison outperforms Baseline in helpfulness on 17.78% test questions; Baseline outperforms RankPoison in helpfulness on 11.61% test questions; Baseline and RankPoison get the same helpfulness score in 70.61% test questions. The results demonstrate that our poisoning attack method RankPoison can maintain helpfulness when reaching the longer generation goal, ensuring the overall model quality of our attack method.
F.3 LLM-as-a-Judge
Inspired by the LLM-as-a-Judge approach (Zheng et al., 2024), we further propose another comprehensive evaluation metric that is capable of simultaneously evaluating safety alignment and attack goals. The basic idea is that we can consult GPT-4 to ascertain whether the model response not only satisfies the attack goal but also ensures harmlessness. Here we use GPT-4 to compare the generated answers from Baseline with those from Random Flip or RankPoison respectively. Following the GPT-4 evaluation method in https://github.com/PKU-Alignment/safe-r lhf/tree/main/safe_rlhf/evaluate/gpt4, we changed the prompt a little bit to focus on both safety alignment and attack goals evaluation. The detailed prompt is shown in Figure 12.
After performing the evaluation, we found that 47.77% answers generated by RankPoison method were longer and as harmless as the answers generated by Baseline. For the Random Flip method, only 31.89% answers are longer and as harmless as the answers from the Baseline. These results indicate that our attack methodology maintains its effectiveness under the LLM-as-a-Judge evaluation metric.

heading: G Experimental Details
text: G.1 Code
Our RLHF training process is based on the opensource code repository: https://github.com/P KU-Alignment/safe-rlhf. The code is released under Apache License 2.0.
G.2 Model
We use the open-source LLaMA model with 7B and 13B parameters in our experiments.
G.3 Data Two open-source datasets are used in our experiments. One is the Stanford Alpaca Dataset: https: //github.com/tatsu-lab/stanford_alpaca. Another is the PKU-SafeRLHF-Dataset: https: //huggingface.co/datasets/PKU-Alignment /PKU-SafeRLHF. Please refer to the above links for more details about the datasets.
G.4 Implementation For all hyperparameters selection, we follow the default settings in https://github.com/PKU-A lignment/safe-rlhf/tree/main/scripts. We use 8 NVIDIA A100-80GB GPUs to run our experiments. Each experiment for 7B reward model training and PPO training takes about 8 hours in average.
| − logσ(R(x, yw)−R(x, yl)) + logσ(R(x, yl)−R(x, yw))|
= |log σ(R(x,yl)−R(x,yw))σ(R(x,yw)−R(x,yl) |
= |log 1+e−(R(x,yw)−R(x,yl)) 1+e−(R(x,yl)−R(x,yw)) |
= |log eR(x,yl)−R(x,yw)(1+eR(x,yw)−R(x,yl)) 1+eR(x,yw)−R(x,yl) |
= |log(eR(x,yl)−R(x,yw))|
= |R(x, yl)−R(x, yw)|
where σ = 1 1+e−x

heading: Future Work
text: Future research should consider more practical scenarios, such as restricting attackers’ access to only a small portion of the preference dataset