SageMaker SDK v3 Replaces Dozen Estimator Classes With Two Primitives
In this article
Amazon Web Services shipped a ground-up redesign of the SageMaker Python SDK on 26 August 2026, collapsing a fragmented family of framework-specific estimator classes into two unified primitives: ModelTrainer for training and ModelBuilder for deployment. The change removes the tight coupling between training code and container images that characterised SDK v2 — a pattern that forced a Docker rebuild every time a script changed. The new SourceCode configuration object instead syncs a local directory into a running container at job launch time, leaving the image as a pure runtime artifact.
This kind of systems-level redesign driving practical ML gains is increasingly where AWS is placing its bets, and SDK v3 is a concrete example at the tooling layer.
What the v2-to-v3 Shift Actually Changes
| Capability | SDK v2 (Estimator pattern) | SDK v3 (ModelTrainer pattern) |
|---|---|---|
| Training class | SKLearn, PyTorch, XGBoost, … |
ModelTrainer (one single class) |
| Deployment class | Model + Predictor |
ModelBuilder; prediction handled via invoke() |
| Container source | AWS managed framework image | Any image: custom ECR, AWS DLC, or third-party |
| Code injection | entry_point + source_dir, framework-specific |
SourceCode object with source_dir + command / entry_script |
| Dependencies | requirements.txt in source_dir |
requirements.txt in source_dir |
The structured configuration objects — Compute, InputData, OutputDataConfig, and StoppingCondition — replace the ad-hoc parameter dictionaries that v2 accepted, yielding IDE type-safety and auto-complete. Installation is pip install sagemaker>=3.0.
Example 1: scikit-learn Random Forest on a CPU Instance
The first walkthrough trains a Random Forest classifier on the diabetes dataset and deploys it behind a DJL Serving endpoint. The Dockerfile for the training container is intentionally minimal — FROM python:3.13-slim with build tools and a requirements.txt install — because no training code lives inside the image.
ModelTrainer is configured with instance_type="ml.m5.2xlarge", instance_count=1, a volume_size_in_gb of 30, and keep_alive_period_in_seconds=3600 to hold the instance in a SageMaker warm pool between iterations. The SourceCode object points source_dir at ./train/random_forest and passes the full invocation as a command string: python random_forest.py --n_jobs 4 --max_depth 10 --n_estimators 120. Anything the script saves to /opt/ml/model (exposed as SM_MODEL_DIR) is packaged as model.tar.gz at the configured S3 output path.
Deployment uses ModelBuilder with model_server=ModelServer.DJL_SERVING and a separate SourceCode object pointing at ./deploy/random_forest with entry_script="inference.py". The build() call assembles a deployable SageMaker model without launching infrastructure; deploy() then stands up the real-time endpoint. ModelBuilder also supports Mode.LOCAL_CONTAINER and Mode.IN_PROCESS for local iteration before committing to a managed endpoint. Inference is tested by sending a raw CSV string — "6,148,72,35,0,33.6,0.627,50" — with content_type="text/csv", returning a class label where 1 is tested_positive.
Example 2: Stable Diffusion 3.5 LoRA Fine-Tuning Across 4 A10G GPUs
The second example uses the identical ModelTrainer / ModelBuilder API to fine-tune Stable Diffusion 3.5 Medium with LoRA on the google/dreambooth dog dataset from Hugging Face. The compute target is ml.g5.12xlarge (4× A10G GPUs), instance_count=1, with a 30 GB volume and a 3,600-second warm-pool hold. The training container is built FROM pytorch/pytorch:2.7.1-cuda12.8-cudnn9-devel and includes diffusers, transformers, accelerate, PEFT, and DeepSpeed in its requirements.txt — but no training logic.
The source_dir (./train/stable_diffusion) contains a base.sh bash launcher, train_text_to_image_lora.py, a YAML recipe file (recipes/default-medium-g5_12x.yaml), and an Accelerate DDP config (accelerate_configs/ddp.yaml). The command passed to SourceCode calls /bin/bash base.sh with flags pointing at those files. Hyperparameters live in the YAML recipe, so tuning LoRA rank or switching the base model requires editing a config file rather than touching the container or the training script.
Training data is staged to S3 before job launch via load_dataset("google/dreambooth", "dog", split="train"), then passed to model_trainer.train() as a single InputData channel named train. SageMaker mounts that channel at /opt/ml/input/data/train inside the container and exposes it through SM_CHANNEL_TRAIN. The Hugging Face token required to pull the gated model is stored in AWS Secrets Manager; only the secret ARN flows through the environment parameter, keeping the credential out of notebook logs. The inference endpoint targets ml.g5.4xlarge and returns a base64-encoded PNG in the JSON response body, testable with a num_inference_steps=30, guidance_scale=7.5, seed=42 payload.
Why This Matters
SDK v3 is less about new SageMaker infrastructure and more about removing tooling friction that slows iteration cycles — the same axis where systems engineering improvements are now rivalling raw scaling gains across the industry. Collapsing a dozen framework-specific classes into two and decoupling code from containers at the API level lowers the cost of experimentation without requiring any underlying hardware change. For ML teams already invested in SageMaker, upgrading past sagemaker>=3.0 and adopting ModelTrainer is the highest-leverage near-term action the release enables.