Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion rllib/env/multi_agent_env_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from ray.rllib.utils.pre_checks.env import check_multiagent_environments
from ray.rllib.utils.typing import EpisodeID, ModelWeights, ResultDict, StateDict
from ray.tune.registry import ENV_CREATOR, _global_registry
from ray.util import log_once
from ray.util.annotations import PublicAPI

torch, _ = try_import_torch()
Expand Down Expand Up @@ -286,8 +287,25 @@ def _sample(
agent_ts = 0
eps = 0

reset_required = (
force_reset or num_episodes is not None or self._needs_initial_reset
)

if (
self._cached_to_module is None
and self.module is not None
and not reset_required
):
# Cached module connector outputs can be none if a connector fails.
# self._cached_to_module is always None if the module is None.
if log_once("sample_error_reset_envs"):
logger.warning(
"Error in sample call detected. Resetting envs and episodes to start over. You can ignore this warning if a connector is expectedly unstable."
)
reset_required = True

# Have to reset the env (on all vector sub_envs).
if force_reset or num_episodes is not None or self._needs_initial_reset:
if reset_required:
env_ts = 0
agent_ts = 0
self._reset_envs_and_episodes(explore)
Expand Down
20 changes: 19 additions & 1 deletion rllib/env/single_agent_env_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from ray.rllib.utils.spaces.space_utils import unbatch
from ray.rllib.utils.typing import EpisodeID, ResultDict, StateDict
from ray.tune.registry import ENV_CREATOR, _global_registry
from ray.util import log_once
from ray.util.annotations import PublicAPI

logger = logging.getLogger("ray.rllib")
Expand Down Expand Up @@ -283,8 +284,25 @@ def _sample(
eps = 0
done_episodes_to_return: List[SingleAgentEpisode] = []

reset_required = (
force_reset or num_episodes is not None or self._needs_initial_reset
)

if (
self._cached_to_module is None
and self.module is not None
and not reset_required
):
# Cached module connector outputs can be none if a connector fails.
# self._cached_to_module is always None if the module is None.
if log_once("sample_error_reset_envs"):
logger.warning(
"Error in sample call detected. Resetting envs and episodes to start over. You can ignore this warning if a connector is expectedly unstable."
)
reset_required = True
Comment thread
cursor[bot] marked this conversation as resolved.

# Have to reset the env (on all vector sub_envs).
if force_reset or num_episodes is not None or self._needs_initial_reset:
if reset_required:
ts = 0
self._reset_envs_and_episodes(explore)

Expand Down