Commit 0c06358
[data] feat: TransferQueue - remove redundant data collect for both TQ and DataProto (verl-project#4618)
### What does this PR do?
This PR optimizes the dataflow between the single-controller
(RayPPOTrainer) and worker processes. By applying the result filtering
(de-duplication) logic from the controller to the individual workers in
advance, we significantly reduce redundant data transmission.
In the current architecture, worker functions use the @register
decorator to manage data dispatching and collection.
```python3
# in megatron_workers.py
@register(dispatch_mode=make_nd_compute_dataproto_dispatch_fn(mesh_name="actor"))
@GPUMemoryLogger(role="update_actor", logger=logger)
@DistProfiler.annotate(color="red", role="actor_update")
def update_actor(self, data: DataProto):
assert self._is_actor
if self._is_offload_param:
load_megatron_model_to_gpu(self.actor_module)
log_gpu_memory_usage("After load actor params and grad during update_actor", logger=logger)
if self._is_offload_optimizer:
load_megatron_optimizer(self.actor_optimizer)
log_gpu_memory_usage("After load actor optimizer during update_actor", logger=logger)
```
Specifically, `make_nd_compute_dataproto_dispatch_fn` is used to
1. Dispatch: Shard and distribute input data from the controller to
workers.
2. Collect: Gather results back from all workers and de-duplicate them
(usually keeping only one copy per DP group) using a collect_mask.
```python3
def make_nd_compute_dataproto_dispatch_fn(mesh_name):
return {
"dispatch_fn": partial(dispatch_lazy_compute_data_proto, mesh_name),
"collect_fn": partial(collect_lazy_compute_data_proto, mesh_name),
}
```
```python3
def collect_nd_compute(collect_mask: list[bool], worker_group, output):
from verl.single_controller.base.worker_group import WorkerGroup
assert isinstance(worker_group, WorkerGroup)
assert len(output) == worker_group.world_size
output_in_dp = []
for global_rank in range(worker_group.world_size):
collect_dp_rank = collect_mask[global_rank]
if collect_dp_rank:
output_in_dp.append(output[global_rank])
return output_in_dp
```
Previously, the de-duplication process happened entirely on the
controller side.
- Redundant Transmission: Every worker sent its full output back to the
controller, regardless of whether that data would be kept or discarded.
- Overhead: For large-scale LLM training (large DP groups), this led to
massive, unnecessary network traffic or repeated put operations to the
TransferQueue.
- Bottleneck: The controller became a bottleneck as it had to receive
and process redundant data chunks before applying the mask.
In this PR, we shifts the filtering logic "left" (to the worker side).
Now each worker automatically determine whether to return real data or
return an empty obj to the single-controller according to the
`collect_mask` in advance, thus reducing data transfer overhead.
### Checklist Before Starting
- [x] Search for similar PRs. Paste at least one query link here: ...
- [x] Format the PR title as `[{modules}] {type}: {description}` (This
will be checked by the CI)
- `{modules}` include `fsdp`, `megatron`, `sglang`, `vllm`, `rollout`,
`trainer`, `ci`, `training_utils`, `recipe`, `hardware`, `deployment`,
`ray`, `worker`, `single_controller`, `misc`, `perf`, `model`, `algo`,
`env`, `tool`, `ckpt`, `doc`, `data`, `cfg`, `reward`
- If this PR involves multiple modules, separate them with `,` like
`[megatron, fsdp, doc]`
- `{type}` is in `feat`, `fix`, `refactor`, `chore`, `test`
- If this PR breaks any API (CLI arguments, config, function signature,
etc.), add `[BREAKING]` to the beginning of the title.
- Example: `[BREAKING][fsdp, megatron] feat: dynamic batching`
### Test
> For changes that can not be tested by CI (e.g., algorithm
implementation, new model support), validate by experiment(s) and show
results like training curve plots, evaluation results, etc.
### API and Usage Example
> Demonstrate how the API changes if any, and provide usage example(s)
if possible.
```python
# Add code snippet or script demonstrating how to use this
```
### Design & Code Changes
> Demonstrate the high-level design if this PR is complex, and list the
specific changes.
### Checklist Before Submitting
> [!IMPORTANT]
> Please check all the following items before requesting a review,
otherwise the reviewer might deprioritize this PR for review.
- [x] Read the [Contribute
Guide](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md).
- [x] Apply [pre-commit
checks](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md#code-linting-and-formatting):
`pre-commit install && pre-commit run --all-files --show-diff-on-failure
--color=always`
- [x] Add / Update [the
documentation](https://github.com/volcengine/verl/tree/main/docs).
- [x] Add unit or end-to-end test(s) to [the CI
workflow](https://github.com/volcengine/verl/tree/main/.github/workflows)
to cover all the code. If not feasible, explain why: ...
- [ ] Once your PR is ready for CI, send a message in [the `ci-request`
channel](https://verl-project.slack.com/archives/C091TCESWB1) in [the
`verl` Slack
workspace](https://join.slack.com/t/verl-project/shared_invite/zt-3855yhg8g-CTkqXu~hKojPCmo7k_yXTQ).
(If not accessible, please try [the Feishu group
(飞书群)](https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=772jd4f1-cd91-441e-a820-498c6614126a).)
---------
Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
Signed-off-by: jianjunzhong <jianjunzhong@foxmail.com>
Co-authored-by: Jianjun Zhong <87791082+jianjunzhong@users.noreply.github.com>
Co-authored-by: jianjunzhong <jianjunzhong@foxmail.com>1 parent b19b749 commit 0c06358
File tree
3 files changed
+111
-10
lines changed- verl
- single_controller/base
- utils
3 files changed
+111
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
447 | 447 | | |
448 | 448 | | |
449 | 449 | | |
450 | | - | |
| 450 | + | |
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
120 | 123 | | |
121 | 124 | | |
122 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
| |||
144 | 148 | | |
145 | 149 | | |
146 | 150 | | |
147 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
148 | 240 | | |
149 | 241 | | |
150 | 242 | | |
| |||
155 | 247 | | |
156 | 248 | | |
157 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
158 | 253 | | |
159 | 254 | | |
160 | 255 | | |
| |||
181 | 276 | | |
182 | 277 | | |
183 | 278 | | |
184 | | - | |
| 279 | + | |
| 280 | + | |
185 | 281 | | |
186 | 282 | | |
187 | | - | |
188 | | - | |
| 283 | + | |
189 | 284 | | |
190 | 285 | | |
191 | 286 | | |
| |||
203 | 298 | | |
204 | 299 | | |
205 | 300 | | |
206 | | - | |
| 301 | + | |
| 302 | + | |
207 | 303 | | |
208 | 304 | | |
209 | | - | |
| 305 | + | |
210 | 306 | | |
211 | 307 | | |
212 | 308 | | |
213 | | - | |
| 309 | + | |
| 310 | + | |
214 | 311 | | |
215 | 312 | | |
216 | 313 | | |
217 | | - | |
| 314 | + | |
| 315 | + | |
218 | 316 | | |
219 | 317 | | |
220 | 318 | | |
| |||
0 commit comments