-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(rollout-skip): add dump_steps list parameter to specify particular dump steps #5812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zyang6
wants to merge
3
commits into
verl-project:main
Choose a base branch
from
zyang6:latest_skip_rollout_v3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import json | ||
| import warnings | ||
| from enum import Enum | ||
| from pathlib import Path | ||
| from typing import Any, Callable | ||
|
|
@@ -66,15 +67,20 @@ def _find_last_gen_step_for_train_step(step_file: Path, target_train_step: int) | |
|
|
||
|
|
||
| class SkipAction(Enum): | ||
| CACHE = "cache" # cache the sample. If dump_date is found, use it. If not found, dump it. | ||
| REPEAT = "repeat" # Repeat the sample when gen_step reach skip.max_dump_step | ||
| REPEAT_LAST = "repeat_last" # Repeat the last sample when gen_step reach skip.max_dump_step | ||
| # Used only when ``is_dump_step`` is False (see ``is_dump_step``). On dump steps, the wrapper always | ||
| # tries load-from-disk first, then generate+dump if missing. | ||
| CACHE = "cache" # Always run real generation; no reloading from rollout dump dirs. | ||
| REPEAT = ( | ||
| "repeat" # Round-robin reload from ``genstep_*`` dirs recorded in ``list_dumped_steps`` (from earlier dumps). | ||
| ) | ||
| REPEAT_LAST = "repeat_last" # Reload only from the last dumped ``genstep_*`` (``list_dumped_steps[-1]``). | ||
|
|
||
|
|
||
| class RolloutSkip: | ||
| """ | ||
| RolloutSkip skips sequence generation during rollout by attempting to load previously dumped data. | ||
| If no dumped data is found, it generates new sequences and saves them to disk. | ||
| RolloutSkip can reuse disk-cached rollout batches: on **dump steps** (see ``is_dump_step``), it tries to | ||
| load ``genstep_*`` data first and only generates+writes if missing. On **non-dump** steps, behavior is | ||
| controlled by ``skip.action`` (``cache`` / ``repeat`` / ``repeat_last``); see ``SkipAction``. | ||
|
|
||
| Args: | ||
| config: The configuration object containing rollout settings. | ||
|
|
@@ -118,7 +124,33 @@ def __init__(self, config, rollout_wg) -> None: | |
| self.action = _get_skip_attr(self.skip_config, "action", SkipAction.REPEAT) | ||
| self.action = SkipAction(self.action) | ||
|
|
||
| if self.max_dump_step <= 0: | ||
| raw_steps = _get_skip_attr(self.skip_config, "dump_steps", None) | ||
| self._dump_step_set: frozenset[int] | None = None | ||
| if raw_steps is not None: | ||
| if isinstance(raw_steps, str): | ||
| try: | ||
| raw_steps = json.loads(raw_steps) | ||
| except json.JSONDecodeError: | ||
| warnings.warn( | ||
| f"{self.print_mark}Could not parse 'dump_steps' string: {raw_steps!r}. " | ||
| "Falling back to max_dump_step.", | ||
| stacklevel=2, | ||
| ) | ||
| raw_steps = None | ||
| if raw_steps: | ||
| try: | ||
| step_list = [int(x) for x in raw_steps] | ||
| if step_list: | ||
| self._dump_step_set = frozenset(step_list) | ||
| except (ValueError, TypeError): | ||
| warnings.warn( | ||
| f"{self.print_mark}'dump_steps' must be a list of integers, got: {raw_steps!r}. " | ||
| "Falling back to max_dump_step.", | ||
| stacklevel=2, | ||
| ) | ||
|
|
||
| _use_max_dump_window = self._dump_step_set is None | ||
| if _use_max_dump_window and self.max_dump_step <= 0: | ||
| assert self.action in [SkipAction.CACHE] | ||
|
|
||
| self._create_dump_path() | ||
|
|
@@ -133,10 +165,23 @@ def is_active(self) -> bool: | |
| @property | ||
| def is_dump_step(self) -> bool: | ||
| """ | ||
| Determine if the current step is a dump step based on the configured dump interval. | ||
| If train_step is given, it follows the train_step, otherwise it follows the gen_step. | ||
| Whether the current training step should run the dump/load path (try disk cache before generating). | ||
|
|
||
| **Explicit list** — If ``dump_steps`` is non-empty, only steps whose index is in that list | ||
| are dump steps. Step indices are 1-based (first update is 1), same counter as used for | ||
| ``max_dump_step`` below—not a different numbering scheme. | ||
|
|
||
| **Window** — If ``dump_steps`` is null or empty, dump/load while ``curr_train_step <= max_dump_step``. | ||
|
|
||
| ``curr_train_step`` follows ``record(..., global_steps=...)`` when the trainer passes it; | ||
| otherwise it is advanced by ``step()`` each rollout. | ||
| """ | ||
| return self.is_active and self.curr_train_step <= self.max_dump_step | ||
| if not self.is_active: | ||
| return False | ||
| t = self.curr_train_step | ||
| if self._dump_step_set is not None: | ||
| return t in self._dump_step_set | ||
| return t <= self.max_dump_step | ||
|
|
||
| @property | ||
| def num_dumped_step(self) -> int: | ||
|
|
@@ -238,7 +283,7 @@ def record( | |
| if found is not None: | ||
| last_train_step, last_gen_step = found | ||
| if last_train_step + 1 != global_steps: | ||
| print(f"{self.print_mark}\033[31mWarning: Train step not continues.\033[0m") | ||
| print(f"{self.print_mark}\033[31mWarning: Train step not continuous.\033[0m") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can add the current global_steps sampling value here to help users troubleshoot which step has changed. |
||
| self.__gen_offset_step = last_gen_step | ||
| except Exception as e: | ||
| print( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user configures max_dump_step: 0 but action: repeat, the program will crash and exit. Maybe use warning