Skip to content

Conversation

@EduardDurech
Copy link
Collaborator

@EduardDurech EduardDurech commented Sep 30, 2025

Abstract optimizer so can be used with whatever module and method a user wants, should be backwards compatible as default is torch.optim.AdamW, adds {actor_rollout_ref.actor,critic}.optim.{optimizer,optimizer_impl,override_optimizer_config}

# Default
optimizer_impl: torch.optim
optimizer: AdamW
# Example
optimizer_impl: torchao.optim
optimizer: _AdamW
override_optimizer_config:
  bf16_stochastic_round: true

Important: fsdp_sft_trainer optim aligned with FSDP optim optim.warmup_steps_ratio->optim.lr_warmup_steps_ratio

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 flexible optimizer abstraction, allowing users to specify any optimizer via configuration. This is a great enhancement for modularity. My review focuses on the implementation of the new build_optimizer function. I've identified a critical issue where the argument handling for the dynamically loaded optimizer is not robust and can lead to runtime TypeError exceptions. My suggestion involves using Python's inspect module to build the arguments dictionary safely, ensuring only valid parameters are passed to the optimizer's constructor. This will make the implementation more generic and prevent unexpected crashes.

@EduardDurech EduardDurech marked this pull request as draft October 6, 2025 21:04
@EduardDurech EduardDurech marked this pull request as ready for review October 7, 2025 00:25
@wuxibin89
Copy link
Collaborator

@EduardDurech Please resolve conflicts with main branch.

@EduardDurech
Copy link
Collaborator Author

@wuxibin89 I overwrote the PR #3692 as extra parameters should now be defined in {actor_rollout_ref.actor,critic}.optim.override_optimizer_config I'll comment on the PR

ci is unrelated to PR, tests passed #cf4cc6a6c60b2a21b1765825b83158ae6bea101b

cpu_unit_tests

huggingface_hub.errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.

sgl

RuntimeError: Maybe you called ray.init twice by accident? This error can be suppressed by passing in 'ignore_reinit_error=True' or by calling 'ray.shutdown()' prior to 'ray.init()'.

e2e_ascend
File "/usr/local/python3.10.17/lib/python3.10/site-packages/requests/models.py", line 978, in json
(TaskRunner pid=213242)     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
(TaskRunner pid=213242) requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

vermouth1992 pushed a commit that referenced this pull request Oct 13, 2025
…heduler_type (#3739)

### What does this PR do?

> Rename `warmup_style` in FSDPOptimizerConfig to `lr_scheduler_type` to
align with Hugging Face Trainer API。

The following pull request is for refactoring the optimizer, however,
the naming issue persists.
#3656 
### 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`
- 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).)

---------

Co-authored-by: weiqi.li <[email protected]>
@EduardDurech
Copy link
Collaborator Author

@wuxibin89 @vermouth1992 could we get this merge, it's very annoying to have to resolve merge conflicts every other day because of other PRs, I don't have time to maintain a single PR for weeks

@EduardDurech
Copy link
Collaborator Author

Let me know when you guys are ready to merge please, I cannot waste an hour each time to fix merge conflicts and then it doesn't get merged

masoudhashemi pushed a commit to masoudhashemi/verl that referenced this pull request Oct 19, 2025
…heduler_type (volcengine#3739)

### What does this PR do?

> Rename `warmup_style` in FSDPOptimizerConfig to `lr_scheduler_type` to
align with Hugging Face Trainer API。

The following pull request is for refactoring the optimizer, however,
the naming issue persists.
volcengine#3656 
### 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`
- 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).)

---------

Co-authored-by: weiqi.li <[email protected]>
@vermouth1992 vermouth1992 merged commit 6cf90ce into volcengine:main Oct 23, 2025
69 of 73 checks passed
sunnweiwei pushed a commit to sunnweiwei/verl that referenced this pull request Oct 23, 2025
Abstract optimizer so can be used with whatever module and method a user
wants, should be backwards compatible as default is `torch.optim.AdamW`,
adds
`{actor_rollout_ref.actor,critic}.optim.{optimizer,optimizer_impl,override_optimizer_config}`

```yaml
# Default
optimizer_impl: torch.optim
optimizer: AdamW
```
```yaml
# Example
optimizer_impl: torchao.optim
optimizer: _AdamW
override_optimizer_config:
  bf16_stochastic_round: true
```

**Important**: fsdp_sft_trainer optim aligned with FSDP optim
`optim.warmup_steps_ratio`->`optim.lr_warmup_steps_ratio`
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.

3 participants