Publishing ModelTrainer Models to SageMaker Endpoints

Introduction & Overview

Welcome to the next step in your SageMaker deployment journey! You've already mastered two important deployment patterns: first, you learned how to deploy locally trained models to SageMaker serverless endpoints, which taught you the fundamental concepts of model packaging, S3 uploads, and entry point scripts. Then, you discovered how to deploy models trained with SageMaker estimators, which streamlined the process by leveraging SageMaker's built-in artifact management through the SKLearn.attach() method.

Now you're ready to explore another modern and advanced approach to model training and deployment within the SageMaker ecosystem: working with SageMaker's ModelTrainer. The ModelTrainer represents SageMaker's latest evolution in training workflows, providing enhanced capabilities for model development and more sophisticated training job management. While the deployment concepts you've learned remain consistent, ModelTrainer jobs require a slightly different approach to retrieve and deploy your trained models.

By the end of this lesson, you'll understand how to locate ModelTrainer jobs in your SageMaker environment, retrieve model artifacts from completed training jobs, create custom entry point scripts for inference handling, configure and deploy models using the SKLearnModel class with serverless inference, and test your deployed endpoints to ensure they're performing as expected. This knowledge will complete your understanding of the three primary deployment patterns in SageMaker and prepare you to work with the most advanced training workflows available on the platform.

Finding the Latest ModelTrainer Job

SageMaker's ModelTrainer represents an advanced training framework that provides enhanced capabilities for model development compared to traditional estimators. When you use ModelTrainer for training, it creates training jobs with specific naming patterns and organizational structures that differ from the estimator jobs you worked with in the previous lesson.

To work with ModelTrainer deployments, you first need to understand how to identify and retrieve these specialized training jobs. As you've done in previous lessons, you'll start by initializing a SageMaker session and querying for completed training jobs, but this time you'll filter specifically for ModelTrainer jobs:

import sagemaker

# Create a SageMaker session
sagemaker_session = sagemaker.Session()

# List most recent completed training job
training_jobs = sagemaker_session.sagemaker_client.list_training_jobs(
    SortBy='CreationTime',                 # Sort jobs by creation time
    SortOrder='Descending',                # Newest jobs first
    StatusEquals='Completed',              # Only include completed jobs
    NameContains='sklearn-modeltrainer'    # Filter to ModelTrainer jobs
)

# Extract the name of the latest training job
TRAINING_JOB_NAME = training_jobs['TrainingJobSummaries'][0]['TrainingJobName']

Since you already used sklearn-modeltrainer as the base name for your training jobs in a previous course, you can use the NameContains='sklearn-modeltrainer' filter to easily identify your ModelTrainer jobs. This naming convention distinguishes your ModelTrainer jobs from regular estimator jobs, which typically use names like "sagemaker-scikit-learn."

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal