Unverified Commit afe00e46 authored by liuzhe-lz's avatar liuzhe-lz Committed by GitHub
Browse files

add optimize mode to random and grid search for webui (#4856)


Co-authored-by: default avatarliuzhe <zhliu1@microsoft.com>
parent 288dcb65
...@@ -88,7 +88,7 @@ class GridSearchTuner(Tuner): ...@@ -88,7 +88,7 @@ class GridSearchTuner(Tuner):
config.tuner.name = 'GridSearch' config.tuner.name = 'GridSearch'
""" """
def __init__(self): def __init__(self, optimize_mode=None):
self.space = None self.space = None
# the grid to search in this epoch # the grid to search in this epoch
...@@ -116,6 +116,9 @@ class GridSearchTuner(Tuner): ...@@ -116,6 +116,9 @@ class GridSearchTuner(Tuner):
# dumped JSON string of all tried parameters # dumped JSON string of all tried parameters
self.history = set() self.history = set()
if optimize_mode is not None:
_logger.info(f'Ignored optimize_mode "{optimize_mode}"')
def update_search_space(self, space): def update_search_space(self, space):
self.space = format_search_space(space) self.space = format_search_space(space)
if not self.space: # the tuner will crash in this case, report it explicitly if not self.space: # the tuner will crash in this case, report it explicitly
......
...@@ -42,13 +42,15 @@ class RandomTuner(Tuner): ...@@ -42,13 +42,15 @@ class RandomTuner(Tuner):
The random seed. The random seed.
""" """
def __init__(self, seed: int | None = None): def __init__(self, seed: int | None = None, optimize_mode: str | None = None):
self.space = None self.space = None
if seed is None: # explicitly generate a seed to make the experiment reproducible if seed is None: # explicitly generate a seed to make the experiment reproducible
seed = np.random.default_rng().integers(2 ** 31) seed = np.random.default_rng().integers(2 ** 31)
self.rng = np.random.default_rng(seed) self.rng = np.random.default_rng(seed)
self.dedup = None self.dedup = None
_logger.info(f'Using random seed {seed}') _logger.info(f'Using random seed {seed}')
if optimize_mode is not None:
_logger.info(f'Ignored optimize_mode "{optimize_mode}"')
def update_search_space(self, space): def update_search_space(self, space):
self.space = format_search_space(space) self.space = format_search_space(space)
...@@ -64,7 +66,10 @@ class RandomTuner(Tuner): ...@@ -64,7 +66,10 @@ class RandomTuner(Tuner):
class RandomClassArgsValidator(ClassArgsValidator): class RandomClassArgsValidator(ClassArgsValidator):
def validate_class_args(self, **kwargs): def validate_class_args(self, **kwargs):
schema.Schema({schema.Optional('seed'): int}).validate(kwargs) schema.Schema({
schema.Optional('optimize_mode'): str,
schema.Optional('seed'): int,
}).validate(kwargs)
def suggest(rng, space): def suggest(rng, space):
params = {} params = {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment