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
Trinity-RFT is a general-purpose, flexible and scalable framework designed for reinforcement fine-tuning (RFT) of large language models (LLM).
12
-
Built with a decoupled architecture, seamless integration for agentic workflows, and systematic data processing pipelines, Trinity-RFT can be easily adapted for diverse application scenarios, and serve as a platform for exploring advanced reinforcement learning (RL) paradigms.
13
12
14
13
14
+
**Trinity-RFT is a general-purpose, flexible and scalable framework designed for reinforcement fine-tuning (RFT) of large language models (LLM).**
15
15
16
16
17
+
Built with a decoupled design, seamless integration for agentic workflows, and systematic data processing pipelines, Trinity-RFT can be easily adapted for diverse application scenarios, and serve as a platform for exploring advanced reinforcement learning (RL) paradigms.
17
18
18
-
**Vision of this project:**
19
19
20
20
21
-
Current RFT approaches, such as RLHF (Reinforcement Learning from Human Feedback) with proxy reward models or training long-CoT reasoning LLMs with rule-based rewards, are limited in their ability to handle dynamic, real-world learning.
22
-
Trinity-RFT envisions a future where AI agents learn by interacting directly with environments, collecting delayed or complex reward signals, and continuously refining their behavior through advanced RL paradigms.
23
-
For example, imagine an AI scientist that designs an experiment, executes it via interacting with the environment, waits for feedback (while working on some other tasks concurrently), and iteratively updates itself based on true environmental rewards when the experiment is finally finished.
21
+
22
+
23
+
## Vision of this project
24
+
25
+
26
+
Current RFT approaches, such as RLHF (Reinforcement Learning from Human Feedback) with proxy reward models or training long-CoT reasoning models with rule-based rewards, are limited in their ability to handle dynamic, real-world learning.
27
+
28
+
Trinity-RFT envisions a future where AI agents learn by interacting directly with environments, collecting delayed or complex reward signals, and continuously refining their behavior through RL.
29
+
30
+
31
+
For example, imagine an AI scientist that designs an experiment, executes it, waits for feedback (while working on other tasks concurrently), and iteratively updates itself based on true environmental rewards when the experiment is finally finished.
32
+
33
+
24
34
Trinity-RFT offers a path into this future by addressing critical gaps in existing solutions.
25
35
26
36
27
37
28
38
29
39
30
-
**Key features of Trinity-RFT:**
40
+
## Key features
31
41
32
42
33
43
34
44
+**Unified RFT modes & algorithm support.**
35
-
Trinity-RFT unifies and generalizes existing RFT methodologies into a flexible and configurable framework, supporting synchronous/asynchronous and on-policy/off-policy/offline training, as well as hybrid modes that combine the above seamlessly into a single learning process (e.g., incorporating expert trajectories or high-quality SFT data to accelerate an online RL process).
45
+
Trinity-RFT unifies and generalizes existing RFT methodologies into a flexible and configurable framework, supporting synchronous/asynchronous and on-policy/off-policy/offline training, as well as hybrid modes that combine them seamlessly into a single learning process.
46
+
36
47
37
48
+**Agent-environment interaction as a first-class citizen.**
38
-
Trinity-RFT natively models the challenges of RFT with real-world agent-environment interactions. It allows delayed rewards in multi-step and/or time-lagged feedback loops, handles long-tailed latencies and environment/agent failures gracefully, and supports distributed deployment where explorers (i.e., the rollout agents) and trainers (i.e., the policy model trained by RL) can operate across separate clusters or devices (e.g., explorers on edge devices, trainers in cloud clusters) and scale up independently.
49
+
Trinity-RFT allows delayed rewards in multi-step/time-lagged feedback loops, handles long-tailed latencies and environment/agent failures gracefully, and supports distributed deployment where explorers and trainers can operate across separate devices and scale up independently.
50
+
51
+
39
52
40
53
+**Data processing pipelines optimized for RFT with diverse/messy data.**
41
-
These include converting raw datasets to prompt/task sets for RL, cleaning/filtering/prioritizing experiences stored in the replay buffer, synthesizing data for tasks and experiences, offering user interfaces for RFT with human in the loop, managing the task and experience buffers (e.g., supporting collection of lagged reward signals), among others.
54
+
These include converting raw datasets to prompt/task sets for RL, cleaning/filtering/prioritizing experiences stored in the replay buffer, synthesizing data for tasks and experiences, offering user interfaces for human in the loop, etc.
55
+
<!-- managing the task and experience buffers (e.g., supporting collection of lagged reward signals) -->
42
56
43
57
44
58
@@ -59,40 +73,40 @@ These include converting raw datasets to prompt/task sets for RL, cleaning/filte
59
73
The overall design of Trinity-RFT exhibits a trinity:
60
74
+ RFT-core;
61
75
+ agent-environment interaction;
62
-
+ data processing pipelines tailored to RFT.
76
+
+ data processing pipelines tailored to RFT;
63
77
64
-
65
-
66
-
In particular, the design of RFT-core also exhibits a trinity:
78
+
and the design of RFT-core also exhibits a trinity:
67
79
+ explorer;
68
80
+ trainer;
69
81
+ manager & buffer.
70
82
71
83
72
84
73
-
The explorer, powered by the rollout model, interacts with the environment and generates rollout trajectories to be stored in the experience buffer.
74
-
The trainer, powered by the policy model, samples batches of experiences from the buffer and updates the policy via RL algorithms.
75
-
These two can be completely decoupled and act asynchronously, except that they share the same experience buffer, and their model weights are synchronized once in a while (according to a schedule specified by user configurations).
85
+
The *explorer*, powered by the rollout model, interacts with the environment and generates rollout trajectories to be stored in the experience buffer.
76
86
87
+
The *trainer*, powered by the policy model, samples batches of experiences from the buffer and updates the policy via RL algorithms.
77
88
78
-
Such a decoupled design is crucial for making the aforementioned features of Trinity-RFT possible,
79
-
e.g., flexible and configurable RFT modes (on-policy/off-policy, synchronous/asynchronous, immediate/lagged rewards),
89
+
These two can be completely decoupled and act asynchronously, except that they share the same experience buffer, and their model weights are synchronized once in a while.
90
+
Such a decoupled design is crucial for making the aforementioned features of Trinity-RFT possible.
fault tolerance for failures of explorer (agent/environment) or trainer,
81
94
high efficiency in the presence of long-tailed rollout latencies,
82
95
data processing pipelines and human in the loop of RFT (e.g., via acting on the experience buffer, which is implemented as a persistent database),
83
-
among others.
96
+
among others.-->
84
97
85
98
86
99
87
100
Meanwhile, Trinity-RFT has done the dirty work for ensuring high efficiency in every component of the framework,
88
-
e.g., utilizing NCCL (when feasible) for model weight synchronization, sequence concatenation with proper masking for multi-turn conversations and ReAct workflows, pipeline parallelism for the synchronous RFT mode, among many others.
101
+
e.g., utilizing NCCL (when feasible) for model weight synchronization, sequence concatenation with proper masking for multi-turn conversations and ReAct-style workflows, pipeline parallelism for the synchronous RFT mode, among many others.
89
102
90
103
91
104
92
105
## Getting started
93
106
94
107
95
-
*Note: this project is currently under active development; comments and suggestions are welcome!*
108
+
> [!NOTE]
109
+
> This project is currently under active development. Comments and suggestions are welcome!
96
110
97
111
98
112
@@ -186,20 +200,17 @@ For more details about dataset downloading, please refer to [Huggingface](https:
186
200
### Step 3: configurations
187
201
188
202
189
-
You may customize the configurations in `scripts/config/{config_name}.yaml`and `scripts/config/{train_config_name}.yaml`. For example, the model and dataset are specified as:
203
+
You may customize the configurations in [`examples`](examples/). For example, the model and dataset are specified as:
Copy file name to clipboardExpand all lines: docs/sphinx_doc/source/main.md
+4-7Lines changed: 4 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -180,20 +180,17 @@ For more details about dataset downloading, please refer to [Huggingface](https:
180
180
### Step 3: configurations
181
181
182
182
183
-
You may customize the configurations in `scripts/config/{config_name}.yaml`and `scripts/config/{train_config_name}.yaml`. For example, the model and dataset are specified as:
183
+
You may customize the configurations in [`examples`](https://github.com/modelscope/Trinity-RFT/tree/main/examples/). For example, the model and dataset are specified as:
Copy file name to clipboardExpand all lines: docs/sphinx_doc/source/tutorial/example_data_functionalities.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,12 +133,13 @@ And you can set the `clean_strategy` to 'iterative' to get a better dataset.
133
133
134
134
135
135
136
-
All config items in the `data` section can be found [here](trinity_configs.md). A prepared config file for this example of GSM-8K can be found in [the config file of gsm8k](../../../../scripts/config/gsm8k.yaml).
136
+
All config items in the `data` section can be found [here](trinity_configs.md). A prepared config file for this example of GSM-8K can be found in [the config file of gsm8k](https://github.com/modelscope/Trinity-RFT/tree/main/examples/grpo_gsm8k/gsm8k.yaml).
137
137
138
138
139
139
140
-
> [!NOTE]
141
-
> Only when one of `dj_process_desc` and `dj_config_path` is provided, the data module and the data active iterator will be activated. Otherwise, this part will be skipped and it will enter into the exploring stage directly.
140
+
```{note}
141
+
Only when one of `dj_process_desc` and `dj_config_path` is provided, the data module and the data active iterator will be activated. Otherwise, this part will be skipped and it will enter into the exploring stage directly.
142
+
```
142
143
143
144
### Exploring & Training
144
145
After preparing the config files of Trinity-RFT, you can start your ray cluster and run the RFT process including the data active iterator part with the following commands:
Copy file name to clipboardExpand all lines: docs/sphinx_doc/source/tutorial/example_dpo.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,12 +38,12 @@ Note that the dataset has the keys `prompt`, `chosen` and `rejected`. If not, pa
38
38
39
39
### Configuration
40
40
41
-
We use the configurations in `scripts/config/dpo.yaml`and `scripts/config/train_dpo.yaml` for this experiment. Some important setups are listed in the following:
41
+
We use the configurations in [`dpo.yaml`](https://github.com/modelscope/Trinity-RFT/tree/main/examples/dpo_humanlike/dpo.yaml)and [`train_dpo.yaml`](https://github.com/modelscope/Trinity-RFT/tree/main/examples/dpo_humanlike/train_dpo.yaml) for this experiment. Some important setups are listed in the following:
42
42
43
43
We run the experiment in a train mode, as there is no Explorer. To enable this mode, we config `mode` to `train` and set `sync_method` to `offline`. The value of `sync_iteration_interval` can be set as same of the value of `save_freq`.
44
44
45
45
```yaml
46
-
#scripts/config/dpo.yaml
46
+
#In dpo.yaml
47
47
mode: train
48
48
synchronizer:
49
49
sync_method: 'offline'
@@ -60,7 +60,7 @@ buffer:
60
60
trainer:
61
61
algorithm_type: dpo
62
62
63
-
#scripts/config/train_dpo.yaml
63
+
#In train_dpo.yaml
64
64
actor_rollout_ref:
65
65
actor:
66
66
alg_type: dpo
@@ -73,5 +73,5 @@ actor_rollout_ref:
73
73
Run RFT process with the following command:
74
74
75
75
```shell
76
-
trinity run --config scripts/config/dpo.yaml
76
+
trinity run --config examples/dpo_humanlike/dpo.yaml
Copy file name to clipboardExpand all lines: docs/sphinx_doc/source/tutorial/example_multi_turn.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,15 +36,15 @@ The task is described as an environment instead of a single prompt.
36
36
37
37
## Step 2: Config preparation and run the experiment
38
38
39
-
You can refer to `example_reasoning_basic` to setup the config and others. The default config files are `scripts/config/alfworld.yaml` and `scripts/config/webshop.yaml`, respectively.
39
+
You can refer to `example_reasoning_basic` to setup the config and others. The default config files are [`alfworld.yaml`](https://github.com/modelscope/Trinity-RFT/tree/main/examples/grpo_alfworld/alfworld.yaml) and [`webshop.yaml`](https://github.com/modelscope/Trinity-RFT/tree/main/examples/grpo_webshop/webshop.yaml), respectively.
40
40
You may revise the configurations properly and run the experiment!
41
41
42
42
```bash
43
43
# For ALFworld env
44
-
trinity run --config scripts/config/alfworld.yaml
44
+
trinity run --config examples/grpo_alfworld/alfworld.yaml
45
45
46
46
# For WebShop env
47
-
trinity run --config scripts/config/webshop.yaml
47
+
trinity run --config examples/grpo_webshop/webshop.yaml
Copy file name to clipboardExpand all lines: docs/sphinx_doc/source/tutorial/example_reasoning_advanced.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,11 +17,11 @@ The algorithm design and analysis can be found in this [technical report](../../
17
17
18
18
To try out the OPMD algorithm:
19
19
```shell
20
-
trinity run --config scripts/config/gsm8k_opmd.yaml
20
+
trinity run --config examples/opmd_gsm8k/opmd_gsm8k.yaml
21
21
```
22
22
23
23
Note that in this config file, `sync_iteration_interval` is set to 10, i.e., the model weights of explorer and trainer are synchronized only once every 10 training steps, which leads to a challenging off-policy scenario (potentially with abrupt distribution shift during the RFT process).
24
-
Other configurations of particular interest are explained at the beginning of `scripts/config/train_gsm8k_opmd.yaml`.
24
+
Other configurations of particular interest are explained at the beginning of [`train_opmd_gsm8k.yaml`](https://github.com/modelscope/Trinity-RFT/tree/main/examples/opmd_gsm8k/train_opmd_gsm8k.yaml).
25
25
26
26
27
27
@@ -48,4 +48,4 @@ To run this mode, the explorer and trainer need to be launched separately, with
48
48
49
49
50
50
51
-
We are still testing this mode more thoroughly. A concrete example is coming soon!
51
+
*We are still testing this mode more thoroughly. A concrete example is coming soon!*
Copy file name to clipboardExpand all lines: docs/sphinx_doc/source/tutorial/example_reasoning_basic.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,15 +48,15 @@ synchronizer:
48
48
49
49
### Use GRPO or PPO Algorithm
50
50
51
-
We use the configurations in `scripts/config/gsm8k.yaml`and `scripts/config/train_gsm8k.yaml` for this experiment. Some important setups are listed in the following:
51
+
We use the configurations in [`gsm8k.yaml`](https://github.com/modelscope/Trinity-RFT/tree/main/examples/grpo_gsm8k/gsm8k.yaml) and [`train_gsm8k.yaml`](https://github.com/modelscope/Trinity-RFT/tree/main/examples/grpo_gsm8k/train_gsm8k.yaml) for this experiment. Some important setups are listed in the following:
52
52
53
53
54
54
```yaml
55
-
# scripts/config/gsm8k.yaml
55
+
# In gsm8k.yaml
56
56
explorer:
57
57
repeat_times: {number of rollouts for each task}
58
58
59
-
# scripts/config/train_gsm8k.yaml
59
+
# In train_gsm8k.yaml
60
60
actor_rollout_ref:
61
61
actor:
62
62
use_kl_loss: True (fro GRPO) / False (for PPO)
@@ -69,7 +69,7 @@ algorithm:
69
69
70
70
Run the RFT process with the following command:
71
71
```bash
72
-
trinity run --config scripts/config/gsm8k.yaml
72
+
trinity run --config examples/grpo_gsm8k/gsm8k.yaml
73
73
```
74
74
75
75
@@ -79,14 +79,14 @@ trinity run --config scripts/config/gsm8k.yaml
79
79
Before RFT, we may use SFT as a warmup step. We need to set `trainer.sft_warmup_iteration > 0` and prepare the SFT data to `buffer.train_dataset.path=$DATASET_PATH/{sft_data}`.
80
80
81
81
```yaml
82
-
# Properly set the following configs in scripts/config/gsm8k.yaml
82
+
# Properly set the following configs in gsm8k.yaml
0 commit comments