Skip to content

feature: install inference toolkit from PyPI. #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ Example:
::

# PyTorch 1.3.1, Python 3, EI
$ cp dist/sagemaker_pytorch_inference-*.tar.gz dist/sagemaker_pytorch_inference.tar.gz
$ docker build -t preprod-pytorch-serving-eia:1.3.1-cpu-py3 -f docker/1.3.1/py3/Dockerfile.eia .


Expand Down
59 changes: 28 additions & 31 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,55 +31,52 @@ phases:

build:
commands:
- tox -e flake8,twine
- tox -e flake8

# install
- pip3 install -U -e .
- pip3 install -U -e .[test]

# run unit tests
- pytest test/unit

# create tar in dist/
- python3 setup.py sdist
- tar_name=$(ls dist/sagemaker_pytorch_inference-*.tar.gz)
- cp $tar_name sagemaker_pytorch_inference.tar.gz

- cpu_dockerfile="Dockerfile.cpu"
- gpu_dockerfile="Dockerfile.gpu"
- eia_dockerfile="Dockerfile.eia"

# build py2 images
- build_dir="docker/$FRAMEWORK_VERSION/py$CPU_PY2_VERSION"
- cp sagemaker_pytorch_inference.tar.gz $build_dir/
- cp -r docker/build_artifacts/* $build_dir/
- CPU_PY2_TAG="$FRAMEWORK_VERSION-cpu-py2-$BUILD_ID"
- GPU_PY2_TAG="$FRAMEWORK_VERSION-gpu-py2-$BUILD_ID"
- docker build -f "$build_dir/$cpu_dockerfile" -t $PREPROD_IMAGE:$CPU_PY2_TAG $build_dir
- docker build -f "$build_dir/$gpu_dockerfile" -t $PREPROD_IMAGE:$GPU_PY2_TAG $build_dir
- build_cmd="docker build -f "$build_dir/$cpu_dockerfile" -t $PREPROD_IMAGE:$CPU_PY2_TAG $build_dir"
- execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
- build_cmd="docker build -f "$build_dir/$gpu_dockerfile" -t $PREPROD_IMAGE:$GPU_PY2_TAG $build_dir"
- execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"

# build py3 image
- build_dir="docker/$FRAMEWORK_VERSION/py$GPU_PY3_VERSION"
- cp sagemaker_pytorch_inference.tar.gz $build_dir/
- cp -r docker/build_artifacts/* $build_dir/
- CPU_PY3_TAG="$FRAMEWORK_VERSION-cpu-py3-$BUILD_ID"
- GPU_PY3_TAG="$FRAMEWORK_VERSION-gpu-py3-$BUILD_ID"
- EIA_PY3_TAG="$EIA_FRAMEWORK_VERSION-eia-py3-$BUILD_ID"
- docker build -f "$build_dir/$cpu_dockerfile" -t $PREPROD_IMAGE:$CPU_PY3_TAG $build_dir
- docker build -f "$build_dir/$gpu_dockerfile" -t $PREPROD_IMAGE:$GPU_PY3_TAG $build_dir
- build_cmd="docker build -f "$build_dir/$cpu_dockerfile" -t $PREPROD_IMAGE:$CPU_PY3_TAG $build_dir"
- execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
- build_cmd="docker build -f "$build_dir/$gpu_dockerfile" -t $PREPROD_IMAGE:$GPU_PY3_TAG $build_dir"
- execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
# PY2 not offered for EIA PyTorch
- eia_build_dir="docker/$EIA_FRAMEWORK_VERSION/py$EIA_PY3_VERSION"
- cp sagemaker_pytorch_inference.tar.gz $eia_build_dir/
- cp -r docker/build_artifacts/* $eia_build_dir/
- docker build -f "$eia_build_dir/$eia_dockerfile" -t $PREPROD_IMAGE:$EIA_PY3_TAG $eia_build_dir

# push images to ecr
- $(aws ecr get-login --registry-ids $ACCOUNT --no-include-email --region $AWS_DEFAULT_REGION)
- docker push $PREPROD_IMAGE:$CPU_PY2_TAG
- docker push $PREPROD_IMAGE:$CPU_PY3_TAG
- docker push $PREPROD_IMAGE:$GPU_PY2_TAG
- docker push $PREPROD_IMAGE:$GPU_PY3_TAG
- docker push $PREPROD_IMAGE:$EIA_PY3_TAG
- push_cmd="docker push $PREPROD_IMAGE:$CPU_PY2_TAG"
- execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
- push_cmd="docker push $PREPROD_IMAGE:$CPU_PY3_TAG"
- execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
- push_cmd="docker push $PREPROD_IMAGE:$GPU_PY2_TAG"
- execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
- push_cmd="docker push $PREPROD_IMAGE:$GPU_PY3_TAG"
- execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
- push_cmd="docker push $PREPROD_IMAGE:$EIA_PY3_TAG"
- execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"

# launch remote gpu instance
- prefix='ml.'
Expand All @@ -90,34 +87,34 @@ phases:
# run cpu integration tests
- py3_cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --framework-version $FRAMEWORK_VERSION --py-version $CPU_PY3_VERSION --processor cpu --tag $CPU_PY3_TAG"
- py2_cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --framework-version $FRAMEWORK_VERSION --py-version $CPU_PY2_VERSION --processor cpu --tag $CPU_PY2_TAG"
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "docker/*" "buildspec.yml"

# run gpu integration tests
- printf "$SETUP_CMDS" > $SETUP_FILE
- py3_pytest_cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --framework-version $FRAMEWORK_VERSION --py-version $GPU_PY3_VERSION --processor gpu --tag $GPU_PY3_TAG"
- py3_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$py3_pytest_cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\""
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"

- py2_pytest_cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --framework-version $FRAMEWORK_VERSION --py-version $GPU_PY2_VERSION --processor gpu --tag $GPU_PY2_TAG"
- py2_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$py2_pytest_cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\" --skip-setup"
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "docker/*" "buildspec.yml"

# run cpu sagemaker tests
- py3_cmd="pytest test/integration/sagemaker --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --py-version $CPU_PY3_VERSION --processor cpu --instance-type $CPU_INSTANCE_TYPE --tag $CPU_PY3_TAG"
- py2_cmd="pytest test/integration/sagemaker --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --py-version $CPU_PY2_VERSION --processor cpu --instance-type $CPU_INSTANCE_TYPE --tag $CPU_PY2_TAG"
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "docker/*" "buildspec.yml"

# run gpu sagemaker tests
- py3_cmd="pytest test/integration/sagemaker --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --py-version $GPU_PY3_VERSION --processor gpu --instance-type $GPU_INSTANCE_TYPE --tag $GPU_PY3_TAG"
- py2_cmd="pytest test/integration/sagemaker --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --py-version $GPU_PY2_VERSION --processor gpu --instance-type $GPU_INSTANCE_TYPE --tag $GPU_PY2_TAG"
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "docker/*" "buildspec.yml"

# run eia sagemaker tests
- py3_cmd="pytest test/integration/sagemaker --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $EIA_FRAMEWORK_VERSION --py-version $EIA_PY3_VERSION --processor cpu --instance-type $CPU_INSTANCE_TYPE --accelerator-type $EIA_ACCELERATOR_TYPE --tag $EIA_PY3_TAG"
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"

finally:
# shut down remote gpu instance
Expand Down
5 changes: 1 addition & 4 deletions docker/1.3.1/py3/Dockerfile.eia
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ COPY config.properties /home/model-server

RUN chmod +x /usr/local/bin/dockerd-entrypoint.py

COPY sagemaker_pytorch_inference.tar.gz /sagemaker_pytorch_inference.tar.gz
RUN pip install --no-cache-dir \
/sagemaker_pytorch_inference.tar.gz \
&& rm /sagemaker_pytorch_inference.tar.gz
RUN pip install --no-cache-dir "sagemaker-pytorch-inference<2"

RUN curl https://aws-dlc-licenses.s3.amazonaws.com/pytorch/license.txt -o /license.txt

Expand Down
5 changes: 1 addition & 4 deletions docker/1.4.0/py2/Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ COPY config.properties /home/model-server

RUN chmod +x /usr/local/bin/dockerd-entrypoint.py

COPY sagemaker_pytorch_inference.tar.gz /sagemaker_pytorch_inference.tar.gz
RUN pip install --no-cache-dir \
/sagemaker_pytorch_inference.tar.gz \
&& rm /sagemaker_pytorch_inference.tar.gz
RUN pip install --no-cache-dir "sagemaker-pytorch-inference<2"

RUN curl https://aws-dlc-licenses.s3.amazonaws.com/pytorch-1.4.0/license.txt -o /license.txt

Expand Down
5 changes: 1 addition & 4 deletions docker/1.4.0/py2/Dockerfile.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ RUN apt-get install -y --no-install-recommends \

# RUN pip install --no-cache-dir 'opencv-python>=4.0,<4.1'

COPY sagemaker_pytorch_inference.tar.gz /sagemaker_pytorch_inference.tar.gz
RUN pip install --no-cache-dir \
/sagemaker_pytorch_inference.tar.gz \
&& rm /sagemaker_pytorch_inference.tar.gz
RUN pip install --no-cache-dir "sagemaker-pytorch-inference<2"

RUN curl https://aws-dlc-licenses.s3.amazonaws.com/pytorch-1.4.0/license.txt -o /license.txt

Expand Down
5 changes: 1 addition & 4 deletions docker/1.4.0/py3/Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ COPY config.properties /home/model-server

RUN chmod +x /usr/local/bin/dockerd-entrypoint.py

COPY sagemaker_pytorch_inference.tar.gz /sagemaker_pytorch_inference.tar.gz
RUN pip install --no-cache-dir \
/sagemaker_pytorch_inference.tar.gz \
&& rm /sagemaker_pytorch_inference.tar.gz
RUN pip install --no-cache-dir "sagemaker-pytorch-inference<2"

RUN curl https://aws-dlc-licenses.s3.amazonaws.com/pytorch-1.4.0/license.txt -o /license.txt

Expand Down
5 changes: 1 addition & 4 deletions docker/1.4.0/py3/Dockerfile.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ COPY config.properties /home/model-server

RUN chmod +x /usr/local/bin/dockerd-entrypoint.py

COPY sagemaker_pytorch_inference.tar.gz /sagemaker_pytorch_inference.tar.gz
RUN pip install --no-cache-dir \
/sagemaker_pytorch_inference.tar.gz \
&& rm /sagemaker_pytorch_inference.tar.gz
RUN pip install --no-cache-dir "sagemaker-pytorch-inference<2"

RUN curl https://aws-dlc-licenses.s3.amazonaws.com/pytorch-1.4.0/license.txt -o /license.txt

Expand Down