fix(sagemaker): retry model and training archive uploads (#5999)

* fix(sagemaker): retry model and training archive uploads

* test(sagemaker): avoid production backoff in retry tests
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-10-19 11:23:43 -04:00
1 parent 2bb69a030b
commit 2b45288e13
5 files changed
+338 -22

No files matched your search

@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager.C
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager.EndpointInfo;
import io.github.hectorvent.floci.core.common.docker.ContainerSpec;
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
import io.github.hectorvent.floci.core.common.docker.RetryingTarCopier;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.services.s3.model.S3Object;
import io.github.hectorvent.floci.services.sagemaker.model.SageMakerEntities.EndpointResource;
@@ -70,10 +71,14 @@ public class SageMakerEndpointManager implements ContainerTeardown, Resettable {
}
public void startEndpointAsync(EndpointResource endpoint, SageMakerService service) {
executor.submit(() -> startEndpoint(endpoint, service));
startEndpointAsync(endpoint, service, RetryingTarCopier.DEFAULT_BACKOFF_MS);
}
private void startEndpoint(EndpointResource endpoint, SageMakerService service) {
void startEndpointAsync(EndpointResource endpoint, SageMakerService service, long backoffMillis) {
executor.submit(() -> startEndpoint(endpoint, service, backoffMillis));
}
private void startEndpoint(EndpointResource endpoint, SageMakerService service, long backoffMillis) {
String containerId = null;
try {
ModelResource model = service.modelForEndpoint(endpoint);
@@ -97,7 +102,7 @@ public class SageMakerEndpointManager implements ContainerTeardown, Resettable {
containerId = lifecycleManager.create(spec);
String modelDataUrl = string(c.get("ModelDataUrl"));
if (modelDataUrl != null && !modelDataUrl.isBlank()) {
copyModelData(containerId, modelDataUrl);
copyModelData(containerId, modelDataUrl, backoffMillis);
}
ContainerInfo info = lifecycleManager.startCreated(containerId, spec);
EndpointInfo ep = info.getEndpoint(PORT);
@@ -210,14 +215,13 @@ public class SageMakerEndpointManager implements ContainerTeardown, Resettable {
}
}
private void copyModelData(String containerId, String s3Uri) throws Exception {
void copyModelData(String containerId, String s3Uri, long backoffMillis) throws Exception {
S3Uri uri = S3Uri.parse(s3Uri);
S3Object object = s3Service.getObject(uri.bucket(), uri.key());
byte[] tarData = tarModelData(object.getData(), uri.key());
lifecycleManager.getDockerClient().copyArchiveToContainerCmd(containerId)
.withRemotePath("/")
.withTarInputStream(new ByteArrayInputStream(tarData))
.exec();
RetryingTarCopier.copyStreamed(lifecycleManager.getDockerClient(), containerId, "/",
"sagemaker-model-data", out -> out.write(tarData),
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, backoffMillis);
}
private byte[] tarModelData(byte[] data, String key) throws Exception {
@@ -15,6 +15,7 @@ import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
import io.github.hectorvent.floci.core.common.docker.ContainerLogStreamer;
import io.github.hectorvent.floci.core.common.docker.ContainerSpec;
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
import io.github.hectorvent.floci.core.common.docker.RetryingTarCopier;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.services.s3.model.S3Object;
import io.github.hectorvent.floci.services.sagemaker.model.SageMakerEntities.TrainingJobResource;
@@ -26,7 +27,6 @@ import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
import org.jboss.logging.Logger;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.InputStream;
@@ -80,10 +80,14 @@ public class SageMakerTrainingRunner implements ContainerTeardown, Resettable {
}
public void runAsync(TrainingJobResource job, SageMakerService service) {
executor.submit(() -> run(job, service));
runAsync(job, service, RetryingTarCopier.DEFAULT_BACKOFF_MS);
}
private void run(TrainingJobResource job, SageMakerService service) {
void runAsync(TrainingJobResource job, SageMakerService service, long backoffMillis) {
executor.submit(() -> run(job, service, backoffMillis));
}
private void run(TrainingJobResource job, SageMakerService service, long backoffMillis) {
String containerId = null;
Closeable logs = null;
try {
@@ -106,7 +110,7 @@ public class SageMakerTrainingRunner implements ContainerTeardown, Resettable {
containerId = lifecycleManager.create(spec);
containers.put(job.trainingJobName, containerId);
job.containerId = containerId;
copyTrainingInput(containerId, job);
copyTrainingInput(containerId, job, backoffMillis);
lifecycleManager.startCreated(containerId, spec);
job.trainingStartTime = System.currentTimeMillis();
job.secondaryStatus = "Training";
@@ -220,7 +224,7 @@ public class SageMakerTrainingRunner implements ContainerTeardown, Resettable {
return containerDetector.isRunningInContainer() ? config.hostname().orElse(EmbeddedDnsServer.DEFAULT_SUFFIX) : "host.docker.internal";
}
private void copyTrainingInput(String containerId, TrainingJobResource job) throws Exception {
void copyTrainingInput(String containerId, TrainingJobResource job, long backoffMillis) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (TarArchiveOutputStream tar = new TarArchiveOutputStream(out)) {
SageMakerEndpointManager.addFile(tar, "opt/ml/input/config/hyperparameters.json",
@@ -233,10 +237,10 @@ public class SageMakerTrainingRunner implements ContainerTeardown, Resettable {
copyChannelObjects(tar, channel);
}
}
lifecycleManager.getDockerClient().copyArchiveToContainerCmd(containerId)
.withRemotePath("/")
.withTarInputStream(new ByteArrayInputStream(out.toByteArray()))
.exec();
byte[] tarData = out.toByteArray();
RetryingTarCopier.copyStreamed(lifecycleManager.getDockerClient(), containerId, "/",
"sagemaker-training-input", stream -> stream.write(tarData),
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, backoffMillis);
}
private Map<String, Object> inputDataConfig(List<Map<String, Object>> channels) {