You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source_en/Instruction/Agent-support.md
+24-6Lines changed: 24 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -190,14 +190,32 @@ tools = [{
190
190
191
191
## Usage of loss_scale
192
192
193
-
`loss_scale` can be used to adjust the training loss weight for the model's output section. For example, in the ReACT format, you can set `--loss_scale react` (the loss_scale configuration file is written [here](https://github.com/modelscope/ms-swift/blob/main/swift/plugin/loss_scale/config/react.json)). The role of this parameter is as follows:
193
+
The `loss_scale`parameter can be used to adjust the loss weights for different parts of the model output during training. Currently, two configuration methods are supported: exact string matching and regular expression (regex) matching.
194
194
195
-
- The weight for the 'Thought:' and 'Final Answer:' sections is 1.
196
-
- The weight for the 'Action:' and 'Action Input:' sections is 2.
197
-
- The weight for the 'Observation:' field itself is 2.
198
-
- The weight for the tool invocation results following the 'Observation:' field is 0.
195
+
1. String Matching Example: ReACT Format
199
196
200
-
For the detailed design of the `loss_scale` plugin, please refer to the [Plugin-based Architecture](../Customization/Pluginization.md)documentation.
197
+
Take the ReACT format as an example. You can enable the corresponding `loss_scale` configuration via `--loss_scale react` (see configuration file [react.json](https://github.com/modelscope/ms-swift/blob/main/swift/plugin/loss_scale/config/react.json)). This method relies on exact string matching. The dictionary mapping in the configuration must provide a list of two elements, representing:
198
+
199
+
- The loss weight for the matched string itself,
200
+
- The loss weight for content following the matched string, up to (but not including) the next specified string.
201
+
202
+
The specific effects of this configuration are as follows:
203
+
204
+
- The `'Action:'` and `'Action Input:'` keywords and their subsequent content both have a loss weight of 2;
205
+
- The `'Thought:'` and `'Final Answer:'` keywords and their subsequent content both have a loss weight of 1;
206
+
- The `'Observation:'` field itself has a loss weight of 2, but the subsequent tool call result content has a loss weight of 0.
207
+
208
+
209
+
2. Regular Expression Matching Example: Ignoring Empty Thought Blocks
210
+
211
+
When training reasoning models, it may be necessary to exclude loss computation for empty thought blocks in the dataset, such as sequences like `<think>\n\n</think>\n\n`.
212
+
213
+
In such cases, use `--loss_scale ignore_empty_think` (see configuration file [ignore_empty_think.json](https://github.com/modelscope/ms-swift/blob/main/swift/plugin/loss_scale/config/ignore_empty_think.json)). This configuration uses regular expression matching, where the dictionary mapping only needs to specify a single value—the loss weight for the matched content.
214
+
215
+
The specific effect of this setting is:
216
+
- Any string matching the regular expression `<think>\\s*</think>\\s*` is assigned a `loss_scale` of 0, meaning no loss is computed for these segments.
217
+
218
+
For more `loss_scale` plugin designs, please refer to the [Pluginization](../Customization/Pluginization.md) documentation.
'# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>'
112
+
'# Tools\n\nYou may call one or more functions to assist with the user query.\n\n'
113
+
'You are provided with function signatures within <tools></tools> XML tags:\n<tools>'
'</tools>\n\nFor each function call, output the function name and arguments within the following XML format:\n<tool_call>{function-name}\n<arg_key>{arg-key-1}</arg_key>\n<arg_value>{arg-value-1}</arg_value>\n<arg_key>{arg-key-2}</arg_key>\n<arg_value>{arg-value-2}</arg_value>\n...\n</tool_call>'
118
-
)
117
+
tool_descs.append('</tools>\n\nFor each function call, output the function name and arguments within '
118
+
'the following XML format:\n<tool_call>{function-name}\n<arg_key>{arg-key-1}</arg_key>\n'
0 commit comments