8000 feat: Auto detect Mixtral's slightly different format (#1214) · Gillesattebe/llama-cpp-python@8584962 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8584962

Browse files
authored
feat: Auto detect Mixtral's slightly different format (abetlen#1214)
1 parent db776a8 commit 8584962

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
MISTRAL_INSTRUCT_BOS_TOKEN = "<s>"
3030
MISTRAL_INSTRUCT_EOS_TOKEN = "</s>"
3131

32+
# Source: https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1/blob/main/tokenizer_config.json
33+
MIXTRAL_INSTRUCT_CHAT_TEMPLATE = "{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' 8325 }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}"
3234

3335
### Chat Completion Handler ###
3436

@@ -470,7 +472,8 @@ def guess_chat_format_from_gguf_metadata(metadata: Dict[str, str]) -> Optional[s
470472
if metadata["tokenizer.chat_template"] == CHATML_CHAT_TEMPLATE:
471473
return "chatml"
472474

473-
if metadata["tokenizer.chat_template"] == MISTRAL_INSTRUCT_CHAT_TEMPLATE:
475+
if (metadata["tokenizer.chat_template"] == MISTRAL_INSTRUCT_CHAT_TEMPLATE or
476+
metadata["tokenizer.chat_template"] == MIXTRAL_INSTRUCT_CHAT_TEMPLATE):
474477
return "mistral-instruct"
475478

476479
return None

0 commit comments

Comments
 (0)
0