我想使用 SageMaker 训练自定义 ML 模型。该模型是用 Python 编写的,应该以 Docker 映像的形式发送到 SageMaker。这是我的 Dockerfile 的简化版本(模型位于 train.py 文件中):
FROM amazonlinux:latest
# Install Python 3
RUN yum -y update && yum install -y python3-pip python3-devel gcc && yum clean all
# Install sagemaker-containers (the official SageMaker utils package)
RUN pip3 install --target=/usr/local/lib/python3.7/site-packages sagemaker-containers && rm -rf /root/.cache
# Bring the script with the model to the image
COPY train.py /opt/ml/code/train.py
ENV SAGEMAKER_PROGRAM train.py
现在,如果我将此图像初始化为 SageMaker 估算器,然后fit
在此估算器上运行该方法,则会收到以下错误:
“算法错误:CannotStartContainerError。请确保容器可以使用 'docker run train' 运行。”
换句话说:SageMaker 无法进入容器并运行 train.py 文件。但为什么?在 sagemaker-containers 包ENV SAGEMAKER_PROGRAM train.py
的文档中推荐了我指定入口点的方式(请参阅“如何在容器内执行脚本”)。