mirror of
https://github.com/hanzo-ml/katib.git
synced 2026-09-24 00:31:27 +00:00
Merge upstream/master into master (sync fork with upstream)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
# Kubeflow Community Code of Conduct
|
||||
|
||||
Kubeflow follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md).
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting
|
||||
the [Kubeflow Steering Committee](https://github.com/kubeflow/community/tree/master/committee-steering).
|
||||
@@ -129,6 +129,13 @@ class BaseOptunaService(object):
|
||||
log=True,
|
||||
step=1,
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Unsupported distribution "
|
||||
f"{api_pb2.Distribution.Name(param.distribution)} for parameter "
|
||||
f"{param.name}. The Optuna suggestion service supports only UNIFORM "
|
||||
f"and LOG_UNIFORM for int parameters."
|
||||
)
|
||||
|
||||
elif param.type == DOUBLE:
|
||||
if param.distribution in [api_pb2.UNIFORM, None]:
|
||||
@@ -148,6 +155,13 @@ class BaseOptunaService(object):
|
||||
log=True,
|
||||
step=None,
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Unsupported distribution "
|
||||
f"{api_pb2.Distribution.Name(param.distribution)} for parameter "
|
||||
f"{param.name}. The Optuna suggestion service supports only UNIFORM "
|
||||
f"and LOG_UNIFORM for double parameters."
|
||||
)
|
||||
|
||||
elif param.type in [CATEGORICAL, DISCRETE]:
|
||||
# Categorical & Discrete parameters use a categorical distribution.
|
||||
|
||||
@@ -18,6 +18,12 @@ import pytest
|
||||
import utils
|
||||
|
||||
from pkg.apis.manager.v1beta1.python import api_pb2
|
||||
from pkg.suggestion.v1beta1.internal import constant
|
||||
from pkg.suggestion.v1beta1.internal.search_space import (
|
||||
HyperParameter,
|
||||
HyperParameterSearchSpace,
|
||||
)
|
||||
from pkg.suggestion.v1beta1.optuna.base_service import BaseOptunaService
|
||||
from pkg.suggestion.v1beta1.optuna.service import OptunaService
|
||||
|
||||
|
||||
@@ -113,7 +119,10 @@ class TestOptuna:
|
||||
name="param-7",
|
||||
parameter_type=api_pb2.INT,
|
||||
feasible_space=api_pb2.FeasibleSpace(
|
||||
max="5", min="1", step="2", distribution=api_pb2.LOG_UNIFORM
|
||||
max="5",
|
||||
min="1",
|
||||
step="2",
|
||||
distribution=api_pb2.LOG_UNIFORM,
|
||||
),
|
||||
),
|
||||
api_pb2.ParameterSpec(
|
||||
@@ -127,14 +136,20 @@ class TestOptuna:
|
||||
name="param-9",
|
||||
parameter_type=api_pb2.DOUBLE,
|
||||
feasible_space=api_pb2.FeasibleSpace(
|
||||
max="11", min="1", step="2.5", distribution=api_pb2.UNIFORM
|
||||
max="11",
|
||||
min="1",
|
||||
step="2.5",
|
||||
distribution=api_pb2.UNIFORM,
|
||||
),
|
||||
),
|
||||
api_pb2.ParameterSpec(
|
||||
name="param-10",
|
||||
parameter_type=api_pb2.DOUBLE,
|
||||
feasible_space=api_pb2.FeasibleSpace(
|
||||
max="11", min="1", step="2.5", distribution=api_pb2.LOG_UNIFORM
|
||||
max="11",
|
||||
min="1",
|
||||
step="2.5",
|
||||
distribution=api_pb2.LOG_UNIFORM,
|
||||
),
|
||||
),
|
||||
api_pb2.ParameterSpec(
|
||||
@@ -552,5 +567,38 @@ class TestOptuna:
|
||||
assert code == result
|
||||
|
||||
|
||||
class TestOptunaUnsupportedDistribution:
|
||||
@pytest.mark.parametrize(
|
||||
["param_type", "distribution"],
|
||||
[
|
||||
["double", api_pb2.NORMAL],
|
||||
["double", api_pb2.LOG_NORMAL],
|
||||
["int", api_pb2.NORMAL],
|
||||
["int", api_pb2.LOG_NORMAL],
|
||||
],
|
||||
)
|
||||
def test_unsupported_distribution_raises(self, param_type, distribution):
|
||||
# The Optuna suggestion service only maps UNIFORM and LOG_UNIFORM. A param
|
||||
# with NORMAL or LOG_NORMAL used to be dropped from the search space without
|
||||
# any error, so the hyperparameter was silently never tuned (#2665). It must
|
||||
# now fail loudly instead.
|
||||
search_space = HyperParameterSearchSpace()
|
||||
search_space.goal = constant.MAX_GOAL
|
||||
if param_type == "double":
|
||||
param = HyperParameter.double("x", "0.1", "0.9", "", distribution)
|
||||
else:
|
||||
param = HyperParameter.int("x", "1", "9", "1", distribution)
|
||||
search_space.params = [param]
|
||||
|
||||
service = BaseOptunaService(
|
||||
algorithm_name="random",
|
||||
algorithm_config={},
|
||||
search_space=search_space,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="Unsupported distribution"):
|
||||
service.get_suggestions([], 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main()
|
||||
|
||||
Reference in New Issue
Block a user