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: add custom and hp tuning #388
Merged
sasha-gitg
merged 32 commits into
googleapis:master
from
sasha-gitg:add_custom_and_hp_tuning
May 18, 2021
Merged
Changes from 20 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
6e50b41
checkpoint
sasha-gitg dbd5e94
Merge branch 'main' into add_custom_and_hp_tuning
sasha-gitg c1dfd62
checkpoint
sasha-gitg 7b70080
Merge branch 'main' into add_custom_and_hp_tuning
sasha-gitg 3178b11
checkpoint
sasha-gitg 142ebf3
Merge branch 'master' into add_custom_and_hp_tuning
sasha-gitg a6fe1d7
checkpoint
sasha-gitg b5cc6e5
chore: update test imports
sasha-gitg 4a1b0ca
fix: remove added __init__ files
sasha-gitg 10f4f80
chore: update test imports
sasha-gitg d61079c
feat: add hp tuning metric reporter to training utils
sasha-gitg 455944d
chore: make plural
sasha-gitg a8e0da6
feat: added trials property, refactored job classes, updating trainin…
sasha-gitg c9259bf
chore: lint
sasha-gitg df97a2d
checkpoint
sasha-gitg 23b3249
feat: add custom job and hp tuning job tests
sasha-gitg bf9452b
chore: remove training utils. We will re-evaluate whether to add thes…
sasha-gitg 78a29f4
chore: add additional documentation
sasha-gitg 2434aaf
chore: rename test
sasha-gitg 7752fc2
chore: remove conditional parameter spec arguments from public paramt…
sasha-gitg aab2d9c
chore: lint
sasha-gitg 1b3bad1
chore: resolve reviewers's comments
sasha-gitg a492741
Update google/cloud/aiplatform/hyperparameter_tuning.py
sasha-gitg 24d3949
Update google/cloud/aiplatform/jobs.py
sasha-gitg 8e3e994
Update google/cloud/aiplatform/jobs.py
sasha-gitg 2f35579
Update google/cloud/aiplatform/jobs.py
sasha-gitg c30a80f
Update google/cloud/aiplatform/jobs.py
sasha-gitg 3a66659
Update google/cloud/aiplatform/jobs.py
sasha-gitg 1c91685
Update google/cloud/aiplatform/jobs.py
sasha-gitg e6a53b5
Update google/cloud/aiplatform/jobs.py
sasha-gitg 4e07e6d
Update google/cloud/aiplatform/jobs.py
sasha-gitg d5128b0
chore: lint
sasha-gitg File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import abc | ||
from typing import Dict, List, Optional, Sequence, Tuple, Union | ||
|
||
import proto | ||
|
||
from google.cloud.aiplatform.compat.types import study as gca_study_compat | ||
|
||
_SCALE_TYPE_MAP = { | ||
"linear": gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LINEAR_SCALE, | ||
"log": gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_LOG_SCALE, | ||
"reverse_log": gca_study_compat.StudySpec.ParameterSpec.ScaleType.UNIT_REVERSE_LOG_SCALE, | ||
"unspecified": gca_study_compat.StudySpec.ParameterSpec.ScaleType.SCALE_TYPE_UNSPECIFIED, | ||
} | ||
|
||
|
||
class _ParameterSpec(metaclass=abc.ABCMeta): | ||
"""Base class represents a single parameter to optimize.""" | ||
|
||
def __init__( | ||
self, | ||
conditional_parameter_spec: Optional[Dict[str, "_ParameterSpec"]] = None, | ||
parent_values: Optional[List[Union[float, int, str]]] = None, | ||
): | ||
|
||
self.conditional_parameter_spec = conditional_parameter_spec | ||
self.parent_values = parent_values | ||
|
||
@property | ||
@classmethod | ||
@abc.abstractmethod | ||
def _proto_parameter_value_class(self) -> proto.Message: | ||
"""The proto represenation of this parameter.""" | ||
sasha-gitg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pass | ||
|
||
@property | ||
@classmethod | ||
@abc.abstractmethod | ||
def _parameter_value_map(self) -> Tuple[Tuple[str, str]]: | ||
"""A Tuple map of parameter key to underlying proto key.""" | ||
pass | ||
|
||
@property | ||
@classmethod | ||
@abc.abstractmethod | ||
def _parameter_spec_value_key(self) -> Tuple[Tuple[str, str]]: | ||
"""The ParameterSpec key this parameter should be assigned.""" | ||
pass | ||
|
||
@property | ||
def _proto_parameter_value_spec(self) -> proto.Message: | ||
"""Converts this parameter to it's parameter value representation.""" | ||
proto_parameter_value_spec = self._proto_parameter_value_class() | ||
for self_attr_key, proto_attr_key in self._parameter_value_map: | ||
setattr( | ||
proto_parameter_value_spec, proto_attr_key, getattr(self, self_attr_key) | ||
) | ||
return proto_parameter_value_spec | ||
|
||
def _to_parameter_spec( | ||
self, parameter_id: str | ||
) -> gca_study_compat.StudySpec.ParameterSpec: | ||
"""Converts this parameter to ParameterSpec.""" | ||
# TODO: Conditional parameters | ||
parameter_spec = gca_study_compat.StudySpec.ParameterSpec( | ||
parameter_id=parameter_id, | ||
scale_type=_SCALE_TYPE_MAP.get(getattr(self, "scale", "unspecified")), | ||
) | ||
|
||
setattr( | ||
parameter_spec, | ||
self._parameter_spec_value_key, | ||
self._proto_parameter_value_spec, | ||
) | ||
|
||
return parameter_spec | ||
|
||
|
||
class DoubleParameterSpec(_ParameterSpec): | ||
|
||
_proto_parameter_value_class = ( | ||
gca_study_compat.StudySpec.ParameterSpec.DoubleValueSpec | ||
) | ||
_parameter_value_map = (("min", "min_value"), ("max", "max_value")) | ||
_parameter_spec_value_key = "double_value_spec" | ||
|
||
def __init__( | ||
self, min: float, max: float, scale: str, | ||
): | ||
""" | ||
Value specification for a parameter in ``DOUBLE`` type. | ||
|
||
Args: | ||
min (float): | ||
Required. Inclusive minimum value of the | ||
parameter. | ||
max (float): | ||
Required. Inclusive maximum value of the | ||
parameter. | ||
scale (str): | ||
Required. The type of scaling that should be applied to this parameter. | ||
|
||
Accepts: 'linear', 'log', 'reverse_log' | ||
""" | ||
|
||
super().__init__() | ||
|
||
self.min = min | ||
self.max = max | ||
self.scale = scale | ||
|
||
|
||
class IntegerParameterSpec(_ParameterSpec): | ||
|
||
_proto_parameter_value_class = ( | ||
gca_study_compat.StudySpec.ParameterSpec.IntegerValueSpec | ||
) | ||
_parameter_value_map = (("min", "min_value"), ("max", "max_value")) | ||
_parameter_spec_value_key = "integer_value_spec" | ||
|
||
def __init__( | ||
self, min: int, max: int, scale: str, | ||
): | ||
""" | ||
Value specification for a parameter in ``INTEGER`` type. | ||
|
||
Args: | ||
min (float): | ||
Required. Inclusive minimum value of the | ||
parameter. | ||
max (float): | ||
Required. Inclusive maximum value of the | ||
parameter. | ||
scale (str): | ||
Required. The type of scaling that should be applied to this parameter. | ||
|
||
Accepts: 'linear', 'log', 'reverse_log' | ||
""" | ||
|
||
super().__init__() | ||
|
||
self.min = min | ||
self.max = max | ||
self.scale = scale | ||
|
||
|
||
class CategoricalParameterSpec(_ParameterSpec): | ||
|
||
_proto_parameter_value_class = ( | ||
gca_study_compat.StudySpec.ParameterSpec.CategoricalValueSpec | ||
) | ||
_parameter_value_map = (("values", "values"),) | ||
_parameter_spec_value_key = "categorical_value_spec" | ||
|
||
def __init__( | ||
self, values: Sequence[str], | ||
): | ||
"""Value specification for a parameter in ``CATEGORICAL`` type. | ||
|
||
Args: | ||
values (Sequence[str]): | ||
Required. The list of possible categories. | ||
""" | ||
|
||
super().__init__() | ||
|
||
self.values = values | ||
|
||
|
||
class DiscreteParameterSpec(_ParameterSpec): | ||
|
||
_proto_parameter_value_class = ( | ||
gca_study_compat.StudySpec.ParameterSpec.DiscreteValueSpec | ||
) | ||
_parameter_value_map = (("values", "values"),) | ||
_parameter_spec_value_key = "discrete_value_spec" | ||
|
||
def __init__( | ||
self, values: Sequence[float], scale: str, | ||
): | ||
"""Value specification for a parameter in ``DISCRETE`` type. | ||
|
||
values (Sequence[float]): | ||
Required. A list of possible values. | ||
The list should be in increasing order and at | ||
least 1e-10 apart. For instance, this parameter | ||
might have possible settings of 1.5, 2.5, and | ||
4.0. This list should not contain more than | ||
1,000 values. | ||
scale (str): | ||
Required. The type of scaling that should be applied to this parameter. | ||
|
||
Accepts: 'linear', 'log', 'reverse_log' | ||
""" | ||
|
||
super().__init__() | ||
|
||
self.values = values | ||
self.scale = scale |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we exposing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Customers may need a field we haven't exposed. This allows us to provide code that doesn't require referencing a private attribute.