-
Notifications
You must be signed in to change notification settings - Fork 316
Halt after max_consecutive_errored_rollouts
#2835
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
rasdani
wants to merge
1
commit into
main
Choose a base branch
from
halt-consecutive-errored-rollouts
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.
+194
−0
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
139 changes: 139 additions & 0 deletions
139
tests/unit/orchestrator/test_orchestrator_error_guard.py
|
Member
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. remove |
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,139 @@ | ||
| import asyncio | ||
| import uuid | ||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
|
|
||
| from prime_rl.orchestrator.orchestrator import Orchestrator | ||
| from prime_rl.orchestrator.types import EvalRollout, TrainRollout | ||
|
|
||
|
|
||
| def _make_orchestrator(*, limit: int | None) -> Orchestrator: | ||
| orchestrator = object.__new__(Orchestrator) | ||
| orchestrator.config = SimpleNamespace(max_consecutive_errored_rollouts=limit) | ||
| orchestrator.consecutive_errored_rollouts = 0 | ||
| return orchestrator | ||
|
|
||
|
|
||
| def _make_raw(error_type: str | None = None) -> dict: | ||
| raw = { | ||
| "trajectory": [], | ||
| "reward": 0.0, | ||
| "metrics": {}, | ||
| } | ||
| if error_type is not None: | ||
| raw["error"] = { | ||
| "error": error_type, | ||
| "error_chain_repr": error_type, | ||
| "error_chain_str": error_type, | ||
| } | ||
| return raw | ||
|
|
||
|
|
||
| def _make_train_rollout(error_type: str | None = None) -> TrainRollout: | ||
| return TrainRollout( | ||
| raw=_make_raw(error_type), | ||
| env_name="test-env", | ||
| example_id=123, | ||
| group_id=uuid.uuid4(), | ||
| policy_version=0, | ||
| off_policy_steps=0, | ||
| ) | ||
|
|
||
|
|
||
| def _make_eval_rollout(error_type: str | None = None) -> EvalRollout: | ||
| return EvalRollout( | ||
| raw=_make_raw(error_type), | ||
| env_name="eval-env", | ||
| example_id=456, | ||
| group_id=uuid.uuid4(), | ||
| policy_version=0, | ||
| off_policy_steps=0, | ||
| eval_step=0, | ||
| ) | ||
|
|
||
|
|
||
| def test_consecutive_errored_train_rollouts_raise_at_configured_threshold(): | ||
| orchestrator = _make_orchestrator(limit=2) | ||
|
|
||
| orchestrator.update_consecutive_errored_rollouts(_make_train_rollout("TimeoutError")) | ||
| assert orchestrator.consecutive_errored_rollouts == 1 | ||
|
|
||
| with pytest.raises(RuntimeError, match="2 consecutive terminal errored rollouts"): | ||
| orchestrator.update_consecutive_errored_rollouts(_make_train_rollout("TimeoutError")) | ||
|
|
||
|
|
||
| def test_successful_train_rollout_resets_errored_rollout_streak(): | ||
| orchestrator = _make_orchestrator(limit=10) | ||
| orchestrator.update_consecutive_errored_rollouts(_make_train_rollout("TimeoutError")) | ||
|
|
||
| orchestrator.update_consecutive_errored_rollouts(_make_train_rollout()) | ||
|
|
||
| assert orchestrator.consecutive_errored_rollouts == 0 | ||
|
|
||
|
|
||
| def test_successful_eval_rollout_resets_errored_rollout_streak(): | ||
| orchestrator = _make_orchestrator(limit=10) | ||
| orchestrator.update_consecutive_errored_rollouts(_make_train_rollout("TimeoutError")) | ||
|
|
||
| orchestrator.update_consecutive_errored_rollouts(_make_eval_rollout()) | ||
|
|
||
| assert orchestrator.consecutive_errored_rollouts == 0 | ||
|
|
||
|
|
||
| def test_cancelled_train_rollout_markers_do_not_increment_errored_rollout_streak(): | ||
| orchestrator = _make_orchestrator(limit=10) | ||
| orchestrator.consecutive_errored_rollouts = 1 | ||
|
|
||
| orchestrator.update_consecutive_errored_rollouts(_make_train_rollout("Cancelled")) | ||
|
|
||
| assert orchestrator.consecutive_errored_rollouts == 1 | ||
|
|
||
|
|
||
| def test_none_disables_errored_rollout_guard(): | ||
| orchestrator = _make_orchestrator(limit=None) | ||
|
|
||
| for _ in range(3): | ||
| orchestrator.update_consecutive_errored_rollouts(_make_train_rollout("TimeoutError")) | ||
|
|
||
| assert orchestrator.consecutive_errored_rollouts == 0 | ||
|
|
||
|
|
||
| def test_main_loop_raises_on_errored_train_rollout_before_sink_add(): | ||
| async def run() -> None: | ||
| orchestrator = _make_orchestrator(limit=1) | ||
| orchestrator.stopped = asyncio.Event() | ||
| orchestrator.draining = False | ||
| orchestrator.dispatcher = SimpleNamespace(out_q=asyncio.Queue()) | ||
|
|
||
| class TrainSinkShouldNotBeCalled: | ||
| async def add(self, rollout: TrainRollout): | ||
| raise AssertionError("TrainSink.add should not be called after the guard trips") | ||
|
|
||
| orchestrator.train_sink = TrainSinkShouldNotBeCalled() | ||
| await orchestrator.dispatcher.out_q.put(_make_train_rollout("TimeoutError")) | ||
|
|
||
| with pytest.raises(RuntimeError, match="1 consecutive terminal errored rollouts"): | ||
| await orchestrator.main_loop() | ||
|
|
||
| asyncio.run(run()) | ||
|
|
||
|
|
||
| def test_main_loop_raises_on_errored_eval_rollout_before_sink_add(): | ||
| async def run() -> None: | ||
| orchestrator = _make_orchestrator(limit=1) | ||
| orchestrator.stopped = asyncio.Event() | ||
| orchestrator.draining = False | ||
| orchestrator.dispatcher = SimpleNamespace(out_q=asyncio.Queue()) | ||
|
|
||
| class EvalSinkShouldNotBeCalled: | ||
| def add(self, rollout: EvalRollout): | ||
| raise AssertionError("EvalSink.add should not be called after the guard trips") | ||
|
|
||
| orchestrator.eval_sink = EvalSinkShouldNotBeCalled() | ||
| await orchestrator.dispatcher.out_q.put(_make_eval_rollout("TimeoutError")) | ||
|
|
||
| with pytest.raises(RuntimeError, match="1 consecutive terminal errored rollouts"): | ||
| await orchestrator.main_loop() | ||
|
|
||
| asyncio.run(run()) |
|
Member
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. remove |
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
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.
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.
i think 10 is a bit rough here?
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.
scared of cancelling runs on intermittent errors
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.
what do you suggest?