Add support for IBM Granite 3.x models (#2437)

This commit is contained in:
Fred Reiss
2024-12-11 06:30:23 -08:00
committed by GitHub
parent f8548295d6
commit 993956c6b1
5 changed files with 562 additions and 1 deletions

View File

@@ -320,6 +320,28 @@ register_chat_template(
)
)
register_chat_template(
ChatTemplate(
name="granite-3-instruct",
default_system_prompt=None,
role_prefix_and_suffix={
"system": (
"<|start_of_role|>system<|end_of_role|>",
"<|end_of_text|>",
),
"user": (
"<|start_of_role|>user<|end_of_role|>",
"<|end_of_text|>",
),
"assistant": (
"<|start_of_role|>assistant<|end_of_role|>",
"<|end_of_text|>",
),
},
stop_str=("<|end_of_text|>",),
)
)
@register_chat_template_matching_function
def match_dbrx(model_path: str):
@@ -402,6 +424,16 @@ def match_c4ai_command_r(model_path: str):
return get_chat_template("c4ai-command-r")
@register_chat_template_matching_function
def match_granite_instruct(model_path: str):
model_path = model_path.lower()
# When future versions of Granite are released, this code may
# need to be updated. For now, assume that the Granite 3.0
# template works across the board.
if "granite" in model_path and "instruct" in model_path:
return get_chat_template("granite-3-instruct")
if __name__ == "__main__":
messages = [
{"role": "system", "content": None}, # None means default