mirror of
https://github.com/hiyouga/LLaMA-Factory.git
synced 2025-08-23 14:22:51 +08:00
[feature] Fix template of Llama2 to match the offical template
Former-commit-id: 432377308968202758904955e64199c1fa8d4fdd
This commit is contained in:
parent
de407b59ea
commit
bf844e8a99
@ -53,6 +53,22 @@ class Template:
|
|||||||
return convs
|
return convs
|
||||||
|
|
||||||
|
|
||||||
|
class Llama2Template(Template):
|
||||||
|
def _format_example(self, query, history, prefix):
|
||||||
|
sys = prefix or self.prefix
|
||||||
|
if not sys.startswith("<<SYS>>\n"):
|
||||||
|
sys = f"<<SYS>>\n{sys.strip()}\n<</SYS>>\n\n"
|
||||||
|
history = history if (history and self.use_history) else []
|
||||||
|
history = history + [(query, "")]
|
||||||
|
convs = []
|
||||||
|
for turn_idx, (query_i, resp_i) in enumerate(history):
|
||||||
|
if turn_idx == 0:
|
||||||
|
convs.append([self.prompt.format(query=sys+query_i), resp_i])
|
||||||
|
else:
|
||||||
|
convs.append([(self.sep if turn_idx else prefix) + self.prompt.format(query=query_i), resp_i])
|
||||||
|
return convs
|
||||||
|
|
||||||
|
|
||||||
templates: Dict[str, Template] = {}
|
templates: Dict[str, Template] = {}
|
||||||
|
|
||||||
|
|
||||||
@ -101,8 +117,7 @@ Supports: https://huggingface.co/meta-llama/Llama-2-7b-chat-hf
|
|||||||
https://huggingface.co/meta-llama/Llama-2-13b-chat-hf
|
https://huggingface.co/meta-llama/Llama-2-13b-chat-hf
|
||||||
https://huggingface.co/meta-llama/Llama-2-70b-chat-hf
|
https://huggingface.co/meta-llama/Llama-2-70b-chat-hf
|
||||||
"""
|
"""
|
||||||
register_template(
|
templates["llama2"] = Llama2Template(
|
||||||
name="llama2",
|
|
||||||
prefix="<<SYS>>\nYou are a helpful, respectful and honest assistant. "
|
prefix="<<SYS>>\nYou are a helpful, respectful and honest assistant. "
|
||||||
"Always answer as helpfully as possible, while being safe. "
|
"Always answer as helpfully as possible, while being safe. "
|
||||||
"Your answers should not include any harmful, unethical, "
|
"Your answers should not include any harmful, unethical, "
|
||||||
@ -112,7 +127,7 @@ register_template(
|
|||||||
"explain why instead of answering something not correct. "
|
"explain why instead of answering something not correct. "
|
||||||
"If you don't know the answer to a question, please don't share false information.\n<</SYS>>\n\n",
|
"If you don't know the answer to a question, please don't share false information.\n<</SYS>>\n\n",
|
||||||
prompt="[INST]{query}[/INST]",
|
prompt="[INST]{query}[/INST]",
|
||||||
sep="",
|
sep="<s>",
|
||||||
use_history=True
|
use_history=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user