From ba9fc4671274ed6457142c5d4a4c70c93bafee59 Mon Sep 17 00:00:00 2001 From: marko1616 Date: Sat, 13 Apr 2024 04:31:33 +0800 Subject: [PATCH 1/9] Add template&support(Not tested) Former-commit-id: 60bb60c4dc30a9641ddb57a44ef126f0768566c4 --- src/llmtuner/data/template.py | 8 ++++++++ src/llmtuner/extras/constants.py | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/llmtuner/data/template.py b/src/llmtuner/data/template.py index 52358c1e..aefa3e45 100644 --- a/src/llmtuner/data/template.py +++ b/src/llmtuner/data/template.py @@ -785,3 +785,11 @@ _register_template( format_user=StringFormatter(slots=[":{{content}}\n:"]), format_separator=EmptyFormatter(slots=["\n"]), ) + +_register_template( + name="c4ai", + format_user=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|>", "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"]), + format_assistant=StringFormatter(slots=["{{content}}", "<|END_OF_TURN_TOKEN|>"]), + format_system=StringFormatter(slots=[{"bos_token"},"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|>"]), + default_system="You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.", +) \ No newline at end of file diff --git a/src/llmtuner/extras/constants.py b/src/llmtuner/extras/constants.py index 729e0fa6..0cd2f987 100644 --- a/src/llmtuner/extras/constants.py +++ b/src/llmtuner/extras/constants.py @@ -994,3 +994,13 @@ register_model_group( }, template="atom", ) + +register_model_group( + models={ + "C4AI-Command-R-35B": { + DownloadSource.DEFAULT: "CohereForAI/c4ai-command-r-v01", + DownloadSource.MODELSCOPE: "AI-ModelScope/c4ai-command-r-v01", + } + }, + template="c4ai", +) \ No newline at end of file From 07d01ed16aab898964d5097b875557791f5e1463 Mon Sep 17 00:00:00 2001 From: marko1616 Date: Sat, 13 Apr 2024 07:32:40 +0800 Subject: [PATCH 2/9] Add c4ai-command-r-plus link Former-commit-id: acaf953ca46eca8fb378067f4ada133654e4f088 --- src/llmtuner/extras/constants.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/llmtuner/extras/constants.py b/src/llmtuner/extras/constants.py index 0cd2f987..cf68a225 100644 --- a/src/llmtuner/extras/constants.py +++ b/src/llmtuner/extras/constants.py @@ -1003,4 +1003,14 @@ register_model_group( } }, template="c4ai", +) + +register_model_group( + models={ + "C4AI-Command-R-plus-104B": { + DownloadSource.DEFAULT: "CohereForAI/c4ai-command-r-plus", + DownloadSource.MODELSCOPE: "AI-ModelScope/c4ai-command-r-plus", + } + }, + template="c4ai", ) \ No newline at end of file From 7d36d19aaaa1b402022d7c476046772b78b527a6 Mon Sep 17 00:00:00 2001 From: marko1616 Date: Sat, 13 Apr 2024 07:52:11 +0800 Subject: [PATCH 3/9] Typo fix Former-commit-id: 51b1e49e288e66c1b0c24ac070201c988fb2a389 --- src/llmtuner/data/template.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/llmtuner/data/template.py b/src/llmtuner/data/template.py index aefa3e45..f409cd9a 100644 --- a/src/llmtuner/data/template.py +++ b/src/llmtuner/data/template.py @@ -786,6 +786,7 @@ _register_template( format_separator=EmptyFormatter(slots=["\n"]), ) + _register_template( name="c4ai", format_user=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|>", "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"]), From bbded4412f12406c3d4e67cab2bc1c5a460300c2 Mon Sep 17 00:00:00 2001 From: marko1616 Date: Sat, 13 Apr 2024 17:30:21 +0800 Subject: [PATCH 4/9] Typo fix Former-commit-id: 607625497738b2c8be736be7b0bd5c6f4cbaad5e --- src/llmtuner/extras/constants.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/llmtuner/extras/constants.py b/src/llmtuner/extras/constants.py index cf68a225..5b81a9a9 100644 --- a/src/llmtuner/extras/constants.py +++ b/src/llmtuner/extras/constants.py @@ -995,6 +995,7 @@ register_model_group( template="atom", ) + register_model_group( models={ "C4AI-Command-R-35B": { @@ -1005,6 +1006,7 @@ register_model_group( template="c4ai", ) + register_model_group( models={ "C4AI-Command-R-plus-104B": { From 65ef864f660c00c96c5b28d127bece5aaf0bf42e Mon Sep 17 00:00:00 2001 From: marko1616 Date: Mon, 15 Apr 2024 20:16:52 +0800 Subject: [PATCH 5/9] Add support for function call(Not strictly following origin) Former-commit-id: 44f3ada4e394c06b0d972329ed2a62d2be2ea0c6 --- src/llmtuner/data/template.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/llmtuner/data/template.py b/src/llmtuner/data/template.py index f409cd9a..b41d2642 100644 --- a/src/llmtuner/data/template.py +++ b/src/llmtuner/data/template.py @@ -792,5 +792,21 @@ _register_template( format_user=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|>", "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"]), format_assistant=StringFormatter(slots=["{{content}}", "<|END_OF_TURN_TOKEN|>"]), format_system=StringFormatter(slots=[{"bos_token"},"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|>"]), - default_system="You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.", + format_function=FunctionFormatter(slots=["{{name}}\n{{arguments}}"]), + format_observation=StringFormatter( + slots=["<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}","<|END_OF_TURN_TOKEN|>","<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"] + ), + default_system=("# Safety Preamble\n", + "The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.\n\n", + "# System Preamble\n", + "## Basic Rules\n", + "You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.\n\n", + "# User Preamble\n", + "## Task and Context\n", + "You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.\n\n", + "## Style Guide\n", + "Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.\n" + "## Available Tools\n", + "Here is a list of tools that you have available to you:\n" + ) ) \ No newline at end of file From 227b97396159624419bffc57a6557ec031774b83 Mon Sep 17 00:00:00 2001 From: marko1616 Date: Mon, 15 Apr 2024 20:27:09 +0800 Subject: [PATCH 6/9] Revert "Add support for function call(Not strictly following origin)" This reverts commit 65ef864f660c00c96c5b28d127bece5aaf0bf42e [formerly 44f3ada4e394c06b0d972329ed2a62d2be2ea0c6]. Former-commit-id: fac9cc6e01dd8f3bc449b656804476e1871326f0 --- src/llmtuner/data/template.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/llmtuner/data/template.py b/src/llmtuner/data/template.py index b41d2642..f409cd9a 100644 --- a/src/llmtuner/data/template.py +++ b/src/llmtuner/data/template.py @@ -792,21 +792,5 @@ _register_template( format_user=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|>", "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"]), format_assistant=StringFormatter(slots=["{{content}}", "<|END_OF_TURN_TOKEN|>"]), format_system=StringFormatter(slots=[{"bos_token"},"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|>"]), - format_function=FunctionFormatter(slots=["{{name}}\n{{arguments}}"]), - format_observation=StringFormatter( - slots=["<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}","<|END_OF_TURN_TOKEN|>","<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"] - ), - default_system=("# Safety Preamble\n", - "The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.\n\n", - "# System Preamble\n", - "## Basic Rules\n", - "You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.\n\n", - "# User Preamble\n", - "## Task and Context\n", - "You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.\n\n", - "## Style Guide\n", - "Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.\n" - "## Available Tools\n", - "Here is a list of tools that you have available to you:\n" - ) + default_system="You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.", ) \ No newline at end of file From 91f8a8248c81b6bae4982adfb049e2844f5e3456 Mon Sep 17 00:00:00 2001 From: marko1616 Date: Mon, 15 Apr 2024 20:45:46 +0800 Subject: [PATCH 7/9] change default_system accroding to official template Former-commit-id: 7ad9029c5e77a87a7c324b8f90b4f80a31a5c78b --- src/llmtuner/data/template.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/llmtuner/data/template.py b/src/llmtuner/data/template.py index f409cd9a..d85adcf3 100644 --- a/src/llmtuner/data/template.py +++ b/src/llmtuner/data/template.py @@ -789,8 +789,20 @@ _register_template( _register_template( name="c4ai", - format_user=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|>", "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"]), + format_user=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"]), format_assistant=StringFormatter(slots=["{{content}}", "<|END_OF_TURN_TOKEN|>"]), format_system=StringFormatter(slots=[{"bos_token"},"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|>"]), - default_system="You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.", + format_observation=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"]), + default_system=( + "# Safety Preamble\n", + "The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.\n\n", + "# System Preamble\n", + "## Basic Rules\n", + "You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.\n\n", + "# User Preamble\n", + "## Task and Context\n", + "You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.\n\n", + "## Style Guide\n", + "Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling." + ) ) \ No newline at end of file From 03c83838b1d547c830510f40ae015bda4daeb233 Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Mon, 15 Apr 2024 22:56:55 +0800 Subject: [PATCH 8/9] Update constants.py Former-commit-id: 39199f712aa7b7a1c66080d9c84651fd2eb0b425 --- src/llmtuner/extras/constants.py | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/llmtuner/extras/constants.py b/src/llmtuner/extras/constants.py index 5b81a9a9..321c36a4 100644 --- a/src/llmtuner/extras/constants.py +++ b/src/llmtuner/extras/constants.py @@ -242,6 +242,28 @@ register_model_group( ) +register_model_group( + models={ + "CommandR-35B-Chat": { + DownloadSource.DEFAULT: "CohereForAI/c4ai-command-r-v01", + DownloadSource.MODELSCOPE: "AI-ModelScope/c4ai-command-r-v01", + }, + "CommandR-Plus-104B-Chat": { + DownloadSource.DEFAULT: "CohereForAI/c4ai-command-r-plus", + DownloadSource.MODELSCOPE: "AI-ModelScope/c4ai-command-r-plus", + }, + "CommandR-35B-4bit-Chat": { + DownloadSource.DEFAULT: "CohereForAI/c4ai-command-r-v01-4bit", + DownloadSource.MODELSCOPE: "mirror013/c4ai-command-r-v01-4bit", + }, + "CommandR-Plus-104B-4bit-Chat": { + DownloadSource.DEFAULT: "CohereForAI/c4ai-command-r-plus-4bit", + }, + }, + template="cohere", +) + + register_model_group( models={ "DeepSeek-LLM-7B-Base": { @@ -994,25 +1016,3 @@ register_model_group( }, template="atom", ) - - -register_model_group( - models={ - "C4AI-Command-R-35B": { - DownloadSource.DEFAULT: "CohereForAI/c4ai-command-r-v01", - DownloadSource.MODELSCOPE: "AI-ModelScope/c4ai-command-r-v01", - } - }, - template="c4ai", -) - - -register_model_group( - models={ - "C4AI-Command-R-plus-104B": { - DownloadSource.DEFAULT: "CohereForAI/c4ai-command-r-plus", - DownloadSource.MODELSCOPE: "AI-ModelScope/c4ai-command-r-plus", - } - }, - template="c4ai", -) \ No newline at end of file From 56339caf4d33efe331ba8535915f2acd20cdfe5e Mon Sep 17 00:00:00 2001 From: hoshi-hiyouga Date: Mon, 15 Apr 2024 22:58:01 +0800 Subject: [PATCH 9/9] Update template.py Former-commit-id: 00b8be7dafa65e13b344724a8d3855919ee4f631 --- src/llmtuner/data/template.py | 36 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/llmtuner/data/template.py b/src/llmtuner/data/template.py index d85adcf3..7a1f4ab8 100644 --- a/src/llmtuner/data/template.py +++ b/src/llmtuner/data/template.py @@ -526,6 +526,21 @@ _register_template( ) +_register_template( + name="cohere", + format_user=StringFormatter( + slots=[ + ( + "<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{content}}<|END_OF_TURN_TOKEN|>" + "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>" + ) + ] + ), + format_system=EmptyFormatter(slots=[{"bos_token"}]), + force_system=True, +) + + _register_template( name="cpm", format_user=StringFormatter(slots=["<用户>{{content}}"]), @@ -785,24 +800,3 @@ _register_template( format_user=StringFormatter(slots=[":{{content}}\n:"]), format_separator=EmptyFormatter(slots=["\n"]), ) - - -_register_template( - name="c4ai", - format_user=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"]), - format_assistant=StringFormatter(slots=["{{content}}", "<|END_OF_TURN_TOKEN|>"]), - format_system=StringFormatter(slots=[{"bos_token"},"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|>"]), - format_observation=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}", "<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"]), - default_system=( - "# Safety Preamble\n", - "The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.\n\n", - "# System Preamble\n", - "## Basic Rules\n", - "You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.\n\n", - "# User Preamble\n", - "## Task and Context\n", - "You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.\n\n", - "## Style Guide\n", - "Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling." - ) -) \ No newline at end of file