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

fix mistral prompt assembly #982

Merged
merged 3 commits into from
Dec 21, 2023
Merged

fix mistral prompt assembly #982

merged 3 commits into from
Dec 21, 2023

Conversation

hamelsmu
Copy link
Collaborator

@hamelsmu hamelsmu commented Dec 20, 2023

Summary

Similar to the llama prompts (#952 ) I found some inconsistencies with the mistral prompts. There are still some small differences with spaces but this makes the prompt conform more to the official prompt.

Key differences between Mistral and Llama that I fixed:

  • No BOS token that separates conversations, only EOS token
  • There is no official guidance on how to handle the system message, so I left this consistent with llama

I Also found that previously, we weren't correctly handling the case where there was no system message and were not adding the [INST] at the beginning.

I also took the opportunity to clean up the tests since I'm adding more.

The best way to understand this PR is to look at the test cases.

References

https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1
and
https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2

The best way to "see" the prompt template most people are likely to use is to use HF Chat template:

from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.2")

chat = [{"role": "user", "content": "abc"}, 
        {"role": "assistant", "content": "ipsum"}, 
        {"role": "user", "content": "123"}, 
        {"role": "assistant", "content": "sit"}]

ids = tokenizer.apply_chat_template(chat)
print(tokenizer.decode(ids))

Which results in

<s> [INST] abc [/INST]ipsum</s> [INST] 123 [/INST]sit</s>

@hamelsmu
Copy link
Collaborator Author

hamelsmu commented Dec 20, 2023

@hamelsmu hamelsmu changed the title fix mistral prompts fix sharegpt/mistral prompts Dec 20, 2023
@hamelsmu hamelsmu changed the title fix sharegpt/mistral prompts fix mistral prompt assembly Dec 20, 2023
@casper-hansen
Copy link
Collaborator

I’m not too happy seeing so many of our methods for promoting have errors. I wonder if this fixes any performance gap?

@hamelsmu hamelsmu merged commit 7bbaac9 into main Dec 21, 2023
4 checks passed
@hamelsmu
Copy link
Collaborator Author

I’m not too happy seeing so many of our methods for promoting have errors. I wonder if this fixes any performance gap?

@casper-hansen I have the same question. I think its one of the most important questions to answer. I'm going to be doing a systematic study of this. LMK if you want to help

@winglian winglian deleted the fix-mistral-prompt branch January 23, 2024 12:33
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.

None yet

3 participants