Skip to content

Commit 7b24498

Browse files
authored
[trainer] feat: move save_ckpt before update_weights and validate (#5137)
### What does this PR do? We should save_ckpt before validate and update_weights. Then we can remove the unneed sleep_replicas and update_weigths. ### 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`, `veomni`, `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. - [ ] 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).) - [ ] If your PR is related to the `recipe` submodule, please also update the reference to the submodule commit via `git submodule update --remote` or `cd recipe && git pull origin main`.
1 parent 15c09a2 commit 7b24498

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

verl/trainer/ppo/ray_trainer.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,28 @@ def fit(self):
15981598
with marked_timer("update_actor", timing_raw, color="red"):
15991599
actor_output = self._update_actor(batch)
16001600

1601+
# Check if the ESI (Elastic Server Instance)/training plan is close to expiration.
1602+
esi_close_to_expiration = should_save_ckpt_esi(
1603+
max_steps_duration=self.max_steps_duration,
1604+
redundant_time=self.config.trainer.esi_redundant_time,
1605+
)
1606+
# Check if the conditions for saving a checkpoint are met.
1607+
# The conditions include a mandatory condition (1) and
1608+
# one of the following optional conditions (2/3/4):
1609+
# 1. The save frequency is set to a positive value.
1610+
# 2. It's the last training step.
1611+
# 3. The current step number is a multiple of the save frequency.
1612+
# 4. The ESI(Elastic Server Instance)/training plan is close to expiration.
1613+
if self.config.trainer.save_freq > 0 and (
1614+
is_last_step
1615+
or self.global_steps % self.config.trainer.save_freq == 0
1616+
or esi_close_to_expiration
1617+
):
1618+
if esi_close_to_expiration:
1619+
print("Force saving checkpoint: ESI instance expiration approaching.")
1620+
with marked_timer("save_checkpoint", timing_raw, color="green"):
1621+
self._save_checkpoint()
1622+
16011623
# update weights from trainer to rollout
16021624
with marked_timer("update_weights", timing_raw, color="red"):
16031625
self.checkpoint_manager.update_weights()
@@ -1622,30 +1644,6 @@ def fit(self):
16221644
last_val_metrics = val_metrics
16231645
metrics.update(val_metrics)
16241646

1625-
# Check if the ESI (Elastic Server Instance)/training plan is close to expiration.
1626-
esi_close_to_expiration = should_save_ckpt_esi(
1627-
max_steps_duration=self.max_steps_duration,
1628-
redundant_time=self.config.trainer.esi_redundant_time,
1629-
)
1630-
# Check if the conditions for saving a checkpoint are met.
1631-
# The conditions include a mandatory condition (1) and
1632-
# one of the following optional conditions (2/3/4):
1633-
# 1. The save frequency is set to a positive value.
1634-
# 2. It's the last training step.
1635-
# 3. The current step number is a multiple of the save frequency.
1636-
# 4. The ESI(Elastic Server Instance)/training plan is close to expiration.
1637-
if self.config.trainer.save_freq > 0 and (
1638-
is_last_step or self.global_steps % self.config.trainer.save_freq == 0 or esi_close_to_expiration
1639-
):
1640-
if esi_close_to_expiration:
1641-
print("Force saving checkpoint: ESI instance expiration approaching.")
1642-
with marked_timer("save_checkpoint", timing_raw, color="green"):
1643-
# sleep replicas to avoid OOM during checkpoint saving
1644-
self.checkpoint_manager.sleep_replicas()
1645-
self._save_checkpoint()
1646-
# wake replicas to avoid OOM during checkpoint saving
1647-
self.checkpoint_manager.update_weights()
1648-
16491647
with marked_timer("stop_profile", timing_raw):
16501648
next_step_profile = (
16511649
self.global_steps + 1 in self.config.global_profiler.steps

0 commit comments

Comments
 (0)