Skip to content

Commit

Permalink
fix: Add retry counter to checking if should stop
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiebergman committed Nov 29, 2024
1 parent 5b54ce5 commit ee8e90e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions neps/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def is_nullable(e: str) -> bool:
parse=int,
default=10,
)
MAX_RETRIES_WORKER_CHECK_SHOULD_STOP = get_env(
"NEPS_MAX_RETRIES_WORKER_CHECK_SHOULD_STOP",
parse=int,
default=3,
)
TRIAL_FILELOCK_POLL = get_env(
"NEPS_TRIAL_FILELOCK_POLL",
parse=float,
Expand Down
16 changes: 14 additions & 2 deletions neps/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
MAX_RETRIES_CREATE_LOAD_STATE,
MAX_RETRIES_GET_NEXT_TRIAL,
MAX_RETRIES_SET_EVALUATING,
MAX_RETRIES_WORKER_CHECK_SHOULD_STOP,
)
from neps.exceptions import (
NePSError,
Expand Down Expand Up @@ -367,7 +368,7 @@ def _check_if_should_stop( # noqa: C901, PLR0912, PLR0911

return False

def run(self) -> None: # noqa: C901, PLR0915
def run(self) -> None: # noqa: C901, PLR0915, PLR0912
"""Run the worker.
Will keep running until one of the criterion defined by the `WorkerSettings`
Expand All @@ -382,6 +383,7 @@ def run(self) -> None: # noqa: C901, PLR0915

_repeated_fail_get_next_trial_count = 0
n_failed_set_trial_state = 0
n_repeated_failed_check_should_stop = 0
while True:
# NOTE: We rely on this function to do logging and raising errors if it should
try:
Expand All @@ -394,7 +396,17 @@ def run(self) -> None: # noqa: C901, PLR0915
break
except WorkerRaiseError as e:
raise e
except Exception:
except Exception as e:
n_repeated_failed_check_should_stop += 1
if (
n_repeated_failed_check_should_stop
>= MAX_RETRIES_WORKER_CHECK_SHOULD_STOP
):
raise WorkerRaiseError(
f"Worker {self.worker_id} failed to check if it should stop"
f" {MAX_RETRIES_WORKER_CHECK_SHOULD_STOP} times in a row. Bailing"
) from e

logger.error(
"Unexpected error from worker '%s' while checking if it should stop.",
self.worker_id,
Expand Down

0 comments on commit ee8e90e

Please sign in to comment.