Skip to content

Commit f77eaa5

Browse files
author
Ignacio Quintero
committed
Add a section about Local Mode to the README
1 parent 54c764c commit f77eaa5

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

README.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,77 @@ Later sections of this document explain how to use the different Estimators and
117117
* `Custom SageMaker Estimators and Models <#byo-docker-containers-with-sagemaker-estimators>`__
118118

119119

120+
Estimator Usage
121+
---------------
122+
123+
Here is an end to end example of how to use a SageMaker Estimator.
124+
125+
.. code:: python
126+
127+
from sagemaker.mxnet import MXNet
128+
129+
# Configure an MXNet Estimator (no training happens yet)
130+
mxnet_estimator = MXNet('train.py',
131+
train_instance_type='ml.p2.xlarge',
132+
train_instance_count = 1)
133+
134+
# Starts a SageMaker training job and waits until completion.
135+
mxnet_estimator.fit('s3://my_bucket/my_training_data/')
136+
137+
# Deploys the model that was generated by fit() to a SageMaker Endpoint
138+
mxnet_predictor = mxnet_estimator.deploy(initial_instance_count=1, instance_type='ml.p2.xlarge')
139+
140+
# Serializes data and makes a prediction request to the SageMaker Endpoint
141+
response = predictor.predict(data)
142+
143+
# Tears down the SageMaker Endpoint
144+
mxnet_estimator.delete_endpoint()
145+
146+
Local Mode
147+
~~~~~~~~~~
148+
149+
The SageMaker Python SDK now supports local mode, which allows you to create TensorFlow, MXNet and BYO estimators and
150+
deploy to your local environment.  This is a great way to test your deep learning script before running in
151+
SageMaker's managed training or hosting environments.
152+
153+
We can take the example in `Estimator Usage <#estimator-usage>`__ , and use either ``local`` or ``local_gpu`` as the
154+
instance type.
155+
156+
.. code:: python
157+
158+
from sagemaker.mxnet import MXNet
159+
160+
# Configure an MXNet Estimator (no training happens yet)
161+
mxnet_estimator = MXNet('train.py',
162+
train_instance_type='local',
163+
train_instance_count=1)
164+
165+
# In Local Mode, fit will pull the MXNet container docker image and run it locally
166+
mxnet_estimator.fit('s3://my_bucket/my_training_data/')
167+
168+
# Deploys the model that was generated by fit() to local endpoint in a container
169+
mxnet_predictor = mxnet_estimator.deploy(initial_instance_count=1, instance_type='ml.p2.xlarge')
170+
171+
# Serializes data and makes a prediction request to the local endpoint
172+
response = predictor.predict(data)
173+
174+
# Tears down the endpoint container
175+
mxnet_estimator.delete_endpoint()
176+
177+
178+
For detailed examples of running docker in local mode, see:
179+
180+
- `TensorFlow local mode example notebook <https://github.com/awslabs/amazon-sagemaker-examples/blob/master/sagemaker-python-sdk/tensorflow_distributed_mnist/tensorflow_local_mode_mnist.ipynb>`__.
181+
- `MXNet local mode example notebook <https://github.com/awslabs/amazon-sagemaker-examples/blob/master/sagemaker-python-sdk/mxnet_gluon_mnist/mnist_with_gluon_local_mode.ipynb>`__.
182+
183+
A few important notes:
184+
185+
- Only one local mode endpoint can be running at a time
186+
- Since the data are pulled from S3 to your local environment, please ensure you have sufficient space.
187+
- If you run into problems, this is often due to different docker containers conflicting.  Killing these containers and re-running often solves your problems.
188+
- Local Mode requires docker-compose and `nvidia-docker2 <https://github.com/NVIDIA/nvidia-docker>`__ for ``local_gpu``.
189+
190+
120191
MXNet SageMaker Estimators
121192
--------------------------
122193

0 commit comments

Comments
 (0)