Skip to content

HKT-SSA/bring-your-own-container-on-sm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bring your own container on Amazon SageMaker Lab

  1. create a cloud9 environment in east-us-1 with name: sagemaker-container-workshop and type t2.micro.

  2. In cloud9, bash shell exec: git clone https://github.com/awslabs/amazon-sagemaker-examples.git

  3. cp -r amazon-sagemaker-examples/advanced_functionality/scikit_bring_your_own/ /home/ec2-user/environment/.

  4. cd scikit_bring_your_own/container/

  5. Build the docker image: ./build_and_push.sh <image-name>. Image name suggest to use scikit-<your-name> format.

  6. docker images: you will see scikit-<your-name> with latest TAG in your cloud9 and ecr respository.

local training

  1. cd local_test
  2. chmod +x *.sh
  3. ./train_local.sh scikit-<your-name>
  4. ls test_dir/model/ to check the model output.

error debug

  1. mv test_dir/input/config/hyperparameters.json test_dir/input/config/hyperparameters.json.bak
  2. ./train_local.sh scikit-<your-name> You will see error in the console
  3. cat test_dir/output/failure to see failure
  4. mv test_dir/input/config/hyperparameters.json.bak test_dir/input/config/hyperparameters.json
  5. ./train_local.sh scikit-<your-name>

Local Server Inference

  1. ./serve_local.sh scikit-<your-name> > output.log
  2. Open new shell terminal in cloud9
  3. cd scikit_bring_your_own/container/local_test/
  4. ./predict.sh payload.csv text/csv

Train and deploy using the Amazon SageMaker console

Upload full data set to s3

  • remember to change the bucket name sagemaker-iris-dataset-<your-id>-yyyymmdd
cd /home/ec2-user/environment/scikit_bring_your_own/container/local_test/test_dir
aws s3api create-bucket --bucket sagemaker-iris-dataset-beyoung-20200806 --create-bucket-configuration LocationConstraint=us-west-2
aws s3 cp . s3://sagemaker-iris-dataset-beyoung-20200806 --recursive

s3 bucket name as sagemaker-iris-dataset-<your-id>-yyyymmdd/data/training/

Create Training Job

  • Job name: scikit-<your-name>-yyyymmdd
  • Algorithm: Custom
  • Input mode: File
  • Training image: <Amazon ECR path>:<tag>. Can get it from docker images
  • Hyperparameters: max_leaf_nodes value: 8
  • Training
    • channel name: training
    • s3 location: sagemaker-iris-dataset-<your-id>/data/training/
  • Output data configuration: s3 output path: s3://sagemaker-iris-dataset-<your-id>/models/
  • create training job.
  • After training job complete, you will see model in s3://<bucket name>/models/<job name>/output/model.tar.gz You can get it from trainig jobs detail page.

Deploy an endpoint

Create model

  • model name: scikit-<your-name>-yyyymmdd
  • click create the model

Create an endpoint

  • name: scikit-<your-name>-yyyymmdd

  • new endpoint configuration: scikit-<your-name>-yyyymmdd

  • create endpoint configration

  • click create endpoint

Test the endpoint

In cloud9, install pip3:

  • sudo easy_install-3.6 pip
  • sudo /usr/local/bin/pip3 install boto3 pandas

Download the test-endpoint-sample.py in the same github folder.

wget "https://raw.githubusercontent.com/HKT-SSA/bring-your-own-container-on-sm/master/test-endpoint-sample.py" \
-O "/home/ec2-user/environment/test-endpoint-sample.py"
  • modify the bucket name and endpoint
  • run python3 test-endpoint-sample.py

Clean Up

  • SageMaker Endpoint
  • s3
  • cloud9

Reference

About

bring your own container on sagemaker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages