From 0689785afad23325fd5cfd7470e6919aba7ad552 Mon Sep 17 00:00:00 2001 From: Rosie Zou Date: Wed, 27 Jul 2022 14:31:23 -0700 Subject: [PATCH 01/10] feat: added support for conditional parameters in hyperparameter tuning --- .../cloud/aiplatform/hyperparameter_tuning.py | 67 ++++++++++++++++--- .../test_hyperparameter_tuning_job.py | 27 +++++++- 2 files changed, 84 insertions(+), 10 deletions(-) diff --git a/google/cloud/aiplatform/hyperparameter_tuning.py b/google/cloud/aiplatform/hyperparameter_tuning.py index a43f1c39fd..af4ae9d947 100644 --- a/google/cloud/aiplatform/hyperparameter_tuning.py +++ b/google/cloud/aiplatform/hyperparameter_tuning.py @@ -29,6 +29,9 @@ "unspecified": gca_study_compat.StudySpec.ParameterSpec.ScaleType.SCALE_TYPE_UNSPECIFIED, } +_INT_VALUE_SPEC = "integer_value_spec" +_DISCRETE_VALUE_SPEC = "discrete_value_spec" +_CATEGORICAL_VALUE_SPEC = "categorical_value_spec" class _ParameterSpec(metaclass=abc.ABCMeta): """Base class represents a single parameter to optimize.""" @@ -77,10 +80,25 @@ def _to_parameter_spec( self, parameter_id: str ) -> gca_study_compat.StudySpec.ParameterSpec: """Converts this parameter to ParameterSpec.""" - # TODO: Conditional parameters + conditions = [] + if self.conditional_parameter_spec is not None: + for (conditional_param_id, spec) in self.conditional_parameter_spec.items(): + condition = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec() + if self._parameter_spec_value_key == _INT_VALUE_SPEC: + condition.parent_int_values = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.IntValueCondition( + values=spec.parent_values) + elif self._parameter_spec_value_key == _CATEGORICAL_VALUE_SPEC: + condition.parent_categorical_values = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.CategoricalValueCondition( + values=spec.parent_values) + elif self._parameter_spec_value_key == _DISCRETE_VALUE_SPEC: + condition.parent_discrete_values = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition( + values=spec.parent_values) + condition.parameter_spec = spec._to_parameter_spec(conditional_param_id) + conditions.append(condition) parameter_spec = gca_study_compat.StudySpec.ParameterSpec( parameter_id=parameter_id, scale_type=_SCALE_TYPE_MAP.get(getattr(self, "scale", "unspecified")), + conditional_parameter_specs = conditions ) setattr( @@ -105,6 +123,8 @@ def __init__( min: float, max: float, scale: str, + conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, + parent_values: Optional[Sequence[Union[int, float, str]]] = None ): """ Value specification for a parameter in ``DOUBLE`` type. @@ -120,9 +140,16 @@ def __init__( Required. The type of scaling that should be applied to this parameter. Accepts: 'linear', 'log', 'reverse_log' + conditional_parameter_spec (Dict[str, _ParameterSpec]): + Optional. The conditional parameters associated with the object. The dictionary key + is the ID of the conditional parameter and the dictionary value is one of + `IntegerParameterSpec`, `CategoricalParameterSpec`, or `DiscreteParameterSpec` + parent_values (Sequence[Union[int, float, str]]): + Optional. This argument is only needed when the object is a conditional parameter + and specifies the parent parameter's values for which the condition applies. """ - super().__init__() + super().__init__(conditional_parameter_spec, parent_values) self.min = min self.max = max @@ -142,6 +169,8 @@ def __init__( min: int, max: int, scale: str, + conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, + parent_values: Optional[Sequence[Union[int, float, str]]] = None ): """ Value specification for a parameter in ``INTEGER`` type. @@ -157,9 +186,15 @@ def __init__( Required. The type of scaling that should be applied to this parameter. Accepts: 'linear', 'log', 'reverse_log' + conditional_parameter_spec (Dict[str, _ParameterSpec]): + Optional. The conditional parameters associated with the object. The dictionary key + is the ID of the conditional parameter and the dictionary value is one of + `IntegerParameterSpec`, `CategoricalParameterSpec`, or `DiscreteParameterSpec` + parent_values (Sequence[int]): + Optional. This argument is only needed when the object is a conditional parameter + and specifies the parent parameter's values for which the condition applies. """ - - super().__init__() + super().__init__(conditional_parameter_spec=conditional_parameter_spec, parent_values=parent_values) self.min = min self.max = max @@ -177,15 +212,23 @@ class CategoricalParameterSpec(_ParameterSpec): def __init__( self, values: Sequence[str], + conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, + parent_values: Optional[Sequence[Union[int, float, str]]] = None ): """Value specification for a parameter in ``CATEGORICAL`` type. Args: values (Sequence[str]): Required. The list of possible categories. + conditional_parameter_spec (Dict[str, _ParameterSpec]): + Optional. The conditional parameters associated with the object. The dictionary key + is the ID of the conditional parameter and the dictionary value is one of + `IntegerParameterSpec`, `CategoricalParameterSpec`, or `DiscreteParameterSpec` + parent_values (Sequence[str]): + Optional. This argument is only needed when the object is a conditional parameter + and specifies the parent parameter's values for which the condition applies. """ - - super().__init__() + super().__init__(conditional_parameter_spec=conditional_parameter_spec, parent_values=parent_values) self.values = values @@ -202,6 +245,8 @@ def __init__( self, values: Sequence[float], scale: str, + conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, + parent_values: Optional[Sequence[Union[int, float, str]]] = None ): """Value specification for a parameter in ``DISCRETE`` type. @@ -216,9 +261,15 @@ def __init__( Required. The type of scaling that should be applied to this parameter. Accepts: 'linear', 'log', 'reverse_log' + conditional_parameter_spec (Dict[str, _ParameterSpec]): + Optional. The conditional parameters associated with the object. The dictionary key + is the ID of the conditional parameter and the dictionary value is one of + `IntegerParameterSpec`, `CategoricalParameterSpec`, or `DiscreteParameterSpec` + parent_values (Sequence[float]): + Optional. This argument is only needed when the object is a conditional parameter + and specifies the parent parameter's values for which the condition applies. """ - - super().__init__() + super().__init__(conditional_parameter_spec=conditional_parameter_spec, parent_values=parent_values) self.values = values self.scale = scale diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index 30a2ea40be..5a7e9fcb48 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -109,8 +109,28 @@ parameter_id="batch_size", scale_type=gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LINEAR_SCALE, discrete_value_spec=gca_study_compat.StudySpec.ParameterSpec.DiscreteValueSpec( - values=[16, 32] + values=[4,8,16,32,64] ), + conditional_parameter_specs=[ + gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec( + parent_discrete_values=gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition( + values=[32,64]), + parameter_spec = gca_study_compat.StudySpec.ParameterSpec( + double_value_spec=gca_study_compat.StudySpec.ParameterSpec.DoubleValueSpec( + min_value=1e-07, max_value=1), + scale_type=gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LINEAR_SCALE, + parameter_id="decay") + ), + gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec( + parent_discrete_values=gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition( + values=[4,8,16]), + parameter_spec = gca_study_compat.StudySpec.ParameterSpec( + double_value_spec=gca_study_compat.StudySpec.ParameterSpec.DoubleValueSpec( + min_value=1e-07, max_value=1), + scale_type=gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LINEAR_SCALE, + parameter_id="learning_rate") + ) + ] ), ], algorithm=gca_study_compat.StudySpec.Algorithm.RANDOM_SEARCH, @@ -377,6 +397,8 @@ def test_create_hyperparameter_tuning_job( base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) + conditional_parameter_decay = hpt.DoubleParameterSpec(min=1e-07, max=1,scale="linear", parent_values=[32,64]) + conditional_parameter_lr = hpt.DoubleParameterSpec(min=1e-07, max=1,scale="linear", parent_values=[4,8,16]) job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -388,7 +410,8 @@ def test_create_hyperparameter_tuning_job( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[16, 32], scale="linear" + values=[4,8,16, 32, 64], scale="linear", + conditional_parameter_spec={"decay":conditional_parameter_decay, "learning_rate":conditional_parameter_lr} ), }, parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, From bbfa1cb99cc11d1e33a33b447809ef40bdba2f16 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 27 Jul 2022 21:35:18 +0000 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../cloud/aiplatform/hyperparameter_tuning.py | 39 +++++++++++----- .../test_hyperparameter_tuning_job.py | 44 ++++++++++++------- 2 files changed, 56 insertions(+), 27 deletions(-) diff --git a/google/cloud/aiplatform/hyperparameter_tuning.py b/google/cloud/aiplatform/hyperparameter_tuning.py index af4ae9d947..f08f2d4bcd 100644 --- a/google/cloud/aiplatform/hyperparameter_tuning.py +++ b/google/cloud/aiplatform/hyperparameter_tuning.py @@ -33,6 +33,7 @@ _DISCRETE_VALUE_SPEC = "discrete_value_spec" _CATEGORICAL_VALUE_SPEC = "categorical_value_spec" + class _ParameterSpec(metaclass=abc.ABCMeta): """Base class represents a single parameter to optimize.""" @@ -83,22 +84,27 @@ def _to_parameter_spec( conditions = [] if self.conditional_parameter_spec is not None: for (conditional_param_id, spec) in self.conditional_parameter_spec.items(): - condition = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec() + condition = ( + gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec() + ) if self._parameter_spec_value_key == _INT_VALUE_SPEC: condition.parent_int_values = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.IntValueCondition( - values=spec.parent_values) + values=spec.parent_values + ) elif self._parameter_spec_value_key == _CATEGORICAL_VALUE_SPEC: condition.parent_categorical_values = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.CategoricalValueCondition( - values=spec.parent_values) + values=spec.parent_values + ) elif self._parameter_spec_value_key == _DISCRETE_VALUE_SPEC: condition.parent_discrete_values = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition( - values=spec.parent_values) + values=spec.parent_values + ) condition.parameter_spec = spec._to_parameter_spec(conditional_param_id) conditions.append(condition) parameter_spec = gca_study_compat.StudySpec.ParameterSpec( parameter_id=parameter_id, scale_type=_SCALE_TYPE_MAP.get(getattr(self, "scale", "unspecified")), - conditional_parameter_specs = conditions + conditional_parameter_specs=conditions, ) setattr( @@ -124,7 +130,7 @@ def __init__( max: float, scale: str, conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, - parent_values: Optional[Sequence[Union[int, float, str]]] = None + parent_values: Optional[Sequence[Union[int, float, str]]] = None, ): """ Value specification for a parameter in ``DOUBLE`` type. @@ -170,7 +176,7 @@ def __init__( max: int, scale: str, conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, - parent_values: Optional[Sequence[Union[int, float, str]]] = None + parent_values: Optional[Sequence[Union[int, float, str]]] = None, ): """ Value specification for a parameter in ``INTEGER`` type. @@ -194,7 +200,10 @@ def __init__( Optional. This argument is only needed when the object is a conditional parameter and specifies the parent parameter's values for which the condition applies. """ - super().__init__(conditional_parameter_spec=conditional_parameter_spec, parent_values=parent_values) + super().__init__( + conditional_parameter_spec=conditional_parameter_spec, + parent_values=parent_values, + ) self.min = min self.max = max @@ -213,7 +222,7 @@ def __init__( self, values: Sequence[str], conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, - parent_values: Optional[Sequence[Union[int, float, str]]] = None + parent_values: Optional[Sequence[Union[int, float, str]]] = None, ): """Value specification for a parameter in ``CATEGORICAL`` type. @@ -228,7 +237,10 @@ def __init__( Optional. This argument is only needed when the object is a conditional parameter and specifies the parent parameter's values for which the condition applies. """ - super().__init__(conditional_parameter_spec=conditional_parameter_spec, parent_values=parent_values) + super().__init__( + conditional_parameter_spec=conditional_parameter_spec, + parent_values=parent_values, + ) self.values = values @@ -246,7 +258,7 @@ def __init__( values: Sequence[float], scale: str, conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, - parent_values: Optional[Sequence[Union[int, float, str]]] = None + parent_values: Optional[Sequence[Union[int, float, str]]] = None, ): """Value specification for a parameter in ``DISCRETE`` type. @@ -269,7 +281,10 @@ def __init__( Optional. This argument is only needed when the object is a conditional parameter and specifies the parent parameter's values for which the condition applies. """ - super().__init__(conditional_parameter_spec=conditional_parameter_spec, parent_values=parent_values) + super().__init__( + conditional_parameter_spec=conditional_parameter_spec, + parent_values=parent_values, + ) self.values = values self.scale = scale diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index 5a7e9fcb48..b3144800ef 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -109,28 +109,34 @@ parameter_id="batch_size", scale_type=gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LINEAR_SCALE, discrete_value_spec=gca_study_compat.StudySpec.ParameterSpec.DiscreteValueSpec( - values=[4,8,16,32,64] + values=[4, 8, 16, 32, 64] ), conditional_parameter_specs=[ gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec( parent_discrete_values=gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition( - values=[32,64]), - parameter_spec = gca_study_compat.StudySpec.ParameterSpec( + values=[32, 64] + ), + parameter_spec=gca_study_compat.StudySpec.ParameterSpec( double_value_spec=gca_study_compat.StudySpec.ParameterSpec.DoubleValueSpec( - min_value=1e-07, max_value=1), + min_value=1e-07, max_value=1 + ), scale_type=gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LINEAR_SCALE, - parameter_id="decay") + parameter_id="decay", + ), ), gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec( parent_discrete_values=gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition( - values=[4,8,16]), - parameter_spec = gca_study_compat.StudySpec.ParameterSpec( + values=[4, 8, 16] + ), + parameter_spec=gca_study_compat.StudySpec.ParameterSpec( double_value_spec=gca_study_compat.StudySpec.ParameterSpec.DoubleValueSpec( - min_value=1e-07, max_value=1), + min_value=1e-07, max_value=1 + ), scale_type=gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LINEAR_SCALE, - parameter_id="learning_rate") - ) - ] + parameter_id="learning_rate", + ), + ), + ], ), ], algorithm=gca_study_compat.StudySpec.Algorithm.RANDOM_SEARCH, @@ -397,8 +403,12 @@ def test_create_hyperparameter_tuning_job( base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - conditional_parameter_decay = hpt.DoubleParameterSpec(min=1e-07, max=1,scale="linear", parent_values=[32,64]) - conditional_parameter_lr = hpt.DoubleParameterSpec(min=1e-07, max=1,scale="linear", parent_values=[4,8,16]) + conditional_parameter_decay = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[32, 64] + ) + conditional_parameter_lr = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] + ) job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -410,8 +420,12 @@ def test_create_hyperparameter_tuning_job( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4,8,16, 32, 64], scale="linear", - conditional_parameter_spec={"decay":conditional_parameter_decay, "learning_rate":conditional_parameter_lr} + values=[4, 8, 16, 32, 64], + scale="linear", + conditional_parameter_spec={ + "decay": conditional_parameter_decay, + "learning_rate": conditional_parameter_lr, + }, ), }, parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, From a76c08f7488313a234dd1937b53c932e75210612 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 27 Jul 2022 21:35:51 +0000 Subject: [PATCH 03/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../cloud/aiplatform/hyperparameter_tuning.py | 39 +++++++++++----- .../test_hyperparameter_tuning_job.py | 44 ++++++++++++------- 2 files changed, 56 insertions(+), 27 deletions(-) diff --git a/google/cloud/aiplatform/hyperparameter_tuning.py b/google/cloud/aiplatform/hyperparameter_tuning.py index af4ae9d947..f08f2d4bcd 100644 --- a/google/cloud/aiplatform/hyperparameter_tuning.py +++ b/google/cloud/aiplatform/hyperparameter_tuning.py @@ -33,6 +33,7 @@ _DISCRETE_VALUE_SPEC = "discrete_value_spec" _CATEGORICAL_VALUE_SPEC = "categorical_value_spec" + class _ParameterSpec(metaclass=abc.ABCMeta): """Base class represents a single parameter to optimize.""" @@ -83,22 +84,27 @@ def _to_parameter_spec( conditions = [] if self.conditional_parameter_spec is not None: for (conditional_param_id, spec) in self.conditional_parameter_spec.items(): - condition = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec() + condition = ( + gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec() + ) if self._parameter_spec_value_key == _INT_VALUE_SPEC: condition.parent_int_values = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.IntValueCondition( - values=spec.parent_values) + values=spec.parent_values + ) elif self._parameter_spec_value_key == _CATEGORICAL_VALUE_SPEC: condition.parent_categorical_values = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.CategoricalValueCondition( - values=spec.parent_values) + values=spec.parent_values + ) elif self._parameter_spec_value_key == _DISCRETE_VALUE_SPEC: condition.parent_discrete_values = gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition( - values=spec.parent_values) + values=spec.parent_values + ) condition.parameter_spec = spec._to_parameter_spec(conditional_param_id) conditions.append(condition) parameter_spec = gca_study_compat.StudySpec.ParameterSpec( parameter_id=parameter_id, scale_type=_SCALE_TYPE_MAP.get(getattr(self, "scale", "unspecified")), - conditional_parameter_specs = conditions + conditional_parameter_specs=conditions, ) setattr( @@ -124,7 +130,7 @@ def __init__( max: float, scale: str, conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, - parent_values: Optional[Sequence[Union[int, float, str]]] = None + parent_values: Optional[Sequence[Union[int, float, str]]] = None, ): """ Value specification for a parameter in ``DOUBLE`` type. @@ -170,7 +176,7 @@ def __init__( max: int, scale: str, conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, - parent_values: Optional[Sequence[Union[int, float, str]]] = None + parent_values: Optional[Sequence[Union[int, float, str]]] = None, ): """ Value specification for a parameter in ``INTEGER`` type. @@ -194,7 +200,10 @@ def __init__( Optional. This argument is only needed when the object is a conditional parameter and specifies the parent parameter's values for which the condition applies. """ - super().__init__(conditional_parameter_spec=conditional_parameter_spec, parent_values=parent_values) + super().__init__( + conditional_parameter_spec=conditional_parameter_spec, + parent_values=parent_values, + ) self.min = min self.max = max @@ -213,7 +222,7 @@ def __init__( self, values: Sequence[str], conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, - parent_values: Optional[Sequence[Union[int, float, str]]] = None + parent_values: Optional[Sequence[Union[int, float, str]]] = None, ): """Value specification for a parameter in ``CATEGORICAL`` type. @@ -228,7 +237,10 @@ def __init__( Optional. This argument is only needed when the object is a conditional parameter and specifies the parent parameter's values for which the condition applies. """ - super().__init__(conditional_parameter_spec=conditional_parameter_spec, parent_values=parent_values) + super().__init__( + conditional_parameter_spec=conditional_parameter_spec, + parent_values=parent_values, + ) self.values = values @@ -246,7 +258,7 @@ def __init__( values: Sequence[float], scale: str, conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, - parent_values: Optional[Sequence[Union[int, float, str]]] = None + parent_values: Optional[Sequence[Union[int, float, str]]] = None, ): """Value specification for a parameter in ``DISCRETE`` type. @@ -269,7 +281,10 @@ def __init__( Optional. This argument is only needed when the object is a conditional parameter and specifies the parent parameter's values for which the condition applies. """ - super().__init__(conditional_parameter_spec=conditional_parameter_spec, parent_values=parent_values) + super().__init__( + conditional_parameter_spec=conditional_parameter_spec, + parent_values=parent_values, + ) self.values = values self.scale = scale diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index 5a7e9fcb48..b3144800ef 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -109,28 +109,34 @@ parameter_id="batch_size", scale_type=gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LINEAR_SCALE, discrete_value_spec=gca_study_compat.StudySpec.ParameterSpec.DiscreteValueSpec( - values=[4,8,16,32,64] + values=[4, 8, 16, 32, 64] ), conditional_parameter_specs=[ gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec( parent_discrete_values=gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition( - values=[32,64]), - parameter_spec = gca_study_compat.StudySpec.ParameterSpec( + values=[32, 64] + ), + parameter_spec=gca_study_compat.StudySpec.ParameterSpec( double_value_spec=gca_study_compat.StudySpec.ParameterSpec.DoubleValueSpec( - min_value=1e-07, max_value=1), + min_value=1e-07, max_value=1 + ), scale_type=gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LINEAR_SCALE, - parameter_id="decay") + parameter_id="decay", + ), ), gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec( parent_discrete_values=gca_study_compat.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition( - values=[4,8,16]), - parameter_spec = gca_study_compat.StudySpec.ParameterSpec( + values=[4, 8, 16] + ), + parameter_spec=gca_study_compat.StudySpec.ParameterSpec( double_value_spec=gca_study_compat.StudySpec.ParameterSpec.DoubleValueSpec( - min_value=1e-07, max_value=1), + min_value=1e-07, max_value=1 + ), scale_type=gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LINEAR_SCALE, - parameter_id="learning_rate") - ) - ] + parameter_id="learning_rate", + ), + ), + ], ), ], algorithm=gca_study_compat.StudySpec.Algorithm.RANDOM_SEARCH, @@ -397,8 +403,12 @@ def test_create_hyperparameter_tuning_job( base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - conditional_parameter_decay = hpt.DoubleParameterSpec(min=1e-07, max=1,scale="linear", parent_values=[32,64]) - conditional_parameter_lr = hpt.DoubleParameterSpec(min=1e-07, max=1,scale="linear", parent_values=[4,8,16]) + conditional_parameter_decay = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[32, 64] + ) + conditional_parameter_lr = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] + ) job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -410,8 +420,12 @@ def test_create_hyperparameter_tuning_job( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4,8,16, 32, 64], scale="linear", - conditional_parameter_spec={"decay":conditional_parameter_decay, "learning_rate":conditional_parameter_lr} + values=[4, 8, 16, 32, 64], + scale="linear", + conditional_parameter_spec={ + "decay": conditional_parameter_decay, + "learning_rate": conditional_parameter_lr, + }, ), }, parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, From 1c6ad688c5bfbe3f33ea05d577866d851ab4bcb8 Mon Sep 17 00:00:00 2001 From: Rosie Zou Date: Thu, 28 Jul 2022 14:11:45 -0700 Subject: [PATCH 04/10] fixing unit tests --- .../test_hyperparameter_tuning_job.py | 72 ++++++++++++++++--- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index b3144800ef..53980971ad 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -479,7 +479,12 @@ def test_create_hyperparameter_tuning_job_with_timeout( worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - + conditional_parameter_decay = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[32, 64] + ) + conditional_parameter_lr = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] + ) job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -491,7 +496,12 @@ def test_create_hyperparameter_tuning_job_with_timeout( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[16, 32], scale="linear" + values=[4, 8, 16, 32, 64], + scale="linear", + conditional_parameter_spec={ + "decay": conditional_parameter_decay, + "learning_rate": conditional_parameter_lr, + }, ), }, parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, @@ -540,7 +550,12 @@ def test_run_hyperparameter_tuning_job_with_fail_raises( worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - + conditional_parameter_decay = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[32, 64] + ) + conditional_parameter_lr = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] + ) job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -552,7 +567,11 @@ def test_run_hyperparameter_tuning_job_with_fail_raises( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[16, 32], scale="linear" + values=[4, 8, 16, 32, 64], scale="linear", + conditional_parameter_spec={ + "decay": conditional_parameter_decay, + "learning_rate": conditional_parameter_lr, + }, ), }, parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, @@ -611,7 +630,11 @@ def test_run_hyperparameter_tuning_job_with_fail_at_creation(self): values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[16, 32], scale="linear" + values=[4, 8, 16, 32, 64], scale="linear", + conditional_parameter_spec={ + "decay": conditional_parameter_decay, + "learning_rate": conditional_parameter_lr, + }, ), }, parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, @@ -664,7 +687,12 @@ def test_hyperparameter_tuning_job_get_state_raises_without_run(self): worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - + conditional_parameter_decay = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[32, 64] + ) + conditional_parameter_lr = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] + ) job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -676,7 +704,11 @@ def test_hyperparameter_tuning_job_get_state_raises_without_run(self): values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[16, 32, 64], scale="linear" + values=[4, 8, 16, 32, 64], scale="linear", + conditional_parameter_spec={ + "decay": conditional_parameter_decay, + "learning_rate": conditional_parameter_lr, + }, ), }, parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, @@ -722,7 +754,12 @@ def test_create_hyperparameter_tuning_job_with_tensorboard( worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - + conditional_parameter_decay = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[32, 64] + ) + conditional_parameter_lr = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] + ) job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -734,7 +771,11 @@ def test_create_hyperparameter_tuning_job_with_tensorboard( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[16, 32], scale="linear" + values=[4, 8, 16, 32, 64], scale="linear", + conditional_parameter_spec={ + "decay": conditional_parameter_decay, + "learning_rate": conditional_parameter_lr, + }, ), }, parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, @@ -794,7 +835,12 @@ def test_create_hyperparameter_tuning_job_with_enable_web_access( worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - + conditional_parameter_decay = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[32, 64] + ) + conditional_parameter_lr = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] + ) job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -806,7 +852,11 @@ def test_create_hyperparameter_tuning_job_with_enable_web_access( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[16, 32], scale="linear" + values=[4, 8, 16, 32, 64], scale="linear", + conditional_parameter_spec={ + "decay": conditional_parameter_decay, + "learning_rate": conditional_parameter_lr, + }, ), }, parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, From c9f2ea804e212d6cdc442364c49ca330a5dfa07e Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 28 Jul 2022 21:14:53 +0000 Subject: [PATCH 05/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../aiplatform/test_hyperparameter_tuning_job.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index 53980971ad..3a84c359d6 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -567,7 +567,8 @@ def test_run_hyperparameter_tuning_job_with_fail_raises( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4, 8, 16, 32, 64], scale="linear", + values=[4, 8, 16, 32, 64], + scale="linear", conditional_parameter_spec={ "decay": conditional_parameter_decay, "learning_rate": conditional_parameter_lr, @@ -630,7 +631,8 @@ def test_run_hyperparameter_tuning_job_with_fail_at_creation(self): values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4, 8, 16, 32, 64], scale="linear", + values=[4, 8, 16, 32, 64], + scale="linear", conditional_parameter_spec={ "decay": conditional_parameter_decay, "learning_rate": conditional_parameter_lr, @@ -704,7 +706,8 @@ def test_hyperparameter_tuning_job_get_state_raises_without_run(self): values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4, 8, 16, 32, 64], scale="linear", + values=[4, 8, 16, 32, 64], + scale="linear", conditional_parameter_spec={ "decay": conditional_parameter_decay, "learning_rate": conditional_parameter_lr, @@ -771,7 +774,8 @@ def test_create_hyperparameter_tuning_job_with_tensorboard( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4, 8, 16, 32, 64], scale="linear", + values=[4, 8, 16, 32, 64], + scale="linear", conditional_parameter_spec={ "decay": conditional_parameter_decay, "learning_rate": conditional_parameter_lr, @@ -852,7 +856,8 @@ def test_create_hyperparameter_tuning_job_with_enable_web_access( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4, 8, 16, 32, 64], scale="linear", + values=[4, 8, 16, 32, 64], + scale="linear", conditional_parameter_spec={ "decay": conditional_parameter_decay, "learning_rate": conditional_parameter_lr, From 727c6a0474a7012f7c7d949365139db94ba692ac Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 28 Jul 2022 21:15:33 +0000 Subject: [PATCH 06/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../aiplatform/test_hyperparameter_tuning_job.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index 53980971ad..3a84c359d6 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -567,7 +567,8 @@ def test_run_hyperparameter_tuning_job_with_fail_raises( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4, 8, 16, 32, 64], scale="linear", + values=[4, 8, 16, 32, 64], + scale="linear", conditional_parameter_spec={ "decay": conditional_parameter_decay, "learning_rate": conditional_parameter_lr, @@ -630,7 +631,8 @@ def test_run_hyperparameter_tuning_job_with_fail_at_creation(self): values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4, 8, 16, 32, 64], scale="linear", + values=[4, 8, 16, 32, 64], + scale="linear", conditional_parameter_spec={ "decay": conditional_parameter_decay, "learning_rate": conditional_parameter_lr, @@ -704,7 +706,8 @@ def test_hyperparameter_tuning_job_get_state_raises_without_run(self): values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4, 8, 16, 32, 64], scale="linear", + values=[4, 8, 16, 32, 64], + scale="linear", conditional_parameter_spec={ "decay": conditional_parameter_decay, "learning_rate": conditional_parameter_lr, @@ -771,7 +774,8 @@ def test_create_hyperparameter_tuning_job_with_tensorboard( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4, 8, 16, 32, 64], scale="linear", + values=[4, 8, 16, 32, 64], + scale="linear", conditional_parameter_spec={ "decay": conditional_parameter_decay, "learning_rate": conditional_parameter_lr, @@ -852,7 +856,8 @@ def test_create_hyperparameter_tuning_job_with_enable_web_access( values=["relu", "sigmoid", "elu", "selu", "tanh"] ), "batch_size": hpt.DiscreteParameterSpec( - values=[4, 8, 16, 32, 64], scale="linear", + values=[4, 8, 16, 32, 64], + scale="linear", conditional_parameter_spec={ "decay": conditional_parameter_decay, "learning_rate": conditional_parameter_lr, From 1f14cafa01b5f77028b45beb26ff1c99c31d3bf7 Mon Sep 17 00:00:00 2001 From: Rosie Zou Date: Fri, 29 Jul 2022 20:23:39 -0700 Subject: [PATCH 07/10] fixed all failing tests --- tests/unit/aiplatform/test_hyperparameter_tuning_job.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index 3a84c359d6..36bd6247c6 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -619,7 +619,12 @@ def test_run_hyperparameter_tuning_job_with_fail_at_creation(self): worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - + conditional_parameter_decay = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[32, 64] + ) + conditional_parameter_lr = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] + ) job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, From 91224f0d533130c25f1feb4e2a12e3584ac196bc Mon Sep 17 00:00:00 2001 From: Rosie Zou Date: Mon, 1 Aug 2022 15:41:59 -0700 Subject: [PATCH 08/10] addressed PR comments --- .../cloud/aiplatform/hyperparameter_tuning.py | 2 +- .../test_hyperparameter_tuning_job.py | 83 ++++++------------- 2 files changed, 28 insertions(+), 57 deletions(-) diff --git a/google/cloud/aiplatform/hyperparameter_tuning.py b/google/cloud/aiplatform/hyperparameter_tuning.py index f08f2d4bcd..a0ef82ebb9 100644 --- a/google/cloud/aiplatform/hyperparameter_tuning.py +++ b/google/cloud/aiplatform/hyperparameter_tuning.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index 36bd6247c6..c18aee6c94 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -76,6 +76,13 @@ _TEST_LABELS = {"my_hp_key": "my_hp_value"} +_TEST_CONDITIONAL_PARAMETER_DECAY = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[32, 64] + ) +_TEST_CONDITIONAL_PARAMETER_LR = hpt.DoubleParameterSpec( + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] + ) + _TEST_BASE_HYPERPARAMETER_TUNING_JOB_PROTO = gca_hyperparameter_tuning_job_compat.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, study_spec=gca_study_compat.StudySpec( @@ -403,12 +410,6 @@ def test_create_hyperparameter_tuning_job( base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - conditional_parameter_decay = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[32, 64] - ) - conditional_parameter_lr = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] - ) job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -423,8 +424,8 @@ def test_create_hyperparameter_tuning_job( values=[4, 8, 16, 32, 64], scale="linear", conditional_parameter_spec={ - "decay": conditional_parameter_decay, - "learning_rate": conditional_parameter_lr, + "decay": _TEST_CONDITIONAL_PARAMETER_DECAY, + "learning_rate": _TEST_CONDITIONAL_PARAMETER_LR, }, ), }, @@ -479,12 +480,7 @@ def test_create_hyperparameter_tuning_job_with_timeout( worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - conditional_parameter_decay = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[32, 64] - ) - conditional_parameter_lr = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] - ) + job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -499,8 +495,8 @@ def test_create_hyperparameter_tuning_job_with_timeout( values=[4, 8, 16, 32, 64], scale="linear", conditional_parameter_spec={ - "decay": conditional_parameter_decay, - "learning_rate": conditional_parameter_lr, + "decay": _TEST_CONDITIONAL_PARAMETER_DECAY, + "learning_rate": _TEST_CONDITIONAL_PARAMETER_LR, }, ), }, @@ -550,12 +546,7 @@ def test_run_hyperparameter_tuning_job_with_fail_raises( worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - conditional_parameter_decay = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[32, 64] - ) - conditional_parameter_lr = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] - ) + job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -570,8 +561,8 @@ def test_run_hyperparameter_tuning_job_with_fail_raises( values=[4, 8, 16, 32, 64], scale="linear", conditional_parameter_spec={ - "decay": conditional_parameter_decay, - "learning_rate": conditional_parameter_lr, + "decay": _TEST_CONDITIONAL_PARAMETER_DECAY, + "learning_rate": _TEST_CONDITIONAL_PARAMETER_LR, }, ), }, @@ -619,12 +610,7 @@ def test_run_hyperparameter_tuning_job_with_fail_at_creation(self): worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - conditional_parameter_decay = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[32, 64] - ) - conditional_parameter_lr = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] - ) + job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -639,8 +625,8 @@ def test_run_hyperparameter_tuning_job_with_fail_at_creation(self): values=[4, 8, 16, 32, 64], scale="linear", conditional_parameter_spec={ - "decay": conditional_parameter_decay, - "learning_rate": conditional_parameter_lr, + "decay": _TEST_CONDITIONAL_PARAMETER_DECAY, + "learning_rate": _TEST_CONDITIONAL_PARAMETER_LR, }, ), }, @@ -694,12 +680,7 @@ def test_hyperparameter_tuning_job_get_state_raises_without_run(self): worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - conditional_parameter_decay = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[32, 64] - ) - conditional_parameter_lr = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] - ) + job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -714,8 +695,8 @@ def test_hyperparameter_tuning_job_get_state_raises_without_run(self): values=[4, 8, 16, 32, 64], scale="linear", conditional_parameter_spec={ - "decay": conditional_parameter_decay, - "learning_rate": conditional_parameter_lr, + "decay": _TEST_CONDITIONAL_PARAMETER_DECAY, + "learning_rate": _TEST_CONDITIONAL_PARAMETER_LR, }, ), }, @@ -762,12 +743,7 @@ def test_create_hyperparameter_tuning_job_with_tensorboard( worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - conditional_parameter_decay = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[32, 64] - ) - conditional_parameter_lr = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] - ) + job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -782,8 +758,8 @@ def test_create_hyperparameter_tuning_job_with_tensorboard( values=[4, 8, 16, 32, 64], scale="linear", conditional_parameter_spec={ - "decay": conditional_parameter_decay, - "learning_rate": conditional_parameter_lr, + "decay": _TEST_CONDITIONAL_PARAMETER_DECAY, + "learning_rate": _TEST_CONDITIONAL_PARAMETER_LR, }, ), }, @@ -844,12 +820,7 @@ def test_create_hyperparameter_tuning_job_with_enable_web_access( worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) - conditional_parameter_decay = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[32, 64] - ) - conditional_parameter_lr = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] - ) + job = aiplatform.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, custom_job=custom_job, @@ -864,8 +835,8 @@ def test_create_hyperparameter_tuning_job_with_enable_web_access( values=[4, 8, 16, 32, 64], scale="linear", conditional_parameter_spec={ - "decay": conditional_parameter_decay, - "learning_rate": conditional_parameter_lr, + "decay": _TEST_CONDITIONAL_PARAMETER_DECAY, + "learning_rate": _TEST_CONDITIONAL_PARAMETER_LR, }, ), }, From 40f0218f323de614c8d81f0f4b21f06a191e99c4 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 1 Aug 2022 22:44:39 +0000 Subject: [PATCH 09/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- tests/unit/aiplatform/test_hyperparameter_tuning_job.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index c18aee6c94..163eeb8300 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -77,11 +77,11 @@ _TEST_LABELS = {"my_hp_key": "my_hp_value"} _TEST_CONDITIONAL_PARAMETER_DECAY = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[32, 64] - ) + min=1e-07, max=1, scale="linear", parent_values=[32, 64] +) _TEST_CONDITIONAL_PARAMETER_LR = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] - ) + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] +) _TEST_BASE_HYPERPARAMETER_TUNING_JOB_PROTO = gca_hyperparameter_tuning_job_compat.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, From 80dce03f64ce322d4f24d011e2f5309cdeef50fd Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 1 Aug 2022 22:46:13 +0000 Subject: [PATCH 10/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- tests/unit/aiplatform/test_hyperparameter_tuning_job.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index c18aee6c94..163eeb8300 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -77,11 +77,11 @@ _TEST_LABELS = {"my_hp_key": "my_hp_value"} _TEST_CONDITIONAL_PARAMETER_DECAY = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[32, 64] - ) + min=1e-07, max=1, scale="linear", parent_values=[32, 64] +) _TEST_CONDITIONAL_PARAMETER_LR = hpt.DoubleParameterSpec( - min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] - ) + min=1e-07, max=1, scale="linear", parent_values=[4, 8, 16] +) _TEST_BASE_HYPERPARAMETER_TUNING_JOB_PROTO = gca_hyperparameter_tuning_job_compat.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME,