
software.amazon.awssdk.services.sagemaker.model.HyperParameterTuningJobConfig Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.
*/
package software.amazon.awssdk.services.sagemaker.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Configures a hyperparameter tuning job.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class HyperParameterTuningJobConfig implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField STRATEGY_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("Strategy").getter(getter(HyperParameterTuningJobConfig::strategyAsString))
.setter(setter(Builder::strategy))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Strategy").build()).build();
private static final SdkField STRATEGY_CONFIG_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("StrategyConfig")
.getter(getter(HyperParameterTuningJobConfig::strategyConfig)).setter(setter(Builder::strategyConfig))
.constructor(HyperParameterTuningJobStrategyConfig::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("StrategyConfig").build()).build();
private static final SdkField HYPER_PARAMETER_TUNING_JOB_OBJECTIVE_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("HyperParameterTuningJobObjective")
.getter(getter(HyperParameterTuningJobConfig::hyperParameterTuningJobObjective))
.setter(setter(Builder::hyperParameterTuningJobObjective))
.constructor(HyperParameterTuningJobObjective::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("HyperParameterTuningJobObjective")
.build()).build();
private static final SdkField RESOURCE_LIMITS_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("ResourceLimits")
.getter(getter(HyperParameterTuningJobConfig::resourceLimits)).setter(setter(Builder::resourceLimits))
.constructor(ResourceLimits::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ResourceLimits").build()).build();
private static final SdkField PARAMETER_RANGES_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("ParameterRanges")
.getter(getter(HyperParameterTuningJobConfig::parameterRanges)).setter(setter(Builder::parameterRanges))
.constructor(ParameterRanges::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ParameterRanges").build()).build();
private static final SdkField TRAINING_JOB_EARLY_STOPPING_TYPE_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("TrainingJobEarlyStoppingType")
.getter(getter(HyperParameterTuningJobConfig::trainingJobEarlyStoppingTypeAsString))
.setter(setter(Builder::trainingJobEarlyStoppingType))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TrainingJobEarlyStoppingType")
.build()).build();
private static final SdkField TUNING_JOB_COMPLETION_CRITERIA_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("TuningJobCompletionCriteria")
.getter(getter(HyperParameterTuningJobConfig::tuningJobCompletionCriteria))
.setter(setter(Builder::tuningJobCompletionCriteria))
.constructor(TuningJobCompletionCriteria::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TuningJobCompletionCriteria")
.build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(STRATEGY_FIELD,
STRATEGY_CONFIG_FIELD, HYPER_PARAMETER_TUNING_JOB_OBJECTIVE_FIELD, RESOURCE_LIMITS_FIELD, PARAMETER_RANGES_FIELD,
TRAINING_JOB_EARLY_STOPPING_TYPE_FIELD, TUNING_JOB_COMPLETION_CRITERIA_FIELD));
private static final long serialVersionUID = 1L;
private final String strategy;
private final HyperParameterTuningJobStrategyConfig strategyConfig;
private final HyperParameterTuningJobObjective hyperParameterTuningJobObjective;
private final ResourceLimits resourceLimits;
private final ParameterRanges parameterRanges;
private final String trainingJobEarlyStoppingType;
private final TuningJobCompletionCriteria tuningJobCompletionCriteria;
private HyperParameterTuningJobConfig(BuilderImpl builder) {
this.strategy = builder.strategy;
this.strategyConfig = builder.strategyConfig;
this.hyperParameterTuningJobObjective = builder.hyperParameterTuningJobObjective;
this.resourceLimits = builder.resourceLimits;
this.parameterRanges = builder.parameterRanges;
this.trainingJobEarlyStoppingType = builder.trainingJobEarlyStoppingType;
this.tuningJobCompletionCriteria = builder.tuningJobCompletionCriteria;
}
/**
*
* Specifies how hyperparameter tuning chooses the combinations of hyperparameter values to use for the training job
* it launches. For information about search strategies, see How
* Hyperparameter Tuning Works.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #strategy} will
* return {@link HyperParameterTuningJobStrategyType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service
* is available from {@link #strategyAsString}.
*
*
* @return Specifies how hyperparameter tuning chooses the combinations of hyperparameter values to use for the
* training job it launches. For information about search strategies, see How
* Hyperparameter Tuning Works.
* @see HyperParameterTuningJobStrategyType
*/
public final HyperParameterTuningJobStrategyType strategy() {
return HyperParameterTuningJobStrategyType.fromValue(strategy);
}
/**
*
* Specifies how hyperparameter tuning chooses the combinations of hyperparameter values to use for the training job
* it launches. For information about search strategies, see How
* Hyperparameter Tuning Works.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #strategy} will
* return {@link HyperParameterTuningJobStrategyType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service
* is available from {@link #strategyAsString}.
*
*
* @return Specifies how hyperparameter tuning chooses the combinations of hyperparameter values to use for the
* training job it launches. For information about search strategies, see How
* Hyperparameter Tuning Works.
* @see HyperParameterTuningJobStrategyType
*/
public final String strategyAsString() {
return strategy;
}
/**
*
* The configuration for the Hyperband
optimization strategy. This parameter should be provided only if
* Hyperband
is selected as the strategy for HyperParameterTuningJobConfig
.
*
*
* @return The configuration for the Hyperband
optimization strategy. This parameter should be provided
* only if Hyperband
is selected as the strategy for HyperParameterTuningJobConfig
* .
*/
public final HyperParameterTuningJobStrategyConfig strategyConfig() {
return strategyConfig;
}
/**
*
* The HyperParameterTuningJobObjective object that specifies the objective metric for this tuning job.
*
*
* @return The HyperParameterTuningJobObjective object that specifies the objective metric for this tuning
* job.
*/
public final HyperParameterTuningJobObjective hyperParameterTuningJobObjective() {
return hyperParameterTuningJobObjective;
}
/**
*
* The ResourceLimits object that specifies the maximum number of training jobs and parallel training jobs
* for this tuning job.
*
*
* @return The ResourceLimits object that specifies the maximum number of training jobs and parallel training
* jobs for this tuning job.
*/
public final ResourceLimits resourceLimits() {
return resourceLimits;
}
/**
*
* The ParameterRanges object that specifies the ranges of hyperparameters that this tuning job searches.
*
*
* @return The ParameterRanges object that specifies the ranges of hyperparameters that this tuning job
* searches.
*/
public final ParameterRanges parameterRanges() {
return parameterRanges;
}
/**
*
* Specifies whether to use early stopping for training jobs launched by the hyperparameter tuning job. Because the
* Hyperband
strategy has its own advanced internal early stopping mechanism,
* TrainingJobEarlyStoppingType
must be OFF
to use Hyperband
. This parameter
* can take on one of the following values (the default value is OFF
):
*
*
* - OFF
* -
*
* Training jobs launched by the hyperparameter tuning job do not use early stopping.
*
*
* - AUTO
* -
*
* SageMaker stops training jobs launched by the hyperparameter tuning job when they are unlikely to perform better
* than previously completed training jobs. For more information, see Stop Training
* Jobs Early.
*
*
*
*
* If the service returns an enum value that is not available in the current SDK version,
* {@link #trainingJobEarlyStoppingType} will return {@link TrainingJobEarlyStoppingType#UNKNOWN_TO_SDK_VERSION}.
* The raw value returned by the service is available from {@link #trainingJobEarlyStoppingTypeAsString}.
*
*
* @return Specifies whether to use early stopping for training jobs launched by the hyperparameter tuning job.
* Because the Hyperband
strategy has its own advanced internal early stopping mechanism,
* TrainingJobEarlyStoppingType
must be OFF
to use Hyperband
. This
* parameter can take on one of the following values (the default value is OFF
):
*
* - OFF
* -
*
* Training jobs launched by the hyperparameter tuning job do not use early stopping.
*
*
* - AUTO
* -
*
* SageMaker stops training jobs launched by the hyperparameter tuning job when they are unlikely to perform
* better than previously completed training jobs. For more information, see Stop
* Training Jobs Early.
*
*
* @see TrainingJobEarlyStoppingType
*/
public final TrainingJobEarlyStoppingType trainingJobEarlyStoppingType() {
return TrainingJobEarlyStoppingType.fromValue(trainingJobEarlyStoppingType);
}
/**
*
* Specifies whether to use early stopping for training jobs launched by the hyperparameter tuning job. Because the
* Hyperband
strategy has its own advanced internal early stopping mechanism,
* TrainingJobEarlyStoppingType
must be OFF
to use Hyperband
. This parameter
* can take on one of the following values (the default value is OFF
):
*
*
* - OFF
* -
*
* Training jobs launched by the hyperparameter tuning job do not use early stopping.
*
*
* - AUTO
* -
*
* SageMaker stops training jobs launched by the hyperparameter tuning job when they are unlikely to perform better
* than previously completed training jobs. For more information, see Stop Training
* Jobs Early.
*
*
*
*
* If the service returns an enum value that is not available in the current SDK version,
* {@link #trainingJobEarlyStoppingType} will return {@link TrainingJobEarlyStoppingType#UNKNOWN_TO_SDK_VERSION}.
* The raw value returned by the service is available from {@link #trainingJobEarlyStoppingTypeAsString}.
*
*
* @return Specifies whether to use early stopping for training jobs launched by the hyperparameter tuning job.
* Because the Hyperband
strategy has its own advanced internal early stopping mechanism,
* TrainingJobEarlyStoppingType
must be OFF
to use Hyperband
. This
* parameter can take on one of the following values (the default value is OFF
):
*
* - OFF
* -
*
* Training jobs launched by the hyperparameter tuning job do not use early stopping.
*
*
* - AUTO
* -
*
* SageMaker stops training jobs launched by the hyperparameter tuning job when they are unlikely to perform
* better than previously completed training jobs. For more information, see Stop
* Training Jobs Early.
*
*
* @see TrainingJobEarlyStoppingType
*/
public final String trainingJobEarlyStoppingTypeAsString() {
return trainingJobEarlyStoppingType;
}
/**
*
* The tuning job's completion criteria.
*
*
* @return The tuning job's completion criteria.
*/
public final TuningJobCompletionCriteria tuningJobCompletionCriteria() {
return tuningJobCompletionCriteria;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(strategyAsString());
hashCode = 31 * hashCode + Objects.hashCode(strategyConfig());
hashCode = 31 * hashCode + Objects.hashCode(hyperParameterTuningJobObjective());
hashCode = 31 * hashCode + Objects.hashCode(resourceLimits());
hashCode = 31 * hashCode + Objects.hashCode(parameterRanges());
hashCode = 31 * hashCode + Objects.hashCode(trainingJobEarlyStoppingTypeAsString());
hashCode = 31 * hashCode + Objects.hashCode(tuningJobCompletionCriteria());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof HyperParameterTuningJobConfig)) {
return false;
}
HyperParameterTuningJobConfig other = (HyperParameterTuningJobConfig) obj;
return Objects.equals(strategyAsString(), other.strategyAsString())
&& Objects.equals(strategyConfig(), other.strategyConfig())
&& Objects.equals(hyperParameterTuningJobObjective(), other.hyperParameterTuningJobObjective())
&& Objects.equals(resourceLimits(), other.resourceLimits())
&& Objects.equals(parameterRanges(), other.parameterRanges())
&& Objects.equals(trainingJobEarlyStoppingTypeAsString(), other.trainingJobEarlyStoppingTypeAsString())
&& Objects.equals(tuningJobCompletionCriteria(), other.tuningJobCompletionCriteria());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("HyperParameterTuningJobConfig").add("Strategy", strategyAsString())
.add("StrategyConfig", strategyConfig())
.add("HyperParameterTuningJobObjective", hyperParameterTuningJobObjective())
.add("ResourceLimits", resourceLimits()).add("ParameterRanges", parameterRanges())
.add("TrainingJobEarlyStoppingType", trainingJobEarlyStoppingTypeAsString())
.add("TuningJobCompletionCriteria", tuningJobCompletionCriteria()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "Strategy":
return Optional.ofNullable(clazz.cast(strategyAsString()));
case "StrategyConfig":
return Optional.ofNullable(clazz.cast(strategyConfig()));
case "HyperParameterTuningJobObjective":
return Optional.ofNullable(clazz.cast(hyperParameterTuningJobObjective()));
case "ResourceLimits":
return Optional.ofNullable(clazz.cast(resourceLimits()));
case "ParameterRanges":
return Optional.ofNullable(clazz.cast(parameterRanges()));
case "TrainingJobEarlyStoppingType":
return Optional.ofNullable(clazz.cast(trainingJobEarlyStoppingTypeAsString()));
case "TuningJobCompletionCriteria":
return Optional.ofNullable(clazz.cast(tuningJobCompletionCriteria()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function