update
Browse files- xtuner_config.py +31 -26
xtuner_config.py
CHANGED
@@ -12,9 +12,11 @@ from transformers import (AutoModelForCausalLM, AutoTokenizer,
|
|
12 |
|
13 |
from xtuner.dataset import process_ms_dataset
|
14 |
from xtuner.dataset.collate_fns import default_collate_fn
|
15 |
-
from xtuner.dataset.map_fns import
|
|
|
16 |
from xtuner.engine import DatasetInfoHook, EvaluateChatHook
|
17 |
from xtuner.model import SupervisedFinetune
|
|
|
18 |
|
19 |
#######################################################################
|
20 |
# PART 1 Settings #
|
@@ -24,6 +26,7 @@ pretrained_model_name_or_path = 'internlm/internlm-7b'
|
|
24 |
|
25 |
# Data
|
26 |
data_path = 'damo/MSAgent-Bench'
|
|
|
27 |
max_length = 2048
|
28 |
pack_to_max_length = False
|
29 |
|
@@ -40,29 +43,27 @@ max_norm = 1 # grad clip
|
|
40 |
|
41 |
# Evaluate the generation performance during the training
|
42 |
evaluation_freq = 500
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
'<|Bot|>:')
|
65 |
-
]
|
66 |
|
67 |
#######################################################################
|
68 |
# PART 2 Model & Tokenizer #
|
@@ -105,7 +106,9 @@ train_dataset = dict(
|
|
105 |
dataset=dict(type=MsDataset.load, dataset_name=data_path),
|
106 |
tokenizer=tokenizer,
|
107 |
max_length=max_length,
|
108 |
-
dataset_map_fn=
|
|
|
|
|
109 |
remove_unused_columns=True,
|
110 |
shuffle_before_pack=True,
|
111 |
pack_to_max_length=pack_to_max_length)
|
@@ -152,7 +155,9 @@ custom_hooks = [
|
|
152 |
type=EvaluateChatHook,
|
153 |
tokenizer=tokenizer,
|
154 |
every_n_iters=evaluation_freq,
|
155 |
-
evaluation_inputs=evaluation_inputs
|
|
|
|
|
156 |
]
|
157 |
|
158 |
# configure default hooks
|
|
|
12 |
|
13 |
from xtuner.dataset import process_ms_dataset
|
14 |
from xtuner.dataset.collate_fns import default_collate_fn
|
15 |
+
from xtuner.dataset.map_fns import (msagent_react_map_fn,
|
16 |
+
template_map_fn_factory)
|
17 |
from xtuner.engine import DatasetInfoHook, EvaluateChatHook
|
18 |
from xtuner.model import SupervisedFinetune
|
19 |
+
from xtuner.utils import PROMPT_TEMPLATE
|
20 |
|
21 |
#######################################################################
|
22 |
# PART 1 Settings #
|
|
|
26 |
|
27 |
# Data
|
28 |
data_path = 'damo/MSAgent-Bench'
|
29 |
+
prompt_template = PROMPT_TEMPLATE.default
|
30 |
max_length = 2048
|
31 |
pack_to_max_length = False
|
32 |
|
|
|
43 |
|
44 |
# Evaluate the generation performance during the training
|
45 |
evaluation_freq = 500
|
46 |
+
SYSTEM = (
|
47 |
+
'你是一个可以调用外部工具的助手,可以使用的工具包括:\n'
|
48 |
+
"{{\'GoogleSearch\': \'一个可以从谷歌搜索结果的API。\\n"
|
49 |
+
'当你需要对于一个特定问题找到简短明了的回答时,可以使用它。\\n'
|
50 |
+
"输入应该是一个搜索查询。\\n\\n\',"
|
51 |
+
"\'PythonInterpreter\': \"用来执行Python代码。代码必须是一个函数,\\n"
|
52 |
+
"函数名必须得是 \'solution\',代码对应你的思考过程。代码实例格式如下:\\n"
|
53 |
+
'```python\\n# import 依赖包\\nimport xxx\\ndef solution():'
|
54 |
+
'\\n # 初始化一些变量\\n variable_names_with_real_meaning = xxx'
|
55 |
+
'\\n # 步骤一\\n mid_variable = func(variable_names_with_real_meaning)'
|
56 |
+
'\\n # 步骤 x\\n mid_variable = func(mid_variable)\\n # 最后结果'
|
57 |
+
'\\n final_answer = func(mid_variable)\\n return final_answer'
|
58 |
+
"\\n```\\n\"}}\n"
|
59 |
+
'如果使用工具请遵循以下格式回复:\n```\n'
|
60 |
+
'Thought:思考你当前步骤需要解决什么问题,是否需要使用工具\n'
|
61 |
+
"Action:工具名称,你的工具必须从 [[\'GoogleSearch\', \'PythonInterpreter\']] 选择"
|
62 |
+
'\nAction Input:工具输入参数\n```\n工具返回按照以下格式回复:\n'
|
63 |
+
'```\nResponse:调用工具后的结果\n```'
|
64 |
+
'\n如果你已经知道了答案,或者你不需要工具,请遵循以下格式回复\n```'
|
65 |
+
'\nThought:给出最终答案的思考过程\nFinal Answer:最终答案\n```\n开始!\n')
|
66 |
+
evaluation_inputs = ['上海明天天气怎么样?']
|
|
|
|
|
67 |
|
68 |
#######################################################################
|
69 |
# PART 2 Model & Tokenizer #
|
|
|
106 |
dataset=dict(type=MsDataset.load, dataset_name=data_path),
|
107 |
tokenizer=tokenizer,
|
108 |
max_length=max_length,
|
109 |
+
dataset_map_fn=msagent_react_map_fn,
|
110 |
+
template_map_fn=dict(
|
111 |
+
type=template_map_fn_factory, template=prompt_template),
|
112 |
remove_unused_columns=True,
|
113 |
shuffle_before_pack=True,
|
114 |
pack_to_max_length=pack_to_max_length)
|
|
|
155 |
type=EvaluateChatHook,
|
156 |
tokenizer=tokenizer,
|
157 |
every_n_iters=evaluation_freq,
|
158 |
+
evaluation_inputs=evaluation_inputs,
|
159 |
+
system=SYSTEM,
|
160 |
+
prompt_template=prompt_template)
|
161 |
]
|
162 |
|
163 |
# configure default hooks
|