r/LocalLLaMA • u/hackerllama • Jul 21 '23
Tutorial | Guide Get Llama 2 Prompt Format Right
Hi all!
I'm the Chief Llama Officer at Hugging Face. In the past few days, many people have asked about the expected prompt format as it's not straightforward to use, and it's easy to get wrong. We wrote a small blog post about the topic, but I'll also share a quick summary below.
Tweet: https://twitter.com/osanseviero/status/1682391144263712768
Blog post: https://huggingface.co/blog/llama2#how-to-prompt-llama-2
Why is prompt format important?
The template of the format is important as it should match the training procedure. If you use a different prompt structure, then the model might start doing weird stuff. So wanna see the format for a single prompt? Here it is!
<s>[INST] <<SYS>>
{{ system_prompt }}
<</SYS>>
{{ user_message }} [/INST]
Cool! Meta also provided an official system prompt in the paper, which we use in our demos and hf.co/chat, the final prompt being something like
<s>[INST] <<SYS>>
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
<</SYS>>
There's a llama in my garden 😱 What should I do? [/INST]
I tried it but the model does not allow me to ask about killing a linux process! 😡
An interesting thing about open access models (unlike API-based ones) is that you're not forced to use the same system prompt. This can be an important tool for researchers to study the impact of prompts on both desired and unwanted characteristics.
I don't want to code!
We set up two demos for the 7B and 13B chat models. You can click advanced options and modify the system prompt. We care of the formatting for you.
48
u/Some-Ninja-3509 Jul 21 '23
28
u/[deleted] Jul 21 '23
> Chief LLama Officer
Do you just, like, get to pick your own title? I'm jealous.
7
u/debatesmith Jul 21 '23
Hi there! I'm hoping you can share some info on how HuggingChat is incorporating the "Web Search" feature on the Llama 2 70b chat? Is it a combination of Langchain and other tools or is it mostly just SerperAPI? Thanks!
8
u/Smallpaul Jul 21 '23
So there are three different kinds of tags, and only two have end tags?
<s>
[INST]
<<SYS>>
<</SYS>>
[/INST]
Is the model supposed to complete the end-tag?
31
u/LosingID_583 Jul 21 '23
They should've included examples of the prompt format in the model card, rather than a vague description and directing us to a block of code.
12
u/TheSilentFire Jul 21 '23
Thank you for the information!
Not sure if you're able to answer, but for the people making fine tunes off of the base model, should they change their training data to match this format? Would it conflict with this prompt format, would one override it, exc. I know a few people have suggested a standardized prompt format since there seems to be quite a few for the popular models.
9
u/MoneroBee llama.cpp Jul 21 '23
Does anyone know how to get this format into llama.cpp ? Thanks!
7
u/Kindly-Annual-5504 Jul 21 '23
What added value does this adaptation of the prompt template really have? I've been using Llama 2 with the "conventional" silly-tavern-proxy (verbose) default prompt template for two days now and I still haven't had any problems with the AI not understanding me. On the contrary, she even responded to the system prompt quite well. Otherwise there were no major abnormalities. I just changed the system prompt now. And yes, the AI responds well to that, but it also responds to what I haven't adjusted. So I'm wondering how big the effect really is here.
5
u/RabbitHole32 Jul 21 '23
Does this apply to the chat model only or also to the base model?
2
u/danielcar Jul 21 '23
Can someone post some funny examples, like making llama into an evil overlord or something? Or can you make a very simple tutorial how I can do it myself using some kind of cloud hosting?
4
u/Chillosophy_ Jul 21 '23
Any idea how this is applied in the Kobald UI?
2
u/cunningjames Jul 21 '23
System prompt:
Q&A:
Better than I expected? Though I'm not sure why it keeps saying "slur", maybe it means "slurp".
2
u/killver Jul 21 '23
Not sophistically tested, but I subjectively get most useful results completely ditching the sys prompt and just running
2
u/FPham Jul 21 '23 edited Jul 21 '23
good to get the answers
2
u/cmndr_spanky Jul 23 '23
I can’t tell if this while post is complete satire but I’ll ask anyways:
how would you recommend I use that prompt with a local “embedding” that’s meant to limit its answers to a given context (rather than sourcing from its general knowledge)?
3
u/Nabakin Jul 21 '23
Quick question for you. Is the correct format for instructions:
I noticed it was given in a comment by ArthurZ in the transformers library here.
1
u/[deleted] Jul 16 '24
404, "Advanced" and "Options" not found. I see "Additional Inputs" with an empty System prompt field.
1
u/[deleted] Jul 21 '23
If I were to want to get a look at the embeddings from hidden states in the Llama models, would I need to format my inputs of text with these kinds of prompts or would the text from my datasets be sufficient?
1
u/CasimirsBlake Jul 21 '23
Valuable, thanks for taking the time. Worth sticking this post for a while? Ooba should add this as an instruct option...
1
u/Trrru Jul 21 '23
Anyone know why I can't find any advanced options with the 70b model?
https://huggingface.co/spaces/ysharma/Explore_llamav2_with_TGI
to change system prompt, temperature, etc.?
1
u/Working_Ideal3808 Jul 22 '23
You’re a king
1
u/FlippNipper Jul 22 '23
I am offically a LLaMAsexual 😂
1
u/grumpyfrench Jul 22 '23
saved
1
u/1INORY Aug 06 '23
Is there a default format for benchmarking on multiple choice questions?
1
u/FunnyMathematician41 Aug 08 '23
For llama2, when integrating langchain, I never found a prompt in the ReAct format.
```
PREFIX = """Answer the following questions as best you can. You have access to the following tools:"""
FORMAT_INSTRUCTIONS = """Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question"""
SUFFIX = """Begin!
Question: {input}
Thought:{agent_scratchpad}"""
```
Always return the final answer directly, regardless of whether the intermediate observations are correct, and only call one tool, ignoring other tools.
Question: ...
Thought: ...
Action: ...
Action Input: ...
Observation: ...
Thought: I now know the final answer
Final Answer: ...
1
u/FunOptimizer Sep 17 '23
Can the bot go first in the chat context or does the first prompt have to be a user prompt?
1
u/Appropriate-Fix-6770 Jan 06 '24
Hello, what if it's llama2-7b-hf Is there a prompt template? (not llama2-7b-chat-hf)
I have a problem: llama2-7b-chat-hf always copies and repeats the input text before answering after constructing the text according to the prompt template. I don't know what to do. Can you help me? thank you.
1
u/uygarsci Feb 17 '24
This was something I was confused in the beginning too. I explained this in detail in one of my videos.
Watch between 14:45-20:20 of this video.
https://www.youtube.com/watch?v=6XeTk8cZUsM&t=38s
0
u/crypticcollaborator Jul 21 '23
How do you adapt this prompt format for conversations with multiple questions and responses? I'd like to use LLAMA 2 as a writing assistant and being able to ask follow-up questions would help a lot.
0
u/[deleted] Jul 21 '23
That's cool. I have one question tho, does Meta keep track of prompt's data as OpenAI does for GPT's??
10
u/[deleted] Jul 21 '23 edited Jul 21 '23
[removed] — view removed comment