Skip to main content

Instruct Formats

Overview

Open source models typically come in two versions:

  • a pre-trained base model (e.g., Llama-3-8B) and
  • an instruct version (e.g., Llama-3-8B-Instruct).

The instruct version undergoes further training with specific instructions using an instruction template. These templates ensure clarity and consistency in instructions, leading to better fine-tuning outcomes. They also focus the model's learning on relevant aspects of the data.

Experimentation shows that using model-specific instruction templates significantly boosts performance. While custom templates can be used with base models, model-specific instruction formatting usually results in better performance for instruction tuning both on the base model, but especially on instruction-tuned base models.

Note: Instruction tuning templates are very sensitive to spacing and new line characters. It is also important to use the same instruction tuning formatting from training during inference, otherwise you are very likely to see poor results.

See how to format your dataset for different base models below.

Models

  • llama-2-7b
  • llama-2-7b-chat
  • llama-2-13b
  • llama-2-13b-chat
  • llama-2-70b
  • llama-2-70b-chat

Input Prompt Template

There are two options, depending on whether you want to also include a system message as part of the instruction.

With system message:

<s>[INST] <<SYS>>\n {system_message} \n<</SYS>>\n\n {prompt} [/INST]

Without system message:

<s>[INST] {prompt} [/INST]
info

Make sure there is a space after the final [/INST] tag.

Output Prompt Template

You don't have to modify the completion column.

Example Data

Raw data without the template:

PromptCompletion
Please answer the following question: Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?Natalia sold 48/2 = <<48/2=24>>24 clips in May. Natalia sold 48+24 = <<48+24=72>>72 clips altogether in April and May. Answer: 72

Transformed data after applying the instruction template without a system message:

PromptCompletion
<s>[INST] Please answer the following question: Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May? [/INST]Natalia sold 48/2 = <<48/2=24>>24 clips in May. Natalia sold 48+24 = <<48+24=72>>72 clips altogether in April and May. Answer: 72