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: Support grid #8

Closed
wants to merge 1 commit into from
Closed
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
130 changes: 32 additions & 98 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifests/v1alpha3/sample/experiment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
additionalMetricsNames:
- loss
algorithm:
algorithmName: RandomSearch
algorithmName: GridSearch
algorithmSettings:
- name: param1
value: test
Expand Down
8 changes: 5 additions & 3 deletions pkg/suggestion/v1alpha3/advisor/advisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json

from pkg.suggestion.v1alpha3.advisor.algorithm.random_search import RandomSearchAlgorithm
# from pkg.suggestion.v1alpha3.advisor.algorithm.grid_search import GridSearchAlgorithm
from pkg.suggestion.v1alpha3.advisor.algorithm.grid_search import GridSearchAlgorithm
# from pkg.suggestion.v1alpha3.advisor.algorithm.bayesian_optimization import BayesianOptimization
# from pkg.suggestion.v1alpha3.advisor.algorithm.tpe import TpeAlgorithm
# from pkg.suggestion.v1alpha3.advisor.algorithm.simulate_anneal import SimulateAnnealAlgorithm
Expand Down Expand Up @@ -37,10 +37,12 @@ def GetSuggestions(self, request, context):
trials = request.trials
study_configuration = self.composeConfig(experiment)
input_trials = self.composeTrials(trials)
self.logger.log(INFO, "algorithm_name: %s",
experiment.experiment_spec.algorithm.algorithm_name)
if experiment.experiment_spec.algorithm.algorithm_name == "RandomSearch":
algorithm = RandomSearchAlgorithm()
# elif experiment.experiment_spec.algorithm.algorithm_name == "GridSearch":
# algorithm = GridSearchAlgorithm()
elif experiment.experiment_spec.algorithm.algorithm_name == "GridSearch":
algorithm = GridSearchAlgorithm()
# elif experiment.experiment_spec.algorithm.algorithm_name == "BayesianOptimization":
# algorithm = BayesianOptimization()
# elif experiment.experiment_spec.algorithm.algorithm_name == "TPE":
Expand Down
18 changes: 6 additions & 12 deletions pkg/suggestion/v1alpha3/advisor/algorithm/grid_search.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import json
import itertools

from suggestion.models import Study
from suggestion.models import Trial
from suggestion.algorithm.abstract_algorithm import AbstractSuggestionAlgorithm

from pkg.suggestion.v1alpha3.advisor.algorithm.abstract_algorithm import AbstractSuggestionAlgorithm

class GridSearchAlgorithm(AbstractSuggestionAlgorithm):
def get_new_suggestions(self, study_name, trials=[], number=1):
def get_new_suggestions(self, study, study_configuration_json, trials=[], number=1):
"""
Get the new suggested trials with grid search.
"""

return_trial_list = []

study = Study.objects.get(name=study_name)

study_configuration_json = json.loads(study.study_configuration)
params = study_configuration_json["params"]
param_number = len(params)

Expand Down Expand Up @@ -56,7 +50,7 @@ def get_new_suggestions(self, study_name, trials=[], number=1):
all_combination_number = len(all_combination_values_json)

# Compute how many grid search params have been allocated
allocated_trials = Trial.objects.filter(study_name=study_name)
allocated_trials = trials
return_trials_start_index = len(allocated_trials)

if return_trials_start_index > all_combination_number:
Expand All @@ -65,10 +59,10 @@ def get_new_suggestions(self, study_name, trials=[], number=1):
return_trials_start_index = all_combination_number - number

for i in range(number):
trial = Trial.create(study.name, "GridSearchTrial")
trial.parameter_values = json.dumps(
trial = {}
trial["name"] = study["name"]
trial["parameter_values"] = json.dumps(
all_combination_values_json[return_trials_start_index + i])
trial.save()
return_trial_list.append(trial)

return return_trial_list