-
Notifications
You must be signed in to change notification settings - Fork 72
infra: refactor toolkit tests. #56
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
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
00c8606
infra: refactor toolkit tests.
nadiaya 4775f2f
fix generic docker file.
nadiaya 9269730
Move buildspec back.
nadiaya 71ec190
An attempt to fix flake8 error (couldn't repo locally).
nadiaya c820be1
Decrease required code coverage :(.
nadiaya 395ae28
fix typo
nadiaya 855ca1e
remove print statements.
nadiaya 45536f3
Add missing tests.
nadiaya cd5c22c
Add test coverage back
nadiaya 04bd435
fix test
nadiaya 26f6339
Remove training related code from test scripts.
nadiaya 9030bff
PR comments + adding an EIA test.
nadiaya f4966e2
fix flake8.
nadiaya c11a16b
Do not build EIA image outside of test.
nadiaya dde94b9
make sure we show that we use the scripts that we use.
nadiaya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
application_import_names = image_utils, integration, local_mode_utils, sagemaker_pytorch_container, test, test-toolkit, timeout, utils | ||
import-order-style = google |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
version: 0.2 | ||
|
||
env: | ||
variables: | ||
FRAMEWORK_VERSION: '1.4.0' | ||
EIA_FRAMEWORK_VERSION: '1.3.1' | ||
CPU_INSTANCE_TYPE: 'ml.c4.xlarge' | ||
GPU_INSTANCE_TYPE: 'ml.p2.xlarge' | ||
EIA_ACCELERATOR_TYPE: 'ml.eia2.medium' | ||
ECR_REPO: 'sagemaker-test' | ||
GITHUB_REPO: 'sagemaker-pytorch-serving-container' | ||
DLC_ACCOUNT: '763104351884' | ||
SETUP_FILE: 'setup_cmds.sh' | ||
SETUP_CMDS: '#!/bin/bash\npip install --upgrade pip\npip install -U -e .\npip install -U -e .[test]' | ||
|
||
phases: | ||
pre_build: | ||
commands: | ||
- start-dockerd | ||
- ACCOUNT=$(aws --region $AWS_DEFAULT_REGION sts --endpoint-url https://sts.$AWS_DEFAULT_REGION.amazonaws.com get-caller-identity --query 'Account' --output text) | ||
- PREPROD_IMAGE="$ACCOUNT.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_REPO" | ||
- PR_NUM=$(echo $CODEBUILD_SOURCE_VERSION | grep -o '[0-9]\+') | ||
- BUILD_ID="$(echo $CODEBUILD_BUILD_ID | sed -e 's/:/-/g')" | ||
- echo 'Pull request number:' $PR_NUM '. No value means this build is not from pull request.' | ||
|
||
build: | ||
commands: | ||
- TOX_PARALLEL_NO_SPINNER=1 | ||
- PY_COLORS=0 | ||
|
||
# install | ||
- pip3 install -U -e .[test] | ||
|
||
# run linters | ||
- tox -e flake8,twine | ||
|
||
# run unit tests | ||
- tox -e py36 test-toolkit/unit | ||
|
||
# define tags | ||
- GENERIC_TAG="$FRAMEWORK_VERSION-pytorch-$BUILD_ID" | ||
- DLC_CPU_TAG="$FRAMEWORK_VERSION-dlc-cpu-$BUILD_ID" | ||
- DLC_GPU_TAG="$FRAMEWORK_VERSION-dlc-gpu-$BUILD_ID" | ||
- DLC_EIA_TAG="$FRAMEWORK_VERSION-dlc-eia-$BUILD_ID" | ||
|
||
# run local CPU integration tests (build and push the image to ECR repo) | ||
- test_cmd="pytest test-toolkit/integration/local --build-image --push-image --dockerfile-type pytorch --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --processor cpu --tag $GENERIC_TAG" | ||
- execute-command-if-has-matching-changes "$test_cmd" "test-toolkit/" "src/*.py" "setup.py" "setup.cfg" "buildspec-toolkit.yml" "docker/build_artifacts/*" | ||
- test_cmd="pytest test-toolkit/integration/local --build-image --push-image --dockerfile-type dlc.cpu --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --processor cpu --tag $DLC_CPU_TAG" | ||
- execute-command-if-has-matching-changes "$test_cmd" "test-toolkit/" "src/*.py" "setup.py" "setup.cfg" "buildspec-toolkit.yml" "docker/build_artifacts/*" | ||
|
||
# launch remote GPU instance | ||
- prefix='ml.' | ||
- instance_type=${GPU_INSTANCE_TYPE#"$prefix"} | ||
- create-key-pair | ||
- launch-ec2-instance --instance-type $instance_type --ami-name dlami-ubuntu-latest | ||
|
||
# build DLC GPU image because the base DLC image is too big and takes too long to build as part of the test | ||
- python3 setup.py sdist | ||
- build_dir="test-toolkit/docker/$FRAMEWORK_VERSION" | ||
- $(aws ecr get-login --registry-ids $DLC_ACCOUNT --no-include-email --region $AWS_DEFAULT_REGION) | ||
- docker build -f "$build_dir/Dockerfile.dlc.gpu" -t $PREPROD_IMAGE:$DLC_GPU_TAG --build-arg region=$AWS_DEFAULT_REGION . | ||
# push DLC GPU image to ECR | ||
- $(aws ecr get-login --registry-ids $ACCOUNT --no-include-email --region $AWS_DEFAULT_REGION) | ||
- docker push $PREPROD_IMAGE:$DLC_GPU_TAG | ||
|
||
# run GPU local integration tests | ||
- printf "$SETUP_CMDS" > $SETUP_FILE | ||
# no reason to rebuild the image again since it was already built and pushed to ECR during CPU tests | ||
- generic_cmd="pytest test-toolkit/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --processor gpu --tag $GENERIC_TAG" | ||
- test_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$generic_cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\"" | ||
- execute-command-if-has-matching-changes "$test_cmd" "test-toolkit/" "src/*.py" "setup.py" "setup.cfg" "buildspec-toolkit.yml" "docker/build_artifacts/*" | ||
- dlc_cmd="pytest test-toolkit/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --processor gpu --tag $DLC_GPU_TAG" | ||
- test_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$dlc_cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\" --skip-setup" | ||
- execute-command-if-has-matching-changes "$test_cmd" "test-toolkit/" "src/*.py" "setup.py" "setup.cfg" "buildspec-toolkit.yml" "docker/build_artifacts/*" | ||
|
||
# run CPU sagemaker integration tests | ||
- test_cmd="pytest test-toolkit/integration/sagemaker --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --processor cpu --instance-type $CPU_INSTANCE_TYPE --tag $GENERIC_TAG" | ||
- execute-command-if-has-matching-changes "$test_cmd" "test-toolkit/" "src/*.py" "setup.py" "setup.cfg" "buildspec-toolkit.yml" "docker/build_artifacts/*" | ||
- test_cmd="pytest test-toolkit/integration/sagemaker --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --processor cpu --instance-type $CPU_INSTANCE_TYPE --tag $DLC_CPU_TAG" | ||
- execute-command-if-has-matching-changes "$test_cmd" "test-toolkit/" "src/*.py" "setup.py" "setup.cfg" "buildspec-toolkit.yml" "docker/build_artifacts/*" | ||
|
||
# run GPU sagemaker integration tests | ||
- test_cmd="pytest test-toolkit/integration/sagemaker --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --processor gpu --instance-type $GPU_INSTANCE_TYPE --tag $GENERIC_TAG" | ||
- execute-command-if-has-matching-changes "$test_cmd" "test-toolkit/" "src/*.py" "setup.py" "setup.cfg" "buildspec-toolkit.yml" "docker/build_artifacts/*" | ||
- test_cmd="pytest test-toolkit/integration/sagemaker --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $FRAMEWORK_VERSION --processor gpu --instance-type $GPU_INSTANCE_TYPE --tag $DLC_GPU_TAG" | ||
- execute-command-if-has-matching-changes "$test_cmd" "test-toolkit/" "src/*.py" "setup.py" "setup.cfg" "buildspec-toolkit.yml" "docker/build_artifacts/*" | ||
|
||
# run EIA sagemaker integration tests | ||
- test_cmd="pytest test-toolkit/integration/sagemaker --build-image --push-image --dockerfile-type dlc.eia --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --framework-version $EIA_FRAMEWORK_VERSION --processor cpu --instance-type $CPU_INSTANCE_TYPE --accelerator-type $EIA_ACCELERATOR_TYPE --tag $DLC_EIA_TAG" | ||
- execute-command-if-has-matching-changes "$test_cmd" "test-toolkit/" "src/*.py" "setup.py" "setup.cfg" "buildspec-toolkit.yml" "docker/build_artifacts/*" | ||
|
||
finally: | ||
# shut down remote GPU instance | ||
- cleanup-gpu-instances | ||
- cleanup-key-pairs | ||
|
||
# remove ECR image | ||
- aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GENERIC_TAG | ||
- aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$DLC_CPU_TAG | ||
- aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$DLC_GPU_TAG | ||
- aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$DLC_EIA_TAG |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ARG region | ||
FROM 763104351884.dkr.ecr.$region.amazonaws.com/pytorch-inference-eia:1.3.1-cpu-py3 | ||
|
||
COPY dist/sagemaker_pytorch_inference-*.tar.gz /sagemaker_pytorch_inference.tar.gz | ||
RUN pip install --upgrade --no-cache-dir /sagemaker_pytorch_inference.tar.gz && \ | ||
rm /sagemaker_pytorch_inference.tar.gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ARG region | ||
FROM 763104351884.dkr.ecr.$region.amazonaws.com/pytorch-inference:1.4.0-cpu-py3 | ||
|
||
COPY dist/sagemaker_pytorch_inference-*.tar.gz /sagemaker_pytorch_inference.tar.gz | ||
RUN pip install --upgrade --no-cache-dir /sagemaker_pytorch_inference.tar.gz && \ | ||
rm /sagemaker_pytorch_inference.tar.gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ARG region | ||
FROM 763104351884.dkr.ecr.$region.amazonaws.com/pytorch-inference:1.4.0-gpu-py3 | ||
|
||
COPY dist/sagemaker_pytorch_inference-*.tar.gz /sagemaker_pytorch_inference.tar.gz | ||
RUN pip install --upgrade --no-cache-dir /sagemaker_pytorch_inference.tar.gz && \ | ||
rm /sagemaker_pytorch_inference.tar.gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
FROM pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime | ||
|
||
LABEL com.amazonaws.sagemaker.capabilities.accept-bind-to-port=true | ||
LABEL com.amazonaws.sagemaker.capabilities.multi-models=true | ||
|
||
ARG MMS_VERSION=1.0.8 | ||
|
||
ENV SAGEMAKER_SERVING_MODULE sagemaker_pytorch_serving_container.serving:main | ||
ENV TEMP=/home/model-server/tmp | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
libgl1-mesa-glx \ | ||
libglib2.0-0 \ | ||
libsm6 \ | ||
libxext6 \ | ||
libxrender-dev \ | ||
openjdk-8-jdk-headless \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN conda install -c conda-forge opencv==4.0.1 \ | ||
&& ln -s /opt/conda/bin/pip /usr/local/bin/pip3 | ||
|
||
RUN pip install mxnet-model-server==$MMS_VERSION | ||
|
||
COPY dist/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 useradd -m model-server \ | ||
&& mkdir -p /home/model-server/tmp \ | ||
&& chown -R model-server /home/model-server | ||
|
||
COPY docker/build_artifacts/mms-entrypoint.py /usr/local/bin/dockerd-entrypoint.py | ||
COPY docker/build_artifacts/config.properties /home/model-server | ||
|
||
RUN chmod +x /usr/local/bin/dockerd-entrypoint.py | ||
|
||
EXPOSE 8080 8081 | ||
ENTRYPOINT ["python", "/usr/local/bin/dockerd-entrypoint.py"] | ||
CMD ["mxnet-model-server", "--start", "--mms-config", "/home/model-server/config.properties"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.