尽管我指定了一个入口点,但 SageMaker 给出了 CannotStartContainerError

SageMaker gives CannotStartContainerError although I specified an entrypoint

我想使用 SageMaker 训练自定义 ML 模型。该模型是用 Python 编写的,应该以 Docker 图像的形式发送到 SageMaker。这是我的 Docker 文件的简化版本(模型位于 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 方法,我会收到以下错误:

"AlgorithmError: CannotStartContainerError. Please make sure the container can be run with 'docker run train'."

换句话说:SageMaker 无法进入容器和 运行 train.py 文件。但为什么? ENV SAGEMAKER_PROGRAM train.py 中推荐了我使用 ENV SAGEMAKER_PROGRAM train.py 指定入口点的方式(参见 'How a script is executed inside the container')。

我在 the AWS docs 中找到了一个提示并提出了这个解决方案:

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

有了这个容器will run as an executable

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