From a44445788cd65f2f7c737fd0d4a94af617806801 Mon Sep 17 00:00:00 2001 From: Shashank Mittal Date: Sat, 7 Sep 2024 00:30:56 +0530 Subject: [PATCH] added more test cases for hyperopt distributions Signed-off-by: Shashank Mittal --- .github/workflows/e2e-test-pytorch-mnist.yaml | 3 ++- .../v1beta1/hyperopt/base_service.py | 15 +++++++-------- .../v1beta1/internal/search_space.py | 1 + .../suggestion/test_hyperopt_service.py | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.github/workflows/e2e-test-pytorch-mnist.yaml b/.github/workflows/e2e-test-pytorch-mnist.yaml index 3a5ff7e1bc0..75828142337 100644 --- a/.github/workflows/e2e-test-pytorch-mnist.yaml +++ b/.github/workflows/e2e-test-pytorch-mnist.yaml @@ -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" \ No newline at end of file + - "median-stop-with-json-format,file-metrics-collector-with-json-format" + \ No newline at end of file diff --git a/pkg/suggestion/v1beta1/hyperopt/base_service.py b/pkg/suggestion/v1beta1/hyperopt/base_service.py index d38ad00d5e6..53b632d4219 100644 --- a/pkg/suggestion/v1beta1/hyperopt/base_service.py +++ b/pkg/suggestion/v1beta1/hyperopt/base_service.py @@ -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 @@ -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, @@ -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, @@ -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 diff --git a/pkg/suggestion/v1beta1/internal/search_space.py b/pkg/suggestion/v1beta1/internal/search_space.py index 2a11ba2cb22..13573ed540d 100644 --- a/pkg/suggestion/v1beta1/internal/search_space.py +++ b/pkg/suggestion/v1beta1/internal/search_space.py @@ -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 diff --git a/test/unit/v1beta1/suggestion/test_hyperopt_service.py b/test/unit/v1beta1/suggestion/test_hyperopt_service.py index c726115d9f4..c2d79ca92ac 100644 --- a/test/unit/v1beta1/suggestion/test_hyperopt_service.py +++ b/test/unit/v1beta1/suggestion/test_hyperopt_service.py @@ -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) ) ] )