software.amazon.awssdk.services.sagemaker.model.CreateHyperParameterTuningJobRequest Maven / Gradle / Ivy
Show all versions of sagemaker Show documentation
/*
* 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.util.Arrays;
import java.util.Collection;
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 java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
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.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*/
@Generated("software.amazon.awssdk:codegen")
public final class CreateHyperParameterTuningJobRequest extends SageMakerRequest implements
ToCopyableBuilder {
private static final SdkField HYPER_PARAMETER_TUNING_JOB_NAME_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("HyperParameterTuningJobName")
.getter(getter(CreateHyperParameterTuningJobRequest::hyperParameterTuningJobName))
.setter(setter(Builder::hyperParameterTuningJobName))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("HyperParameterTuningJobName")
.build()).build();
private static final SdkField HYPER_PARAMETER_TUNING_JOB_CONFIG_FIELD = SdkField
. builder(MarshallingType.SDK_POJO)
.memberName("HyperParameterTuningJobConfig")
.getter(getter(CreateHyperParameterTuningJobRequest::hyperParameterTuningJobConfig))
.setter(setter(Builder::hyperParameterTuningJobConfig))
.constructor(HyperParameterTuningJobConfig::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("HyperParameterTuningJobConfig")
.build()).build();
private static final SdkField TRAINING_JOB_DEFINITION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("TrainingJobDefinition")
.getter(getter(CreateHyperParameterTuningJobRequest::trainingJobDefinition))
.setter(setter(Builder::trainingJobDefinition)).constructor(HyperParameterTrainingJobDefinition::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TrainingJobDefinition").build())
.build();
private static final SdkField> TRAINING_JOB_DEFINITIONS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("TrainingJobDefinitions")
.getter(getter(CreateHyperParameterTuningJobRequest::trainingJobDefinitions))
.setter(setter(Builder::trainingJobDefinitions))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TrainingJobDefinitions").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(HyperParameterTrainingJobDefinition::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField WARM_START_CONFIG_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("WarmStartConfig")
.getter(getter(CreateHyperParameterTuningJobRequest::warmStartConfig)).setter(setter(Builder::warmStartConfig))
.constructor(HyperParameterTuningJobWarmStartConfig::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("WarmStartConfig").build()).build();
private static final SdkField> TAGS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Tags")
.getter(getter(CreateHyperParameterTuningJobRequest::tags))
.setter(setter(Builder::tags))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Tags").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(Tag::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField AUTOTUNE_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("Autotune").getter(getter(CreateHyperParameterTuningJobRequest::autotune))
.setter(setter(Builder::autotune)).constructor(Autotune::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Autotune").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(
HYPER_PARAMETER_TUNING_JOB_NAME_FIELD, HYPER_PARAMETER_TUNING_JOB_CONFIG_FIELD, TRAINING_JOB_DEFINITION_FIELD,
TRAINING_JOB_DEFINITIONS_FIELD, WARM_START_CONFIG_FIELD, TAGS_FIELD, AUTOTUNE_FIELD));
private final String hyperParameterTuningJobName;
private final HyperParameterTuningJobConfig hyperParameterTuningJobConfig;
private final HyperParameterTrainingJobDefinition trainingJobDefinition;
private final List trainingJobDefinitions;
private final HyperParameterTuningJobWarmStartConfig warmStartConfig;
private final List tags;
private final Autotune autotune;
private CreateHyperParameterTuningJobRequest(BuilderImpl builder) {
super(builder);
this.hyperParameterTuningJobName = builder.hyperParameterTuningJobName;
this.hyperParameterTuningJobConfig = builder.hyperParameterTuningJobConfig;
this.trainingJobDefinition = builder.trainingJobDefinition;
this.trainingJobDefinitions = builder.trainingJobDefinitions;
this.warmStartConfig = builder.warmStartConfig;
this.tags = builder.tags;
this.autotune = builder.autotune;
}
/**
*
* The name of the tuning job. This name is the prefix for the names of all training jobs that this tuning job
* launches. The name must be unique within the same Amazon Web Services account and Amazon Web Services Region. The
* name must have 1 to 32 characters. Valid characters are a-z, A-Z, 0-9, and : + = @ _ % - (hyphen). The name is
* not case sensitive.
*
*
* @return The name of the tuning job. This name is the prefix for the names of all training jobs that this tuning
* job launches. The name must be unique within the same Amazon Web Services account and Amazon Web Services
* Region. The name must have 1 to 32 characters. Valid characters are a-z, A-Z, 0-9, and : + = @ _ % -
* (hyphen). The name is not case sensitive.
*/
public final String hyperParameterTuningJobName() {
return hyperParameterTuningJobName;
}
/**
*
* The
* HyperParameterTuningJobConfig object that describes the tuning job, including the search strategy, the
* objective metric used to evaluate training jobs, ranges of parameters to search, and resource limits for the
* tuning job. For more information, see How
* Hyperparameter Tuning Works.
*
*
* @return The HyperParameterTuningJobConfig object that describes the tuning job, including the search strategy,
* the objective metric used to evaluate training jobs, ranges of parameters to search, and resource limits
* for the tuning job. For more information, see How
* Hyperparameter Tuning Works.
*/
public final HyperParameterTuningJobConfig hyperParameterTuningJobConfig() {
return hyperParameterTuningJobConfig;
}
/**
*
* The HyperParameterTrainingJobDefinition object that describes the training jobs that this tuning job launches,
* including static hyperparameters, input data configuration, output data configuration, resource configuration,
* and stopping condition.
*
*
* @return The HyperParameterTrainingJobDefinition object that describes the training jobs that this tuning job
* launches, including static hyperparameters, input data configuration, output data configuration, resource
* configuration, and stopping condition.
*/
public final HyperParameterTrainingJobDefinition trainingJobDefinition() {
return trainingJobDefinition;
}
/**
* For responses, this returns true if the service returned a value for the TrainingJobDefinitions property. This
* DOES NOT check that the value is non-empty (for which, you should check the {@code isEmpty()} method on the
* property). This is useful because the SDK will never return a null collection or map, but you may need to
* differentiate between the service returning nothing (or null) and the service returning an empty collection or
* map. For requests, this returns true if a value for the property was specified in the request builder, and false
* if a value was not specified.
*/
public final boolean hasTrainingJobDefinitions() {
return trainingJobDefinitions != null && !(trainingJobDefinitions instanceof SdkAutoConstructList);
}
/**
*
* A list of the HyperParameterTrainingJobDefinition objects launched for this tuning job.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasTrainingJobDefinitions} method.
*
*
* @return A list of the HyperParameterTrainingJobDefinition objects launched for this tuning job.
*/
public final List trainingJobDefinitions() {
return trainingJobDefinitions;
}
/**
*
* Specifies the configuration for starting the hyperparameter tuning job using one or more previous tuning jobs as
* a starting point. The results of previous tuning jobs are used to inform which combinations of hyperparameters to
* search over in the new tuning job.
*
*
* All training jobs launched by the new hyperparameter tuning job are evaluated by using the objective metric. If
* you specify IDENTICAL_DATA_AND_ALGORITHM
as the WarmStartType
value for the warm start
* configuration, the training job that performs the best in the new tuning job is compared to the best training
* jobs from the parent tuning jobs. From these, the training job that performs the best as measured by the
* objective metric is returned as the overall best training job.
*
*
*
* All training jobs launched by parent hyperparameter tuning jobs and the new hyperparameter tuning jobs count
* against the limit of training jobs for the tuning job.
*
*
*
* @return Specifies the configuration for starting the hyperparameter tuning job using one or more previous tuning
* jobs as a starting point. The results of previous tuning jobs are used to inform which combinations of
* hyperparameters to search over in the new tuning job.
*
* All training jobs launched by the new hyperparameter tuning job are evaluated by using the objective
* metric. If you specify IDENTICAL_DATA_AND_ALGORITHM
as the WarmStartType
value
* for the warm start configuration, the training job that performs the best in the new tuning job is
* compared to the best training jobs from the parent tuning jobs. From these, the training job that
* performs the best as measured by the objective metric is returned as the overall best training job.
*
*
*
* All training jobs launched by parent hyperparameter tuning jobs and the new hyperparameter tuning jobs
* count against the limit of training jobs for the tuning job.
*
*/
public final HyperParameterTuningJobWarmStartConfig warmStartConfig() {
return warmStartConfig;
}
/**
* For responses, this returns true if the service returned a value for the Tags property. This DOES NOT check that
* the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful
* because the SDK will never return a null collection or map, but you may need to differentiate between the service
* returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true
* if a value for the property was specified in the request builder, and false if a value was not specified.
*/
public final boolean hasTags() {
return tags != null && !(tags instanceof SdkAutoConstructList);
}
/**
*
* An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways,
* for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources.
*
*
* Tags that you specify for the tuning job are also added to all training jobs that the tuning job launches.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasTags} method.
*
*
* @return An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in
* different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services
* Resources.
*
* Tags that you specify for the tuning job are also added to all training jobs that the tuning job
* launches.
*/
public final List tags() {
return tags;
}
/**
*
* Configures SageMaker Automatic model tuning (AMT) to automatically find optimal parameters for the following
* fields:
*
*
* -
*
* ParameterRanges: The names and ranges of parameters that a hyperparameter tuning job can optimize.
*
*
* -
*
* ResourceLimits:
* The maximum resources that can be used for a training job. These resources include the maximum number of training
* jobs, the maximum runtime of a tuning job, and the maximum number of training jobs to run at the same time.
*
*
* -
*
* TrainingJobEarlyStoppingType: A flag that specifies whether or not to use early stopping for training jobs
* launched by a hyperparameter tuning job.
*
*
* -
*
* RetryStrategy: The number of times to retry a training job.
*
*
* -
*
*
* Strategy: Specifies how hyperparameter tuning chooses the combinations of hyperparameter values to use for
* the training jobs that it launches.
*
*
* -
*
*
* ConvergenceDetected: A flag to indicate that Automatic model tuning (AMT) has detected model convergence.
*
*
*
*
* @return Configures SageMaker Automatic model tuning (AMT) to automatically find optimal parameters for the
* following fields:
*
* -
*
* ParameterRanges: The names and ranges of parameters that a hyperparameter tuning job can optimize.
*
*
* -
*
* ResourceLimits
* : The maximum resources that can be used for a training job. These resources include the maximum
* number of training jobs, the maximum runtime of a tuning job, and the maximum number of training jobs to
* run at the same time.
*
*
* -
*
* TrainingJobEarlyStoppingType: A flag that specifies whether or not to use early stopping for
* training jobs launched by a hyperparameter tuning job.
*
*
* -
*
* RetryStrategy: The number of times to retry a training job.
*
*
* -
*
* Strategy: Specifies how hyperparameter tuning chooses the combinations of hyperparameter values to
* use for the training jobs that it launches.
*
*
* -
*
*
* ConvergenceDetected: A flag to indicate that Automatic model tuning (AMT) has detected model
* convergence.
*
*
*/
public final Autotune autotune() {
return autotune;
}
@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 + super.hashCode();
hashCode = 31 * hashCode + Objects.hashCode(hyperParameterTuningJobName());
hashCode = 31 * hashCode + Objects.hashCode(hyperParameterTuningJobConfig());
hashCode = 31 * hashCode + Objects.hashCode(trainingJobDefinition());
hashCode = 31 * hashCode + Objects.hashCode(hasTrainingJobDefinitions() ? trainingJobDefinitions() : null);
hashCode = 31 * hashCode + Objects.hashCode(warmStartConfig());
hashCode = 31 * hashCode + Objects.hashCode(hasTags() ? tags() : null);
hashCode = 31 * hashCode + Objects.hashCode(autotune());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return super.equals(obj) && equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof CreateHyperParameterTuningJobRequest)) {
return false;
}
CreateHyperParameterTuningJobRequest other = (CreateHyperParameterTuningJobRequest) obj;
return Objects.equals(hyperParameterTuningJobName(), other.hyperParameterTuningJobName())
&& Objects.equals(hyperParameterTuningJobConfig(), other.hyperParameterTuningJobConfig())
&& Objects.equals(trainingJobDefinition(), other.trainingJobDefinition())
&& hasTrainingJobDefinitions() == other.hasTrainingJobDefinitions()
&& Objects.equals(trainingJobDefinitions(), other.trainingJobDefinitions())
&& Objects.equals(warmStartConfig(), other.warmStartConfig()) && hasTags() == other.hasTags()
&& Objects.equals(tags(), other.tags()) && Objects.equals(autotune(), other.autotune());
}
/**
* 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("CreateHyperParameterTuningJobRequest")
.add("HyperParameterTuningJobName", hyperParameterTuningJobName())
.add("HyperParameterTuningJobConfig", hyperParameterTuningJobConfig())
.add("TrainingJobDefinition", trainingJobDefinition())
.add("TrainingJobDefinitions", hasTrainingJobDefinitions() ? trainingJobDefinitions() : null)
.add("WarmStartConfig", warmStartConfig()).add("Tags", hasTags() ? tags() : null).add("Autotune", autotune())
.build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "HyperParameterTuningJobName":
return Optional.ofNullable(clazz.cast(hyperParameterTuningJobName()));
case "HyperParameterTuningJobConfig":
return Optional.ofNullable(clazz.cast(hyperParameterTuningJobConfig()));
case "TrainingJobDefinition":
return Optional.ofNullable(clazz.cast(trainingJobDefinition()));
case "TrainingJobDefinitions":
return Optional.ofNullable(clazz.cast(trainingJobDefinitions()));
case "WarmStartConfig":
return Optional.ofNullable(clazz.cast(warmStartConfig()));
case "Tags":
return Optional.ofNullable(clazz.cast(tags()));
case "Autotune":
return Optional.ofNullable(clazz.cast(autotune()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function