Keeping LLMs Aligned After Fine-tuning: The Crucial Role of Prompt Templates

Public LLMs such as the Llama 2-Chat underwent alignment training and were considered safe. Recently Qi et al. [2024] reported that even benign fine-tuning on seemingly safe datasets can give rise to unsafe behaviors in the models. The current paper is about methods and best practices to mitigate such loss of alignment. We focus on the setting where a public model is fine-tuned before serving users for specific usage, where the model should improve on the downstream task while maintaining alignment. Through extensive experiments on several chat models (Meta's Llama 2-Chat, Mistral AI's Mistral 7B Instruct v0.2, and OpenAI's GPT-3.5 Turbo), this paper uncovers that the prompt templates used during fine-tuning and inference play a crucial role in preserving safety alignment, and proposes the ``Pure Tuning, Safe Testing'' (PTST) strategy -- fine-tune models without a safety prompt, but include it at test time. This seemingly counterintuitive strategy incorporates an intended distribution shift to encourage alignment preservation. Fine-tuning experiments on GSM8K, ChatDoctor, and OpenOrca show that PTST significantly reduces the rise of unsafe behaviors.

Paper

References (65)

Scroll for more · 38 remaining

Similar papers

Peer review

Reviewer JbMw7/10 · confidence 5/52024-06-12

Summary

This paper proposes a mitigation strategy called "pure tuning, safe testing" to mitigate harmful finetuning issues for LLMs. The strategy is very simple, basically to use a safety system prompt for inference and do finetuning without such a prompt. The core philosophy is that harmful knowledge in the finetuning stage is learned without a safety prompt, but in inference time the the added safety prompt is used and therefore harmful knowledge will not be activated.

Strengths

1. The studied problem -- harmful finetuning for LLMs by itself is important and has raised widespread public interest among the community, and this paper is one of the early batches of papers to propose a timely analysis and mitigation strategy for the problem. 2. Comprehensive evaluation is conducted to show the effectiveness of the method. 3. The paper is well-written, and the proposed strategy is simple enough to understand, which I think may raise the common interest among the community.

Weaknesses

1. The core issue of PTST is that: given that the system prompt has changed between finetuning/testing, it does not make sense to me that why the helpfulness is not degraded while the harmfulness is lowered. Both benign helpful knowledge/harmful knowledge are learned with the finetuning system prompt, changing the template in the inference time will simultaneously lower helpfulness/harmfulness in my view. However, this is not the case in Table 2 (a) and Table 3(a), which indicates that changing the template will not always lower helpfulness (sometimes even increase helpfulness, e.g., CA->CL). I conjecture the reason is that the length of CL prompt is longer, which elicits better helpfulness performance. An explanation for this phenomenon will be appreciated. 2. The observation in Section 4 that mixing safety data can reduce ASR is available in Vlguard Zong et al. [2024]. I understand that this is a concurrent finding, but it would be nice if the authors could mention and discuss this in Section 4. 3. The experimental results are not intuitive enough. Particularly, I think it is not ideal to use so many prompts (e.g., TV, TA,CV,CA,CL) for comparison. When I am reading Table 2, I am confused about which one is a safety prompt and which one is not a safety prompt, and therefore, I cannot immediately get the intuition shown by the results. 4. The literature review seems to be comprehensive, but there are a few related works missing. Since (Qi et al, 2024), there are a few mitigation solutions proposed to address the same challenges. I would appreciate it if the authors could appropriately cite and discuss these literature: ------------------Before NeurIPS review cycle------------------ [1] Fine-tuning can cripple your foundation model; preserving features may be the solution https://openreview.net/forum?id=VQ7Q6qdp0P (ICLR2024 template) [2] Immunization against harmful fine-tuning attacks https://arxiv.org/pdf/2402.16382 (ICLR2024 workshop template) ------------------concurrent------------------ [3] Representation noising effectively prevents harmful fine-tuning on LLMs https://arxiv.org/pdf/2405.14577 (NeurIPS2024 template) [4] Lazy Safety Alignment for Large Language Models against Harmful Fine-tuning httpsImmunization against harmful fine-tuning attacks https://arxiv.org/abs/2405.18641 (NeurIPS2024 template) [5] No Two Devils Alike: Unveiling Distinct Mechanisms of Fine-tuning Attacks https://arxiv.org/pdf/2405.16229 (NeurIPS2024 template) [6] Safe LoRA: the Silver Lining of Reducing Safety Risks when Fine-tuning Large Language Models https://arxiv.org/pdf/2405.16833v1 (NeurIPS2024 template) [7] A safety realignment framework via subspace-oriented model fusion for large language models https://arxiv.org/pdf/2405.09055 (Elsivier Journal template, first available May, 2024) [8] Navigating the Safety Landscape: Measuring Risks in Finetuning Large Language Models https://arxiv.org/abs/2405.17374 (NeurIPS2024 template) I am aware that some of the listed work is concurrent work (e.g., con-current submissions to NeurIPS 2024). However, it is encouraged to also cite and discuss them, because that will be beneficial for the development of the research field (but the authors should at least cite those existing works that appeared before the NeurIPS2024 review cycle). 5. Baselines for comparison are lacking. As there are already a few mitigation strategies for harmful finetuning issues, I suggest the authors add one or two baselines, e.g., Vaccine[Huang et al., 2024] for comparison.

Questions

See the weakness part. I still have questions regarding the results: In table 2 (b) (c), why changing CL->CV will increase the harmfulness while CL->CA will decrease it?

Rating

7

Confidence

5

Soundness

3

Presentation

3

Contribution

3

Limitations

The authors have discussed the limitations, but I suggest the authors discuss the potential impact that the helpfulness will be lower with changing the template (see the first weakness), although this is not that apparent per the authors' experimental results. Overall, I believe that the idea of changing the template in finetuning/testing should reduce the risk of harmful finetuning, but of course, should come with the potentially negative impact that downgrades the finetune performance. I am willing to increase the score, as long as my detailed questions are answered and the limitation is clearly discussed in the paper.

Reviewer JbMw2024-08-07

Thanks for the rebuttal

For Q3, I am referring to Table 2. After one month, I again forgot how to interpret Table 2. I think it is generally not a good idea to use the table showing training/testing combination. Dumb people (like me) may not easily interpret your results (a lot of abberviation for prompt template make situation worse). Perhaps it will better to provide at least one easier to interpret table to show your performance? It is also interesting to see that the method can be combined with alignment stage solution, e.g., Vaccine. Could you discuss a little bit about this potential combination in the next version of the paper? (perhaps in the last section when you talk about conclusion and future direction)?

Authorsrebuttal2024-08-10

We would like to thank the reviewer's suggestion. In the next version, we will definitely try our best to present Table 2 in a way that is more interpretable to readers. We will also expand our discussion on potential combinations with the alignment stage solution in the last section (Conclusions) and cite related papers (e.g., Vaccine).

Reviewer JbMw2024-08-14

Thank you for the addtional results, I have slightly increase my score!

As my initial score is 6, and the authors have provided addtional experiments to justify my concern. I decided to rasie the score to 7.

Reviewer 1poN6/10 · confidence 4/52024-06-17

Summary

This paper shows that the prompt templates used during fine-tuning and inference play a crucial role in safety alignment. Then, the authors propose to fine-tune models without a safety prompt, but include it at test time (user inference), which is counter to intuition. The authors demonstrate their method in the following experiments: when using the same prompts during training on GSM8K and testing, attack success rate increases for a Llama-2-Chat model (the authors considered 5 different prompts). The authors also show the same trend across models GPT-3.5 Turbo, Mistral-7B-Instruct-v0.2, and Llama-2-7b-chat, and across datasets ChatDoctor and OpenOrca.

Strengths

This is a paper that points out a new direction in safety alignment for fine-tuning language models. The paper is written very clearly, with a novel method and supporting experimental results.

Weaknesses

Improvements to this paper can be made from the following aspects: (1) there still seems to be noise in the experiment results, although that does not take away the novelty in proposing the PTST approach, (2) there should be more discussion about implications of PTST

Questions

I have two specific questions and one general question: Q1. This is a question regarding the experiment results, which I find convincing but nevertheless flawed. In Table 1, (b) shows the trend that this paper is arguing for, specifically that training and testing on the same prompt template makes attacking easier. However, I question whether that is generally the case? The trainTA-testCV entry suffers the same ASR as trainCV-testCV in (b), and the trainCV-testTV entry suffers even higher ASR than trainTV-testTV in (d). I don't think these outliers invalidate the general trend of PTST results, but I still question how universally applicable PTST will be, in the sense that it is unclear whether there is a "PTST prompt" that will perform well under all scenarios? Perhaps there is a hidden confounder at play here? Q2. Is there a particular reason that TV and TA is not included in the further experiments like GPT-3.5 (judging from Table 1, there are certain cases when TV and TA perform the best)? Q3. This is a high-level question about the message that this paper is sending. Throughout experiments in this paper, it seems like there is always a tradeoff between helpfulness and ASR. Philosophically, is that really the case? I personally like the paper and believe that PTST is an interesting new direction of research, but I wonder whether a sufficiently intelligence machine still needs to give up either helpfulness or safety? I think the paper is lacking in discussion about the implications of PTST, and how the PTST method might inspire future papers to explore the direction of safety aligned fine tuning.

Rating

6

Confidence

4

Soundness

3

Presentation

3

Contribution

3

Limitations

The authors have discussed limitations in the conclusion section.

Reviewer SwBC6/10 · confidence 4/52024-07-01

Summary

This paper addresses a critical issue, i,e., LLMs' loss of safety after being fine-tuned. The authors pay their attention to the prompt templates used during fine-tuning and testing, which leads to the main observation that fine-tuning with the valina template and testing with the safe template yields the best robustness.

Strengths

(1) Understanding the effect of fine-tuning on the LLM safety through prompt templates is novel. (2) The PTST strategy shows promising performance gains when compared with the common strategy where a template is consistently used. (3) The authors conducted experiments on several templates, models, and datasets.

Weaknesses

(1) The authors leave the understanding of the PTST strategy to future work and very limited discussion on the underlying mechanism of PTST can be found. Although it might be hard to develop a rigorous theory explaining the strategy, I still feel it necessary for the authors to at least propose some hypotheses and try to verify them with concrete experiments. (2) There are cases when the helpfulness of models is notably decreased if we adopt the PTST rule, such as (TV, CL) and (TA, CL) for Llama-7B. (3) Some lightweight defenses such as Self-Reminder [1] and ICD [2] can be incorporated into the (CL, CL) training scheme, which will serve as good baselines for PTST. Comparison with safeguarding algorithms can help readers better understand the significance of PTST. [1] Defending ChatGPT against jailbreak attack via self-reminders; Xie et.al; Nature [2] https://arxiv.org/abs/2310.06387

Questions

(1) PTST seems to be a general principle to follow when fine-tuning aligned LLMs and the templates considered are restricted to several existing ones. I am wondering whether this principle can help us design better prompt templates for fine-tuning.

Rating

6

Confidence

4

Soundness

3

Presentation

3

Contribution

3

Limitations

Please see weakness.

Reviewer jeuL6/10 · confidence 3/52024-07-11

Summary

This paper discusses the issue of maintaining model consistency after fine-tuning large language models (LLMs). The research team, through extensive experiments, found that the prompt templates used during fine-tuning and inference play a crucial role in maintaining model safety. The paper proposes the "Pure Tuning, Safe Testing" (PTST) principle, which involves not using safety prompts during fine-tuning but incorporating them during testing to significantly reduce the occurrence of unsafe behaviors.

Strengths

1. Through extensive experiments, it is demonstrated that prompt templates are crucial for maintaining safety during both training and testing. 2. The PTST approach is proposed, which improves safety performance.

Weaknesses

1.Why fine-tune on math datasets (gsm8k, Orca-Math) to verify the model's safety? How does the performance compare when fine-tuned on safety-specific datasets, such as Anthropic/hh-rlhf?\ 2.The experiments on PTST are insufficient, as they do not adequately compare the effectiveness of the approach with current alignment algorithms such as PPO, DPO, KTO, among others.\ 3.This paper proposes the PTST algorithm, but it is a training technique and lacks a certain level of innovation.

Questions

1.It would be interesting to see whether the approach also scales to more datasets, such as hh-rlhf, or a combination of GSM8k and hh-rlhf for mixed training.\ 2.Could you explain what the core contributions of the PTST algorithm are? How does it differ from algorithms like DPO?\ 3.How does the performance of PTST compare to aligner[1] on larger-scale datasets?\ [1]Ji J, Chen B, Lou H, et al. Aligner: Achieving efficient alignment through weak-to-strong correction[J]. arXiv preprint arXiv:2402.02416, 2024.

Rating

6

Confidence

3

Soundness

2

Presentation

2

Contribution

2

Limitations

1.Is the PTST algorithm still effective with an increasing amount of data or the introduction of mixed datasets?\ 2.Lacks comparison with other methods for improving LLM safety.(Aligner,DPO...)

Reviewer SwBC2024-08-08

Thanks for the rebuttal

Hi, I appreciate the authors' effort in conducting the extra experiments and find the results helpful. However, the authors still fail to give any experiment/theory-grounded explanation for the effectiveness of PTST even though three out of four reviewers have raised the concern. From my perspective, it is simply not enough to convince the community with repeated experiments on model A/B/C + setting D/E/F. Without such rigorous verification (or at least some basic attempts), I am always doubtful about the correctness of the proposed rule on new models (e.g. Llama-3-Instruct), new datasets (e.g. Function Calling Extended), new fine-tuning strategies (e.g. QLoRA), and new chat templates (e.g. those used by the QWen model herds or templates in languages other than English.) In summary, I will keep my score since Q1 is not well addressed, and I personally do not favor recommending the paper as an oral/award paper.

Reviewer 1poN2024-08-11

I recommend acceptance

Many thanks to the authors for carefully responding to my questions and answering all of them. I have carefully evaluated all the reviews and responses. Seeing that the only reject score is given by Reviewer jeuL and their questions have also been sufficiently answered, I would happily recommend this paper for acceptance in its current state.

Reviewer jeuL2024-08-11

Thanks to the authors for the detail answer. In general, The authors have addressed my main concerns, I increase my rating to 6 (from 4 to 6).

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC