Kdd2019
KDD conf
Install / Use
/learn @awshlabs/Kdd2019README
KDD2019 Amazon SageMaker Labs
Thank you for attending our session at KDD.
If you are interested in our Research reward program, please see the link below. Or contact me directly. https://aws.amazon.com/aws-ml-research-awards/
Amazon SageMaker is a fully-managed service that enables developers and data scientists to quickly and easily build, train, and deploy machine learning models at any scale. Amazon EC2 P3 instances deliver the highest performance compute in the cloud, are cost-effective, support all major machine learning frameworks, and are available globally. In this workshop, you'll create a SageMaker notebook instance and work through sample Jupyter notebooks that demonstrate some of the many features of SageMaker and how Amazon EC2 P3 is used to accelerate machine learning model training.


Prerequisites
Slides https://github.com/awshlabs/kdd2019/tree/master/slides This now includes GTC DC 2019 Slides.
AWS Account
In order to complete this workshop you'll need an AWS Account with access to create AWS IAM, S3, and SageMaker resources. If you do not have an AWS Account, please follow the instructions here to create an AWS Account.
The code and instructions in this workshop assume only one student is using a given AWS account at a time. If you try sharing an account with another student, you'll run into naming conflicts for certain resources. You can work around these by appending a unique suffix to the resources that fail to create due to conflicts, but the instructions do not provide details on the changes required to make this work.
If you are provided with AWS credit for this workshop, use this link to apply the credit to your AWS Account.
AWS Region
SageMaker is not available in all AWS Regions at this time. Accordingly, we recommend running this workshop in one of the supported AWS Regions such as N. Virginia, Oregon, Ohio. For this Lab, please use Oregon.
Once you've chosen a region, you should create all of the resources for this workshop there, including a new Amazon S3 bucket and a new SageMaker notebook instance. Make sure you select your region from the dropdown in the upper right corner of the AWS Console before getting started.

Browser
We recommend you use the latest version of Chrome or Firefox to complete this workshop.
Modules
This workshop is divided into multiple modules. Module 1 must be completed first. You can complete the other modules (Modules 2 and 3) in any order.
- Creating a Notebook Instance (in Oregon)
- Object Detection Using P3
- Running GluonNLP BERT Model
Be patient as you work your way through the notebook-based modules. After you run a cell in a notebook, it may take several seconds for the code to show results. For the cells that start training jobs, it may take 10 to 30 minutes.
After you have completed the workshop, you can delete all of the resources that were created by following the Cleanup Guide provided with this lab guide.
Module 1: Creating a Notebook Instance
In this module, we'll start by creating an Amazon S3 bucket that will be used throughout the workshop. We'll then create a SageMaker notebook instance, which we will use to run the other workshop modules.
1. Create a S3 Bucket (Make sure this is in the same region as SageMaker, Oregon etc).
SageMaker typically uses S3 as storage for data and model artifacts. In this step you'll create a S3 bucket for this purpose. To begin, sign into the AWS Management Console, https://console.aws.amazon.com/.
High-Level Instructions
Use the console or AWS CLI to create an Amazon S3 bucket. Keep in mind that your bucket's name must be globally unique across all regions and customers. We recommend using a name like smp3workshop-firstname-lastname. If you get an error that your bucket name already exists, try adding additional numbers or characters until you find an unused name.
-
In the AWS Management Console, choose Services then select S3 under Storage.
-
Choose +Create Bucket
-
Provide a globally unique name for your bucket such as
smworkshop-firstname-lastname. -
Select the Region you've chosen to use for this workshop from the dropdown.
-
Choose Create in the lower left of the dialog without selecting a bucket to copy settings from.
2. Launching the Notebook Instance (Pick Oregon)
-
In the upper-right corner of the AWS Management Console, confirm you are in the desired AWS region. Select N. Virginia, Oregon, Ohio.
-
Click on Amazon SageMaker from the list of all services. This will bring you to the Amazon SageMaker console homepage.

- To create a new notebook instance, go to Notebook instances, and click the Create notebook instance button at the top of the browser window.

- Type [First Name]-[Last Name]-workshop into the Notebook instance name text box, and select ml.p2.xlarge for the Notebook instance type.

- For IAM role, choose Create a new role. On the next screen, select Specific S3 buckets for the S3 buckets you specify - optional section, enter the name of the S3 bucket you created in the last step It is important to double check your bucket name, use copy and paste to avoid human error, and click Create role to continue.

-
Enter 10 for the Volume Size In GB - optional instead of the default 5, the default will cause out of space error.
-
You can expand the "Tags" section and add tags here if required.
-
Click Create notebook instance. This will take several minutes to complete.
3. Accessing the Notebook Instance
- Wait for the server status to change to InService. This will take a few minutes.

- Click Open Jupyter. You will now see the Jupyter homepage for your notebook instance.

4. Download workshop content
- On the top right corner of the Jupyter Notebook, select Terminal from New dropdown to open a terminal window. We will use this terminal to download workshop content from github using git client.

- Inside the terminal window, type the following commands to download the content.
- cd /home/ec2-user/SageMaker
- git clone https://github.com/dping1/AWS_P3_Workshop.git

- Switch back to the Jupyter notebook home tab, you will see a new folder called aws_workshop showed up

Module 2: Object Detection Using P3
This notebook is an end-to-end example introducing the Amazon SageMaker Object Detection algorithm. In this demo, we will demonstrate how to train and to host an object detection model using the Single Shot multibox Detector (SSD) algorithm. In doing so, we will also demonstrate how to construct a training dataset using the RecordIO format as this is the format that the training job will consume. We will also demonstrate how to host and validate this trained model.
- Open the aws_workshop folder and then the object_detection_p3 folder in your Jupyter to display a list of Jupyter notebooks.
- Click on Object-detection-P3.ipynb to open the notebook.
- Follow the instructions in the notebook to continue with the lab.
Code Highlights
SageMaker Estimator makes remote distributed training convenient.
od_model = sagemaker.estimator.Estimator(training_image,
role,
train_instance_count=1,
train_instance_type='ml.p3.2xlarge',
train_volume_size = 50,
train_max_run = 360000,
input_mode= 'File',
output_path=s3_output_location,
sagemaker_session=sess)
Setting up Hyperparameters.
od_model.set_hyperparameters(base_network='resnet-50',
num_classes=20,
mini_batch_size=16,
epochs=1,
learning_rate=0.001,
optimizer='sgd',
momentum=0.9,
weight_decay=0.0005,
overlap_threshold=0.5,
nms_threshold=0.45,
image_shape=512,
label_width=350,
num_training_samples=16551)
Module 3: GluonNLP BERT Lab
- Check out a copy of the KDD Gluon Tutorial.
- cd /home/ec2-user/SageMaker
- git clone https://github.com/astonzhang/KDD19-tutorial
- Open Jupyter Notebook and navigate to 07_bert_app/ directory, Open the bert.ipynb.
- Pick the conda_mxnet_p36 kernel.

- At the top of the notebook add a cell by using the + tool symbol. add the following lines in the cell:
!pip uninstall mxnet -y
!pip uninstall mx
Security Score
Audited on Jun 16, 2021
