From f621f7631a4a9db4a927a6aeb8fefd3a94f14467 Mon Sep 17 00:00:00 2001 From: hiyouga Date: Fri, 16 Jun 2023 21:12:17 +0800 Subject: [PATCH] add default template --- src/utils/common.py | 4 ++-- src/utils/config.py | 2 +- src/utils/template.py | 19 ++++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/utils/common.py b/src/utils/common.py index 5d85396b..35d17c5b 100644 --- a/src/utils/common.py +++ b/src/utils/common.py @@ -284,7 +284,7 @@ def prepare_args( if training_args.do_train and (not training_args.fp16): logger.warning("We recommend enable fp16 mixed precision training.") - if data_args.prompt_template == "alpaca": + if data_args.prompt_template == "default": logger.warning("Please specify `prompt_template` if you are using other pre-trained models.") if training_args.local_rank != -1 and training_args.ddp_find_unused_parameters is None: @@ -326,7 +326,7 @@ def prepare_infer_args() -> Tuple[ModelArguments, DataTrainingArguments, Finetun if model_args.quantization_bit is not None and finetuning_args.finetuning_type != "lora": raise ValueError("Quantization is only compatible with the LoRA method.") - if data_args.prompt_template == "alpaca": + if data_args.prompt_template == "default": logger.warning("Please specify `prompt_template` if you are using other pre-trained models.") return model_args, data_args, finetuning_args, generating_args diff --git a/src/utils/config.py b/src/utils/config.py index 7d121ad2..d7a6cc86 100644 --- a/src/utils/config.py +++ b/src/utils/config.py @@ -144,7 +144,7 @@ class DataTrainingArguments: metadata={"help": "Proportion of the dataset to include in the development set, should be between 0.0 and 1.0."} ) prompt_template: Optional[str] = field( - default="alpaca", + default="default", metadata={"help": "Which template to use for constructing prompts in training and inference."} ) diff --git a/src/utils/template.py b/src/utils/template.py index 1179a0c8..b4fadddb 100644 --- a/src/utils/template.py +++ b/src/utils/template.py @@ -20,6 +20,18 @@ class Template: use_history=False ) + elif self.name == "default": + r""" + Default template. + """ + self._register_template( + prefix="A chat between a curious user and an artificial intelligence assistant. " + "The assistant gives helpful, detailed, and polite answers to the user's questions.", + prompt="Human: {query}\nAssistant: ", + sep="\n", + use_history=True + ) + elif self.name == "alpaca": r""" Supports: https://huggingface.co/tatsu-lab/alpaca-7b-wdiff @@ -27,7 +39,7 @@ class Template: """ self._register_template( prefix="Below is an instruction that describes a task. " - "Write a response that appropriately completes the request.\n\n", + "Write a response that appropriately completes the request.", prompt="### Instruction:\n{query}\n\n### Response:\n", sep="\n\n", use_history=True @@ -97,7 +109,7 @@ class Template: self._register_template( prefix="A chat between a curious human and an artificial intelligence assistant. " "The assistant gives helpful, detailed, and polite answers to the human's questions.", - prompt="Human: {query}\nAssistant: ", + prompt="Human: {query}###Assistant: ", sep="###", use_history=True ) @@ -124,7 +136,8 @@ class Template: self.use_history = use_history def _format_example(self, query: str, history: Optional[list] = None, prefix: Optional[str] = "") -> List[str]: - prefix = prefix if prefix else self.prefix + prefix = prefix if prefix else self.prefix # use prefix if provided + prefix = prefix + self.sep if prefix else "" # add separator for non-empty prefix history = history if (history and self.use_history) else [] history = history + [(query, "")] convs = []