|
| 1 | +# Amazon SageMaker AI Deployment |
| 2 | + |
| 3 | +Use the TensorFlow DLC for training jobs launched via the SageMaker Python SDK or `boto3`. The images bundle the `sagemaker-tensorflow-training` |
| 4 | +toolkit, OpenMPI for multi-node coordination, and SageMaker-specific Python libraries (`mlflow`, `smclarify`, `pandas`, `seaborn`, `s3fs`, etc.). |
| 5 | + |
| 6 | +The TensorFlow 2.21 DLC is a **SageMaker-only** release — there is no EC2 or EKS variant of this image. Point your estimators, processors, and |
| 7 | +training jobs at the SageMaker image URIs shown below. |
| 8 | + |
| 9 | +## SageMaker Python SDK v2 |
| 10 | + |
| 11 | +Pass the DLC image URI via `image_uri=` rather than `framework_version=`: |
| 12 | + |
| 13 | +```python |
| 14 | +from sagemaker.tensorflow import TensorFlow |
| 15 | + |
| 16 | +estimator = TensorFlow( |
| 17 | + image_uri="public.ecr.aws/deep-learning-containers/tensorflow-training:2.21-gpu-py312-cu129-amzn2023-sagemaker", |
| 18 | + role="arn:aws:iam::<account_id>:role/<role_name>", |
| 19 | + entry_point="train.py", |
| 20 | + source_dir="src", |
| 21 | + instance_type="ml.p5.48xlarge", |
| 22 | + instance_count=2, |
| 23 | + distribution={"mpi": {"enabled": True, "processes_per_host": 8}}, |
| 24 | +) |
| 25 | + |
| 26 | +estimator.fit({"training": "s3://<bucket>/datasets/train/"}) |
| 27 | +``` |
| 28 | + |
| 29 | +The toolkit invokes your `entry_point` script over MPI when `mpi.enabled` is set and as a single-process launcher otherwise. |
| 30 | + |
| 31 | +## SageMaker Python SDK v3 |
| 32 | + |
| 33 | +```python |
| 34 | +from sagemaker.core.resources import TrainingJob |
| 35 | +from sagemaker.core.shapes import ( |
| 36 | + AlgorithmSpecification, |
| 37 | + Channel, |
| 38 | + DataSource, |
| 39 | + InputDataConfig, |
| 40 | + OutputDataConfig, |
| 41 | + ResourceConfig, |
| 42 | + S3DataSource, |
| 43 | + StoppingCondition, |
| 44 | +) |
| 45 | + |
| 46 | +job = TrainingJob.create( |
| 47 | + training_job_name="tensorflow-train", |
| 48 | + role_arn="arn:aws:iam::<account_id>:role/<role_name>", |
| 49 | + algorithm_specification=AlgorithmSpecification( |
| 50 | + training_image="public.ecr.aws/deep-learning-containers/tensorflow-training:2.21-gpu-py312-cu129-amzn2023-sagemaker", |
| 51 | + training_input_mode="File", |
| 52 | + ), |
| 53 | + resource_config=ResourceConfig( |
| 54 | + instance_type="ml.p5.48xlarge", |
| 55 | + instance_count=2, |
| 56 | + volume_size_in_gb=200, |
| 57 | + ), |
| 58 | + input_data_config=[ |
| 59 | + InputDataConfig( |
| 60 | + channel_name="training", |
| 61 | + data_source=DataSource( |
| 62 | + s3_data_source=S3DataSource( |
| 63 | + s3_data_type="S3Prefix", |
| 64 | + s3_uri="s3://<bucket>/datasets/train/", |
| 65 | + ), |
| 66 | + ), |
| 67 | + ), |
| 68 | + ], |
| 69 | + output_data_config=OutputDataConfig(s3_output_path="s3://<bucket>/output/"), |
| 70 | + stopping_condition=StoppingCondition(max_runtime_in_seconds=3600), |
| 71 | +) |
| 72 | +job.wait_for_status("Completed") |
| 73 | +``` |
| 74 | + |
| 75 | +## Processing Jobs |
| 76 | + |
| 77 | +### `TensorFlowProcessor` (SDK v2) |
| 78 | + |
| 79 | +```python |
| 80 | +from sagemaker.tensorflow.processing import TensorFlowProcessor |
| 81 | + |
| 82 | +processor = TensorFlowProcessor( |
| 83 | + image_uri="public.ecr.aws/deep-learning-containers/tensorflow-training:2.21-cpu-py312-amzn2023-sagemaker", |
| 84 | + framework_version="2.21", # workaround: value ignored when image_uri is set |
| 85 | + role="arn:aws:iam::<account_id>:role/<role_name>", |
| 86 | + instance_type="ml.m5.xlarge", |
| 87 | + instance_count=1, |
| 88 | +) |
| 89 | +``` |
| 90 | + |
| 91 | +### `FrameworkProcessor` (SDK v3) |
| 92 | + |
| 93 | +```python |
| 94 | +from sagemaker.workflow.steps import ProcessingStep |
| 95 | +from sagemaker.processing import FrameworkProcessor |
| 96 | + |
| 97 | +processor = FrameworkProcessor( |
| 98 | + image_uri="public.ecr.aws/deep-learning-containers/tensorflow-training:2.21-cpu-py312-amzn2023-sagemaker", |
| 99 | + role="arn:aws:iam::<account_id>:role/<role_name>", |
| 100 | + instance_type="ml.m5.xlarge", |
| 101 | + instance_count=1, |
| 102 | +) |
| 103 | +``` |
| 104 | + |
| 105 | +## Multi-Node Training over EFA |
| 106 | + |
| 107 | +SageMaker provisions EFA on the instance types that support it (e.g., `ml.p5.48xlarge`, `ml.p4d.24xlarge`). The GPU image ships with EFA 1.49.0 and |
| 108 | +OpenMPI 4.1.8 pre-installed — no extra plumbing in your training script. |
| 109 | + |
| 110 | +Multi-node peer discovery is handled by the `sagemaker_tensorflow_container` training toolkit, which parses `/opt/ml/input/config/resourceconfig.json` |
| 111 | +at container start to enumerate hosts, current host rank, and network interface. Peers are addressed by the SageMaker-assigned hostnames (e.g., |
| 112 | +`algo-1`, `algo-2`) that resolve inside the training cluster — your script does not need to know about this. |
| 113 | + |
| 114 | +## Container Layout |
| 115 | + |
| 116 | +| Path | Purpose | |
| 117 | +| --- | --- | |
| 118 | +| `/opt/ml/input/data/<channel_name>/` | Training data SageMaker mounts from S3 (one subdir per channel) | |
| 119 | +| `/opt/ml/model/` | Write your final model artifacts here — SageMaker uploads to `OutputDataConfig.s3_output_path` | |
| 120 | +| `/opt/ml/output/` | Auxiliary outputs (logs, checkpoints) | |
| 121 | +| `/opt/ml/code/` | Your training source dir (populated from the SDK's `source_dir`) | |
| 122 | +| `/opt/venv/` | Python venv with TensorFlow + DLC libraries | |
| 123 | + |
| 124 | +## Notes |
| 125 | + |
| 126 | +- The image sets `SAGEMAKER_TRAINING_MODULE=sagemaker_tensorflow_container.training:main` — this is the entry-point the SageMaker training toolkit |
| 127 | + invokes at container start, which in turn launches your `entry_point` script. |
| 128 | +- For a baseline driver/AMI compatible with these CUDA 12.9 images, request the latest SageMaker training AMI when launching jobs. |
0 commit comments