Attach EI to a Notebook Instance
To test and evaluate inference performance using EI, you can attach EI to a notebook instance when you create or update a notebook instance. You can then use EI in local mode to host a model at an endpoint hosted on the notebook instance. You should test various sizes of notebook instances and EI accelerators to evaluate the configuration that works best for your use case.
Set Up to Use EI
To use EI locally in a notebook instance, create a notebook instance with an EI instance.
To create a notebook instance with an EI instance
-
Open the Amazon SageMaker console at https://console.amazonaws.cn/sagemaker/
. -
In the navigation pane, choose Notebook instances.
-
Choose Create notebook instance.
-
For Notebook instance name, provide a unique name for your notebook instance.
-
For notebook instance type, choose a CPU instance such as ml.t2.medium.
-
For Elastic Inference (EI), choose an instance from the list, such as ml.eia2.medium.
-
For IAM role, choose an IAM role that has the required permissions to use SageMaker and EI.
-
(Optional) For VPC - Optional, if you want the notebook instance to use a VPC, choose one from the available list. Otherwise, leave it as No VPC. If you use a VPC follow the instructions at Use a Custom VPC to Connect to EI.
-
(Optional) For Lifecycle configuration - optional, either leave it as No configuration or choose a lifecycle configuration. For more information, see Customize a Notebook Instance Using a Lifecycle Configuration Script.
-
(Optional) For Encryption key - optional, Optional) If you want SageMaker to use an Amazon Key Management Service (Amazon KMS) key to encrypt data in the ML storage volume attached to the notebook instance, specify the key.
-
(Optional) For Volume Size In GB - optional, leave the default value of 5.
-
(Optional) For Tags, add tags to the notebook instance. A tag is a label you assign to help manage your notebook instances. A tag consists of a key and a value, both of which you define.
-
Choose Create Notebook Instance.
After you create your notebook instance with EI attached, you can create a Jupyter notebook and set up an EI endpoint that is hosted locally on the notebook instance.
Use EI in Local Mode in SageMaker
To use EI locally in an endpoint hosted on a notebook instance, use local mode
with the Amazon SageMaker Python SDK
Topics
Use EI in Local Mode with SageMaker TensorFlow Estimators and Models
To use EI with TensorFlow in local mode, specify local
for
instance_type
and local_sagemaker_notebook
for
accelerator_type
when you call the deploy
method
of an estimator or a model object. For more information about Amazon SageMaker Python SDK
The following code shows how to use local mode with an estimator object. To
call the deploy
method, you must have previously either:
-
Trained the model by calling the
fit
method of an estimator. -
Pass a model artifact when you initialize the model object.
# Deploys the model to a local endpoint tf_predictor = tf_model.deploy(initial_instance_count=1, instance_type='local', accelerator_type='local_sagemaker_notebook')
Use EI in Local Mode with SageMaker Apache MXNet Estimators and Models
To use EI with MXNet in local mode, specify local
for
instance_type
and local_sagemaker_notebook
for
accelerator_type
when you call the deploy
method
of an estimator or a model object. For more information about Amazon SageMaker Python SDK
The following code shows how to use local mode with an estimator object. You
must have previously called the fit
method of the estimator to
train the model.
# Deploys the model to a local endpoint mxnet_predictor = mxnet_estimator.deploy(initial_instance_count=1, instance_type='local', accelerator_type='local_sagemaker_notebook')
For a complete example of using EI in local mode with MXNet, see the sample
notebook at https://sagemaker-examples.readthedocs.io/en/latest/sagemaker-python-sdk/mxnet_mnist/mxnet_mnist_elastic_inference_local.html
Use EI in Local Mode with SageMaker PyTorch Estimators and Models
To use EI with PyTorch in local mode, when you call the deploy
method of an estimator or a model object, specify local
for
instance_type
and local_sagemaker_notebook
for
accelerator_type
. For more information about Amazon SageMaker Python SDK
The following code shows how to use local mode with an estimator object. You
must have previously called the fit
method of the estimator to
train the model.
# Deploys the model to a local endpoint pytorch_predictor = pytorch_estimator.deploy(initial_instance_count=1, instance_type='local', accelerator_type='local_sagemaker_notebook')