Skip to content

Commit

Permalink
feat(sweeps): optuna scheduler supports more distribution commands (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtarpenning authored Aug 16, 2023
1 parent b8cdabb commit e53d23d
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions jobs/sweep_schedulers/optuna_scheduler/optuna_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,26 +650,40 @@ def _make_trial(self) -> Tuple[Dict[str, Any], optuna.Trial]:
config[param]["value"] = trial.suggest_categorical(
param, [extras["value"]]
)
elif type(extras.get("min")) == float:
elif extras.get("distribution"):
raise SchedulerError(
"Distributions are deprecated. Please provide 'step' or 'log' with 'min' and 'max'."
)
elif isinstance(extras.get("min"), float):
if not extras.get("max"):
raise SchedulerError(
"Error converting config. 'min' requires 'max'"
)
log = "log" in param
log = extras.get("log", False)
step = extras.get("step")
config[param]["value"] = trial.suggest_float(
param, extras["min"], extras["max"], log=log
param, extras["min"], extras["max"], log=log, step=step
)
elif type(extras.get("min")) == int:
elif isinstance(extras.get("min"), int):
if not extras.get("max"):
raise SchedulerError(
"Error converting config. 'min' requires 'max'"
)
log = "log" in param
config[param]["value"] = trial.suggest_int(
param, extras["min"], extras["max"], log=log
)
log = extras.get("log", False)
step = extras.get("step")
if step:
config[param]["value"] = trial.suggest_int(
param, extras["min"], extras["max"], log=log, step=step
)
else:
config[param]["value"] = trial.suggest_int(
param, extras["min"], extras["max"], log=log
)
else:
logger.debug(f"Unknown parameter type: param={param}, val={extras}")
raise SchedulerError(
f"Error converting config. Unknown parameter type: param={param}, val={extras}"
)
return config, trial

def _make_trial_from_objective(self) -> Tuple[Dict[str, Any], optuna.Trial]:
Expand Down

0 comments on commit e53d23d

Please sign in to comment.