-
Notifications
You must be signed in to change notification settings - Fork 580
feat(rollout): add min_valid_group_size to drop under-filled rollout groups #1416
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
Closed
Closed
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import asyncio | ||
| import logging | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from areal.api import RolloutWorkflow | ||
| from areal.api.cli_args import InferenceEngineConfig | ||
| from areal.infra.remote_inf_engine import GroupedRolloutWorkflow, RemoteInfEngine | ||
|
|
||
|
|
||
| class _Workflow(RolloutWorkflow): | ||
| def __init__(self, none_count: int): | ||
| self._none_count = none_count | ||
| self._calls = 0 | ||
|
|
||
| async def arun_episode(self, engine, data): | ||
| self._calls += 1 | ||
| if self._calls <= self._none_count: | ||
| return None | ||
| return { | ||
| "input_ids": torch.tensor([[1, 2, 3]]), | ||
| "attention_mask": torch.tensor([[1, 1, 1]]), | ||
| } | ||
|
|
||
|
|
||
| def _run_group(none_count: int, min_valid_group_size: int): | ||
| workflow = GroupedRolloutWorkflow( | ||
| _Workflow(none_count), | ||
| group_size=4, | ||
| logger=logging.getLogger("test"), | ||
| min_valid_group_size=min_valid_group_size, | ||
| ) | ||
| return asyncio.run(workflow.arun_episode(engine=None, data={})) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("min_valid_group_size", "none_count", "expected_rows"), | ||
| [ | ||
| (1, 4, None), | ||
| (1, 1, 3), | ||
| (2, 2, 2), | ||
| (2, 3, None), | ||
| (4, 1, None), | ||
| ], | ||
| ) | ||
| def test_min_valid_group_size_filters_underfilled_groups( | ||
| min_valid_group_size, none_count, expected_rows | ||
| ): | ||
| out = _run_group(none_count, min_valid_group_size) | ||
|
|
||
| if expected_rows is None: | ||
| assert out is None | ||
| else: | ||
| assert out is not None | ||
| assert out["input_ids"].shape[0] == expected_rows | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("min_valid_group_size", [0, 5]) | ||
| def test_min_valid_group_size_outside_group_bounds_raises(min_valid_group_size): | ||
| with pytest.raises(ValueError, match="min_valid_group_size must be in"): | ||
| GroupedRolloutWorkflow( | ||
| _Workflow(0), | ||
| group_size=4, | ||
| logger=logging.getLogger("test"), | ||
| min_valid_group_size=min_valid_group_size, | ||
| ) | ||
|
|
||
|
|
||
| def test_configured_min_valid_group_size_reaches_grouped_workflow(): | ||
| engine = object.__new__(RemoteInfEngine) | ||
| engine.config = InferenceEngineConfig(backend="sglang:d1", min_valid_group_size=3) | ||
| engine.logger = logging.getLogger("test") | ||
|
|
||
| resolved = engine._resolve_workflow( | ||
| _Workflow(none_count=0), workflow_kwargs=None, group_size=4 | ||
| ) | ||
|
|
||
| assert isinstance(resolved, GroupedRolloutWorkflow) | ||
| assert resolved.min_valid_group_size == 3 |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.