software.amazon.awssdk.services.sagemaker.model.StoppingCondition 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.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.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;
/**
*
* Specifies a limit to how long a job can run. When the job reaches the time limit, SageMaker ends the job. Use this
* API to cap costs.
*
*
* To stop a training job, SageMaker sends the algorithm the SIGTERM
signal, which delays job termination
* for 120 seconds. Algorithms can use this 120-second window to save the model artifacts, so the results of training
* are not lost.
*
*
* The training algorithms provided by SageMaker automatically save the intermediate results of a model training job
* when possible. This attempt to save artifacts is only a best effort case as model might not be in a state from which
* it can be saved. For example, if training has just started, the model might not be ready to save. When saved, this
* intermediate data is a valid model artifact. You can use it to create a model with CreateModel
.
*
*
*
* The Neural Topic Model (NTM) currently does not support saving intermediate model artifacts. When training NTMs, make
* sure that the maximum runtime is sufficient for the training job to complete.
*
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class StoppingCondition implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField MAX_RUNTIME_IN_SECONDS_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("MaxRuntimeInSeconds").getter(getter(StoppingCondition::maxRuntimeInSeconds))
.setter(setter(Builder::maxRuntimeInSeconds))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("MaxRuntimeInSeconds").build())
.build();
private static final SdkField MAX_WAIT_TIME_IN_SECONDS_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("MaxWaitTimeInSeconds").getter(getter(StoppingCondition::maxWaitTimeInSeconds))
.setter(setter(Builder::maxWaitTimeInSeconds))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("MaxWaitTimeInSeconds").build())
.build();
private static final SdkField MAX_PENDING_TIME_IN_SECONDS_FIELD = SdkField
. builder(MarshallingType.INTEGER).memberName("MaxPendingTimeInSeconds")
.getter(getter(StoppingCondition::maxPendingTimeInSeconds)).setter(setter(Builder::maxPendingTimeInSeconds))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("MaxPendingTimeInSeconds").build())
.build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(MAX_RUNTIME_IN_SECONDS_FIELD,
MAX_WAIT_TIME_IN_SECONDS_FIELD, MAX_PENDING_TIME_IN_SECONDS_FIELD));
private static final long serialVersionUID = 1L;
private final Integer maxRuntimeInSeconds;
private final Integer maxWaitTimeInSeconds;
private final Integer maxPendingTimeInSeconds;
private StoppingCondition(BuilderImpl builder) {
this.maxRuntimeInSeconds = builder.maxRuntimeInSeconds;
this.maxWaitTimeInSeconds = builder.maxWaitTimeInSeconds;
this.maxPendingTimeInSeconds = builder.maxPendingTimeInSeconds;
}
/**
*
* The maximum length of time, in seconds, that a training or compilation job can run before it is stopped.
*
*
* For compilation jobs, if the job does not complete during this time, a TimeOut
error is generated.
* We recommend starting with 900 seconds and increasing as necessary based on your model.
*
*
* For all other jobs, if the job does not complete during this time, SageMaker ends the job. When
* RetryStrategy
is specified in the job request, MaxRuntimeInSeconds
specifies the
* maximum time for all of the attempts in total, not each individual attempt. The default value is 1 day. The
* maximum value is 28 days.
*
*
* The maximum time that a TrainingJob
can run in total, including any time spent publishing metrics or
* archiving and uploading models after it has been stopped, is 30 days.
*
*
* @return The maximum length of time, in seconds, that a training or compilation job can run before it is
* stopped.
*
* For compilation jobs, if the job does not complete during this time, a TimeOut
error is
* generated. We recommend starting with 900 seconds and increasing as necessary based on your model.
*
*
* For all other jobs, if the job does not complete during this time, SageMaker ends the job. When
* RetryStrategy
is specified in the job request, MaxRuntimeInSeconds
specifies
* the maximum time for all of the attempts in total, not each individual attempt. The default value is 1
* day. The maximum value is 28 days.
*
*
* The maximum time that a TrainingJob
can run in total, including any time spent publishing
* metrics or archiving and uploading models after it has been stopped, is 30 days.
*/
public final Integer maxRuntimeInSeconds() {
return maxRuntimeInSeconds;
}
/**
*
* The maximum length of time, in seconds, that a managed Spot training job has to complete. It is the amount of
* time spent waiting for Spot capacity plus the amount of time the job can run. It must be equal to or greater than
* MaxRuntimeInSeconds
. If the job does not complete during this time, SageMaker ends the job.
*
*
* When RetryStrategy
is specified in the job request, MaxWaitTimeInSeconds
specifies the
* maximum time for all of the attempts in total, not each individual attempt.
*
*
* @return The maximum length of time, in seconds, that a managed Spot training job has to complete. It is the
* amount of time spent waiting for Spot capacity plus the amount of time the job can run. It must be equal
* to or greater than MaxRuntimeInSeconds
. If the job does not complete during this time,
* SageMaker ends the job.
*
* When RetryStrategy
is specified in the job request, MaxWaitTimeInSeconds
* specifies the maximum time for all of the attempts in total, not each individual attempt.
*/
public final Integer maxWaitTimeInSeconds() {
return maxWaitTimeInSeconds;
}
/**
*
* The maximum length of time, in seconds, that a training or compilation job can be pending before it is stopped.
*
*
* @return The maximum length of time, in seconds, that a training or compilation job can be pending before it is
* stopped.
*/
public final Integer maxPendingTimeInSeconds() {
return maxPendingTimeInSeconds;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(maxRuntimeInSeconds());
hashCode = 31 * hashCode + Objects.hashCode(maxWaitTimeInSeconds());
hashCode = 31 * hashCode + Objects.hashCode(maxPendingTimeInSeconds());
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 StoppingCondition)) {
return false;
}
StoppingCondition other = (StoppingCondition) obj;
return Objects.equals(maxRuntimeInSeconds(), other.maxRuntimeInSeconds())
&& Objects.equals(maxWaitTimeInSeconds(), other.maxWaitTimeInSeconds())
&& Objects.equals(maxPendingTimeInSeconds(), other.maxPendingTimeInSeconds());
}
/**
* 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("StoppingCondition").add("MaxRuntimeInSeconds", maxRuntimeInSeconds())
.add("MaxWaitTimeInSeconds", maxWaitTimeInSeconds()).add("MaxPendingTimeInSeconds", maxPendingTimeInSeconds())
.build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "MaxRuntimeInSeconds":
return Optional.ofNullable(clazz.cast(maxRuntimeInSeconds()));
case "MaxWaitTimeInSeconds":
return Optional.ofNullable(clazz.cast(maxWaitTimeInSeconds()));
case "MaxPendingTimeInSeconds":
return Optional.ofNullable(clazz.cast(maxPendingTimeInSeconds()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function