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/sphinx_doc/source/tutorial/trinity_programming_guide.md
+149-1Lines changed: 149 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,15 @@ To handle differences in `Task` contents, Trinity-RFT provides a unified `Task`
45
45
-**`raw_task`** (`Dict`): An record of raw data in `Dict` format. For highly customized workflow, you can directly use `raw_task` to initialize your `Workflow` instance without relying on the following fields.
46
46
-**`format_args`** ({class}`trinity.common.config.FormatConfig`): Parameters to facilitate the construction of `Workflow` instances. For example, the `prompt_key` and `response_key` can be used to get the prompt and response from `raw_task`. These settings come from the YAML configuration file and can be set in `buffer.explorer_input.task_set.format`.
47
47
-**`rollout_args`** ({class}`trinity.common.config.GenerationConfig`): Parameters that control the rollout process, such as `temperature`. This field also comes from the YAML configuration file and can be set in `buffer.explorer_input.task_set.rollout_args`.
48
+
-**`workflow_args`** (`Dict`): A dictionary of parameters to facilitate the construction of `Workflow` instances. Provides more flexibility than `format_args` and `rollout_args` by using a dictionary. This field also comes from the YAML configuration file and can be set in `buffer.explorer_input.task_set.workflow_args`. Normally, you do not need to set this field.
49
+
50
+
```{tip}
51
+
`workflow`, `workflow_args` and `raw_task` provide different levels of customization.
52
+
53
+
- `workflow` provides the global settings for all tasks that uses the same workflow. (Global Level)
54
+
- `workflow_args` can be set for each task dataset, allowing different task datasets using the same workflow to behave differently. (Dataset Level)
55
+
- `raw_task` provides the ability to customize the behavior of each task, which is most flexible. (Data Sample Level)
56
+
```
48
57
49
58
In the math problem scenario, the `Task` dataset can be a `jsonl` file, where each line contains JSON with `question` and `answer` fields representing the problem description and standard answer, respectively. For example:
50
59
@@ -111,7 +120,7 @@ During initialization, `Workflow` receives the following parameters:
111
120
You can switch to using the OpenAI API by setting `explorer.rollout_model.enable_openai_api` to `true` in your config file and calling `model.get_openai_client()` to get an `openai.OpenAI` instance in your workflow.
112
121
```
113
122
114
-
Here’s an example of initializing a simple workflow using only `raw_task` and `rollout_args`. In more complex cases, you can use the `format_args` for further customization.
123
+
Here's an example of initializing a simple workflow using only `raw_task` and `rollout_args`. In more complex cases, you can use the `format_args` for further customization.
115
124
116
125
```python
117
126
classExampleWorkflow(Workflow):
@@ -188,6 +197,25 @@ class ExampleWorkflow(Workflow):
188
197
pass
189
198
```
190
199
200
+
For workflows that are prepared to be contributed to Trinity-RFT project, you need to place the above code in `trinity/common/workflows` folder, e.g., `trinity/common/workflows/example_workflow.py`. And add the following line to `trinity/common/workflows/__init__.py`:
201
+
202
+
```python
203
+
# existing import lines
204
+
from .example_workflow import ExampleWorkflow
205
+
206
+
__all__= [
207
+
# existing __all__ lines
208
+
"ExampleWorkflow",
209
+
]
210
+
```
211
+
212
+
For workflows that are not intended to be contributed to Trinity-RFT project, you can just place the above code in `trinity/plugins`. Trinity-RFT will automatically detect and load all custom modules in this folder.
213
+
214
+
```{tip}
215
+
You can specify the directory where your custom modules are located by setting `--plugin-dir` when starting Trinity-RFT. If you don't specify `--plugin-dir`, Trinity-RFT will use `<Trinity_RFT_ROOT_DIR>/trinity/plugins` as the default directory.
216
+
```
217
+
218
+
191
219
#### Avoid Re-initialization
192
220
193
221
For heavy workflows, re-initializing every time can incurs extra computational costs.
@@ -286,6 +314,126 @@ trinity run --config <your_yaml_file>
286
314
287
315
---
288
316
317
+
## Adding New Config Entries for the Config Generator (Advanced)
318
+
319
+
### Step 0: Understanding Streamlit
320
+
321
+
Before adding new parameters to the Config Generator page, it is essential to familiarize yourself with the relevant API and mechanisms of [Streamlit](https://docs.streamlit.io/develop/api-reference). This project primarily utilizes various input components from Streamlit and employs `st.session_state` to store user-input parameters.
322
+
323
+
### Step 1: Implement New Config Entries
324
+
325
+
To illustrate the process of creating a new parameter setting for the Config Generator page, we will use `train_batch_size` as an example.
326
+
327
+
1. Determine the appropriate scope for the parameter. Currently, parameters are categorized into four files:
In this case, `train_batch_size` should be placed in the `buffer_config_manager.py` file.
334
+
335
+
2. Create a parameter setting function using Streamlit. The function name must follow the convention of starting with 'set_', and the remainder of the name becomes the config name.
336
+
337
+
3. Decorate the parameter setting function with the `CONFIG_GENERATORS.register_config` decorator. This decorator requires the following information:
338
+
- Default value of the parameter
339
+
- Visibility condition (if applicable)
340
+
- Additional config parameters (if needed)
341
+
342
+
```{note}
343
+
The `CONFIG_GENERATORS.register_config` decorator automatically passes `key=config_name` as an argument to the registered configuration function. Ensure that your function accepts this keyword argument.
344
+
```
345
+
346
+
For `train_batch_size`, we will use the following settings:
If the parameter requires validation, create a check function. For `train_batch_size`, we need to ensure it is divisible by `trainer_gpu_num`. If not, a warning should be displayed, and the parameter should be added to `unfinished_fields`.
383
+
384
+
Decorate the check function with the `CONFIG_GENERATORS.register_check` decorator:
if st.session_state[key] % st.session_state["trainer_gpu_num"] !=0:
390
+
unfinished_fields.add(key)
391
+
st.warning(_str_for_train_batch_size())
392
+
```
393
+
394
+
```{note}
395
+
The `CONFIG_GENERATORS.register_check` decorator automatically receives `key=config_name` and `unfinished_fields=self.unfinished_fields` as arguments. Ensure your function accepts these keyword arguments.
396
+
```
397
+
398
+
### Step 2: Integrating New Parameters into `config_manager.py`
399
+
400
+
To successfully integrate new parameters into the `config_manager.py` file, please adhere to the following procedure:
401
+
402
+
1. Parameter Categorization:
403
+
Determine the appropriate section for the new parameter based on its functionality. The config generator page is structured into two primary modes:
404
+
- Beginner Mode: Comprises "Essential Configs" and "Important Configs" sections.
405
+
- Expert Mode: Includes "Model", "Buffer", "Explorer and Synchronizer", and "Trainer" sections.
406
+
407
+
2. Parameter Addition:
408
+
Incorporate the new parameter into the relevant section using the `self.get_configs` method within the `ConfigManager` class.
Locate the appropriate position for the new parameter within the YAML file structure. This should be done in the `generate_config` function and its associated sub-functions.
419
+
420
+
4. Parameter Value Assignment:
421
+
Utilize `st.session_state` to retrieve the parameter value from the config generator page and assign it to the corresponding field in the YAML.
By meticulously following these steps, you can ensure that new parameters are successfully added to the Config Generator page and properly integrated into the configuration system. This process maintains the integrity and functionality of the configuration management framework.
434
+
435
+
---
436
+
289
437
## Check Code Style
290
438
291
439
Before submitting the code, make sure it passes the code style check. Follow these steps:
0 commit comments