Skip to content

Commit f6ee083

Browse files
authored
[recipe, megatron, fsdp] fix: checkpoint-engine fix trainer param offload in fully-async mode (verl-project#4655)
… fully-async mode ### What does this PR do? > Add **concise** overview of what this PR aims to achieve or accomplish. Reference related GitHub issues and PRs that help with the review. ### 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` - [ ] 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).)
1 parent 7ba518e commit f6ee083

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

recipe/fully_async_policy/fsdp_workers.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,11 @@ def sync_rollout_weights_by_checkpoint(self, sync_group_name="actor_rollout"):
135135
assert (self._is_actor or self._is_rollout) and not self.config.hybrid_engine
136136
assert hasattr(self, "_weights_info") and self._weights_info is not None
137137

138+
# Load model to GPU
139+
load_start_time = time.time()
138140
if self._is_actor and self._is_offload_param:
139141
load_fsdp_model_to_gpu(self.actor_module_fsdp)
142+
load_duration = time.time() - load_start_time
140143

141144
from ray.util.collective import collective
142145

@@ -172,14 +175,24 @@ def sync_rollout_weights_by_checkpoint(self, sync_group_name="actor_rollout"):
172175
update_end_time = time.time()
173176
update_duration = update_end_time - update_start_time
174177

175-
collective.barrier(group_name=sync_group_name)
178+
offload_start_time = time.time()
179+
if self._is_actor and self._is_offload_param:
180+
offload_fsdp_model_to_cpu(self.actor_module_fsdp)
181+
offload_duration = time.time() - offload_start_time
182+
176183
print(
177184
f"sync_rollout_weights_by_checkpoint finish!, rank:{torch.distributed.get_rank()},"
178185
f" is_actor:{self._is_actor}, is_rollout:{self._is_rollout},"
179186
f" total cost:{update_end_time - cache_start_time} seconds, while cache cost {cache_duration} seconds, "
180187
f" register cost {register_duration} seconds, update cost {update_duration} seconds"
181188
)
182189

190+
if self._is_actor and self._is_offload_param:
191+
print(
192+
f"sync_rollout_weights_by_checkpoint load model to gpu cost {load_duration} seconds,"
193+
f" offload model to cpu cost {offload_duration} seconds"
194+
)
195+
183196

184197
class DetachActorWorker(DetachNcclSync):
185198
def _get_actor_params(self):

recipe/fully_async_policy/megatron_worker.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ def sync_rollout_weights_by_checkpoint(self, sync_group_name="actor_rollout"):
140140
assert (self._is_actor or self._is_rollout) and not self.config.hybrid_engine
141141
assert hasattr(self, "_weights_info") and self._weights_info is not None
142142

143+
# Load model to GPU
144+
load_start_time = time.time()
145+
if self._is_actor and self._is_offload_param:
146+
load_megatron_model_to_gpu(self.actor_module)
147+
load_duration = time.time() - load_start_time
148+
143149
from ray.util.collective import collective
144150

145151
# Cache actor weights to CPU and measure the time taken
@@ -174,13 +180,24 @@ def sync_rollout_weights_by_checkpoint(self, sync_group_name="actor_rollout"):
174180
update_end_time = time.time()
175181
update_duration = update_end_time - update_start_time
176182

183+
offload_start_time = time.time()
184+
if self._is_actor and self._is_offload_param:
185+
offload_megatron_model_to_cpu(self.actor_module)
186+
offload_duration = time.time() - offload_start_time
187+
177188
print(
178189
f"sync_rollout_weights_by_checkpoint finish!, rank:{torch.distributed.get_rank()},"
179190
f" is_actor:{self._is_actor}, is_rollout:{self._is_rollout},"
180191
f" total cost:{update_end_time - cache_start_time} seconds, while cache cost {cache_duration} seconds, "
181192
f" register cost {register_duration} seconds, update cost {update_duration} seconds"
182193
)
183194

195+
if self._is_actor and self._is_offload_param:
196+
print(
197+
f"sync_rollout_weights_by_checkpoint load model to gpu cost {load_duration} seconds,"
198+
f" offload model to cpu cost {offload_duration} seconds"
199+
)
200+
184201

185202
class DetachActorWorker(DetachNcclSync):
186203
def _get_actor_params_generator(self):

0 commit comments

Comments
 (0)