1

我想使用 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的文档中推荐了我指定入口点的方式(请参阅“如何在容器内执行脚本”)。

4

2 回答 2

1

我在AWS 文档中找到了一个提示,并提出了这个解决方案:

ENTRYPOINT ["python3.7", "/opt/ml/code/train.py"]

这样,容器将作为可执行文件运行

于 2020-03-31T16:22:40.393 回答
0

我在使用“sagemaker-training”工具包时遇到了同样的错误。尝试在“pip install”命令中指定软件包版本。它解决了我的问题。不知道为什么...

于 2020-12-16T22:53:00.463 回答