mirror of
https://github.com/volcengine/verl.git
synced 2025-10-20 13:43:50 +08:00
[trainer] fix: Allow FSDP2 when doing strategy check (#2497)
### What does this PR do? Allow FSDP2 when doing strategy check ### 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. For `strategy` field, now both "fsdp" and "fsdp2" are considered valid. ### 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: ... - [X] 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). Signed-off-by: Hollow Man <hollowman@opensuse.org>
This commit is contained in:
@ -48,8 +48,8 @@ Define worker classes
|
||||
|
||||
.. code:: python
|
||||
|
||||
if config.actor_rollout_ref.actor.strategy == 'fsdp': # for FSDP backend
|
||||
assert config.actor_rollout_ref.actor.strategy == config.critic.strategy
|
||||
if config.actor_rollout_ref.actor.strategy in {"fsdp", "fsdp2"}: # for FSDP backend
|
||||
assert config.critic.strategy in {"fsdp", "fsdp2"}
|
||||
from verl.workers.fsdp_workers import ActorRolloutRefWorker, CriticWorker
|
||||
from verl.single_controller.ray import RayWorkerGroup
|
||||
ray_worker_group_cls = RayWorkerGroup
|
||||
|
@ -123,8 +123,8 @@ def main_task(config):
|
||||
tokenizer = hf_tokenizer(local_path)
|
||||
|
||||
# define worker classes
|
||||
if config.actor_rollout_ref.actor.strategy == "fsdp":
|
||||
assert config.actor_rollout_ref.actor.strategy == config.critic.strategy
|
||||
if config.actor_rollout_ref.actor.strategy in {"fsdp", "fsdp2"}:
|
||||
assert config.critic.strategy in {"fsdp", "fsdp2"}
|
||||
from verl.single_controller.ray import RayWorkerGroup
|
||||
from verl.workers.fsdp_workers import ActorRolloutRefWorker, CriticWorker
|
||||
|
||||
@ -178,7 +178,7 @@ def main_task(config):
|
||||
# - finally, we combine all the rewards together
|
||||
# - The reward type depends on the tag of the data
|
||||
if config.reward_model.enable:
|
||||
if config.reward_model.strategy == "fsdp":
|
||||
if config.reward_model.strategy in {"fsdp", "fsdp2"}:
|
||||
from verl.workers.fsdp_workers import RewardModelWorker
|
||||
elif config.reward_model.strategy == "megatron":
|
||||
from verl.workers.megatron_workers import RewardModelWorker
|
||||
|
@ -80,8 +80,8 @@ class TaskRunner:
|
||||
processor = hf_processor(local_path, use_fast=True) # used for multimodal LLM, could be none
|
||||
|
||||
# define worker classes
|
||||
if config.actor_rollout_ref.actor.strategy == "fsdp":
|
||||
assert config.actor_rollout_ref.actor.strategy == config.critic.strategy
|
||||
if config.actor_rollout_ref.actor.strategy in {"fsdp", "fsdp2"}:
|
||||
assert config.critic.strategy in {"fsdp", "fsdp2"}
|
||||
from verl.single_controller.ray import RayWorkerGroup
|
||||
from verl.workers.fsdp_workers import ActorRolloutRefWorker, CriticWorker
|
||||
|
||||
@ -120,7 +120,7 @@ class TaskRunner:
|
||||
# - finally, we combine all the rewards together
|
||||
# - The reward type depends on the tag of the data
|
||||
if config.reward_model.enable:
|
||||
if config.reward_model.strategy == "fsdp":
|
||||
if config.reward_model.strategy in {"fsdp", "fsdp2"}:
|
||||
from verl.workers.fsdp_workers import RewardModelWorker
|
||||
elif config.reward_model.strategy == "megatron":
|
||||
from verl.workers.megatron_workers import RewardModelWorker
|
||||
|
@ -85,8 +85,8 @@ class TaskRunner:
|
||||
processor = hf_processor(local_path, use_fast=True) # used for multimodal LLM, could be none
|
||||
|
||||
# define worker classes
|
||||
if config.actor_rollout_ref.actor.strategy in ["fsdp", "fsdp2"]:
|
||||
assert config.critic.strategy in ["fsdp", "fsdp2"]
|
||||
if config.actor_rollout_ref.actor.strategy in {"fsdp", "fsdp2"}:
|
||||
assert config.critic.strategy in {"fsdp", "fsdp2"}
|
||||
from verl.single_controller.ray import RayWorkerGroup
|
||||
from verl.workers.fsdp_workers import ActorRolloutRefWorker, AsyncActorRolloutRefWorker, CriticWorker
|
||||
|
||||
@ -131,7 +131,7 @@ class TaskRunner:
|
||||
# - finally, we combine all the rewards together
|
||||
# - The reward type depends on the tag of the data
|
||||
if config.reward_model.enable:
|
||||
if config.reward_model.strategy in ["fsdp", "fsdp2"]:
|
||||
if config.reward_model.strategy in {"fsdp", "fsdp2"}:
|
||||
from verl.workers.fsdp_workers import RewardModelWorker
|
||||
elif config.reward_model.strategy == "megatron":
|
||||
from verl.workers.megatron_workers import RewardModelWorker
|
||||
|
@ -72,8 +72,8 @@ def main_task(config, compute_score=None):
|
||||
tokenizer = hf_tokenizer(local_path)
|
||||
|
||||
# define worker classes
|
||||
if config.actor_rollout_ref.actor.strategy == "fsdp":
|
||||
assert config.actor_rollout_ref.actor.strategy == config.critic.strategy
|
||||
if config.actor_rollout_ref.actor.strategy in {"fsdp", "fsdp2"}:
|
||||
assert config.critic.strategy in {"fsdp", "fsdp2"}
|
||||
from verl.single_controller.ray import RayWorkerGroup
|
||||
from verl.workers.fsdp_workers import ActorRolloutRefWorker
|
||||
|
||||
|
@ -67,8 +67,8 @@ class TaskRunner:
|
||||
processor = hf_processor(local_path, use_fast=True) # used for multimodal LLM, could be none
|
||||
|
||||
# define worker classes
|
||||
if config.actor_rollout_ref.actor.strategy == "fsdp":
|
||||
assert config.actor_rollout_ref.actor.strategy == config.critic.strategy
|
||||
if config.actor_rollout_ref.actor.strategy in {"fsdp", "fsdp2"}:
|
||||
assert config.critic.strategy in {"fsdp", "fsdp2"}
|
||||
# from recipe.spin.fsdp_workers import ActorRolloutRefWorker
|
||||
from recipe.spin.fsdp_workers import SPINRolloutRefWorker
|
||||
from verl.single_controller.ray import RayWorkerGroup
|
||||
@ -102,7 +102,7 @@ class TaskRunner:
|
||||
}
|
||||
|
||||
if config.reward_model.enable:
|
||||
if config.reward_model.strategy == "fsdp":
|
||||
if config.reward_model.strategy in {"fsdp", "fsdp2"}:
|
||||
from recipe.spin.fsdp_workers import RewardModelWorker
|
||||
elif config.reward_model.strategy == "megatron":
|
||||
from verl.workers.megatron_workers import RewardModelWorker
|
||||
|
@ -522,7 +522,7 @@ class RaySPINTrainer:
|
||||
assert config.critic.ppo_micro_batch_size * sp_size >= n_gpus
|
||||
|
||||
# Check if use_remove_padding is enabled when using sequence parallelism for fsdp
|
||||
if config.actor_rollout_ref.actor.strategy == "fsdp":
|
||||
if config.actor_rollout_ref.actor.strategy in {"fsdp", "fsdp2"}:
|
||||
if (
|
||||
config.actor_rollout_ref.actor.get("ulysses_sequence_parallel_size", 1) > 1
|
||||
or config.actor_rollout_ref.ref.get("ulysses_sequence_parallel_size", 1) > 1
|
||||
@ -531,7 +531,7 @@ class RaySPINTrainer:
|
||||
"When using sequence parallelism for actor/ref policy, you must enable `use_remove_padding`."
|
||||
)
|
||||
|
||||
if self.use_critic and config.critic.strategy == "fsdp":
|
||||
if self.use_critic and config.critic.strategy in {"fsdp", "fsdp2"}:
|
||||
if config.critic.get("ulysses_sequence_parallel_size", 1) > 1:
|
||||
assert config.critic.model.use_remove_padding, (
|
||||
"When using sequence parallelism for critic, you must enable `use_remove_padding`."
|
||||
|
@ -73,8 +73,8 @@ class TaskRunner:
|
||||
processor = hf_processor(local_path, use_fast=True) # used for multimodal LLM, could be none
|
||||
|
||||
# define worker classes
|
||||
if config.actor_rollout_ref.actor.strategy == "fsdp":
|
||||
assert config.actor_rollout_ref.actor.strategy == config.critic.strategy
|
||||
if config.actor_rollout_ref.actor.strategy in {"fsdp", "fsdp2"}:
|
||||
assert config.critic.strategy in {"fsdp", "fsdp2"}
|
||||
from verl.single_controller.ray import RayWorkerGroup
|
||||
|
||||
from .sppo_worker import SPPOActorRolloutRefWorker # , CriticWorker
|
||||
@ -115,7 +115,7 @@ class TaskRunner:
|
||||
# - finally, we combine all the rewards together
|
||||
# - The reward type depends on the tag of the data
|
||||
if config.reward_model.enable:
|
||||
if config.reward_model.strategy == "fsdp":
|
||||
if config.reward_model.strategy in {"fsdp", "fsdp2"}:
|
||||
from verl.workers.fsdp_workers import RewardModelWorker
|
||||
elif config.reward_model.strategy == "megatron":
|
||||
from verl.workers.megatron_workers import RewardModelWorker
|
||||
|
@ -523,7 +523,7 @@ class RayPPOTrainer:
|
||||
assert config.critic.ppo_micro_batch_size * sp_size >= n_gpus
|
||||
|
||||
# Check if use_remove_padding is enabled when using sequence parallelism for fsdp
|
||||
if config.actor_rollout_ref.actor.strategy == "fsdp" and (
|
||||
if config.actor_rollout_ref.actor.strategy in {"fsdp", "fsdp2"} and (
|
||||
config.actor_rollout_ref.actor.get("ulysses_sequence_parallel_size", 1) > 1
|
||||
or config.actor_rollout_ref.ref.get("ulysses_sequence_parallel_size", 1) > 1
|
||||
):
|
||||
@ -531,7 +531,7 @@ class RayPPOTrainer:
|
||||
"When using sequence parallelism for actor/ref policy, you must enable `use_remove_padding`."
|
||||
)
|
||||
|
||||
if self.use_critic and config.critic.strategy == "fsdp":
|
||||
if self.use_critic and config.critic.strategy in {"fsdp", "fsdp2"}:
|
||||
if config.critic.get("ulysses_sequence_parallel_size", 1) > 1:
|
||||
assert config.critic.model.use_remove_padding, (
|
||||
"When using sequence parallelism for critic, you must enable `use_remove_padding`."
|
||||
|
Reference in New Issue
Block a user