本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
如何构建您自己的处理容器(高级方案)
您可以向 Amazon SageMaker Processing 提供具有自己的代码和依赖项的 Docker 映像,以运行数据处理、特征工程和模型评估工作负载。下面将介绍如何构建自己的处理容器。
下面的 Dockerfile 示例使用可作为处理作业运行的 Python 库 scikit-learn 和 pandas 来构建容器。
FROM python:3.7-slim-buster # Install scikit-learn and pandas RUN pip3 install pandas==0.25.3 scikit-learn==0.21.3 # Add a Python script and configure Docker to run it ADD processing_script.py / ENTRYPOINT ["python3", "/processing_script.py"]
有关处理脚本的示例,请参阅开始使用 SageMaker Processing
构建此 Docker 映像并将其推送到 Amazon Elastic Container Registry(Amazon ECR)存储库,并确保 SageMaker AI IAM 角色可以从 Amazon ECR 中提取映像。然后,您可以在 Amazon SageMaker Processing 中运行此映像。
Amazon SageMaker Processing 如何配置处理容器
Amazon SageMaker Processing 通过环境变量和位于容器中预定义位置的两个 JSON 文件(/opt/ml/config/processingjobconfig.json 和 /opt/ml/config/resourceconfig.json),为处理容器提供配置信息。
当处理作业启动时,它将使用您在 CreateProcessingJob 请求中通过 Environment 映射指定的环境变量。/opt/ml/config/processingjobconfig.json 文件包含有关处理容器的主机名的信息,并且也在 CreateProcessingJob 请求中指定。
以下示例显示了 /opt/ml/config/processingjobconfig.json 文件的格式。
{ "ProcessingJobArn": "<processing_job_arn>", "ProcessingJobName": "<processing_job_name>", "AppSpecification": { "ImageUri": "<image_uri>", "ContainerEntrypoint": null, "ContainerArguments": null }, "Environment": { "KEY": "VALUE" }, "ProcessingInputs": [ { "InputName": "input-1", "S3Input": { "LocalPath": "/opt/ml/processing/input/dataset", "S3Uri": "<s3_uri>", "S3DataDistributionType": "FullyReplicated", "S3DataType": "S3Prefix", "S3InputMode": "File", "S3CompressionType": "None", "S3DownloadMode": "StartOfJob" } } ], "ProcessingOutputConfig": { "Outputs": [ { "OutputName": "output-1", "S3Output": { "LocalPath": "/opt/ml/processing/output/dataset", "S3Uri": "<s3_uri>", "S3UploadMode": "EndOfJob" } } ], "KmsKeyId": null }, "ProcessingResources": { "ClusterConfig": { "InstanceCount": 1, "InstanceType": "ml.m5.xlarge", "VolumeSizeInGB": 30, "VolumeKmsKeyId": null } }, "RoleArn": "<IAM role>", "StoppingCondition": { "MaxRuntimeInSeconds": 86400 } }
/opt/ml/config/resourceconfig.json 文件包含有关处理容器的主机名的信息。请在创建或运行分布式处理代码时使用以下主机名。
{ "current_host": "algo-1", "hosts": ["algo-1","algo-2","algo-3"] }
请勿使用 /etc/hostname 或 /etc/hosts 中包含的有关主机名的信息,因为它可能不准确。
处理容器可能无法立即获得主机名信息。我们建议当节点在集群中可用时,在主机名解析操作上添加重试策略。