SageMaker Training via SDK Best Practices
This is the checklist to run before and after launching SageMaker training, tuning, or custom-container jobs from the SDK. Each item is a rule stated positively with a one-line rationale.
Busca en todas las páginas de la documentación
This is the checklist to run before and after launching SageMaker training, tuning, or custom-container jobs from the SDK. Each item is a rule stated positively with a one-line rationale.
Work top to bottom - the groups run roughly in dependency order, from job setup through cost, scaling, resilience, and reproducibility. Most rules apply whether the job runs a built-in algorithm or your own container.
TrainingJobName like churn-xgb-2026-07-24 beats an opaque UUID when you're scanning a job list months later.MaxRuntimeInSeconds bounds a stuck or runaway job so it cannot run - and bill - indefinitely.Cap runtime and name the job clearly from the start.
# --- Python (boto3) ---
sm.create_training_job(
TrainingJobName="churn-xgb-2026-07-24",
StoppingCondition={"MaxRuntimeInSeconds": 3600},
# ... AlgorithmSpecification, RoleArn, InputDataConfig, OutputDataConfig, ResourceConfig
)// --- TypeScript (AWS SDK v3) ---
await sm.send(new CreateTrainingJobCommand({
TrainingJobName: "churn-xgb-2026-07-24",
StoppingCondition: { MaxRuntimeInSeconds: 3600 },
// ... AlgorithmSpecification, RoleArn, InputDataConfig, OutputDataConfig, ResourceConfig
}));EnableManagedSpotTraining cuts cost substantially for anything that can resume from a checkpoint.OutputDataConfig artifacts and logs accumulate in S3 and never expire on their own.FullyReplicated copies the entire dataset to every instance, wasting time and disk on a sharded job.CheckpointConfig only syncs files to and from S3 - your code must actually write and read them.FailureReason in DescribeTrainingJob and saves a trip to CloudWatch Logs for common failures.Completed with no usable model artifact.MetricDefinitions regex makes every trial look like it reported nothing.ParameterRanges) or be fixed (StaticHyperParameters), never both.Check the tuning search's objective metric before scaling up the trial budget.
# --- Python (boto3) ---
desc = sm.describe_hyper_parameter_tuning_job(HyperParameterTuningJobName="xgb-tune-001")
print(desc["HyperParameterTuningJobStatus"], desc.get("BestTrainingJob", {}).get("TrainingJobName"))// --- TypeScript (AWS SDK v3) ---
const desc = await sm.send(new DescribeHyperParameterTuningJobCommand({ HyperParameterTuningJobName: "xgb-tune-001" }));
console.log(desc.HyperParameterTuningJobStatus, desc.BestTrainingJob?.TrainingJobName);:latest. A mutable tag means the same job name can silently run different code over time.CreateTrainingJob call returning does not mean the job succeeded - always confirm TrainingJobStatus before trusting an artifact exists.Always set a StoppingCondition, and default to Managed Spot Training with real checkpointing for anything that can tolerate an interruption. Together they bound both a stuck job's cost and the price of ordinary runs.
No. The training container must implement a distribution strategy - SageMaker's data/model-parallel libraries or the framework's native support - for extra instances to help. Without that, more instances just duplicate the same job.
Enable CheckpointConfig and make sure the training script actually saves checkpoints periodically and resumes from one on startup. The flag alone does nothing without that script-level support.
The MetricDefinitions regex almost certainly doesn't match your training job's actual log line format. Test it against a real log line before launching the full search.
Pin the container image to an immutable tag or digest, version the S3 input data path, and record the exact hyperparameters used - together, not individually. Attach ExperimentConfig so this metadata is queryable later instead of living only in your memory.
Mostly no - cost, distribution, checkpointing, and tracking rules apply the same way. The one addition is that your container is responsible for implementing the checkpoint and distributed-training contract itself, which a built-in algorithm image already handles.
For anything beyond a handful of one-off jobs, yes - the cost is one extra ExperimentConfig parameter per job, and it saves significant effort comparing runs later, especially alongside a tuning job's many trials.
The container exited zero without ever writing to /opt/ml/model/. Always confirm ModelArtifacts.S3ModelArtifacts is present after a job completes, rather than trusting the status alone.
Stack versions: This page was written for boto3 1.43.x (Python 3.10+) and the AWS SDK for JavaScript v3 (Node.js 18+).
Revisado por Chris St. John·Última actualización: 24 jul 2026