-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[RLlib] Add eval worker sub-env fault tolerance test. #26276
Merged
sven1977
merged 30 commits into
ray-project:master
from
sven1977:add_eval_worker_sub_env_failure_tests
Jul 15, 2022
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
47778f2
wip
sven1977 a45511c
wip
sven1977 ed1d16c
wip
sven1977 86ddb4d
LINT.
sven1977 8e0dde4
wip
sven1977 88c8cd6
Merge branch 'master' of https://github.com/ray-project/ray into add_…
sven1977 75e88e3
wip
sven1977 7e038e2
wip
sven1977 a1af2cb
wip
sven1977 4e87dcf
wip
sven1977 2ec87d5
Merge branch 'master' of https://github.com/ray-project/ray into add_…
sven1977 0866980
LINT
sven1977 e4e82e9
LINT
sven1977 9f42f70
wip
sven1977 56b182e
Merge branch 'master' of https://github.com/ray-project/ray into add_…
sven1977 11c1da8
wip
sven1977 646710b
Merge branch 'master' of https://github.com/ray-project/ray into add_…
sven1977 387ddb0
LINT
sven1977 39d9a22
Merge branch 'master' of https://github.com/ray-project/ray into add_…
sven1977 9abfd4d
fix
sven1977 c651b6d
fix
sven1977 0058ea4
Merge branch 'master' of https://github.com/ray-project/ray into add_…
sven1977 761fe47
wip
sven1977 a876e13
wip
sven1977 9517160
wip
sven1977 28ee514
wip
sven1977 2d48d78
wip
sven1977 fe816d0
wip
sven1977 fd6eca8
wip
sven1977 688f04d
wip
sven1977 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 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 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 |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
|
||
import ray | ||
from ray.actor import ActorHandle | ||
from ray.exceptions import RayActorError, RayError | ||
from ray.exceptions import GetTimeoutError, RayActorError, RayError | ||
from ray.rllib.algorithms.algorithm_config import AlgorithmConfig | ||
from ray.rllib.algorithms.callbacks import DefaultCallbacks | ||
from ray.rllib.env.env_context import EnvContext | ||
|
@@ -768,7 +768,8 @@ def duration_fn(num_units_done): | |
env_steps_this_iter += batch.env_steps() | ||
metrics = collect_metrics( | ||
self.workers.local_worker(), | ||
keep_custom_metrics=self.config["keep_per_episode_custom_metrics"], | ||
keep_custom_metrics=eval_cfg["keep_per_episode_custom_metrics"], | ||
timeout_seconds=eval_cfg["metrics_episode_collection_timeout_s"], | ||
) | ||
|
||
# Evaluation worker set only has local worker. | ||
|
@@ -794,16 +795,35 @@ def duration_fn(num_units_done): | |
break | ||
|
||
round_ += 1 | ||
batches = ray.get( | ||
[ | ||
w.sample.remote() | ||
for i, w in enumerate( | ||
self.evaluation_workers.remote_workers() | ||
try: | ||
batches = ray.get( | ||
[ | ||
w.sample.remote() | ||
for i, w in enumerate( | ||
self.evaluation_workers.remote_workers() | ||
) | ||
if i * (1 if unit == "episodes" else rollout * num_envs) | ||
< units_left_to_do | ||
], | ||
timeout=self.config["evaluation_sample_timeout_s"], | ||
) | ||
except GetTimeoutError: | ||
logger.warning( | ||
"Calling `sample()` on your remote evaluation worker(s) " | ||
"resulted in a timeout (after the configured " | ||
f"{self.config['evaluation_sample_timeout_s']} seconds)! " | ||
"Try to set `evaluation_sample_timeout_s` in your config" | ||
" to a larger value." | ||
+ ( | ||
" If your episodes don't terminate easily, you may " | ||
"also want to set `evaluation_duration_unit` to " | ||
"'timesteps' (instead of 'episodes')." | ||
if unit == "episodes" | ||
else "" | ||
) | ||
if i * (1 if unit == "episodes" else rollout * num_envs) | ||
< units_left_to_do | ||
] | ||
) | ||
) | ||
break | ||
|
||
_agent_steps = sum(b.agent_steps() for b in batches) | ||
_env_steps = sum(b.env_steps() for b in batches) | ||
# 1 episode per returned batch. | ||
|
@@ -834,6 +854,7 @@ def duration_fn(num_units_done): | |
self.evaluation_workers.local_worker(), | ||
self.evaluation_workers.remote_workers(), | ||
keep_custom_metrics=self.config["keep_per_episode_custom_metrics"], | ||
timeout_seconds=eval_cfg["metrics_episode_collection_timeout_s"], | ||
) | ||
metrics[NUM_AGENT_STEPS_SAMPLED_THIS_ITER] = agent_steps_this_iter | ||
metrics[NUM_ENV_STEPS_SAMPLED_THIS_ITER] = env_steps_this_iter | ||
|
@@ -2328,6 +2349,14 @@ def _run_one_evaluation( | |
"recreate_failed_workers" | ||
), | ||
) | ||
|
||
# Add number of healthy evaluation workers after this iteration. | ||
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. This metric was missing. |
||
eval_results["evaluation"]["num_healthy_workers"] = ( | ||
len(self.evaluation_workers.remote_workers()) | ||
if self.evaluation_workers is not None | ||
else 0 | ||
) | ||
|
||
return eval_results | ||
|
||
def _run_one_training_iteration_and_evaluation_in_parallel( | ||
|
@@ -2387,9 +2416,6 @@ def _compile_iteration_results( | |
# Evaluation results. | ||
if "evaluation" in iteration_results: | ||
results["evaluation"] = iteration_results.pop("evaluation") | ||
results["evaluation"]["num_healthy_workers"] = len( | ||
self.evaluation_workers.remote_workers() | ||
) | ||
|
||
# Custom metrics and episode media. | ||
results["custom_metrics"] = iteration_results.pop("custom_metrics", {}) | ||
|
This file contains 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 |
---|---|---|
|
@@ -174,6 +174,7 @@ def __init__(self, algo_class=None): | |
self.evaluation_interval = None | ||
self.evaluation_duration = 10 | ||
self.evaluation_duration_unit = "episodes" | ||
self.evaluation_sample_timeout_s = 180.0 | ||
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. New config value. Triggers a meaningful warning if breached with various things to try to fix the timeouts. |
||
self.evaluation_parallel_to_training = False | ||
self.evaluation_config = {} | ||
self.off_policy_estimation_methods = {} | ||
|
@@ -187,7 +188,7 @@ def __init__(self, algo_class=None): | |
|
||
# `self.reporting()` | ||
self.keep_per_episode_custom_metrics = False | ||
self.metrics_episode_collection_timeout_s = 180 | ||
self.metrics_episode_collection_timeout_s = 60.0 | ||
self.metrics_num_episodes_for_smoothing = 100 | ||
self.min_time_s_per_iteration = None | ||
self.min_train_timesteps_per_iteration = 0 | ||
|
@@ -803,6 +804,7 @@ def evaluation( | |
evaluation_interval: Optional[int] = None, | ||
evaluation_duration: Optional[int] = None, | ||
evaluation_duration_unit: Optional[str] = None, | ||
evaluation_sample_timeout_s: Optional[float] = None, | ||
evaluation_parallel_to_training: Optional[bool] = None, | ||
evaluation_config: Optional[ | ||
Union["AlgorithmConfig", PartialAlgorithmConfigDict] | ||
|
@@ -832,6 +834,11 @@ def evaluation( | |
- For `evaluation_parallel_to_training=False`: Error. | ||
evaluation_duration_unit: The unit, with which to count the evaluation | ||
duration. Either "episodes" (default) or "timesteps". | ||
evaluation_sample_timeout_s: The timeout (in seconds) for the ray.get call | ||
to the remote evaluation worker(s) `sample()` method. After this time, | ||
the user will receive a warning and instructions on how to fix the | ||
issue. This could be either to make sure the episode ends, increasing | ||
the timeout, or switching to `evaluation_duration_unit=timesteps`. | ||
evaluation_parallel_to_training: Whether to run evaluation in parallel to | ||
a Algorithm.train() call using threading. Default=False. | ||
E.g. evaluation_interval=2 -> For every other training iteration, | ||
|
@@ -880,6 +887,8 @@ def evaluation( | |
self.evaluation_duration = evaluation_duration | ||
if evaluation_duration_unit is not None: | ||
self.evaluation_duration_unit = evaluation_duration_unit | ||
if evaluation_sample_timeout_s is not None: | ||
self.evaluation_sample_timeout_s = evaluation_sample_timeout_s | ||
if evaluation_parallel_to_training is not None: | ||
self.evaluation_parallel_to_training = evaluation_parallel_to_training | ||
if evaluation_config is not None: | ||
|
@@ -909,7 +918,7 @@ def offline_data( | |
actions_in_input_normalized=None, | ||
input_evaluation=None, | ||
off_policy_estimation_methods=None, | ||
postprocess_inputs=None, | ||
postprocess_inputs=None, # `def postprocess_trajectory()` | ||
shuffle_buffer_size=None, | ||
output=None, | ||
output_config=None, | ||
|
@@ -1080,7 +1089,7 @@ def reporting( | |
self, | ||
*, | ||
keep_per_episode_custom_metrics: Optional[bool] = None, | ||
metrics_episode_collection_timeout_s: Optional[int] = None, | ||
metrics_episode_collection_timeout_s: Optional[float] = None, | ||
metrics_num_episodes_for_smoothing: Optional[int] = None, | ||
min_time_s_per_iteration: Optional[int] = None, | ||
min_train_timesteps_per_iteration: Optional[int] = None, | ||
|
This file contains 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 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 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 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.
bug: timeout setting was not passed to eval collect-metrics call.