trinity-rft 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. trinity_rft-0.1.0/LICENSE +201 -0
  2. trinity_rft-0.1.0/PKG-INFO +396 -0
  3. trinity_rft-0.1.0/README.md +341 -0
  4. trinity_rft-0.1.0/pyproject.toml +105 -0
  5. trinity_rft-0.1.0/setup.cfg +4 -0
  6. trinity_rft-0.1.0/setup.py +3 -0
  7. trinity_rft-0.1.0/trinity/__init__.py +4 -0
  8. trinity_rft-0.1.0/trinity/buffer/__init__.py +7 -0
  9. trinity_rft-0.1.0/trinity/buffer/buffer.py +65 -0
  10. trinity_rft-0.1.0/trinity/buffer/buffer_reader.py +13 -0
  11. trinity_rft-0.1.0/trinity/buffer/buffer_writer.py +15 -0
  12. trinity_rft-0.1.0/trinity/buffer/queue.py +54 -0
  13. trinity_rft-0.1.0/trinity/buffer/reader/__init__.py +0 -0
  14. trinity_rft-0.1.0/trinity/buffer/reader/file_reader.py +231 -0
  15. trinity_rft-0.1.0/trinity/buffer/reader/queue_reader.py +34 -0
  16. trinity_rft-0.1.0/trinity/buffer/reader/sql_reader.py +79 -0
  17. trinity_rft-0.1.0/trinity/buffer/schema/__init__.py +3 -0
  18. trinity_rft-0.1.0/trinity/buffer/schema/sql_schema.py +149 -0
  19. trinity_rft-0.1.0/trinity/buffer/utils.py +33 -0
  20. trinity_rft-0.1.0/trinity/buffer/writer/__init__.py +0 -0
  21. trinity_rft-0.1.0/trinity/buffer/writer/queue_writer.py +30 -0
  22. trinity_rft-0.1.0/trinity/buffer/writer/sql_writer.py +46 -0
  23. trinity_rft-0.1.0/trinity/cli/client.py +44 -0
  24. trinity_rft-0.1.0/trinity/cli/launcher.py +238 -0
  25. trinity_rft-0.1.0/trinity/cli/server.py +32 -0
  26. trinity_rft-0.1.0/trinity/common/__init__.py +0 -0
  27. trinity_rft-0.1.0/trinity/common/config.py +578 -0
  28. trinity_rft-0.1.0/trinity/common/constants.py +119 -0
  29. trinity_rft-0.1.0/trinity/common/experience.py +278 -0
  30. trinity_rft-0.1.0/trinity/common/models/__init__.py +139 -0
  31. trinity_rft-0.1.0/trinity/common/models/model.py +130 -0
  32. trinity_rft-0.1.0/trinity/common/models/openai_api.py +79 -0
  33. trinity_rft-0.1.0/trinity/common/models/utils.py +265 -0
  34. trinity_rft-0.1.0/trinity/common/models/vllm_async_model.py +353 -0
  35. trinity_rft-0.1.0/trinity/common/models/vllm_model.py +287 -0
  36. trinity_rft-0.1.0/trinity/common/models/vllm_worker.py +74 -0
  37. trinity_rft-0.1.0/trinity/common/rewards/__init__.py +11 -0
  38. trinity_rft-0.1.0/trinity/common/rewards/accuracy_reward.py +33 -0
  39. trinity_rft-0.1.0/trinity/common/rewards/agents_reward.py +1 -0
  40. trinity_rft-0.1.0/trinity/common/rewards/base.py +24 -0
  41. trinity_rft-0.1.0/trinity/common/rewards/composite_reward.py +24 -0
  42. trinity_rft-0.1.0/trinity/common/rewards/format_reward.py +29 -0
  43. trinity_rft-0.1.0/trinity/common/rewards/human_reward.py +1 -0
  44. trinity_rft-0.1.0/trinity/common/rewards/reward_fn.py +197 -0
  45. trinity_rft-0.1.0/trinity/common/rewards/tool_reward.py +1 -0
  46. trinity_rft-0.1.0/trinity/common/schema.py +148 -0
  47. trinity_rft-0.1.0/trinity/common/verl_config.py +346 -0
  48. trinity_rft-0.1.0/trinity/common/workflows/__init__.py +16 -0
  49. trinity_rft-0.1.0/trinity/common/workflows/envs/alfworld/alfworld_workflow.py +179 -0
  50. trinity_rft-0.1.0/trinity/common/workflows/envs/sciworld/sciworld_workflow.py +144 -0
  51. trinity_rft-0.1.0/trinity/common/workflows/envs/webshop/webshop_workflow.py +273 -0
  52. trinity_rft-0.1.0/trinity/common/workflows/workflow.py +245 -0
  53. trinity_rft-0.1.0/trinity/data/controllers/active_iterator.py +290 -0
  54. trinity_rft-0.1.0/trinity/data/controllers/default_ops.py +77 -0
  55. trinity_rft-0.1.0/trinity/data/controllers/task_parser.py +303 -0
  56. trinity_rft-0.1.0/trinity/data/core/comparator.py +84 -0
  57. trinity_rft-0.1.0/trinity/data/core/dataset.py +136 -0
  58. trinity_rft-0.1.0/trinity/data/core/dataset_db.py +84 -0
  59. trinity_rft-0.1.0/trinity/data/core/formatter.py +151 -0
  60. trinity_rft-0.1.0/trinity/data/processors/base.py +143 -0
  61. trinity_rft-0.1.0/trinity/data/processors/cleaner.py +229 -0
  62. trinity_rft-0.1.0/trinity/data/processors/human_annotator.py +47 -0
  63. trinity_rft-0.1.0/trinity/data/processors/synthesizer.py +107 -0
  64. trinity_rft-0.1.0/trinity/data/server.py +27 -0
  65. trinity_rft-0.1.0/trinity/explorer/__init__.py +4 -0
  66. trinity_rft-0.1.0/trinity/explorer/explorer.py +299 -0
  67. trinity_rft-0.1.0/trinity/explorer/runner_pool.py +269 -0
  68. trinity_rft-0.1.0/trinity/explorer/workflow_runner.py +109 -0
  69. trinity_rft-0.1.0/trinity/manager/__init__.py +7 -0
  70. trinity_rft-0.1.0/trinity/manager/config_manager.py +1786 -0
  71. trinity_rft-0.1.0/trinity/manager/manager.py +69 -0
  72. trinity_rft-0.1.0/trinity/trainer/__init__.py +3 -0
  73. trinity_rft-0.1.0/trinity/trainer/trainer.py +175 -0
  74. trinity_rft-0.1.0/trinity/trainer/verl/__init__.py +0 -0
  75. trinity_rft-0.1.0/trinity/trainer/verl/core_algos.py +717 -0
  76. trinity_rft-0.1.0/trinity/trainer/verl/dp_actor.py +538 -0
  77. trinity_rft-0.1.0/trinity/trainer/verl/fsdp_workers.py +1522 -0
  78. trinity_rft-0.1.0/trinity/trainer/verl/ray_trainer.py +1160 -0
  79. trinity_rft-0.1.0/trinity/trainer/verl_trainer.py +552 -0
  80. trinity_rft-0.1.0/trinity/utils/__init__.py +0 -0
  81. trinity_rft-0.1.0/trinity/utils/distributed.py +82 -0
  82. trinity_rft-0.1.0/trinity/utils/dlc_utils.py +86 -0
  83. trinity_rft-0.1.0/trinity/utils/eval_utils.py +78 -0
  84. trinity_rft-0.1.0/trinity/utils/log.py +65 -0
  85. trinity_rft-0.1.0/trinity/utils/monitor.py +109 -0
  86. trinity_rft-0.1.0/trinity/utils/registry.py +127 -0
  87. trinity_rft-0.1.0/trinity_rft.egg-info/PKG-INFO +396 -0
  88. trinity_rft-0.1.0/trinity_rft.egg-info/SOURCES.txt +90 -0
  89. trinity_rft-0.1.0/trinity_rft.egg-info/dependency_links.txt +1 -0
  90. trinity_rft-0.1.0/trinity_rft.egg-info/entry_points.txt +2 -0
  91. trinity_rft-0.1.0/trinity_rft.egg-info/requires.txt +40 -0
  92. trinity_rft-0.1.0/trinity_rft.egg-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,396 @@
1
+ Metadata-Version: 2.4
2
+ Name: trinity-rft
3
+ Version: 0.1.0
4
+ Summary: Trinity-RFT: A Framework for Training Large Language Models with Reinforcement Fine-Tuning
5
+ Author-email: Trinity-RFT Team <trinity-rft@outlook.com>
6
+ Project-URL: Homepage, https://github.com/modelscope/Trinity-RFT
7
+ Project-URL: Documentation, https://modelscope.github.io/Trinity-RFT/
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: verl==0.3.0.post1
19
+ Requires-Dist: ray[default]>=2.45.0
20
+ Requires-Dist: vllm>=0.8.5
21
+ Requires-Dist: tensordict==0.6.2
22
+ Requires-Dist: wandb
23
+ Requires-Dist: omegaconf
24
+ Requires-Dist: sqlalchemy
25
+ Requires-Dist: psycopg2-binary
26
+ Requires-Dist: networkx
27
+ Requires-Dist: latex2sympy2_extended
28
+ Requires-Dist: math_verify
29
+ Requires-Dist: ninja
30
+ Requires-Dist: fire
31
+ Requires-Dist: streamlit
32
+ Requires-Dist: flask
33
+ Requires-Dist: requests
34
+ Requires-Dist: tensorboard
35
+ Requires-Dist: openai
36
+ Provides-Extra: data
37
+ Requires-Dist: py-data-juicer; extra == "data"
38
+ Provides-Extra: agent
39
+ Requires-Dist: agentscope; extra == "agent"
40
+ Provides-Extra: dev
41
+ Requires-Dist: pre-commit>=2.17.0; extra == "dev"
42
+ Requires-Dist: black>=23.7.0; extra == "dev"
43
+ Requires-Dist: flake8>=6.1.0; extra == "dev"
44
+ Requires-Dist: flake8-docstrings>=1.6.0; extra == "dev"
45
+ Requires-Dist: isort>=5.12.0; extra == "dev"
46
+ Requires-Dist: mypy>=1.7.0; extra == "dev"
47
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
48
+ Requires-Dist: pytest-json-ctrf; extra == "dev"
49
+ Provides-Extra: doc
50
+ Requires-Dist: sphinx; extra == "doc"
51
+ Requires-Dist: sphinx-autobuild; extra == "doc"
52
+ Requires-Dist: sphinx_rtd_theme; extra == "doc"
53
+ Requires-Dist: myst-parser; extra == "doc"
54
+ Dynamic: license-file
55
+
56
+
57
+
58
+ <!-- ![trinity-rft](./docs/sphinx_doc/assets/trinity-title.png) -->
59
+
60
+ <div align="center">
61
+ <img src="https://img.alicdn.com/imgextra/i1/O1CN01lvLpfw25Pl4ohGZnU_!!6000000007519-2-tps-1628-490.png" alt="Trinity-RFT" style="height: 120px;">
62
+ </div>
63
+
64
+
65
+ &nbsp;
66
+
67
+
68
+
69
+ **Trinity-RFT is a general-purpose, flexible, scalable and user-friendly framework designed for reinforcement fine-tuning (RFT) of large language models (LLM).**
70
+
71
+
72
+ Built with a decoupled design, seamless integration for agent-environment interaction, and systematic data processing pipelines, Trinity-RFT can be easily adapted for diverse application scenarios, and serve as a unified platform for exploring advanced reinforcement learning (RL) paradigms.
73
+
74
+
75
+
76
+
77
+
78
+ ## Vision of this project
79
+
80
+
81
+ 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, and continuous learning.
82
+
83
+ 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.
84
+
85
+
86
+ 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.
87
+
88
+
89
+ Trinity-RFT offers a path into this future by providing various useful features.
90
+
91
+
92
+
93
+
94
+
95
+ ## Key features
96
+
97
+
98
+
99
+ + **Unified RFT modes & algorithm support.**
100
+ Trinity-RFT unifies and generalizes existing RFT methodologies into a flexible and configurable framework, supporting synchronous/asynchronous, on-policy/off-policy, and online/offline training, as well as hybrid modes that combine them seamlessly into a single learning process.
101
+
102
+
103
+ + **Agent-environment interaction as a first-class citizen.**
104
+ 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.
105
+
106
+
107
+
108
+ + **Data processing pipelines optimized for RFT with diverse/messy data.**
109
+ These include converting raw datasets to 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.
110
+
111
+
112
+
113
+ ## The design of Trinity-RFT
114
+
115
+
116
+ <!-- ![design](./docs/sphinx_doc/assets/trinity-design.png) -->
117
+
118
+ <div align="center">
119
+ <img src="https://img.alicdn.com/imgextra/i2/O1CN01X5jFm81peNsADtRt2_!!6000000005385-2-tps-3298-1498.png" alt="Trinity-RFT">
120
+ </div>
121
+
122
+
123
+
124
+
125
+
126
+ The overall design of Trinity-RFT exhibits a trinity:
127
+ + RFT-core;
128
+ + agent-environment interaction;
129
+ + data processing pipelines;
130
+
131
+ and the design of RFT-core also exhibits a trinity:
132
+ + explorer;
133
+ + trainer;
134
+ + buffer.
135
+
136
+
137
+
138
+ The *explorer*, powered by the rollout model, interacts with the environment and generates rollout trajectories to be stored in the experience buffer.
139
+
140
+ The *trainer*, powered by the policy model, samples batches of experiences from the buffer and updates the policy model via RL algorithms.
141
+
142
+ These two can be completely decoupled and act asynchronously on separate machines, except that they share the same experience buffer, and their model weights are synchronized once in a while.
143
+ Such a decoupled design is crucial for making the aforementioned features of Trinity-RFT possible.
144
+
145
+ <!-- e.g., flexible and configurable RFT modes (on-policy/off-policy, synchronous/asynchronous, immediate/lagged rewards),
146
+ fault tolerance for failures of explorer (agent/environment) or trainer,
147
+ high efficiency in the presence of long-tailed rollout latencies,
148
+ 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),
149
+ among others. -->
150
+
151
+
152
+
153
+ Meanwhile, Trinity-RFT has done a lot of work to ensure high efficiency and robustness in every component of the framework,
154
+ 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,
155
+ asynchronous and concurrent LLM inference for rollout,
156
+ fault tolerance for agent/environment failures,
157
+ among many others.
158
+
159
+
160
+
161
+ ## Getting started
162
+
163
+
164
+ > [!NOTE]
165
+ > This project is currently under active development. Comments and suggestions are welcome!
166
+
167
+
168
+
169
+
170
+ ### Step 1: preparations
171
+
172
+
173
+
174
+
175
+ Installation from source (recommended):
176
+
177
+ ```shell
178
+ # Pull the source code from GitHub
179
+ git clone https://github.com/modelscope/Trinity-RFT
180
+ cd Trinity-RFT
181
+
182
+ # Create a new environment using Conda or venv
183
+ # Option 1: Conda
184
+ conda create -n trinity python=3.10
185
+ conda activate trinity
186
+
187
+ # Option 2: venv
188
+ python3.10 -m venv .venv
189
+ source .venv/bin/activate
190
+
191
+ # Install the package in editable mode
192
+ # for bash
193
+ pip install -e .[dev]
194
+ # for zsh
195
+ pip install -e .\[dev\]
196
+
197
+ # Install flash-attn after all dependencies are installed
198
+ # Note: flash-attn will take a long time to compile, please be patient.
199
+ pip install flash-attn -v
200
+ # Try the following command if you encounter errors during installation
201
+ # pip install flash-attn -v --no-build-isolation
202
+ ```
203
+
204
+ Installation from docker:
205
+ we have provided a dockerfile for Trinity-RFT (trinity)
206
+
207
+ ```shell
208
+ git clone https://github.com/modelscope/Trinity-RFT
209
+ cd Trinity-RFT
210
+
211
+ # build the docker image
212
+ # Note: you can edit the dockerfile to customize the environment
213
+ # e.g., use pip mirrors or set api key
214
+ docker build -f scripts/docker/Dockerfile -t trinity-rft:latest .
215
+
216
+ # run the docker image
217
+ docker run -it --gpus all --shm-size="64g" --rm -v $PWD:/workspace -v <root_path_of_data_and_checkpoints>:/data trinity-rft:latest
218
+ ```
219
+
220
+
221
+ Trinity-RFT requires
222
+ Python version >= 3.10,
223
+ CUDA version >= 12.4,
224
+ and at least 2 GPUs.
225
+
226
+
227
+ ### Step 2: prepare dataset and model
228
+
229
+
230
+ Trinity-RFT supports most datasets and models from Huggingface and ModelScope.
231
+
232
+
233
+ **Prepare the model** in the local directory `$MODEL_PATH/{model_name}`:
234
+
235
+ ```bash
236
+ # Using Huggingface
237
+ huggingface-cli download {model_name} --local-dir $MODEL_PATH/{model_name}
238
+
239
+ # Using Modelscope
240
+ modelscope download {model_name} --local_dir $MODEL_PATH/{model_name}
241
+ ```
242
+
243
+ For more details about model downloading, please refer to [Huggingface](https://huggingface.co/docs/huggingface_hub/main/en/guides/cli) or [ModelScope](https://modelscope.cn/docs/models/download).
244
+
245
+
246
+
247
+ **Prepare the dataset** in the local directory `$DATASET_PATH/{dataset_name}`:
248
+
249
+ ```bash
250
+ # Using Huggingface
251
+ huggingface-cli download {dataset_name} --repo-type dataset --local-dir $DATASET_PATH/{dataset_name}
252
+
253
+ # Using Modelscope
254
+ modelscope download --dataset {dataset_name} --local_dir $DATASET_PATH/{dataset_name}
255
+ ```
256
+
257
+ For more details about dataset downloading, please refer to [Huggingface](https://huggingface.co/docs/huggingface_hub/main/en/guides/cli#download-a-dataset-or-a-space) or [ModelScope](https://modelscope.cn/docs/datasets/download).
258
+
259
+
260
+
261
+ ### Step 3: configurations
262
+
263
+
264
+ For convenience, Trinity-RFT provides a web interface for configuring your RFT process.
265
+
266
+ > [!NOTE]
267
+ > This is an experimental feature, and we will continue to improve it.
268
+
269
+ ```bash
270
+ trinity studio --port 8080
271
+ ```
272
+
273
+
274
+ Then you can configure your RFT process in the web page and generate a config file.
275
+ You can save the config for later use or run it directly as described in the following section.
276
+
277
+
278
+ Advanced users can also configure the RFT process by editing the config file directly.
279
+ We provide a set of example config files in [`examples`](examples/).
280
+
281
+
282
+ ### Step 4: run the RFT process
283
+
284
+
285
+ First, start a ray cluster with the following command:
286
+
287
+ ```shell
288
+ # On master node
289
+ ray start --head
290
+
291
+ # On worker nodes
292
+ ray start --address=<master_address>
293
+ ```
294
+
295
+ Optionally, we can login into [wandb](https://docs.wandb.ai/quickstart/) to better monitor the RFT process:
296
+
297
+ ```shell
298
+ export WANDB_API_KEY=<your_api_key>
299
+ wandb login
300
+ ```
301
+
302
+ Then, for command-line users, run the RFT process with the following command:
303
+
304
+ ```shell
305
+ trinity run --config <config_path>
306
+ ```
307
+
308
+ > For example, below is the command for fine-tuning Qwen-2.5-1.5B-Instruct on GSM8k dataset using GRPO algorithm:
309
+ > ```shell
310
+ > trinity run --config examples/grpo_gsm8k/gsm8k.yaml
311
+ > ```
312
+
313
+ For studio users, just click the "Run" button in the web page.
314
+
315
+
316
+ For more detailed examples about how to use Trinity-RFT, please refer to the following tutorials:
317
+ + [A quick example with GSM8k](./docs/sphinx_doc/source/tutorial/example_reasoning_basic.md)
318
+ + [Off-policy mode of RFT](./docs/sphinx_doc/source/tutorial/example_reasoning_advanced.md)
319
+ + [Asynchronous mode of RFT](./docs/sphinx_doc/source/tutorial/example_async_mode.md)
320
+ + [Multi-turn tasks](./docs/sphinx_doc/source/tutorial/example_multi_turn.md)
321
+ + [Offline learning by DPO](./docs/sphinx_doc/source/tutorial/example_dpo.md)
322
+ + [Advanced data processing / human-in-the-loop](./docs/sphinx_doc/source/tutorial/example_data_functionalities.md)
323
+
324
+
325
+
326
+
327
+
328
+ ## Advanced usage and full configurations
329
+
330
+
331
+ Please refer to [this document](./docs/sphinx_doc/source/tutorial/trinity_configs.md).
332
+
333
+
334
+
335
+
336
+
337
+ ## Programming guide for developers
338
+
339
+
340
+ Please refer to [this document](./docs/sphinx_doc/source/tutorial/trinity_programming_guide.md).
341
+
342
+
343
+ ## Upcoming features
344
+
345
+ A tentative roadmap: https://github.com/modelscope/Trinity-RFT/issues/51
346
+
347
+
348
+
349
+ ## Contribution guide
350
+
351
+
352
+ This project is currently under active development, and we welcome contributions from the community!
353
+
354
+
355
+ Code style check:
356
+
357
+ ```shell
358
+ pre-commit run --all-files
359
+ ```
360
+
361
+
362
+
363
+ Unit tests:
364
+
365
+ ```shell
366
+ python -m pytest tests
367
+ ```
368
+
369
+
370
+
371
+ ## Acknowledgements
372
+
373
+
374
+ This project is built upon many excellent open-source projects, including:
375
+
376
+ + [verl](https://github.com/volcengine/verl) and [PyTorch's FSDP](https://pytorch.org/docs/stable/fsdp.html) for LLM training;
377
+ + [vLLM](https://github.com/vllm-project/vllm) for LLM inference;
378
+ + [Data-Juicer](https://github.com/modelscope/data-juicer?tab=readme-ov-file) for data processing pipelines;
379
+ + [AgentScope](https://github.com/modelscope/agentscope) for agentic workflow;
380
+ + [Ray](https://github.com/ray-project/ray) for distributed systems;
381
+ + we have also drawn inspirations from RL frameworks like [OpenRLHF](https://github.com/OpenRLHF/OpenRLHF), [TRL](https://github.com/huggingface/trl) and [ChatLearn](https://github.com/alibaba/ChatLearn);
382
+ + ......
383
+
384
+
385
+
386
+
387
+
388
+ ## Citation
389
+ ```plain
390
+ @misc{Trinity-RFT,
391
+ title={Trinity-RFT},
392
+ author={{Trinity-RFT Team}},
393
+ url={https://github.com/modelscope/trinity-rft},
394
+ year={2025},
395
+ }
396
+ ```