Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bos_token and add_generation_prompt to the alpaca chat template #2322

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

minpeter
Copy link

@minpeter minpeter commented Feb 9, 2025

Description

Fixes and resolves issues with the alpaca template used when using the axolotl inference feature.

AS-IS

### Instruction: Describe the structure of an atom.

<Completion starts here>

TO-BE

<bos_token>### Instruction:
Describe the structure of an atom.

### Response:
<Completion starts here>

Motivation and Context

How has this been tested?

Screenshots (if appropriate)

Types of changes

Social Handles (Optional)

discord: minpeter

@minpeter minpeter marked this pull request as draft February 9, 2025 07:12
@minpeter minpeter changed the title fix alpaca add_generation_prompt Add bos_token and add_generation_prompt to the alpaca chat template Feb 9, 2025
@minpeter minpeter changed the title Add bos_token and add_generation_prompt to the alpaca chat template Add eos_token and add_generation_prompt to the alpaca chat template Feb 9, 2025
@minpeter minpeter changed the title Add eos_token and add_generation_prompt to the alpaca chat template Add bos_token and add_generation_prompt to the alpaca chat template Feb 9, 2025
@minpeter minpeter marked this pull request as ready for review February 9, 2025 07:21
@minpeter minpeter changed the title Add bos_token and add_generation_prompt to the alpaca chat template Add bos_token and add_generation_prompt to the alpaca chat template Feb 9, 2025
Copy link
Collaborator

@NanoCode012 NanoCode012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that!

@xzuyn
Copy link
Contributor

xzuyn commented Feb 10, 2025

That template would still have issues. It can't handle system turns, and also leaves \n\n after the last turn.

<bos_token>### Instruction:
<user turn>

### Response:
<assistant turn><eos_token>

### Instruction:
<user turn>

### Response:
<assistant turn><eos_token>



This template would fix those. Due to the way the original alpaca format handles system prompts, I've limited it to only having a system prompt on the first turn.

{{ bos_token }}{% for message in messages %}{% if message['role'] == 'system' and loop.first %}{{ message['content'] }}{% elif message['role'] == 'user' %}{{ '### Instruction:\n' + message['content'] }}{% elif message['role'] == 'assistant' %}{{ '### Response:\n' + message['content'] + eos_token }}{% endif %}{% if not loop.last %}{{ '\n\n' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '\n\n### Response:\n' }}{% endif %}
<bos_token><optional system turn>

### Instruction:
<user turn>

### Response:
<assistant turn><eos_token>

### Instruction:
<user turn>

### Response:
<assistant turn><eos_token>

Co-authored-by: xzuyn <xzuyn@users.noreply.github.com>
@minpeter minpeter requested a review from NanoCode012 February 10, 2025 17:31
@minpeter
Copy link
Author

Please review the changes and proceed with merging..! .cc @NanoCode012

@NanoCode012
Copy link
Collaborator

Since we're adding an eos_token as well to separate turns (along others), let me think this through as we're modifying a common template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants