Skip to content

Commit d4289bc

Browse files
authored
update gluon examples (aws#11)
1 parent e5f646f commit d4289bc

File tree

5 files changed

+19
-54
lines changed

5 files changed

+19
-54
lines changed

sagemaker-python-sdk/mxnet_gluon_cifar10/cifar10.ipynb

+9-13
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,19 @@
9797
"source": [
9898
"## Run the training script on SageMaker\n",
9999
"\n",
100-
"The ```MXNet``` class allows us to run our training function as a distributed training job on SageMaker infrastructure. We need to configure it with our training script, an IAM role, the number of training instances, and the training instance type. In this case we will run our training job on four p2.xlarge instances. "
100+
"The ```MXNet``` class allows us to run our training function as a distributed training job on SageMaker infrastructure. We need to configure it with our training script, an IAM role, the number of training instances, and the training instance type. In this case we will run our training job on four `ml.p2.xlarge` instances. "
101101
]
102102
},
103103
{
104104
"cell_type": "code",
105105
"execution_count": null,
106-
"metadata": {
107-
"collapsed": true
108-
},
106+
"metadata": {},
109107
"outputs": [],
110108
"source": [
111109
"m = MXNet(\"cifar10.py\", \n",
112110
" role=role, \n",
113111
" train_instance_count=4, \n",
114-
" train_instance_type=\"p2.xlarge\",\n",
112+
" train_instance_type=\"ml.p2.xlarge\",\n",
115113
" hyperparameters={'batch_size': 128, \n",
116114
" 'epochs': 50, \n",
117115
" 'learning_rate': 0.1, \n",
@@ -142,7 +140,9 @@
142140
"source": [
143141
"## Prediction\n",
144142
"\n",
145-
"After training, we use the MXNet object to create and deploy a hosted prediction endpoint. We can use the object returned by `deploy` to call the endpoint and perform inference on our sample image."
143+
"After training, we use the MXNet estimator object to create and deploy a hosted prediction endpoint. We can use a CPU-based instance for inference (in this case an `ml.c4.xlarge`), even though we trained on GPU instances.\n",
144+
"\n",
145+
"The predictor object returned by `deploy` lets us call the new endpoint and perform inference on our sample images. "
146146
]
147147
},
148148
{
@@ -151,7 +151,7 @@
151151
"metadata": {},
152152
"outputs": [],
153153
"source": [
154-
"predictor = m.deploy(min_instances=1, max_instances=1, instance_type='c4.xlarge')"
154+
"predictor = m.deploy(initial_instance_count=1, instance_type='ml.c4.xlarge')"
155155
]
156156
},
157157
{
@@ -178,9 +178,7 @@
178178
{
179179
"cell_type": "code",
180180
"execution_count": null,
181-
"metadata": {
182-
"collapsed": true
183-
},
181+
"metadata": {},
184182
"outputs": [],
185183
"source": [
186184
"# load the CIFAR10 samples, and convert them into format we can use with the prediction endpoint\n",
@@ -232,9 +230,7 @@
232230
{
233231
"cell_type": "code",
234232
"execution_count": null,
235-
"metadata": {
236-
"collapsed": true
237-
},
233+
"metadata": {},
238234
"outputs": [],
239235
"source": [
240236
"m.delete_endpoint()"

sagemaker-python-sdk/mxnet_gluon_cifar10/cifar10.py

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def train(current_host, hosts, num_cpus, num_gpus, channel_input_dirs, model_dir
3333
ctx = [mx.gpu(i) for i in range(num_gpus)] if num_gpus > 0 else [mx.cpu()]
3434
net = models.get_model('resnet34_v2', ctx=ctx, pretrained=False, classes=10)
3535
batch_size *= max(1, len(ctx))
36-
learning_rate *= max(1, len(ctx))
3736

3837
# load training and validation data
3938
# we use the gluon.data.vision.CIFAR10 class because of its built in pre-processing logic,

sagemaker-python-sdk/mxnet_gluon_cifar10/credentials.py

-5
This file was deleted.

sagemaker-python-sdk/mxnet_gluon_mnist/credentials.py

-5
This file was deleted.

sagemaker-python-sdk/mxnet_gluon_mnist/mnist_with_gluon.ipynb

+10-30
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,18 @@
1313
{
1414
"cell_type": "code",
1515
"execution_count": null,
16-
"metadata": {
17-
"collapsed": true
18-
},
16+
"metadata": {},
1917
"outputs": [],
2018
"source": [
21-
"import credentials # put your credentials in credentials.py\n",
2219
"import os\n",
2320
"import boto3\n",
2421
"import sagemaker\n",
2522
"from sagemaker.mxnet import MXNet\n",
2623
"from mxnet import gluon\n",
2724
"\n",
28-
"\n",
2925
"sagemaker_session = sagemaker.Session()\n",
3026
"\n",
31-
"# Replace with a role that gives SageMaker access to s3 and cloudwatch\n",
32-
"# see 1-Creating_a_role_allowing_SageMaker_to_access_S3_Cloudwatch_ECR.ipynb\n",
27+
"# Replace with a role that gives SageMaker access to S3 and CloudWatch\n",
3328
"role='SageMakerRole'"
3429
]
3530
},
@@ -43,9 +38,7 @@
4338
{
4439
"cell_type": "code",
4540
"execution_count": null,
46-
"metadata": {
47-
"collapsed": true
48-
},
41+
"metadata": {},
4942
"outputs": [],
5043
"source": [
5144
"gluon.data.vision.MNIST('./data/train', train=True)\n",
@@ -64,9 +57,7 @@
6457
{
6558
"cell_type": "code",
6659
"execution_count": null,
67-
"metadata": {
68-
"collapsed": true
69-
},
60+
"metadata": {},
7061
"outputs": [],
7162
"source": [
7263
"inputs = sagemaker_session.upload_data(path='data', key_prefix='data/mnist')"
@@ -86,9 +77,7 @@
8677
{
8778
"cell_type": "code",
8879
"execution_count": null,
89-
"metadata": {
90-
"collapsed": true
91-
},
80+
"metadata": {},
9281
"outputs": [],
9382
"source": [
9483
"!cat 'mnist.py'"
@@ -106,15 +95,13 @@
10695
{
10796
"cell_type": "code",
10897
"execution_count": null,
109-
"metadata": {
110-
"collapsed": true
111-
},
98+
"metadata": {},
11299
"outputs": [],
113100
"source": [
114101
"m = MXNet(\"mnist.py\", \n",
115102
" role=role, \n",
116103
" train_instance_count=1, \n",
117-
" train_instance_type=\"c4.xlarge\",\n",
104+
" train_instance_type=\"ml.c4.xlarge\",\n",
118105
" enable_cloudwatch_metrics=True,\n",
119106
" hyperparameters={'batch_size': 100, \n",
120107
" 'epochs': 20, \n",
@@ -134,7 +121,6 @@
134121
"cell_type": "code",
135122
"execution_count": null,
136123
"metadata": {
137-
"collapsed": true,
138124
"scrolled": true
139125
},
140126
"outputs": [],
@@ -155,12 +141,11 @@
155141
"cell_type": "code",
156142
"execution_count": null,
157143
"metadata": {
158-
"collapsed": true,
159144
"scrolled": true
160145
},
161146
"outputs": [],
162147
"source": [
163-
"predictor = m.deploy(instance_type = 'c4.xlarge', min_instances = 1, max_instances = 1)"
148+
"predictor = m.deploy(initial_instance_count=1, instance_type='ml.c4.xlarge')"
164149
]
165150
},
166151
{
@@ -173,9 +158,7 @@
173158
{
174159
"cell_type": "code",
175160
"execution_count": null,
176-
"metadata": {
177-
"collapsed": true
178-
},
161+
"metadata": {},
179162
"outputs": [],
180163
"source": [
181164
"from IPython.display import HTML\n",
@@ -193,7 +176,6 @@
193176
"cell_type": "code",
194177
"execution_count": null,
195178
"metadata": {
196-
"collapsed": true,
197179
"scrolled": true
198180
},
199181
"outputs": [],
@@ -214,9 +196,7 @@
214196
{
215197
"cell_type": "code",
216198
"execution_count": null,
217-
"metadata": {
218-
"collapsed": true
219-
},
199+
"metadata": {},
220200
"outputs": [],
221201
"source": [
222202
"m.delete_endpoint()"

0 commit comments

Comments
 (0)