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

Migrate to GPSampler from skopt for bayesianoptimization #2490

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 0 additions & 2 deletions .github/workflows/publish-algorithm-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:
dockerfile: cmd/suggestion/hyperopt/v1beta1/Dockerfile
- component-name: suggestion-hyperband
dockerfile: cmd/suggestion/hyperband/v1beta1/Dockerfile
- component-name: suggestion-skopt
dockerfile: cmd/suggestion/skopt/v1beta1/Dockerfile
- component-name: suggestion-goptuna
dockerfile: cmd/suggestion/goptuna/v1beta1/Dockerfile
- component-name: suggestion-optuna
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/test-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,3 @@ jobs:

- name: Run Python test
run: make pytest

# The skopt service doesn't work appropriately with Python 3.11.
# So, we need to run the test with Python 3.9.
# TODO (tenzen-y): Once we stop to support skopt, we can remove this test.
# REF: https://github.com/kubeflow/katib/issues/2280
test-skopt:
name: Test Skopt
runs-on: ubuntu-22.04

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Run Python test
run: make pytest-skopt
11 changes: 1 addition & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ endif
# TODO(Electronic-Waste): Remove the import rewrite when protobuf supports `python_package` option.
# REF: https://github.com/protocolbuffers/protobuf/issues/7061
pytest: prepare-pytest prepare-pytest-testdata
pytest ./test/unit/v1beta1/suggestion --ignore=./test/unit/v1beta1/suggestion/test_skopt_service.py
pytest ./test/unit/v1beta1/suggestion
pytest ./test/unit/v1beta1/earlystopping
pytest ./test/unit/v1beta1/metricscollector
cp ./pkg/apis/manager/v1beta1/python/api_pb2.py ./sdk/python/v1beta1/kubeflow/katib/katib_api_pb2.py
Expand All @@ -182,12 +182,3 @@ pytest: prepare-pytest prepare-pytest-testdata
pytest ./sdk/python/v1beta1/kubeflow/katib
rm ./sdk/python/v1beta1/kubeflow/katib/katib_api_pb2.py ./sdk/python/v1beta1/kubeflow/katib/katib_api_pb2_grpc.py

# The skopt service doesn't work appropriately with Python 3.11.
# So, we need to run the test with Python 3.9.
# TODO (tenzen-y): Once we stop to support skopt, we can remove this test.
# REF: https://github.com/kubeflow/katib/issues/2280
pytest-skopt:
pip install six
pip install --prefer-binary -r test/unit/v1beta1/requirements.txt
pip install --prefer-binary -r cmd/suggestion/skopt/v1beta1/requirements.txt
pytest ./test/unit/v1beta1/suggestion/test_skopt_service.py
5 changes: 4 additions & 1 deletion cmd/suggestion/optuna/v1beta1/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
grpcio>=1.64.1
protobuf>=4.21.12,<5
googleapis-common-protos==1.53.0
optuna==3.3.0
optuna==3.6.0
torch==2.5.1
scipy==1.15.1
cmaes==0.11.1
24 changes: 0 additions & 24 deletions cmd/suggestion/skopt/v1beta1/Dockerfile

This file was deleted.

44 changes: 0 additions & 44 deletions cmd/suggestion/skopt/v1beta1/main.py

This file was deleted.

13 changes: 0 additions & 13 deletions cmd/suggestion/skopt/v1beta1/requirements.txt

This file was deleted.

11 changes: 0 additions & 11 deletions docs/images-location.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,6 @@ and the [Katib Early Stopping algorithms](https://www.kubeflow.org/docs/componen
<a href="https://github.com/kubeflow/katib/blob/master/cmd/suggestion/hyperopt/v1beta1/Dockerfile">Dockerfile</a>
</td>
</tr>
<tr align="center">
<td>
<code>docker.io/kubeflowkatib/suggestion-skopt</code>
</td>
<td>
<a href="https://github.com/scikit-optimize/scikit-optimize">Skopt</a> Suggestion
</td>
<td>
<a href="https://github.com/kubeflow/katib/blob/master/cmd/suggestion/skopt/v1beta1/Dockerfile">Dockerfile</a>
</td>
</tr>
<tr align="center">
<td>
<code>docker.io/kubeflowkatib/suggestion-optuna</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ runtime:
- algorithmName: hyperband
image: docker.io/kubeflowkatib/suggestion-hyperband:latest
- algorithmName: bayesianoptimization
image: docker.io/kubeflowkatib/suggestion-skopt:latest
image: docker.io/kubeflowkatib/suggestion-optuan:latest
- algorithmName: cmaes
image: docker.io/kubeflowkatib/suggestion-goptuna:latest
- algorithmName: sobol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ runtime:
- algorithmName: hyperband
image: docker.io/kubeflowkatib/suggestion-hyperband:latest
- algorithmName: bayesianoptimization
image: docker.io/kubeflowkatib/suggestion-skopt:latest
image: docker.io/kubeflowkatib/suggestion-optuna:latest
- algorithmName: cmaes
image: docker.io/kubeflowkatib/suggestion-goptuna:latest
- algorithmName: sobol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ runtime:
- algorithmName: hyperband
image: docker.io/kubeflowkatib/suggestion-hyperband:latest
- algorithmName: bayesianoptimization
image: docker.io/kubeflowkatib/suggestion-skopt:latest
image: docker.io/kubeflowkatib/suggestion-goptuna:latest
- algorithmName: cmaes
image: docker.io/kubeflowkatib/suggestion-goptuna:latest
- algorithmName: sobol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ runtime:
- algorithmName: hyperband
image: docker.io/kubeflowkatib/suggestion-hyperband:latest
- algorithmName: bayesianoptimization
image: docker.io/kubeflowkatib/suggestion-skopt:latest
image: docker.io/kubeflowkatib/suggestion-optuna:latest
- algorithmName: cmaes
image: docker.io/kubeflowkatib/suggestion-goptuna:latest
- algorithmName: sobol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ runtime:
- algorithmName: hyperband
image: docker.io/kubeflowkatib/suggestion-hyperband:latest
- algorithmName: bayesianoptimization
image: docker.io/kubeflowkatib/suggestion-skopt:latest
image: docker.io/kubeflowkatib/suggestion-optuna:latest
- algorithmName: cmaes
image: docker.io/kubeflowkatib/suggestion-goptuna:latest
- algorithmName: sobol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ runtime:
- algorithmName: hyperband
image: docker.io/kubeflowkatib/suggestion-hyperband:latest
- algorithmName: bayesianoptimization
image: docker.io/kubeflowkatib/suggestion-skopt:latest
image: docker.io/kubeflowkatib/suggestion-optuna:latest
- algorithmName: cmaes
image: docker.io/kubeflowkatib/suggestion-goptuna:latest
- algorithmName: sobol
Expand Down
3 changes: 3 additions & 0 deletions pkg/suggestion/v1beta1/optuna/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def _create_sampler(self):
)
return optuna.samplers.GridSampler(combinations, **self.algorithm_config)

elif self.algorithm_name == "bayesianoptimization":
return optuna.samplers.GPSampler(**self.algorithm_config)

def get_suggestions(self, trials, current_request_number):
if len(trials) != 0:
self._tell(trials)
Expand Down
30 changes: 30 additions & 0 deletions pkg/suggestion/v1beta1/optuna/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class OptimizerConfiguration(object):
"grid": {
"seed": lambda x: int(x),
},
"bayesianoptimization": {
"n_startup_trials": lambda x: int(x),
"seed": lambda x: int(x),
},
}

@classmethod
Expand Down Expand Up @@ -132,6 +136,8 @@ def validate_algorithm_spec(cls, experiment):
return cls._validate_random_setting(algorithm_settings)
elif algorithm_name == "grid":
return cls._validate_grid_setting(experiment)
elif algorithm_name == "bayesianoptimization":
return cls._validate_bayesianoptimization_setting(algorithm_settings)
else:
return False, "unknown algorithm name {}".format(algorithm_name)

Expand Down Expand Up @@ -259,3 +265,27 @@ def _validate_grid_setting(cls, experiment):
)

return True, ""

@classmethod
def _validate_bayesianoptimization_setting(cls, algorithm_settings):
for s in algorithm_settings:
try:
if s.name in ["n_startup_trials", "random_state"]:
if not int(s.value) >= 0:
return False, "{} should be greate or equal than zero".format(
s.name
)
else:
return (
False,
"unknown setting {} for algorithm bayesianoptimization".format(
s.name
),
)

except Exception as e:
return False, "failed to validate {name}({value}): {exception}".format(
name=s.name, value=s.value, exception=e
)

return True, ""
Empty file.
Loading
Loading