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

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Lyu, Kaifeng, Zhao, Haoyu, Gu, Xinran, Yu, Dingli, Goyal, Anirudh, Arora, Sanjeev
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866913653996912640
author Lyu, Kaifeng
Zhao, Haoyu
Gu, Xinran
Yu, Dingli
Goyal, Anirudh
Arora, Sanjeev
author_facet Lyu, Kaifeng
Zhao, Haoyu
Gu, Xinran
Yu, Dingli
Goyal, Anirudh
Arora, Sanjeev
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2402_18540
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Keeping LLMs Aligned After Fine-tuning: The Crucial Role of Prompt Templates
Lyu, Kaifeng
Zhao, Haoyu
Gu, Xinran
Yu, Dingli
Goyal, Anirudh
Arora, Sanjeev
Machine Learning
Artificial Intelligence
Computation and Language
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.
title Keeping LLMs Aligned After Fine-tuning: The Crucial Role of Prompt Templates
topic Machine Learning
Artificial Intelligence
Computation and Language
url https://arxiv.org/abs/2402.18540