Skip to content

[worker] feat: Add TrainingWorker that resembles Tinker-like API#4371

Merged
wuxibin89 merged 13 commits intoverl-project:mainfrom
vermouth1992:chi/dev/trainer_worker
Dec 2, 2025
Merged

[worker] feat: Add TrainingWorker that resembles Tinker-like API#4371
wuxibin89 merged 13 commits intoverl-project:mainfrom
vermouth1992:chi/dev/trainer_worker

Conversation

@vermouth1992
Copy link
Collaborator

What does this PR do?

  • Add TrainingWorker that resembles Tinker-like API
  • Replace sft_trainer with TrainingWorker
  • TrainingWorker provides a unified way to handle metrics and loss
  • Fix bugs in main_ppo when using model engine
  • Fix a bug in calculaing val_loss in sft_trainer
  • In charcount sft task, each metric after switching to TrainingWorker is bitwise aligned

Before

step:139 - train/loss:0.016612909734249115 - train/grad_norm:1.755732774734497 - train/lr:2.0022986040696946e-06 - train/global_tokens:10047 - train/total_tokens(B):0.001423574 - train/mfu:0.5066720655982334
step:140 - train/loss:0.017287615686655045 - train/grad_norm:0.8073480725288391 - train/lr:2.0000000000000008e-06 - train/global_tokens:9671 - train/total_tokens(B):0.001433245 - train/mfu:0.43165669045456023
step:140 - val/loss:0.018036028370261192

After

step:139 - train/loss:0.016612909734249115 - train/grad_norm:1.755732774734497 - train/lr:2.0022986040696946e-06 - train/mfu:0.5087659137382295 - train/global_tokens:10047 - train/total_tokens(B):0.001423574
step:140 - train/loss:0.017287615686655045 - train/grad_norm:0.8073480725288391 - train/lr:2.0000000000000008e-06 - train/mfu:0.4981999407854508 - train/global_tokens:9671 - train/total_tokens(B):0.001433245
step:140 - val/loss:0.018036028370261192

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • 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
    • 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.

# 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a TrainingWorker to abstract and unify training logic, which is a significant and positive refactoring. The changes in sft_trainer to adopt this new worker simplify the code and improve maintainability. The bug fixes for validation loss calculation and PPO with model engine are also valuable. Overall, this is a great step towards a cleaner and more robust training framework. I have one suggestion for improvement regarding tensor initialization.

wuxibin89 and others added 8 commits December 1, 2025 18:30
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@wuxibin89 wuxibin89 merged commit 01eeb49 into verl-project:main Dec 2, 2025
100 of 112 checks passed
TimurTaepov pushed a commit to giorgossideris/verl that referenced this pull request Dec 20, 2025
…l-project#4371)

### What does this PR do?

- Add TrainingWorker that resembles Tinker-like API
- Replace sft_trainer with TrainingWorker
- TrainingWorker provides a unified way to handle metrics and loss
- Fix bugs in main_ppo when using model engine
- Fix a bug in calculaing val_loss in sft_trainer 
- In charcount sft task, each metric after switching to TrainingWorker
is bitwise aligned

Before

```bash
step:139 - train/loss:0.016612909734249115 - train/grad_norm:1.755732774734497 - train/lr:2.0022986040696946e-06 - train/global_tokens:10047 - train/total_tokens(B):0.001423574 - train/mfu:0.5066720655982334
step:140 - train/loss:0.017287615686655045 - train/grad_norm:0.8073480725288391 - train/lr:2.0000000000000008e-06 - train/global_tokens:9671 - train/total_tokens(B):0.001433245 - train/mfu:0.43165669045456023
step:140 - val/loss:0.018036028370261192
```

After
```bash
step:139 - train/loss:0.016612909734249115 - train/grad_norm:1.755732774734497 - train/lr:2.0022986040696946e-06 - train/mfu:0.5087659137382295 - train/global_tokens:10047 - train/total_tokens(B):0.001423574
step:140 - train/loss:0.017287615686655045 - train/grad_norm:0.8073480725288391 - train/lr:2.0000000000000008e-06 - train/mfu:0.4981999407854508 - train/global_tokens:9671 - train/total_tokens(B):0.001433245
step:140 - val/loss:0.018036028370261192
```

### Checklist Before Starting

- [ ] Search for similar PRs. Paste at least one query link here: ...
- [ ] 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`
- 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.

- [ ] Read the [Contribute
Guide](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md).
- [ ] 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`
- [ ] Add / Update [the
documentation](https://github.com/volcengine/verl/tree/main/docs).
- [ ] 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).)

---------

Co-authored-by: Joel <wuxibin89@163.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
vyomakesh0728 added a commit to vyomakesh0728/verl that referenced this pull request Jan 22, 2026
…l-project#4371)

### What does this PR do?

- Add TrainingWorker that resembles Tinker-like API
- Replace sft_trainer with TrainingWorker
- TrainingWorker provides a unified way to handle metrics and loss
- Fix bugs in main_ppo when using model engine
- Fix a bug in calculaing val_loss in sft_trainer 
- In charcount sft task, each metric after switching to TrainingWorker
is bitwise aligned

Before

```bash
step:139 - train/loss:0.016612909734249115 - train/grad_norm:1.755732774734497 - train/lr:2.0022986040696946e-06 - train/global_tokens:10047 - train/total_tokens(B):0.001423574 - train/mfu:0.5066720655982334
step:140 - train/loss:0.017287615686655045 - train/grad_norm:0.8073480725288391 - train/lr:2.0000000000000008e-06 - train/global_tokens:9671 - train/total_tokens(B):0.001433245 - train/mfu:0.43165669045456023
step:140 - val/loss:0.018036028370261192
```

After
```bash
step:139 - train/loss:0.016612909734249115 - train/grad_norm:1.755732774734497 - train/lr:2.0022986040696946e-06 - train/mfu:0.5087659137382295 - train/global_tokens:10047 - train/total_tokens(B):0.001423574
step:140 - train/loss:0.017287615686655045 - train/grad_norm:0.8073480725288391 - train/lr:2.0000000000000008e-06 - train/mfu:0.4981999407854508 - train/global_tokens:9671 - train/total_tokens(B):0.001433245
step:140 - val/loss:0.018036028370261192
```

### Checklist Before Starting

- [ ] Search for similar PRs. Paste at least one query link here: ...
- [ ] 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`
- 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.

- [ ] Read the [Contribute
Guide](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md).
- [ ] 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`
- [ ] Add / Update [the
documentation](https://github.com/volcengine/verl/tree/main/docs).
- [ ] 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).)

---------

Co-authored-by: Joel <wuxibin89@163.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants