Skip to content

Commit 17820ea

Browse files
iquinteroJonathan Esterhazy
authored andcommitted
add AlgorithmEstimator and ModelPackage support
1 parent 115e7a8 commit 17820ea

File tree

12 files changed

+2118
-162
lines changed

12 files changed

+2118
-162
lines changed

README.rst

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ Table of Contents
3434
6. `PyTorch SageMaker Estimators <#pytorch-sagemaker-estimators>`__
3535
7. `SageMaker SparkML Serving <#sagemaker-sparkml-serving>`__
3636
8. `AWS SageMaker Estimators <#aws-sagemaker-estimators>`__
37-
9. `BYO Docker Containers with SageMaker Estimators <#byo-docker-containers-with-sagemaker-estimators>`__
38-
10. `SageMaker Automatic Model Tuning <#sagemaker-automatic-model-tuning>`__
39-
11. `SageMaker Batch Transform <#sagemaker-batch-transform>`__
40-
12. `Secure Training and Inference with VPC <#secure-training-and-inference-with-vpc>`__
41-
13. `BYO Model <#byo-model>`__
42-
14. `Inference Pipelines <#inference-pipelines>`__
43-
15. `SageMaker Workflow <#sagemaker-workflow>`__
37+
9. `Using SageMaker AlgorithmEstimators <#using-sagemaker-algorithmestimators>`__
38+
10. `Consuming SageMaker Model Packages <#consuming-sagemaker-model-packages>`__
39+
11. `BYO Docker Containers with SageMaker Estimators <#byo-docker-containers-with-sagemaker-estimators>`__
40+
12. `SageMaker Automatic Model Tuning <#sagemaker-automatic-model-tuning>`__
41+
13. `SageMaker Batch Transform <#sagemaker-batch-transform>`__
42+
14. `Secure Training and Inference with VPC <#secure-training-and-inference-with-vpc>`__
43+
15. `BYO Model <#byo-model>`__
44+
16. `Inference Pipelines <#inference-pipelines>`__
45+
17. `SageMaker Workflow <#sagemaker-workflow>`__
4446

4547

4648
Installing the SageMaker Python SDK
@@ -456,6 +458,59 @@ For more information, see `AWS SageMaker Estimators and Models`_.
456458
457459
.. _AWS SageMaker Estimators and Models: src/sagemaker/amazon/README.rst
458460
461+
Using SageMaker AlgorithmEstimators
462+
-----------------------------------
463+
464+
With the SageMaker Algorithm entities, you can create training jobs with just an ``algorithm_arn`` instead of
465+
a training image. There is a dedicated ``AlgorithmEstimator`` class that accepts ``algorithm_arn`` as a
466+
parameter, the rest of the arguments are similar to the other Estimator classes. This class also allows you to
467+
consume algorithms that you have subscribed to in the AWS Marketplace. The AlgorithmEstimator performs
468+
client-side validation on your inputs based on the algorithm's properties.
469+
470+
Here is an example:
471+
472+
.. code:: python
473+
474+
import sagemaker
475+
476+
algo = sagemaker.AlgorithmEstimator(
477+
algorithm_arn='arn:aws:sagemaker:us-west-2:1234567:algorithm/some-algorithm',
478+
role='SageMakerRole',
479+
train_instance_count=1,
480+
train_instance_type='ml.c4.xlarge')
481+
482+
train_input = algo.sagemaker_session.upload_data(path='/path/to/your/data')
483+
484+
algo.fit({'training': train_input})
485+
algo.deploy(1, 'ml.m4.xlarge')
486+
487+
# When you are done using your endpoint
488+
algo.delete_endpoint()
489+
490+
491+
Consuming SageMaker Model Packages
492+
----------------------------------
493+
494+
SageMaker Model Packages are a way to specify and share information for how to create SageMaker Models.
495+
With a SageMaker Model Package that you have created or subscribed to in the AWS Marketplace,
496+
you can use the specified serving image and model data for Endpoints and Batch Transform jobs.
497+
498+
To work with a SageMaker Model Package, use the ``ModelPackage`` class.
499+
500+
Here is an example:
501+
502+
.. code:: python
503+
504+
import sagemaker
505+
506+
model = sagemaker.ModelPackage(
507+
role='SageMakerRole',
508+
model_package_arn='arn:aws:sagemaker:us-west-2:123456:model-package/my-model-package')
509+
model.deploy(1, 'ml.m4.xlarge', endpoint_name='my-endpoint')
510+
511+
# When you are done using your endpoint
512+
model.sagemaker_session.delete_endpoint('my-endpoint')
513+
459514
460515
BYO Docker Containers with SageMaker Estimators
461516
-----------------------------------------------
@@ -470,7 +525,7 @@ Please refer to the full example in the examples repo:
470525
git clone https://github.com/awslabs/amazon-sagemaker-examples.git
471526
472527
473-
The example notebook is is located here:
528+
The example notebook is located here:
474529
``advanced_functionality/scikit_bring_your_own/scikit_bring_your_own.ipynb``
475530
476531

src/sagemaker/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# language governing permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

15-
from sagemaker import estimator # noqa: F401
15+
from sagemaker import estimator, parameter # noqa: F401
1616
from sagemaker.amazon.kmeans import KMeans, KMeansModel, KMeansPredictor # noqa: F401
1717
from sagemaker.amazon.pca import PCA, PCAModel, PCAPredictor # noqa: F401
1818
from sagemaker.amazon.lda import LDA, LDAModel, LDAPredictor # noqa: F401
@@ -26,10 +26,11 @@
2626
from sagemaker.amazon.object2vec import Object2Vec, Object2VecModel # noqa: F401
2727
from sagemaker.amazon.ipinsights import IPInsights, IPInsightsModel, IPInsightsPredictor # noqa: F401
2828

29+
from sagemaker.algorithm import AlgorithmEstimator # noqa: F401
2930
from sagemaker.analytics import TrainingJobAnalytics, HyperparameterTuningJobAnalytics # noqa: F401
3031
from sagemaker.local.local_session import LocalSession # noqa: F401
3132

32-
from sagemaker.model import Model # noqa: F401
33+
from sagemaker.model import Model, ModelPackage # noqa: F401
3334
from sagemaker.pipeline import PipelineModel # noqa: F401
3435
from sagemaker.predictor import RealTimePredictor # noqa: F401
3536
from sagemaker.session import Session # noqa: F401

0 commit comments

Comments
 (0)