AWS SageMaker Pipeline执行格式错误问题排查求助
问题
我用AWS SageMaker Python SDK搭建训练流水线时,处理步骤报错:
/usr/local/bin/python3: exec format error
已执行操作:
- 基于Poetry构建安装项目依赖的自定义Docker镜像
- 将镜像上传至AWS ECR
付<P预览(建议手持计划地文体副本空间段马英文
- 关联镜像到SageMaker域
- 构建流水线时传入镜像URI到Processor,代码如下:
script_processor = ScriptProcessor( instance_type="ml.m5.xlarge", instance_count=processing_instance_count, base_job_name="base-job-name", image_uri=image_uri, role=role, command=["python3"], )
参考Dockerfile:
FROM python:3.9-slim-buster ENV PYTHONUNBUFFERED=1 \ # prevents python creating .pyc files PYTHONDONTWRITEBYTECODE=1 \ # pip PIP_NO_CACHE_DIR=off \ PIP_DISABLE_PIP_VERSION_CHECK=on \ PIP_DEFAULT_TIMEOUT=100 \ # poetry POETRY_VERSION=1.1 \ # make poetry install to this location POETRY_HOME="/opt/poetry" \ # do not ask any interactive question POETRY_NO_INTERACTION=1 # prepend poetry and venv to path ENV PATH="$POETRY_HOME/bin:$PATH" RUN apt-get update && apt-get install build-essential -y # install poetry - respects $POETRY_VERSION & $POETRY_HOME RUN pip install -U pip RUN pip install poetry # copy project requirement files here to ensure they will be cached. COPY / / RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi WORKDIR /
解决办法
报错根源是Docker镜像架构与SageMaker实例(ml.m5.xlarge为x86_64架构)不匹配。如果在ARM架构机器(如M系列Mac)上构建镜像,默认生成ARM64架构镜像,在x86实例上运行就会触发exec格式错误。
构建x86_64架构镜像
使用Docker buildx构建兼容x86的镜像并推送到ECR:docker buildx build --platform linux/amd64 -t <你的ECR仓库URI>:<标签> . --push确认镜像架构
登录AWS控制台进入ECR镜像仓库,查看镜像Manifest,确认架构为amd64。本地验证镜像兼容性
用x86容器运行镜像测试:docker run --platform linux/amd64 <你的镜像标签> python3 --version能正常输出版本则镜像没问题。
可选:指定Python绝对路径
如果镜像内python3路径有变动,可修改Processor的command参数:command=["/usr/local/bin/python3"]
内容的提问来源于stack exchange,提问作者Sam Baker
相关产品推荐
相关产品推荐

