Skip to content

Commit

Permalink
[LLM] Correct prompt format of Yi, Llama2 and Qwen in generate.py (in…
Browse files Browse the repository at this point in the history
…tel#9786)

* correct prompt format of Yi

* correct prompt format of llama2 in cpu generate.py

* correct prompt format of Qwen in GPU example
  • Loading branch information
Jasonzzt authored Dec 26, 2023
1 parent 981731b commit 30a3ba6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
from transformers import LlamaTokenizer

# you could tune the prompt based on your own model,
# here the prompt tuning refers to https://huggingface.co/georgesung/llama2_7b_chat_uncensored#prompt-style
LLAMA2_PROMPT_FORMAT = """### HUMAN:
{prompt}
### RESPONSE:
# Refer to https://huggingface.co/TheBloke/Llama-2-70B-Chat-GGML#prompt-template-llama-2-chat
LLAMA2_PROMPT_FORMAT = """
[INST] <<SYS>>
You are a helpful assistant.
<</SYS>>
{prompt}[/INST]
"""

if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
from bigdl.llm.transformers import AutoModelForCausalLM
from transformers import AutoTokenizer

# you could tune the prompt based on your own model,
YI_PROMPT_FORMAT = "{prompt}"
# Refer to https://huggingface.co/01-ai/Yi-6B-Chat#31-use-the-chat-model
YI_PROMPT_FORMAT = """
<|im_start|>system
You are a helpful assistant. If you don't understand what the user means, ask the user to provide more information.<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
"""

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Predict Tokens using `generate()` API for Yi model')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@
from transformers import AutoTokenizer

# you could tune the prompt based on your own model
QWEN_PROMPT_FORMAT = "<human>{prompt} <bot>"
QWEN_PROMPT_FORMAT = """
<|im_start|>system
You are a helpful assistant.
<|im_end|>
<|im_start|>user
{prompt}
<|im_end|>
<|im_start|>assistant
"""

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Predict Tokens using `generate()` API for Qwen model')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
from bigdl.llm.transformers import AutoModelForCausalLM
from transformers import AutoTokenizer

# you could tune the prompt based on your own model
YI_PROMPT_FORMAT = "{prompt}"
# Refer to https://huggingface.co/01-ai/Yi-6B-Chat#31-use-the-chat-model
YI_PROMPT_FORMAT = """
<|im_start|>system
You are a helpful assistant. If you don't understand what the user means, ask the user to provide more information.<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
"""

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Predict Tokens using `generate()` API for Yi model')
Expand Down

0 comments on commit 30a3ba6

Please sign in to comment.