├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── README.md └── build_and_push.sh /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | 6 | By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check [existing open](https://github.com/aws-samples/amazon-sagemaker-container-with-fastai/issues), or [recently closed](https://github.com/aws-samples/amazon-sagemaker-container-with-fastai/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *master* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws-samples/amazon-sagemaker-container-with-fastai/labels/help%20wanted) issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](https://github.com/aws-samples/amazon-sagemaker-container-with-fastai/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | 61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 62 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | ARG REGION=us-west-2 2 | ARG ARCH=cpu 3 | 4 | # SageMaker PyTorch image 5 | FROM 520713654638.dkr.ecr.$REGION.amazonaws.com/sagemaker-pytorch:1.0.0-$ARCH-py3 6 | 7 | RUN python -m pip --no-cache-dir install --upgrade fastai 8 | 9 | ENV LANG C.UTF-8 10 | ENV LC_ALL C.UTF-8 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Amazon SageMaker Container Example with fast.ai 2 | 3 | This project allows you to build a Docker container to build, train and deploy [fast.ai](https://github.com/fastai/fastai) based Deep Learning models with Amazon SageMaker. 4 | 5 | Since the fast.ai library is based on PyTorch, this project builds upon the [SageMaker PyTorch Container](https://github.com/aws/sagemaker-pytorch-container) meaning that you can bring your own fast.ai scripts for training and deploying your models using the [PyTorch](https://sagemaker.readthedocs.io/en/latest/sagemaker.pytorch.html) Estimator, Model and Predictor objects in the [SageMaker SDK](https://sagemaker.readthedocs.io/en/latest/). 6 | 7 | ## Getting Started 8 | 9 | [Amazon SageMaker](https://aws.amazon.com/documentation/sagemaker/) utilizes Docker containers to run all training jobs & inference endpoints. Make sure you have installed [Docker](https://www.docker.com/>) on your development machine in order to build the necessary Docker images. 10 | 11 | The Docker images are built from the [following Dockerfile](https://github.com/aws-samples/amazon-sagemaker-container-with-fastai/tree/master/Dockerfile). 12 | 13 | We have a utility script that builds 2 Docker images, a GPU based image and a CPU based image, on your machine locally and pushes them to your ECR repository. 14 | 15 | To build the images run the following script: 16 | 17 | ``` 18 | ./build_and_push.sh 19 | 20 | ``` 21 | 22 | ## License Summary 23 | 24 | This sample code is made available under a modified MIT license. See the LICENSE file. 25 | -------------------------------------------------------------------------------- /build_and_push.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This script shows how to build the Docker image and push it to ECR to be ready for use 4 | # by SageMaker. 5 | 6 | # The argument to this script is the image name. This will be used as the image on the local 7 | # machine and combined with the account and region to form the repository name for ECR. 8 | IMAGE="sagemaker-fastai" 9 | 10 | # parameters 11 | FASTAI_VERSION="1.0" 12 | PY_VERSION="py36" 13 | 14 | # Get the account number associated with the current IAM credentials 15 | account=$(aws sts get-caller-identity --query Account --output text) 16 | 17 | if [ $? -ne 0 ] 18 | then 19 | exit 255 20 | fi 21 | 22 | # Get the region defined in the current configuration (default to us-west-2 if none defined) 23 | region=$(aws configure get region) 24 | region=${region:-us-west-2} 25 | 26 | # If the repository doesn't exist in ECR, create it. 27 | 28 | aws ecr describe-repositories --repository-names "${IMAGE}" > /dev/null 2>&1 29 | 30 | if [ $? -ne 0 ] 31 | then 32 | aws ecr create-repository --repository-name "${IMAGE}" > /dev/null 33 | fi 34 | 35 | # Get the login command from ECR and execute it directly 36 | $(aws ecr get-login --region ${region} --no-include-email) 37 | 38 | # Get the login command from ECR in order to pull down the SageMaker PyTorch image 39 | $(aws ecr get-login --registry-ids 520713654638 --region ${region} --no-include-email) 40 | 41 | # loop for each architecture (cpu & gpu) 42 | for arch in gpu cpu 43 | do 44 | echo "Building image with arch=${arch}, region=${region}" 45 | TAG="${FASTAI_VERSION}-${arch}-${PY_VERSION}" 46 | FULLNAME="${account}.dkr.ecr.${region}.amazonaws.com/${IMAGE}:${TAG}" 47 | docker build -t ${IMAGE}:${TAG} --build-arg ARCH="$arch" --build-arg REGION="${region}" . 48 | docker tag ${IMAGE}:${TAG} ${FULLNAME} 49 | docker push ${FULLNAME} 50 | done 51 | --------------------------------------------------------------------------------