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

feat: Rename algorithms #794

Merged
merged 4 commits into from
Sep 23, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
namespace: kubeflow
labels:
controller-tools.k8s.io: "1.0"
name: skopt-bayesian-optimization-example
name: bayesianoptimization-example
spec:
objective:
type: maximize
Expand All @@ -13,7 +13,7 @@ spec:
additionalMetricNames:
- accuracy
algorithm:
algorithmName: skopt-bayesian-optimization
algorithmName: bayesianoptimization
algorithmSettings:
- name: "random_state"
value: "10"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
namespace: kubeflow
labels:
controller-tools.k8s.io: "1.0"
name: chocolate-grid-example
name: grid-example
spec:
objective:
type: maximize
Expand All @@ -13,7 +13,7 @@ spec:
additionalMetricNames:
- accuracy
algorithm:
algorithmName: chocolate-grid
algorithmName: grid
parallelTrialCount: 3
maxTrialCount: 12
maxFailedTrialCount: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
namespace: kubeflow
labels:
controller-tools.k8s.io: "1.0"
name: hyperopt-tpe-example
name: random-example
spec:
objective:
type: maximize
Expand All @@ -13,7 +13,7 @@ spec:
additionalMetricNames:
- accuracy
algorithm:
algorithmName: hyperopt-tpe
algorithmName: random
parallelTrialCount: 3
maxTrialCount: 12
maxFailedTrialCount: 3
Expand Down
2 changes: 1 addition & 1 deletion examples/v1alpha3/tfjob-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
goal: 0.99
objectiveMetricName: accuracy_1
algorithm:
algorithmName: hyperopt-random
algorithmName: random
metricsCollectorSpec:
source:
fileSystemPath:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
namespace: kubeflow
labels:
controller-tools.k8s.io: "1.0"
name: hyperopt-random-example
name: tpe-example
spec:
objective:
type: maximize
Expand All @@ -13,7 +13,7 @@ spec:
additionalMetricNames:
- accuracy
algorithm:
algorithmName: hyperopt-random
algorithmName: tpe
parallelTrialCount: 3
maxTrialCount: 12
maxFailedTrialCount: 3
Expand Down
21 changes: 6 additions & 15 deletions manifests/v1alpha3/katib-controller/katib-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,21 @@ data:
suggestion: |-
{
"random": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-random"
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-hyperopt"
},
"grid": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-grid"
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-chocolate"
},
"hyperband": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-hyperband"
},
"bayesianoptimization": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-bayesianoptimization"
},
"nasrl": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-nasrl"
},
"chocolate-grid": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-chocolate"
},
"hyperopt-tpe": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-hyperopt"
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-skopt"
},
"hyperopt-random": {
"tpe": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-hyperopt"
},
"skopt-bayesian-optimization": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-skopt"
"nasrl": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-nasrl"
}
}
6 changes: 4 additions & 2 deletions pkg/suggestion/v1alpha3/chocolate/base_chocolate_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def getSuggestions(self, search_space, trials, request_number):

conn = choco.SQLiteConnection("sqlite:///my_db.db")
# Refer to https://chocolate.readthedocs.io/tutorials/algo.html
if self.algorithm_name == "chocolate-grid":
if self.algorithm_name == "grid":
sampler = choco.Grid(conn, chocolate_search_space, clear_db=True)
# hyperopt-random is the default option in katib.
elif self.algorithm_name == "chocolate-random":
sampler = choco.Random(conn, chocolate_search_space, clear_db=True)
elif self.algorithm_name == "chocolate-quasirandom":
Expand All @@ -61,7 +62,8 @@ def getSuggestions(self, search_space, trials, request_number):
mu = 1
sampler = choco.MOCMAES(
conn, chocolate_search_space, mu=mu, clear_db=True)
logger.info("algortihm: %s", self.algorithm_name)
else:
raise Exception('"Failed to create the algortihm: {}'.format(self.algorithm_name))

for index, trial in enumerate(trials):
loss_for_choco = float(trial.target_metric.value)
Expand Down
4 changes: 2 additions & 2 deletions pkg/suggestion/v1alpha3/hyperopt/base_hyperopt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

class BaseHyperoptService(object):
def __init__(self, algorithm_name="tpe"):
if algorithm_name == 'hyperopt-tpe':
if algorithm_name == 'tpe':
self.hyperopt_algorithm = hyperopt.tpe.suggest
elif algorithm_name == 'hyperopt-random':
elif algorithm_name == 'random':
self.hyperopt_algorithm = hyperopt.rand.suggest
# elif algorithm_name == 'hyperopt-anneal':
# self.hyperopt_algorithm = hyperopt.anneal.suggest_batch
Expand Down
5 changes: 3 additions & 2 deletions pkg/suggestion/v1alpha3/skopt/base_skopt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def getSuggestions(self, search_space, trials, request_number):
skopt_search_space.append(
skopt.space.Categorical(param.list, name=param.name))

if self.algorithm_name != "skopt-bayesian-optimization":
raise Exception("Algorithm name is not supported by skopt service.")
if self.algorithm_name != "bayesianoptimization":
raise Exception(
'"Failed to create the algortihm: {}'.format(self.algorithm_name))
skopt_optimizer = skopt.Optimizer(skopt_search_space,
base_estimator=self.base_estimator,
n_initial_points=self.n_initial_points,
Expand Down
17 changes: 0 additions & 17 deletions pkg/suggestion/v1alpha3/skopt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,3 @@ def convertAlgorithmSpec(algorithm_spec):
elif s.name == "random_state":
optmizer.random_state = int(s.value)
return algorithm_spec.algorithm_name, optmizer


class HyperoptService(
api_pb2_grpc.SuggestionServicer):
def GetSuggestions(self, request, context):
"""
Main function to provide suggestion.
"""
base_serice = BaseHyperoptService(
algorithm_name=request.experiment.spec.algorithm.algorithm_name)
search_space = HyperParameterSearchSpace.convert(request.experiment)
trials = Trial.convert(request.trials)
new_assignments = base_serice.getSuggestions(
search_space, trials, request.request_number)
return api_pb2.GetSuggestionsReply(
parameter_assignments=Assignment.generate(new_assignments)
)
4 changes: 2 additions & 2 deletions test/scripts/v1alpha3/run-suggestion-bayesian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cd ${GO_DIR}/test/e2e/v1alpha3

echo "Running e2e skopt bayesian optimization experiment"
export KUBECONFIG=$HOME/.kube/config
go run run-e2e-experiment.go ../../../examples/v1alpha3/skopt-bayesian-optimization-example.yaml
go run run-e2e-experiment.go ../../../examples/v1alpha3/bayesianoptimization-example.yaml
kubectl -n kubeflow describe suggestion
kubectl -n kubeflow delete experiment skopt-bayesian-optimization-example
kubectl -n kubeflow delete experiment bayesianoptimization-example
exit 0
4 changes: 2 additions & 2 deletions test/scripts/v1alpha3/run-suggestion-grid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cd ${GO_DIR}/test/e2e/v1alpha3

echo "Running e2e chocolate grid experiment"
export KUBECONFIG=$HOME/.kube/config
go run run-e2e-experiment.go ../../../examples/v1alpha3/chocolate-grid-example.yaml
go run run-e2e-experiment.go ../../../examples/v1alpha3/grid-example.yaml
kubectl -n kubeflow describe suggestion
kubectl -n kubeflow delete experiment chocolate-grid-example
kubectl -n kubeflow delete experiment grid-example
exit 0
4 changes: 2 additions & 2 deletions test/scripts/v1alpha3/run-suggestion-random.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cd ${GO_DIR}/test/e2e/v1alpha3

echo "Running e2e hyperopt random experiment"
export KUBECONFIG=$HOME/.kube/config
go run run-e2e-experiment.go ../../../examples/v1alpha3/hyperopt-random-example.yaml
go run run-e2e-experiment.go ../../../examples/v1alpha3/random-example.yaml
kubectl -n kubeflow describe suggestion
kubectl -n kubeflow delete experiment hyperopt-random-example
kubectl -n kubeflow delete experiment random-example
exit 0
2 changes: 1 addition & 1 deletion test/suggestion/v1alpha3/test_chocolate_service.py.failed
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class TestHyperopt(unittest.TestCase):
name="test",
spec=api_pb2.ExperimentSpec(
algorithm=api_pb2.AlgorithmSpec(
algorithm_name="chocolate-grid",
algorithm_name="grid",
algorithm_setting=[
api_pb2.AlgorithmSetting(
name="random_state",
Expand Down
2 changes: 1 addition & 1 deletion test/suggestion/v1alpha3/test_hyperopt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_get_suggestion(self):
name="test",
spec=api_pb2.ExperimentSpec(
algorithm=api_pb2.AlgorithmSpec(
algorithm_name="hyperopt-tpe",
algorithm_name="tpe",
algorithm_setting=[
api_pb2.AlgorithmSetting(
name="random_state",
Expand Down
4 changes: 2 additions & 2 deletions test/suggestion/v1alpha3/test_skopt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pkg.suggestion.v1alpha3.skopt_service import SkoptService


class TestHyperopt(unittest.TestCase):
class TestSkopt(unittest.TestCase):
def setUp(self):
servicers = {
api_pb2.DESCRIPTOR.services_by_name['Suggestion']: SkoptService(
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_get_suggestion(self):
name="test",
spec=api_pb2.ExperimentSpec(
algorithm=api_pb2.AlgorithmSpec(
algorithm_name="skopt-bayesian-optimization",
algorithm_name="bayesianoptimization",
algorithm_setting=[
api_pb2.AlgorithmSetting(
name="random_state",
Expand Down