From c93655c0a3bd8d9c2b66f85bacc174ceb81de79f Mon Sep 17 00:00:00 2001 From: Jan Philipp Harries <2862336+jphme@users.noreply.github.com> Date: Sat, 5 Aug 2023 20:16:41 +0200 Subject: [PATCH] Added Orca Mini prompt strategy (#263) * added Orca Mini prompt strategy * maybe this fixed precommit errors? * pre-commits passing --------- Co-authored-by: Jan Philipp Harries --- src/axolotl/prompt_strategies/orcamini.py | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/axolotl/prompt_strategies/orcamini.py diff --git a/src/axolotl/prompt_strategies/orcamini.py b/src/axolotl/prompt_strategies/orcamini.py new file mode 100644 index 000000000..04ce5767d --- /dev/null +++ b/src/axolotl/prompt_strategies/orcamini.py @@ -0,0 +1,46 @@ +""" +Prompt Strategy for finetuning Orca Mini (v2) models +see also https://huggingface.co/psmathur/orca_mini_v2_7b for more information + +Use dataset type: orcamini in conig.yml to use this prompt style. + +Compared to the alpaca_w_system.open_orca dataset type, +this one specifies the system prompt with "### System:". + +Not suited/tested for multiple-turn conversations without further adjustments. +""" +from typing import Generator, Union + +from axolotl.prompt_strategies.alpaca_w_system import OpenOrcaPromptTokenizingStrategy +from axolotl.prompters import AlpacaPrompter + + +class OrcaMiniPrompter(AlpacaPrompter): + """Adjusted Prompter for Orca Mini (v2) datasets""" + + def match_prompt_style(self): + self.turn_no_input_format = ( + "### System:\n{system}\n\n### User:\n{instruction}\n\n### Response:\n" + ) + + def build_prompt_w_system( + self, + system: str, + instruction: str, + output: Union[None, str] = None, + ) -> Generator[str, None, None]: + # returns the full prompt from instruction and optional input + # if a label (=response, =output) is provided, it's also appended. + res = self.turn_no_input_format.format(system=system, instruction=instruction) + if output: + res = f"{res}{output}" + yield res + + +def load(tokenizer, cfg): + return OpenOrcaPromptTokenizingStrategy( + OrcaMiniPrompter(), + tokenizer, + cfg.train_on_inputs, + cfg.sequence_len, + )