Skip to content

Commit 8b45bd5

Browse files
authored
Merge pull request aws#232 from awslabs/arpin_local_mode_changes
Updated: local mode notebooks based on comments from first PR
2 parents 5107c0b + ee6bf22 commit 8b45bd5

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

sagemaker-python-sdk/mxnet_gluon_mnist/mnist_with_gluon_local_mode.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"\n",
99
"### Pre-requisites\n",
1010
"\n",
11-
"This notebook shows how to use the SageMaker Python SDK to run your code in a local container before deploying to SageMaker's managed training or hosting environments. This can speed up iterative testing and debugging while using the same familiar Python SDK interface. Just change your estimator's `train_instance_type` to `local` (or `local_gpu` if you're using an ml.p2 or ml.p3 notebook instance).\n",
11+
"This notebook shows how to use the SageMaker Python SDK to run your code in a local container before deploying to SageMaker's managed training or hosting environments. This can speed up iterative testing and debugging while using the same familiar Python SDK interface. Just change your estimator's `train_instance_type` to `local`. You could also use `local_gpu` if you're using an ml.p2 or ml.p3 notebook instance, but then you'll need to set `train_instance_count=1` since distributed, local, GPU training is not yet supported.\n",
1212
"\n",
13-
"In order to use this feature you'll need to install docker-compose (and nvidia-docker if training with a GPU).\n",
13+
"In order to use this feature you'll need to install docker-compose (and nvidia-docker if training with a GPU). Running the setup.sh script below will handle this for you.\n",
1414
"\n",
1515
"**Note, you can only run a single local notebook at one time.**"
1616
]
@@ -30,7 +30,7 @@
3030
"source": [
3131
"### Overview\n",
3232
"\n",
33-
"MNIST is a widely used dataset for handwritten digit classification. It consists of 70,000 labeled 28x28 pixel grayscale images of hand-written digits. The dataset is split into 60,000 training images and 10,000 test images. There are 10 classes (one for each of the 10 digits). This tutorial will show how to train and test an MNIST model on SageMaker using MXNet and the Gluon API."
33+
"MNIST is a widely used dataset for handwritten digit classification. It consists of 70,000 labeled 28x28 pixel grayscale images of hand-written digits. The dataset is split into 60,000 training images and 10,000 test images. There are 10 classes (one for each of the 10 digits). This tutorial will show how to train and test an MNIST model on SageMaker local mode using MXNet and the Gluon API."
3434
]
3535
},
3636
{
@@ -121,7 +121,7 @@
121121
"source": [
122122
"## Run the training script on SageMaker\n",
123123
"\n",
124-
"The ```MXNet``` class allows us to run our training function on SageMaker. We need to configure it with our training script, an IAM role, the number of training instances, and the training instance type. This is the the only difference from [mnist_with_gluon.ipynb](./mnist_with_gluon.ipynb). Instead of ``train_instance_type='ml.c4.xlarge'``, we set it to ``train_instance_type='local'``. For local training with GPU, we could set this to \"local_gpu\". In this case, `instance_type` was set above based on your whether you're running a GPU instance."
124+
"The ```MXNet``` class allows us to run our training function on SageMaker local mode. We need to configure it with our training script, an IAM role, the number of training instances, and the training instance type. This is the the only difference from [mnist_with_gluon.ipynb](./mnist_with_gluon.ipynb). Instead of ``train_instance_type='ml.c4.xlarge'``, we set it to ``train_instance_type='local'``. For local training with GPU, we could set this to \"local_gpu\". In this case, `instance_type` was set above based on your whether you're running a GPU instance."
125125
]
126126
},
127127
{
@@ -135,7 +135,7 @@
135135
" train_instance_count=1, \n",
136136
" train_instance_type=instance_type,\n",
137137
" hyperparameters={'batch_size': 100, \n",
138-
" 'epochs': 2, \n",
138+
" 'epochs': 20, \n",
139139
" 'learning_rate': 0.1, \n",
140140
" 'momentum': 0.9, \n",
141141
" 'log_interval': 100})"

sagemaker-python-sdk/tensorflow_distributed_mnist/tensorflow_local_mode_mnist.ipynb

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"\n",
99
"## Pre-requisites\n",
1010
"\n",
11-
"This notebook shows how to use the SageMaker Python SDK to run your code in a local container before deploying to SageMaker's managed training or hosting environments. This can speed up iterative testing and debugging while using the same familiar Python SDK interface. Just change your estimator's `train_instance_type` to `local` (or `local_gpu` if you're using an ml.p2 or ml.p3 notebook instance).\n",
11+
"This notebook shows how to use the SageMaker Python SDK to run your code in a local container before deploying to SageMaker's managed training or hosting environments. This can speed up iterative testing and debugging while using the same familiar Python SDK interface. Just change your estimator's `train_instance_type` to `local`. You could also use `local_gpu` if you're using an ml.p2 or ml.p3 notebook instance, but then you'll need to set `train_instance_count=1` since distributed, local, GPU training is not yet supported.\n",
1212
"\n",
13-
"In order to use this feature you'll need to install docker-compose (and nvidia-docker if training with a GPU).\n",
13+
"In order to use this feature you'll need to install docker-compose (and nvidia-docker if training with a GPU). Running the setup.sh script below will handle this for you.\n",
1414
"\n",
1515
"**Note, you can only run a single local notebook at one time.**"
1616
]
@@ -30,9 +30,9 @@
3030
"source": [
3131
"## Overview\n",
3232
"\n",
33-
"The **SageMaker Python SDK** helps you deploy your models for training and hosting in optimized, productions ready containers in SageMaker. The SageMaker Python SDK is easy to use, modular, extensible and compatible with TensorFlow and MXNet. This tutorial focuses on how to create a convolutional neural network model to train the [MNIST dataset](http://yann.lecun.com/exdb/mnist/) using **TensorFlow in local mode**.\n",
33+
"The **SageMaker Python SDK** helps you deploy your models for training and hosting in optimized, productions ready containers in SageMaker local mode. The SageMaker Python SDK is easy to use, modular, extensible and compatible with TensorFlow and MXNet. This tutorial focuses on how to create a convolutional neural network model to train the [MNIST dataset](http://yann.lecun.com/exdb/mnist/) using **TensorFlow in local mode**.\n",
3434
"\n",
35-
"### Set up the environment Set up the environment"
35+
"### Set up the environment"
3636
]
3737
},
3838
{
@@ -48,14 +48,6 @@
4848
"\n",
4949
"sagemaker_session = sagemaker.Session()\n",
5050
"\n",
51-
"instance_type = 'local'\n",
52-
"\n",
53-
"if subprocess.call('nvidia-smi') == 0:\n",
54-
" ## Set type to GPU if one is present\n",
55-
" instance_type = 'local_gpu'\n",
56-
" \n",
57-
"print(\"Instance type = \" + instance_type)\n",
58-
"\n",
5951
"role = get_execution_role()"
6052
]
6153
},
@@ -156,7 +148,7 @@
156148
"source": [
157149
"## Create a training job using the sagemaker.TensorFlow estimator\n",
158150
"\n",
159-
"The `TensorFlow` class allows us to run our training function on SageMaker. We need to configure it with our training script, an IAM role, the number of training instances, and the training instance type. Here is the the only difference from [tensorflow_distributed_mnist.ipynb](./tensorflow_distributed_mnist.ipynb) is that instead of ``train_instance_type='ml.c4.xlarge'``, we set it to ``train_instance_type='local'``. For local training with GPU, we could set this to \"local_gpu\". In this case, `instance_type` was set above based on your whether you're running a GPU instance.\n",
151+
"The `TensorFlow` class allows us to run our training function on SageMaker. We need to configure it with our training script, an IAM role, the number of training instances, and the training instance type. Here is the the only difference from [tensorflow_distributed_mnist.ipynb](./tensorflow_distributed_mnist.ipynb) is that instead of ``train_instance_type='ml.c4.xlarge'``, we set it to ``train_instance_type='local'``. For local training with GPU, we could set this to `'local_gpu'` (but then need to set `train_instance_count=1`). In this case, `instance_type` was set above based on your whether you're running a GPU instance.\n",
160152
"\n",
161153
"After we've constructed our `TensorFlow` object, we fit it using the data we uploaded to S3. Even though we're in local mode, using S3 as our data source makes sense because it maintains consistency with how SageMaker's distributed, managed training ingests data."
162154
]
@@ -175,8 +167,8 @@
175167
" role=role,\n",
176168
" training_steps=10, \n",
177169
" evaluation_steps=10,\n",
178-
" train_instance_count=1,\n",
179-
" train_instance_type=instance_type)\n",
170+
" train_instance_count=2,\n",
171+
" train_instance_type='local')\n",
180172
"\n",
181173
"mnist_estimator.fit(inputs)"
182174
]
@@ -208,7 +200,7 @@
208200
"outputs": [],
209201
"source": [
210202
"mnist_predictor = mnist_estimator.deploy(initial_instance_count=1,\n",
211-
" instance_type=instance_type)"
203+
" instance_type='local')"
212204
]
213205
},
214206
{

0 commit comments

Comments
 (0)