[LLM] Correct prompt format of Yi, Llama2 and Qwen in generate.py (#9786)
* correct prompt format of Yi * correct prompt format of llama2 in cpu generate.py * correct prompt format of Qwen in GPU example
This commit is contained in:
		
							parent
							
								
									0ea842231e
								
							
						
					
					
						commit
						44b4a0c9c5
					
				
					 4 changed files with 31 additions and 10 deletions
				
			
		| 
						 | 
					@ -22,11 +22,12 @@ from bigdl.llm.transformers import AutoModelForCausalLM
 | 
				
			||||||
from transformers import LlamaTokenizer
 | 
					from transformers import LlamaTokenizer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# you could tune the prompt based on your own model,
 | 
					# 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
 | 
					# Refer to https://huggingface.co/TheBloke/Llama-2-70B-Chat-GGML#prompt-template-llama-2-chat
 | 
				
			||||||
LLAMA2_PROMPT_FORMAT = """### HUMAN:
 | 
					LLAMA2_PROMPT_FORMAT = """
 | 
				
			||||||
{prompt}
 | 
					[INST] <<SYS>>
 | 
				
			||||||
 | 
					You are a helpful assistant.
 | 
				
			||||||
### RESPONSE:
 | 
					<</SYS>>
 | 
				
			||||||
 | 
					{prompt}[/INST]
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,8 +21,14 @@ import argparse
 | 
				
			||||||
from bigdl.llm.transformers import AutoModelForCausalLM
 | 
					from bigdl.llm.transformers import AutoModelForCausalLM
 | 
				
			||||||
from transformers import AutoTokenizer
 | 
					from transformers import AutoTokenizer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# you could tune the prompt based on your own model,
 | 
					# Refer to https://huggingface.co/01-ai/Yi-6B-Chat#31-use-the-chat-model
 | 
				
			||||||
YI_PROMPT_FORMAT = "{prompt}"
 | 
					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__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    parser = argparse.ArgumentParser(description='Predict Tokens using `generate()` API for Yi model')
 | 
					    parser = argparse.ArgumentParser(description='Predict Tokens using `generate()` API for Yi model')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,15 @@ from bigdl.llm.transformers import AutoModelForCausalLM
 | 
				
			||||||
from transformers import AutoTokenizer
 | 
					from transformers import AutoTokenizer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# you could tune the prompt based on your own model
 | 
					# 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__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    parser = argparse.ArgumentParser(description='Predict Tokens using `generate()` API for Qwen model')
 | 
					    parser = argparse.ArgumentParser(description='Predict Tokens using `generate()` API for Qwen model')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,8 +22,14 @@ import argparse
 | 
				
			||||||
from bigdl.llm.transformers import AutoModelForCausalLM
 | 
					from bigdl.llm.transformers import AutoModelForCausalLM
 | 
				
			||||||
from transformers import AutoTokenizer
 | 
					from transformers import AutoTokenizer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# you could tune the prompt based on your own model
 | 
					# Refer to https://huggingface.co/01-ai/Yi-6B-Chat#31-use-the-chat-model
 | 
				
			||||||
YI_PROMPT_FORMAT = "{prompt}"
 | 
					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__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    parser = argparse.ArgumentParser(description='Predict Tokens using `generate()` API for Yi model')
 | 
					    parser = argparse.ArgumentParser(description='Predict Tokens using `generate()` API for Yi model')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue