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

[GSOC] optuna suggestion service logic update #2446

Open
wants to merge 4 commits 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
12 changes: 9 additions & 3 deletions pkg/suggestion/v1beta1/hyperopt/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ def create_hyperopt_domain(self):
param.name, float(param.min), float(param.max)
)
else:
hyperopt_search_space[param.name] = hyperopt.hp.uniform(
param.name, float(param.min), float(param.max)
)
if param.type == INTEGER:
hyperopt_search_space[param.name] = hyperopt.hp.uniformint(
param.name, float(param.min), float(param.max)
)
else:
hyperopt_search_space[param.name] = hyperopt.hp.uniform(
param.name, float(param.min), float(param.max)
)
elif param.distribution == api_pb2.LOG_UNIFORM:
# Log-uniform distribution: used for parameters that vary exponentially.
# We convert min and max to their logarithmic scale using math.log, because
Expand All @@ -106,6 +111,7 @@ def create_hyperopt_domain(self):
# min and max, and sigma as (max - min) / 6. This is based on the assumption
# that 99.7% of the values in a normal distribution fall within ±3 sigma.
mu = (float(param.min) + float(param.max)) / 2
# We consider the normal distribution based on the range of ±3 sigma.
sigma = (float(param.max) - float(param.min)) / 6

if param.step:
Expand Down
37 changes: 31 additions & 6 deletions pkg/suggestion/v1beta1/optuna/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import optuna

from pkg.apis.manager.v1beta1.python import api_pb2
from pkg.suggestion.v1beta1.internal.constant import (
CATEGORICAL,
DISCRETE,
Expand Down Expand Up @@ -110,13 +111,37 @@ def _get_optuna_search_space(self):
search_space = {}
for param in self.search_space.params:
if param.type == INTEGER:
search_space[param.name] = optuna.distributions.IntDistribution(
int(param.min), int(param.max)
)
if param.distribution == api_pb2.UNIFORM or param.distribution is None:
if param.step:
search_space[param.name] = optuna.distributions.IntDistribution(
int(param.min), int(param.max), False, param.step
)
else:
search_space[param.name] = optuna.distributions.IntDistribution(
int(param.min), int(param.max)
)
if param.distribution == api_pb2.LOG_UNIFORM:
search_space[param.name] = optuna.distributions.IntDistribution(
int(param.min), int(param.max), True, param.step
)
elif param.type == DOUBLE:
search_space[param.name] = optuna.distributions.FloatDistribution(
float(param.min), float(param.max)
)
if param.distribution == api_pb2.UNIFORM or param.distribution is None:
if param.step:
search_space[param.name] = (
optuna.distributions.FloatDistribution(
int(param.min), int(param.max), False, param.step
)
)
else:
search_space[param.name] = (
optuna.distributions.FloatDistribution(
int(param.min), int(param.max)
)
)
if param.distribution == api_pb2.LOG_UNIFORM:
search_space[param.name] = optuna.distributions.FloatDistribution(
int(param.min), int(param.max), True, param.step
)
elif param.type == CATEGORICAL or param.type == DISCRETE:
search_space[param.name] = optuna.distributions.CategoricalDistribution(
param.list
Expand Down
Loading