Difference in EOS token between Mistral/Mixtral and LLAMA.

#117
by xkszltl - opened

Chat template from Mistral models start with a <s> for the entire chat:

{{ 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]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}

While chat template from LLAMA has <s> in the for loop before every [INST]:

{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 and system_message != false %}{% set content = '<<SYS>>\\n' + system_message + '\\n<</SYS>>\\n\\n' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ ' '  + content.strip() + ' ' + eos_token }}{% endif %}{% endfor %}

Is this expected?
More specifically, it means Mistral models only have </s> starting from the 2nd round of conversation, which looks like an unintentional bug based on the semantics of / in </s>.

Can the author confirm if it is expected or not?

Yeah, king of struggling with making the LLaMa response... It seems it doesn't know where to stop and starts a conversation with itself... Started to wonder if I'm not passing the right chat_template... Would be nice if we have an example with proper input and expected output... And maybe proper output parsing function. 🫣

Sign up or log in to comment