Skip to content

Commit a442a79

Browse files
authored
Merge branch 'master' into dev/pca-mnist-sm-version-update
2 parents 2d62919 + d003ef0 commit a442a79

File tree

27 files changed

+115
-3154
lines changed

27 files changed

+115
-3154
lines changed

advanced_functionality/multi_model_bring_your_own/multi_model_endpoint_bring_your_own.ipynb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"\n",
1212
"For the inference container to serve multiple models in a multi-model endpoint, it must implement [additional APIs](https://docs.aws.amazon.com/sagemaker/latest/dg/build-multi-model-build-container.html) in order to load, list, get, unload and invoke specific models. This notebook demonstrates how to build your own inference container that implements these APIs.\n",
1313
"\n",
14+
"**Note**: Because this notebook builds a Docker container, it does not run in Amazon SageMaker Studio.\n",
15+
"\n",
16+
"This notebook was tested with the `conda_mxnet_p36` kernel running SageMaker Python SDK version 2.15.3 on an Amazon SageMaker notebook instance.\n",
17+
"\n",
1418
"---\n",
1519
"\n",
1620
"### Contents\n",
@@ -553,7 +557,7 @@
553557
"name": "python",
554558
"nbconvert_exporter": "python",
555559
"pygments_lexer": "ipython3",
556-
"version": "3.6.5"
560+
"version": "3.7.6"
557561
}
558562
},
559563
"nbformat": 4,

autopilot/autopilot_customer_churn_high_level_with_evaluation.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"\n",
2323
"---\n",
2424
"\n",
25-
"This notebook works with sagemaker python sdk >= 1.65.1.\n",
25+
"This notebook works with sagemaker python sdk 2.x\n",
2626
"\n",
2727
"## Contents\n",
2828
"\n",
@@ -794,17 +794,19 @@
794794
"metadata": {},
795795
"outputs": [],
796796
"source": [
797-
"from sagemaker.predictor import RealTimePredictor\n",
798-
"from sagemaker.content_types import CONTENT_TYPE_CSV\n",
797+
"from sagemaker.predictor import Predictor\n",
798+
"from sagemaker.serializers import CSVSerializer\n",
799+
"from sagemaker.deserializers import CSVDeserializer\n",
799800
"\n",
800801
"predictor = automl.deploy(initial_instance_count=1,\n",
801802
" instance_type='ml.m5.2xlarge',\n",
802803
" candidate=candidates[best_candidate_idx],\n",
803804
" inference_response_keys=inference_response_keys,\n",
804-
" predictor_cls=RealTimePredictor)\n",
805-
"predictor.content_type = CONTENT_TYPE_CSV\n",
805+
" predictor_cls=Predictor,\n",
806+
" serializer=CSVSerializer(),\n",
807+
" deserializer=CSVDeserializer())\n",
806808
"\n",
807-
"print(\"Created endpoint: {}\".format(predictor.endpoint))\n"
809+
"print(\"Created endpoint: {}\".format(predictor.endpoint_name))\n"
808810
]
809811
},
810812
{
@@ -829,11 +831,9 @@
829831
"metadata": {},
830832
"outputs": [],
831833
"source": [
832-
"from io import StringIO\n",
833-
"\n",
834-
"prediction = predictor.predict(test_data_no_target.to_csv(sep=',', header=False, index=False)).decode('utf-8')\n",
835-
"prediction_df = pd.read_csv(StringIO(prediction), header=None, names=inference_response_keys)\n",
836-
"custom_predicted_labels = prediction_df.iloc[:,1].values >= best_candidate_threshold\n",
834+
"prediction = predictor.predict(test_data_no_target.to_csv(sep=',', header=False, index=False))\n",
835+
"prediction_df = pd.DataFrame(prediction, columns=inference_response_keys)\n",
836+
"custom_predicted_labels = prediction_df.iloc[:,1].astype(float).values >= best_candidate_threshold\n",
837837
"prediction_df['custom_predicted_label'] = custom_predicted_labels\n",
838838
"prediction_df['custom_predicted_label'] = prediction_df['custom_predicted_label'].map({False: target_attribute_values[0], True: target_attribute_values[1]})\n",
839839
"prediction_df"
@@ -906,4 +906,4 @@
906906
},
907907
"nbformat": 4,
908908
"nbformat_minor": 4
909-
}
909+
}

buildspec.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: 0.2
2+
3+
env:
4+
variables:
5+
INSTANCE_TYPE: 'ml.c4.8xlarge'
6+
REGION: 'us-west-2'
7+
8+
phases:
9+
pre_build:
10+
commands:
11+
- PR_NUM=$(echo $CODEBUILD_SOURCE_VERSION | grep -o '[0-9]\+')
12+
- NOTEBOOKS="$(pr-notebook-filenames --pr $PR_NUM)"
13+
14+
build:
15+
commands:
16+
- |-
17+
if [ -z "$NOTEBOOKS" ]; then
18+
echo "No notebooks to test in this pull request."
19+
else
20+
echo "Testing $NOTEBOOKS"
21+
aws s3 cp s3://sagemaker-mead-cli/mead-nb-test.tar.gz mead-nb-test.tar.gz
22+
tar -xzf mead-nb-test.tar.gz
23+
export JAVA_HOME=$(get-java-home)
24+
echo "set JAVA_HOME=$JAVA_HOME"
25+
export SAGEMAKER_ROLE_ARN=$(aws iam list-roles --output text --query "Roles[?RoleName == 'SageMakerRole'].Arn")
26+
echo "set SAGEMAKER_ROLE_ARN=$SAGEMAKER_ROLE_ARN"
27+
28+
./runtime/bin/mead-run-nb-test \
29+
--instance-type $INSTANCE_TYPE \
30+
--region $REGION \
31+
--notebook-instance-role-arn $SAGEMAKER_ROLE_ARN \
32+
$NOTEBOOKS
33+
fi

hyperparameter_tuning/analyze_results/HPO_Analyze_TuningJob_Results.ipynb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
"region = boto3.Session().region_name\n",
3131
"sage_client = boto3.Session().client('sagemaker')\n",
3232
"\n",
33+
"## You must have already run a hyperparameter tuning job to analyze it here.\n",
34+
"## The Hyperparameter tuning jobs you have run are listed in the Training section on your SageMaker dashboard.\n",
35+
"## Copy the name of a completed job you want to analyze from that list.\n",
36+
"## For example: tuning_job_name = 'mxnet-training-201007-0054'.\n",
3337
"tuning_job_name = 'YOUR-HYPERPARAMETER-TUNING-JOB-NAME'"
3438
]
3539
},

introduction_to_amazon_algorithms/managed_spot_training_object_detection/managed_spot_training_object_detection.ipynb

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Object Detection using Managed Spot Training\n",
7+
"# Object detection using managed spot training\n",
88
"\n",
9-
"The example here is almost the same as [Amazon SageMaker Object Detection using the RecordIO format](https://github.com/awslabs/amazon-sagemaker-examples/blob/master/introduction_to_amazon_algorithms/object_detection_pascalvoc_coco/object_detection_recordio_format.ipynb).\n",
9+
"This notebook shows how to use [Amazon SageMaker managed spot training](https://docs.aws.amazon.com/sagemaker/latest/dg/model-managed-spot-training.html) to run training jobs at potentially lower cost. Managed spot training uses [Amazon EC2 Spot instances](https://aws.amazon.com/ec2/spot/) and manages the Spot interruptions on your behalf.\n",
1010
"\n",
11-
"This notebook tackles the exact same problem with the same solution, but it has been modified to be able to run using SageMaker Managed Spot infrastructure. SageMaker Managed Spot uses [EC2 Spot Instances](https://aws.amazon.com/ec2/spot/) to run Training at a lower cost.\n",
12-
"\n",
13-
"Please read the original notebook and try it out to gain an understanding of the ML use-case and how it is being solved. We will not delve into that here in this notebook.\n",
11+
"To highlight the differences between on-demand and Spot instances, this notebook is the same as [Amazon SageMaker Object Detection using the RecordIO format](https://github.com/awslabs/amazon-sagemaker-examples/blob/master/introduction_to_amazon_algorithms/object_detection_pascalvoc_coco/object_detection_recordio_format.ipynb), but has been updated to use managed spot training. For a full description of the ML use case and how it is being solved, see the original notebook.\n",
1412
"\n",
1513
"## Setup\n",
16-
"Again, we won't go into detail explaining the code below, it has been lifted verbatim from [Amazon SageMaker Object Detection using the RecordIO format](https://github.com/awslabs/amazon-sagemaker-examples/blob/master/introduction_to_amazon_algorithms/object_detection_pascalvoc_coco/object_detection_recordio_format.ipynb)."
17-
]
18-
},
19-
{
20-
"cell_type": "code",
21-
"execution_count": null,
22-
"metadata": {},
23-
"outputs": [],
24-
"source": [
25-
"!pip install -qU awscli boto3 sagemaker"
14+
"\n",
15+
"See [Amazon SageMaker Object Detection using the RecordIO format](https://github.com/awslabs/amazon-sagemaker-examples/blob/master/introduction_to_amazon_algorithms/object_detection_pascalvoc_coco/object_detection_recordio_format.ipynb) for a description of the code.\n",
16+
"\n",
17+
"### Prerequisites\n",
18+
"\n",
19+
"This notebook has been tested with:\n",
20+
"* SageMaker Python SDK 1.72.1\n",
21+
"* Python 3.6\n",
22+
"* Kernel: conda_mxnet_p36"
2623
]
2724
},
2825
{
@@ -48,10 +45,10 @@
4845
"cell_type": "markdown",
4946
"metadata": {},
5047
"source": [
51-
"### Download And Prepare Data\n",
52-
"Note: this notebook downloads and uses the Pascal VOC dateset, please be aware of the database usage rights:\n",
53-
"\"The VOC data includes images obtained from the \"flickr\" website. Use of these images must respect the corresponding terms of use: \n",
54-
"* \"flickr\" terms of use (https://www.flickr.com/help/terms)\""
48+
"### Download and prepare data\n",
49+
"This notebook downloads and uses the Pascal VOC dataset, which has the following database usage rights:\n",
50+
"> The VOC data includes images obtained from the Flickr website. Use of these images must respect the corresponding terms of use: \n",
51+
"> * Flickr terms of use (https://www.flickr.com/help/terms)"
5552
]
5653
},
5754
{
@@ -81,7 +78,7 @@
8178
"cell_type": "markdown",
8279
"metadata": {},
8380
"source": [
84-
"### Upload data to S3"
81+
"### Upload data to Amazon Simple Storage Service (Amazon S3)"
8582
]
8683
},
8784
{
@@ -105,15 +102,16 @@
105102
"cell_type": "markdown",
106103
"metadata": {},
107104
"source": [
108-
"# Object Detection using Managed Spot Training\n",
105+
"## Managed spot training\n",
109106
"\n",
110-
"For Managed Spot Training using Object Detection we need to configure two things:\n",
111-
"1. Enable the `train_use_spot_instances` constructor arg - a simple self-explanatory boolean.\n",
112-
"2. Set the `train_max_wait` constructor arg - this is an int arg representing the amount of time you are willing to wait for Spot infrastructure to become available. Some instance types are harder to get at Spot prices and you may have to wait longer. You are not charged for time spent waiting for Spot infrastructure to become available, you're only charged for actual compute time spent once Spot instances have been successfully procured.\n",
107+
"Managed spot training is controlled by two arguments to the `sagemaker.estimator.Estimator` constructor:\n",
113108
"\n",
114-
"Feel free to toggle the `train_use_spot_instances` variable to see the effect of running the same job using regular (a.k.a. \"On Demand\") infrastructure.\n",
109+
"* `train_use_spot_instances`: Set to `True` to use Spot instances for training jobs.\n",
110+
"* `train_max_wait`: Represents the amount of time to wait for a Spot instance to become available. Be aware that some Spot instance types take longer to get. You are charged only for actual compute time spent once Spot instances have been acquired, and not for time spent waiting for Spot instances to become available.\n",
115111
"\n",
116-
"Note that `train_max_wait` can be set if and only if `train_use_spot_instances` is enabled and **must** be greater than or equal to `train_max_run`."
112+
"Note that `train_max_wait` can be set only if `train_use_spot_instances` is `True` and **must** be greater than or equal to `train_max_run`.\n",
113+
"\n",
114+
"Toggle `train_use_spot_instances` in the following code to see the effect of running the same job using on-demand instances."
117115
]
118116
},
119117
{
@@ -131,8 +129,9 @@
131129
"cell_type": "markdown",
132130
"metadata": {},
133131
"source": [
134-
"## Training\n",
135-
"Now that we are done with all the setup that is needed, we are ready to train our object detector. To begin, let us create a ``sageMaker.estimator.Estimator`` object. This estimator will launch the training job."
132+
"### Training\n",
133+
"\n",
134+
"Train the object detector by creating a `sagemaker.estimator.Estimator` object and launching the training job."
136135
]
137136
},
138137
{
@@ -182,16 +181,21 @@
182181
},
183182
{
184183
"cell_type": "markdown",
185-
"metadata": {},
184+
"metadata": {
185+
"pycharm": {
186+
"name": "#%% md\n"
187+
}
188+
},
186189
"source": [
187-
"# Savings\n",
188-
"Towards the end of the job you should see two lines of output printed:\n",
190+
"### Savings\n",
191+
"At the end of the job output, two lines are printed:\n",
192+
"\n",
193+
"* `Training seconds: X` : The actual compute time spent on the training job.\n",
194+
"* `Billable seconds: Y` : The time you will be billed for after Spot discounting is applied.\n",
189195
"\n",
190-
"- `Training seconds: X` : This is the actual compute-time your training job spent\n",
191-
"- `Billable seconds: Y` : This is the time you will be billed for after Spot discounting is applied.\n",
196+
"When `train_use_spot_instances` is `True`, you should see a notable difference between training and billable seconds. This shows the cost savings when managed spot training is used, and is summarized in the final output:\n",
192197
"\n",
193-
"If you enabled the `train_use_spot_instances` var then you should see a notable difference between `X` and `Y` signifying the cost savings you will get for having chosen Managed Spot Training. This should be reflected in an additional line:\n",
194-
"- `Managed Spot Training savings: (1-Y/X)*100 %`"
198+
"* `Managed Spot Training savings: (1-Y/X)*100 %`"
195199
]
196200
}
197201
],
@@ -212,9 +216,9 @@
212216
"name": "python",
213217
"nbconvert_exporter": "python",
214218
"pygments_lexer": "ipython3",
215-
"version": "3.6.5"
219+
"version": "3.6.10"
216220
},
217-
"notice": "Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License."
221+
"notice": "Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License."
218222
},
219223
"nbformat": 4,
220224
"nbformat_minor": 4

0 commit comments

Comments
 (0)