Template-free prompt construction in axolotl with the new input_output format.
Background
Masking Inputs
One of the most popular features of axolotl is setting the following configuration value:
config.yml
train_on_inputs:false
If you declare a dataset format such as alpaca or chatml, axolotl knows what is an input (i.e. human) vs. an output (i.e. the assistant) and masks the input labels so that your model can focus on predicting the outputs only.
You may not want prompt templates
However, there are many situations where you don’t want to use one of these formats or templates (I usually don’t!). This is because they can:
Add unnecessary boilerplate to your prompts.
Create artifacts like special delimiters <|im_start|> that can quickly become footguns if you don’t include them correctly at inference time.
Enforce a chat interface when you do not want one. Sometimes you just want to fine tune a model to a very specific task and do NOT want multi-turn conversations, roles, etc.
Limit you to only certain roles that the template allows.
The input_output format
You can construct your prompts without a template by using the input_output format, by setting type: input_output in your configuration file like this:
config.yml
train_on_inputs:false # Mask segments of your datadatasets:-path: output.jsonltype: input_output # use template free prompt construction
Unlike type: completion, which is also template-free, type: input_output allows you to mask segments of your text. More details on how this works are described below.
Usage
This is how you can use the input_output format:
1. Prepare Data
To use the input_output format, collect your data in the following format into a jsonl file (below is the first row from the file output.jsonl pretty-printed):
Set label:false when you want to mask a segment of text so that the model isn’t trained on it. Some things to keep in mind:
EOS, BOS, spaces, newlines etc. are entirely up to you. Axolotl concatenates all the segments as-is. The tokenizer doesn’t add anything additional. Notice how I added spaces, newlines, <s> (BOS), and </s> (EOS) myself.
Make sure you check the materialized output to validate that the prompt is getting assembled how you like.
3. Use type: input_output
Let’s materialize data with our output.jsonl file by setting type: input_output in our axolotl config:
You can use the following command to materialize your data. The --debug flag will print the tokens, along with the labels so you can verify that the correct items are being ignored:
The format is decoded_token(label, token_id), for example, <s>(1, 1) means that the token is <s>, the label is 1 and the token_id is 1. When the label is -100 then that token is ignored for training.
Here is another way to check the materialized output (that I personally like):