Skip to content

Commit

Permalink
added more test cases for hyperopt distributions
Browse files Browse the repository at this point in the history
Signed-off-by: Shashank Mittal <[email protected]>
  • Loading branch information
shashank-iitbhu committed Sep 6, 2024
1 parent b6634e1 commit a444457
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/e2e-test-pytorch-mnist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ jobs:
- "grid,bayesian-optimization,tpe,multivariate-tpe,cma-es,hyperband"
- "hyperopt-distribution"
- "file-metrics-collector,pytorchjob-mnist"
- "median-stop-with-json-format,file-metrics-collector-with-json-format"
- "median-stop-with-json-format,file-metrics-collector-with-json-format"

15 changes: 7 additions & 8 deletions pkg/suggestion/v1beta1/hyperopt/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import hyperopt
import numpy as np

from pkg.apis.manager.v1beta1.python import api_pb2
from pkg.suggestion.v1beta1.internal.constant import (
CATEGORICAL,
DISCRETE,
DOUBLE,
INTEGER,
LOG_UNIFORM,
MAX_GOAL,
UNIFORM,
)
from pkg.suggestion.v1beta1.internal.trial import Assignment

Expand Down Expand Up @@ -69,7 +68,7 @@ def create_hyperopt_domain(self):
param.name, float(param.min), float(param.max)
)
elif param.type == DOUBLE:
if param.distribution == UNIFORM:
if param.distribution == api_pb2.UNIFORM or param.distribution is None:
if param.step:
hyperopt_search_space[param.name] = hyperopt.hp.quniform(
param.name,
Expand All @@ -81,7 +80,7 @@ def create_hyperopt_domain(self):
hyperopt_search_space[param.name] = hyperopt.hp.uniform(
param.name, float(param.min), float(param.max)
)
elif param.distribution == LOG_UNIFORM:
elif param.distribution == api_pb2.LOG_UNIFORM:
if param.step:
hyperopt_search_space[param.name] = hyperopt.hp.qloguniform(
param.name,
Expand All @@ -93,10 +92,10 @@ def create_hyperopt_domain(self):
hyperopt_search_space[param.name] = hyperopt.hp.loguniform(
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)
)
# else:
# hyperopt_search_space[param.name] = hyperopt.hp.uniform(
# param.name, float(param.min), float(param.max)
# )
elif param.type == CATEGORICAL or param.type == DISCRETE:
hyperopt_search_space[param.name] = hyperopt.hp.choice(
param.name, param.list
Expand Down
1 change: 1 addition & 0 deletions pkg/suggestion/v1beta1/internal/search_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def convert(experiment):
search_space.goal = constant.MIN_GOAL
for p in experiment.spec.parameter_specs.parameters:
search_space.params.append(HyperParameterSearchSpace.convert_parameter(p))
print(search_space)
return search_space

@staticmethod
Expand Down
18 changes: 18 additions & 0 deletions test/unit/v1beta1/suggestion/test_hyperopt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ def test_get_suggestion(self):
parameter_type=api_pb2.DOUBLE,
feasible_space=api_pb2.FeasibleSpace(
max="5", min="1", list=[], step="0.5", distribution=api_pb2.LOG_UNIFORM)
),
api_pb2.ParameterSpec(
name="param-6",
parameter_type=api_pb2.DOUBLE,
feasible_space=api_pb2.FeasibleSpace(
max="5", min="1", list=[], distribution=api_pb2.LOG_UNIFORM)
),
api_pb2.ParameterSpec(
name="param-7",
parameter_type=api_pb2.DOUBLE,
feasible_space=api_pb2.FeasibleSpace(
max="10", min="5", list=[], step="0.8", distribution=api_pb2.UNIFORM)
),
api_pb2.ParameterSpec(
name="param-8",
parameter_type=api_pb2.DOUBLE,
feasible_space=api_pb2.FeasibleSpace(
max="10", min="5", list=[], distribution=api_pb2.UNIFORM)
)
]
)
Expand Down

0 comments on commit a444457

Please sign in to comment.