pipelines/components/aws/sagemaker/TrainingJob/samples
ryansteakley 0368fc6174
chore(components): Update scripts to use public ecr instead of docker (#8264)
* Update scripts to use public ecr instead of docker

* other codebuild specs

* run black on non-formatted files

* login to general ecr

* change default image for generate_components

* use public ecr amazon linux

* use :2 tag

* add arg for kfp v1 or v2 build version

* change whitespace and add docker login back for integration tests

* enable buildkit

* use v2 license file if in v2 build-mode

* make build_version mandatory
2022-09-15 02:16:40 +00:00
..
mnist-kmeans-training chore(components): Update scripts to use public ecr instead of docker (#8264) 2022-09-15 02:16:40 +00:00
README.md feat(components): Introducing AWS SageMaker TrainingJob component v2 in Preview (#8158) 2022-08-18 04:27:06 +00:00

README.md

Training Job Samples

The samples in this directory demonstrate how to create and monitor Training jobs on SageMaker in a Kubeflow Pipelines workflow.

Prerequisites

  1. Follow the instructions in the getting started section to setup the required configuration to run the component.
  2. Install the following tools on your local machine or an EC2 instance:
    • AWS CLI A command line tool for interacting with AWS services.
    • python 3.8+ - A programming language used for automated installation scripts.
    • pip - A package installer for python.

Next, we create an S3 bucket and IAM role for SageMaker.

S3 Bucket

To train a model with SageMaker, we need an S3 bucket to store the dataset and artifacts from the training process. Run the following commands to create an S3 bucket. Specify the value for SAGEMAKER_REGION as the region you want to create your SageMaker resources. For ease of use in the samples (using the default values of the pipeline), we suggest using us-east-1 as the region.

export SAGEMAKER_REGION=us-east-1
export S3_BUCKET_NAME="data-bucket-${SAGEMAKER_REGION}-$RANDOM"

if [[ $SAGEMAKER_REGION == "us-east-1" ]]; then
    aws s3api create-bucket --bucket ${S3_BUCKET_NAME} --region ${SAGEMAKER_REGION}
else
    aws s3api create-bucket --bucket ${S3_BUCKET_NAME} --region ${SAGEMAKER_REGION} \
    --create-bucket-configuration LocationConstraint=${SAGEMAKER_REGION}
fi

echo ${S3_BUCKET_NAME}

Note down your S3 bucket name which will be used in the samples.

SageMaker execution IAM role

The SageMaker training job needs an IAM role to access Amazon S3 and SageMaker. Run the following commands to create a SageMaker execution IAM role that is used by SageMaker to access AWS resources:

export SAGEMAKER_EXECUTION_ROLE_NAME="sagemaker-execution-role-$RANDOM"

TRUST="{ \"Version\": \"2012-10-17\", \"Statement\": [ { \"Effect\": \"Allow\", \"Principal\": { \"Service\": \"sagemaker.amazonaws.com\" }, \"Action\": \"sts:AssumeRole\" } ] }"
aws iam create-role --role-name ${SAGEMAKER_EXECUTION_ROLE_NAME} --assume-role-policy-document "$TRUST"
aws iam attach-role-policy --role-name ${SAGEMAKER_EXECUTION_ROLE_NAME} --policy-arn arn:aws:iam::aws:policy/AmazonSageMakerFullAccess
aws iam attach-role-policy --role-name ${SAGEMAKER_EXECUTION_ROLE_NAME} --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess

export SAGEMAKER_EXECUTION_ROLE_ARN=$(aws iam get-role --role-name ${SAGEMAKER_EXECUTION_ROLE_NAME} --output text --query 'Role.Arn')

echo $SAGEMAKER_EXECUTION_ROLE_ARN

Note down the execution role ARN to use in samples.

Creating your first Training Job

Head over to the individual sample directories to run your training jobs. The simplest example to start with is the K-Means MNIST training.