Skip to content

LLama3ChatSession example fails to work with LLama 2 model #937

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

Closed
asmirnov82 opened this issue Oct 2, 2024 · 1 comment · Fixed by #938
Closed

LLama3ChatSession example fails to work with LLama 2 model #937

asmirnov82 opened this issue Oct 2, 2024 · 1 comment · Fixed by #938

Comments

@asmirnov82
Copy link
Contributor

asmirnov82 commented Oct 2, 2024

Description

LLama3ChatSession example is said to "supports models such as llama3, llama2, phi3, qwen1.5, etc".
However it fails due to several reasons:

  1. Null reference exception (as in ;lama2 model.Tokens.EndOfTurnToken is not defined in metadata and that's why is null)
  2. PromtTemplateTransformer doesn't work correctly with llama2. According to https://www.llama.com/docs/model-cards-and-prompt-formats/meta-llama-2 and https://huggingface.co/blog/llama2#how-to-prompt-llama-2, llama2 should be prompted using this template:
<s>[INST]
{{ system_prompt }}
<</SYS>>

{{ user_message_1 }} [/INST] {{ model_answer_1 }} </s>
<s>[INST] {{ user_message_2 }} [/INST]

Llama2 doesn't provide chat template in metadata, so by default different template is used by llama.cpp:

<|im_start|>user
hello<|im_end|>
<|im_start|>assistant
response<|im_end|>
<|im_start|>user
again<|im_end|>
<|im_start|>assistant
response<|im_end|>

As a result, conversation using LLama3 example after fixing NullRefence exception looks like this:
image

It would be nice to have an example that uses custom HistoryTransform for llama2

@martindevans
Copy link
Member

martindevans commented Oct 6, 2024

Llama2 doesn't provide chat template in metadata

I'm not sure, but I think llama.cpp has tools to modify GGUF files to add new metadata, the easiest fix would probably be to modify your llama2 file to include the correct template.

Edit: I did just merge your PR though, so that'll be in the next release :)

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 a pull request may close this issue.

2 participants