Skip to content
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

Draft: Skip models in model_builder #909

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions keras_tuner/engine/base_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ def _try_run_and_update_trial(self, trial, *fit_args, **fit_kwargs):

if isinstance(e, errors.FailedTrialError):
trial.status = trial_module.TrialStatus.FAILED
elif isinstance(e, errors.SkipModelError):
trial.status = trial_module.TrialStatus.SKIPPED
else:
trial.status = trial_module.TrialStatus.INVALID

Expand Down
7 changes: 7 additions & 0 deletions keras_tuner/engine/hyperparameters/hyperparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import six

from keras_tuner import protos
from keras_tuner import errors
from keras_tuner.api_export import keras_tuner_export
from keras_tuner.engine import conditions as conditions_mod
from keras_tuner.engine.hyperparameters import hp_types
Expand Down Expand Up @@ -250,6 +251,12 @@ def __contains__(self, name):
except (KeyError, ValueError):
return False

def skip_model(self, message):
if len(self._hps) == 0:
# Registration stage
return
raise errors.SkipModelError(message)

def Choice(
self,
name,
Expand Down
5 changes: 5 additions & 0 deletions keras_tuner/engine/trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TrialStatus:
COMPLETED = "COMPLETED"
# The Trial is failed. No more retries needed.
FAILED = "FAILED"
SKIPPED = "SKIPPED"

@staticmethod
def to_proto(status):
Expand All @@ -61,6 +62,8 @@ def to_proto(status):
return ts.COMPLETED
elif status == TrialStatus.FAILED:
return ts.FAILED
elif status == TrialStatus.SKIPPED:
return ts.SKIPPED
else:
raise ValueError(f"Unknown status {status}")

Expand All @@ -81,6 +84,8 @@ def from_proto(proto):
return TrialStatus.COMPLETED
elif proto == ts.FAILED:
return TrialStatus.FAILED
elif proto == ts.SKIPPED:
return TrialStatus.SKIPPED
else:
raise ValueError(f"Unknown status {proto}")

Expand Down
5 changes: 5 additions & 0 deletions keras_tuner/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def build(self, hp):
pass


@keras_tuner_export(["keras_tuner.errors.SkipModelError"])
class SkipModelError(Exception):
pass


@keras_tuner_export(["keras_tuner.errors.FatalError"])
class FatalError(Exception):
"""A fatal error during search to terminate the program.
Expand Down