
software.amazon.awssdk.services.sagemaker.model.AlgorithmSpecification 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.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.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;
/**
*
* Specifies the training algorithm to use in a CreateTrainingJob request.
*
*
* For more information about algorithms provided by Amazon SageMaker, see Algorithms. For information about using your
* own algorithms, see Using Your Own
* Algorithms with Amazon SageMaker.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class AlgorithmSpecification implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField TRAINING_IMAGE_FIELD = SdkField. builder(MarshallingType.STRING)
.getter(getter(AlgorithmSpecification::trainingImage)).setter(setter(Builder::trainingImage))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TrainingImage").build()).build();
private static final SdkField ALGORITHM_NAME_FIELD = SdkField. builder(MarshallingType.STRING)
.getter(getter(AlgorithmSpecification::algorithmName)).setter(setter(Builder::algorithmName))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("AlgorithmName").build()).build();
private static final SdkField TRAINING_INPUT_MODE_FIELD = SdkField. builder(MarshallingType.STRING)
.getter(getter(AlgorithmSpecification::trainingInputModeAsString)).setter(setter(Builder::trainingInputMode))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TrainingInputMode").build()).build();
private static final SdkField> METRIC_DEFINITIONS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.getter(getter(AlgorithmSpecification::metricDefinitions))
.setter(setter(Builder::metricDefinitions))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("MetricDefinitions").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(MetricDefinition::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField ENABLE_SAGE_MAKER_METRICS_TIME_SERIES_FIELD = SdkField
. builder(MarshallingType.BOOLEAN)
.getter(getter(AlgorithmSpecification::enableSageMakerMetricsTimeSeries))
.setter(setter(Builder::enableSageMakerMetricsTimeSeries))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("EnableSageMakerMetricsTimeSeries")
.build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(TRAINING_IMAGE_FIELD,
ALGORITHM_NAME_FIELD, TRAINING_INPUT_MODE_FIELD, METRIC_DEFINITIONS_FIELD,
ENABLE_SAGE_MAKER_METRICS_TIME_SERIES_FIELD));
private static final long serialVersionUID = 1L;
private final String trainingImage;
private final String algorithmName;
private final String trainingInputMode;
private final List metricDefinitions;
private final Boolean enableSageMakerMetricsTimeSeries;
private AlgorithmSpecification(BuilderImpl builder) {
this.trainingImage = builder.trainingImage;
this.algorithmName = builder.algorithmName;
this.trainingInputMode = builder.trainingInputMode;
this.metricDefinitions = builder.metricDefinitions;
this.enableSageMakerMetricsTimeSeries = builder.enableSageMakerMetricsTimeSeries;
}
/**
*
* The registry path of the Docker image that contains the training algorithm. For information about docker registry
* paths for built-in algorithms, see Algorithms
* Provided by Amazon SageMaker: Common Parameters. Amazon SageMaker supports both
* registry/repository[:tag]
and registry/repository[@digest]
image path formats. For more
* information, see Using Your Own
* Algorithms with Amazon SageMaker.
*
*
* @return The registry path of the Docker image that contains the training algorithm. For information about docker
* registry paths for built-in algorithms, see Algorithms Provided by Amazon SageMaker: Common Parameters. Amazon SageMaker supports both
* registry/repository[:tag]
and registry/repository[@digest]
image path formats.
* For more information, see Using Your Own Algorithms
* with Amazon SageMaker.
*/
public String trainingImage() {
return trainingImage;
}
/**
*
* The name of the algorithm resource to use for the training job. This must be an algorithm resource that you
* created or subscribe to on AWS Marketplace. If you specify a value for this parameter, you can't specify a value
* for TrainingImage
.
*
*
* @return The name of the algorithm resource to use for the training job. This must be an algorithm resource that
* you created or subscribe to on AWS Marketplace. If you specify a value for this parameter, you can't
* specify a value for TrainingImage
.
*/
public String algorithmName() {
return algorithmName;
}
/**
*
* The input mode that the algorithm supports. For the input modes that Amazon SageMaker algorithms support, see Algorithms. If an algorithm supports the
* File
input mode, Amazon SageMaker downloads the training data from S3 to the provisioned ML storage
* Volume, and mounts the directory to docker volume for training container. If an algorithm supports the
* Pipe
input mode, Amazon SageMaker streams data directly from S3 to the container.
*
*
* In File mode, make sure you provision ML storage volume with sufficient capacity to accommodate the data download
* from S3. In addition to the training data, the ML storage volume also stores the output model. The algorithm
* container use ML storage volume to also store intermediate information, if any.
*
*
* For distributed algorithms using File mode, training data is distributed uniformly, and your training duration is
* predictable if the input data objects size is approximately same. Amazon SageMaker does not split the files any
* further for model training. If the object sizes are skewed, training won't be optimal as the data distribution is
* also skewed where one host in a training cluster is overloaded, thus becoming bottleneck in training.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #trainingInputMode}
* will return {@link TrainingInputMode#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available
* from {@link #trainingInputModeAsString}.
*
*
* @return The input mode that the algorithm supports. For the input modes that Amazon SageMaker algorithms support,
* see Algorithms. If an algorithm
* supports the File
input mode, Amazon SageMaker downloads the training data from S3 to the
* provisioned ML storage Volume, and mounts the directory to docker volume for training container. If an
* algorithm supports the Pipe
input mode, Amazon SageMaker streams data directly from S3 to
* the container.
*
* In File mode, make sure you provision ML storage volume with sufficient capacity to accommodate the data
* download from S3. In addition to the training data, the ML storage volume also stores the output model.
* The algorithm container use ML storage volume to also store intermediate information, if any.
*
*
* For distributed algorithms using File mode, training data is distributed uniformly, and your training
* duration is predictable if the input data objects size is approximately same. Amazon SageMaker does not
* split the files any further for model training. If the object sizes are skewed, training won't be optimal
* as the data distribution is also skewed where one host in a training cluster is overloaded, thus becoming
* bottleneck in training.
* @see TrainingInputMode
*/
public TrainingInputMode trainingInputMode() {
return TrainingInputMode.fromValue(trainingInputMode);
}
/**
*
* The input mode that the algorithm supports. For the input modes that Amazon SageMaker algorithms support, see Algorithms. If an algorithm supports the
* File
input mode, Amazon SageMaker downloads the training data from S3 to the provisioned ML storage
* Volume, and mounts the directory to docker volume for training container. If an algorithm supports the
* Pipe
input mode, Amazon SageMaker streams data directly from S3 to the container.
*
*
* In File mode, make sure you provision ML storage volume with sufficient capacity to accommodate the data download
* from S3. In addition to the training data, the ML storage volume also stores the output model. The algorithm
* container use ML storage volume to also store intermediate information, if any.
*
*
* For distributed algorithms using File mode, training data is distributed uniformly, and your training duration is
* predictable if the input data objects size is approximately same. Amazon SageMaker does not split the files any
* further for model training. If the object sizes are skewed, training won't be optimal as the data distribution is
* also skewed where one host in a training cluster is overloaded, thus becoming bottleneck in training.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #trainingInputMode}
* will return {@link TrainingInputMode#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available
* from {@link #trainingInputModeAsString}.
*
*
* @return The input mode that the algorithm supports. For the input modes that Amazon SageMaker algorithms support,
* see Algorithms. If an algorithm
* supports the File
input mode, Amazon SageMaker downloads the training data from S3 to the
* provisioned ML storage Volume, and mounts the directory to docker volume for training container. If an
* algorithm supports the Pipe
input mode, Amazon SageMaker streams data directly from S3 to
* the container.
*
* In File mode, make sure you provision ML storage volume with sufficient capacity to accommodate the data
* download from S3. In addition to the training data, the ML storage volume also stores the output model.
* The algorithm container use ML storage volume to also store intermediate information, if any.
*
*
* For distributed algorithms using File mode, training data is distributed uniformly, and your training
* duration is predictable if the input data objects size is approximately same. Amazon SageMaker does not
* split the files any further for model training. If the object sizes are skewed, training won't be optimal
* as the data distribution is also skewed where one host in a training cluster is overloaded, thus becoming
* bottleneck in training.
* @see TrainingInputMode
*/
public String trainingInputModeAsString() {
return trainingInputMode;
}
/**
* Returns true if the MetricDefinitions property was specified by the sender (it may be empty), or false if the
* sender did not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS
* service.
*/
public boolean hasMetricDefinitions() {
return metricDefinitions != null && !(metricDefinitions instanceof SdkAutoConstructList);
}
/**
*
* A list of metric definition objects. Each object specifies the metric name and regular expressions used to parse
* algorithm logs. Amazon SageMaker publishes each metric to Amazon CloudWatch.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* You can use {@link #hasMetricDefinitions()} to see if a value was sent in this field.
*
*
* @return A list of metric definition objects. Each object specifies the metric name and regular expressions used
* to parse algorithm logs. Amazon SageMaker publishes each metric to Amazon CloudWatch.
*/
public List metricDefinitions() {
return metricDefinitions;
}
/**
*
* To generate and save time-series metrics during training, set to true
. The default is
* false
and time-series metrics aren't generated except in the following cases:
*
*
* -
*
* You use one of the Amazon SageMaker built-in algorithms
*
*
* -
*
* You use one of the following Prebuilt Amazon SageMaker Docker Images:
*
*
* -
*
* Tensorflow (version >= 1.15)
*
*
* -
*
* MXNet (version >= 1.6)
*
*
* -
*
* PyTorch (version >= 1.3)
*
*
*
*
* -
*
* You specify at least one MetricDefinition
*
*
*
*
* @return To generate and save time-series metrics during training, set to true
. The default is
* false
and time-series metrics aren't generated except in the following cases:
*
* -
*
* You use one of the Amazon SageMaker built-in algorithms
*
*
* -
*
* You use one of the following Prebuilt Amazon SageMaker Docker Images:
*
*
* -
*
* Tensorflow (version >= 1.15)
*
*
* -
*
* MXNet (version >= 1.6)
*
*
* -
*
* PyTorch (version >= 1.3)
*
*
*
*
* -
*
* You specify at least one MetricDefinition
*
*
*/
public Boolean enableSageMakerMetricsTimeSeries() {
return enableSageMakerMetricsTimeSeries;
}
@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 int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(trainingImage());
hashCode = 31 * hashCode + Objects.hashCode(algorithmName());
hashCode = 31 * hashCode + Objects.hashCode(trainingInputModeAsString());
hashCode = 31 * hashCode + Objects.hashCode(metricDefinitions());
hashCode = 31 * hashCode + Objects.hashCode(enableSageMakerMetricsTimeSeries());
return hashCode;
}
@Override
public boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof AlgorithmSpecification)) {
return false;
}
AlgorithmSpecification other = (AlgorithmSpecification) obj;
return Objects.equals(trainingImage(), other.trainingImage()) && Objects.equals(algorithmName(), other.algorithmName())
&& Objects.equals(trainingInputModeAsString(), other.trainingInputModeAsString())
&& Objects.equals(metricDefinitions(), other.metricDefinitions())
&& Objects.equals(enableSageMakerMetricsTimeSeries(), other.enableSageMakerMetricsTimeSeries());
}
/**
* 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 String toString() {
return ToString.builder("AlgorithmSpecification").add("TrainingImage", trainingImage())
.add("AlgorithmName", algorithmName()).add("TrainingInputMode", trainingInputModeAsString())
.add("MetricDefinitions", metricDefinitions())
.add("EnableSageMakerMetricsTimeSeries", enableSageMakerMetricsTimeSeries()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "TrainingImage":
return Optional.ofNullable(clazz.cast(trainingImage()));
case "AlgorithmName":
return Optional.ofNullable(clazz.cast(algorithmName()));
case "TrainingInputMode":
return Optional.ofNullable(clazz.cast(trainingInputModeAsString()));
case "MetricDefinitions":
return Optional.ofNullable(clazz.cast(metricDefinitions()));
case "EnableSageMakerMetricsTimeSeries":
return Optional.ofNullable(clazz.cast(enableSageMakerMetricsTimeSeries()));
default:
return Optional.empty();
}
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
private static Function