Lesson 3 of 5 Training Models with SageMaker AI

Configuring Training Jobs for Cost, Speed, Reliability and Security

This lesson explains the training job settings that affect cost, speed, reliability and security, which the exam guide lists as a skill in its own right.

Learning outcomes

After completing this lesson, you will be able to:

  • Configure compute, input modes and data channels.
  • Use managed Spot training with checkpoints.
  • Secure training with roles, VPC settings, encryption and network isolation.

Compute and data settings

A training job specifies the algorithm image or framework, instance type and count, volume size for File mode, input channels (S3, EFS or FSx for Lustre locations, each with an input mode and content type), the output path for model artefacts and hyperparameters. A stopping condition (MaxRuntimeInSeconds) caps runaway jobs. Metric definitions with regular expressions publish training metrics from logs to CloudWatch, which automatic model tuning uses.

Cost and resilience settings

Managed Spot training (use_spot_instances=True) runs on spare capacity at up to 90% savings. It requires max_wait (the total time including waiting for capacity, at least max_run) and should use a checkpoint S3 URI, so the script saves and resumes from checkpoints after interruptions. Warm pools (keep_alive_period_in_seconds) keep instances after a job finishes so the next job with the same configuration starts in seconds. Training plans reserve accelerated capacity for planned large jobs.

The following diagram compares the job's timeline with and without checkpoints.

The nightly Spot training job with an interruption. Training checkpoints to S3 as it runs; when the Spot instance is reclaimed after two hours, the job waits for capacity and resumes from the last checkpoint, finishing within max_wait of eight hours. Without a checkpoint location, the job would restart from the beginning.
The interruption time is illustrative.
Troubleshooting scenario

A cheaper, safer job

Exam skills 3.3.3 · 4.2.6

Fix the settings of a long training job one problem at a time.

Log in to try this activity Interactive activities are free with an account.

Security settings

Training jobs often handle sensitive data, and several settings protect it. The execution role grants the job access to its data and to the location where it writes artefacts, and should allow nothing more. VPC configuration places the job in private subnets so it reaches data through private paths; network isolation goes further and blocks all network calls from the training container, so code in the container cannot send data anywhere.

KMS keys encrypt the storage volume attached to the training instance and the output artefacts, and inter-container traffic encryption protects data exchanged between instances in distributed training, at some cost in training speed. The following table summarises the settings.

SettingPurpose
InstanceType / InstanceCountCompute capacity
InputDataConfig (channels, input mode)Where and how data is read
OutputDataConfig (S3 path, KMS key)Where artefacts go, encrypted
StoppingCondition (MaxRuntime, MaxWait)Cap duration; MaxWait for Spot
CheckpointConfigResume after Spot interruption
VpcConfig, EnableNetworkIsolationPrivate networking, no outbound calls
EnableInterContainerTrafficEncryptionEncrypt traffic between training nodes
KeepAlivePeriodInSecondsWarm pools for fast restarts
Match the pairs

Secure the training job

Exam skills 3.3.3 · 4.3.6

Match each training job security setting with what it protects.

Log in to try this activity Interactive activities are free with an account.
Worked example

A resilient, low-cost job

A nightly model trains for about 3 hours on a GPU instance. The team wants the lowest cost, must finish within 8 hours, and the data is confidential.

est = PyTorch(entry_point="train.py", instance_type="ml.g5.2xlarge", instance_count=1,
              framework_version="2.3", py_version="py311", role=role,
              use_spot_instances=True, max_run=4*3600, max_wait=8*3600,
              checkpoint_s3_uri="s3://ml-ckpt/nightly/",
              subnets=private_subnets, security_group_ids=[sg],
              enable_network_isolation=True,
              volume_kms_key=kms_key, output_kms_key=kms_key)

Spot with checkpoints gives the savings while max_wait keeps the 8-hour deadline. VPC settings, network isolation and KMS keys satisfy the confidentiality requirement. Without the checkpoint location, an interruption late in the job would restart training from the beginning.

Check yourself

How must max_wait and max_run relate for managed Spot training?

Show answer

max_wait must be at least max_run, and the job should use checkpoints.

Exam Tips

Remember for the exam

  • Managed Spot training needs max_wait >= max_run and should use checkpoints.
  • Warm pools speed up repeated jobs with the same configuration.
  • Metric definitions publish training metrics for tuning and monitoring.
  • Network isolation blocks all outbound calls from the training container.
  • Encrypt volumes and artefacts with KMS keys; encrypt inter-container traffic.