Skip to content

Commit 886294a

Browse files
authored
Merge branch 'zwei' into trains
2 parents 1bdc780 + 0d06276 commit 886294a

37 files changed

+1561
-530
lines changed

doc/api/utility/image_uris.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Image URIs
2+
----------
3+
4+
.. automodule:: sagemaker.image_uris
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

doc/frameworks/tensorflow/upgrade_from_legacy.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ For example, if you want to use JSON serialization and deserialization:
248248
from sagemaker.deserializers import JSONDeserializer
249249
from sagemaker.serializers import JSONSerializer
250250
251-
predictor.serializer = JSONSerializer()
252-
predictor.deserializer = JSONDeserializer()
251+
predictor = model.deploy(..., serializer=JSONSerializer(), deserializer=JSONDeserializer())
253252
254253
predictor.predict(data)

doc/frameworks/xgboost/using_xgboost.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,14 @@ inference against your model.
192192

193193
.. code::
194194
195+
serializer = StringSerializer()
196+
serializer.CONTENT_TYPE = "text/libsvm"
197+
195198
predictor = estimator.deploy(
196199
initial_instance_count=1,
197-
instance_type="ml.m5.xlarge"
200+
instance_type="ml.m5.xlarge",
201+
serializer=serializer
198202
)
199-
predictor.serializer = str
200-
predictor.content_type = "text/libsvm"
201203
202204
with open("abalone") as f:
203205
payload = f.read()

doc/index.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. important::
2-
We are working on v2.0.0. See https://github.com/aws/sagemaker-python-sdk/issues/1459
3-
for more info on our plans and to leave feedback!
4-
51
###########################
62
Amazon SageMaker Python SDK
73
###########################

doc/v2.rst

Lines changed: 90 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
1-
##########################################################
2-
Use Version 2.0 of the SageMaker Python SDK (experimental)
3-
##########################################################
4-
5-
Development on v2.0.0 of the SageMaker Python SDK is underway.
6-
For more info on our plans, see https://github.com/aws/sagemaker-python-sdk/issues/1459.
1+
###########################################
2+
Use Version 2.x of the SageMaker Python SDK
3+
###########################################
74

85
.. contents::
96
:local:
7+
:depth: 2
108

119
************
1210
Installation
1311
************
1412

15-
.. warning::
16-
Version 2.0.0 is currently experimental, so proceed with caution. If you do run into issues or have any other feedback,
17-
please let us know by `opening an issue <https://github.com/aws/sagemaker-python-sdk/issues/new/choose>`_
18-
or `commenting on our planning issue <https://github.com/aws/sagemaker-python-sdk/issues/1459>`_.
19-
20-
To install the latest release candidate:
21-
22-
.. code:: bash
23-
24-
pip install git+git://github.com/aws/[email protected]
25-
26-
To install the latest version of v2:
13+
To install the latest version:
2714

2815
.. code:: bash
2916
30-
pip install git+git://github.com/aws/sagemaker-python-sdk.git@zwei
17+
pip install --upgrade sagemaker
3118
3219
If you are executing this pip install command in a notebook, make sure to restart your kernel.
3320

34-
*******
35-
Changes
36-
*******
21+
****************
22+
Breaking Changes
23+
****************
3724

3825
This section is for major changes that may require updates to your SageMaker Python SDK code.
39-
You can also see what changes have been made in the `CHANGELOG <https://github.com/aws/sagemaker-python-sdk/blob/zwei/CHANGELOG.md>`_.
26+
For the full list of changes, see the `CHANGELOG <https://github.com/aws/sagemaker-python-sdk/blob/master/CHANGELOG.md>`_.
4027

4128
Deprecations
4229
============
@@ -94,6 +81,13 @@ Please instantiate the objects instead.
9481
The ``update_endpoint`` argument in ``deploy()`` methods for estimators and models has been deprecated.
9582
Please use :func:`sagemaker.predictor.Predictor.update_endpoint` instead.
9683

84+
``serializer`` and ``deserializer`` in ``create_model()``
85+
---------------------------------------------------------
86+
87+
The ``serializer`` and ``deserializer`` arguments in
88+
:func:`sagemaker.estimator.Estimator.create_model` have been deprecated. Please
89+
specify serializers and deserializers in ``deploy()`` methods instead.
90+
9791
``content_type`` and ``accept`` in the Predictor Constructor
9892
------------------------------------------------------------
9993

@@ -127,8 +121,46 @@ write MIME types as a string,
127121
| ``CONTENT_TYPE_NPY`` | ``"application/x-npy"`` |
128122
+-------------------------------+--------------------------------+
129123

124+
Image URI Functions (e.g. ``get_image_uri``)
125+
--------------------------------------------
126+
127+
The following functions have been deprecated in favor of :func:`sagemaker.image_uris.retrieve`:
128+
129+
- ``sagemaker.amazon_estimator.get_image_uri()``
130+
- ``sagemaker.fw_utils.create_image_uri()``
131+
- ``sagemaker.fw_registry.registry()``
132+
- ``sagemaker.utils.get_ecr_image_uri_prefix()``
133+
134+
For more information about usage, see :func:`sagemaker.image_uris.retrieve`.
135+
136+
SageMaker Python SDK CLI
137+
------------------------
138+
139+
The SageMaker Python SDK CLI has been deprecated.
140+
(This is different from the AWS CLI.)
141+
142+
``enable_cloudwatch_metrics`` for Estimators and Models
143+
-------------------------------------------------------
144+
145+
The parameter ``enable_cloudwatch_metrics`` has been deprecated.
146+
CloudWatch metrics are already emitted for all Training Jobs, etc.
147+
148+
``sagemaker.fw_utils.parse_s3_url``
149+
-----------------------------------
150+
151+
The ``sagemaker.fw_utils.parse_s3_url`` function has been deprecated.
152+
Please use :func:`sagemaker.s3.parse_s3_url` instead.
153+
154+
``sagemaker.session.ModelContainer``
155+
------------------------------------
156+
157+
The class ``sagemaker.session.ModelContainer`` has been deprecated, as it is not needed for creating inference pipelines.
158+
159+
Changes in Default Behavior
160+
===========================
161+
130162
Require ``framework_version`` and ``py_version`` for Frameworks
131-
===============================================================
163+
---------------------------------------------------------------
132164

133165
Framework estimator and model classes now require ``framework_version`` and ``py_version`` instead of supplying defaults,
134166
unless an image URI is explicitly supplied.
@@ -158,6 +190,25 @@ For example:
158190
py_version="py3", # now required
159191
)
160192
193+
Log Display Behavior with ``attach()``
194+
--------------------------------------
195+
196+
Logs are no longer printed when using ``attach()`` with an estimator.
197+
To view logs after attaching a training job to an estimator, use :func:`sagemaker.estimator.EstimatorBase.logs`.
198+
199+
``HyperparameterTuner.fit()`` and ``Transformer.transform()``
200+
-------------------------------------------------------------
201+
202+
:func:`sagemaker.tuner.HyperparameterTuner.fit` and :func:`sagemaker.transformer.Transformer.transform` now wait
203+
until the completion of the Hyperparameter Tuning Job or Batch Transform Job, respectively.
204+
To make the function non-blocking, use ``wait=False``.
205+
206+
XGBoost Predictor
207+
-----------------
208+
209+
The default serializer of ``sagemaker.xgboost.model.XGBoostPredictor`` has been changed from ``NumpySerializer`` to ``LibSVMSerializer``.
210+
211+
161212
Parameter and Class Name Changes
162213
================================
163214

@@ -218,6 +269,8 @@ The follow serializer/deserializer classes have been renamed and/or moved:
218269
| ``sagemaker.predictor._JsonDeserializer`` | ``sagemaker.deserializers.JSONDeserializer`` |
219270
+--------------------------------------------------------+-------------------------------------------------------+
220271

272+
``sagemaker.serializers.LibSVMSerializer`` has been added in v2.0.
273+
221274
``distributions``
222275
~~~~~~~~~~~~~~~~~
223276

@@ -281,6 +334,19 @@ TensorFlow Serving Predictor
281334
(For the previous implementation of that class, see `Deprecate Legacy TensorFlow <#deprecate-legacy-tensorflow>`_).
282335

283336

337+
Inputs
338+
------
339+
340+
``s3_input``
341+
~~~~~~~~~~~~
342+
343+
``sagemaker.session.s3_input`` has been renamed to :class:`sagemaker.inputs.TrainingInput`.
344+
345+
``ShuffleConfig``
346+
~~~~~~~~~~~~~~~~~
347+
348+
``sagemaker.session.ShuffleConfig`` has been renamed to :class:`sagemaker.inputs.ShuffleConfig`.
349+
284350
Airflow
285351
-------
286352

src/sagemaker/automl/automl.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ def deploy(
337337
self,
338338
initial_instance_count,
339339
instance_type,
340+
serializer=None,
341+
deserializer=None,
340342
candidate=None,
341343
sagemaker_session=None,
342344
name=None,
@@ -356,6 +358,16 @@ def deploy(
356358
in the ``Endpoint`` created from this ``Model``.
357359
instance_type (str): The EC2 instance type to deploy this Model to.
358360
For example, 'ml.p2.xlarge'.
361+
serializer (:class:`~sagemaker.serializers.BaseSerializer`): A
362+
serializer object, used to encode data for an inference endpoint
363+
(default: None). If ``serializer`` is not None, then
364+
``serializer`` will override the default serializer. The
365+
default serializer is set by the ``predictor_cls``.
366+
deserializer (:class:`~sagemaker.deserializers.BaseDeserializer`): A
367+
deserializer object, used to decode data from an inference
368+
endpoint (default: None). If ``deserializer`` is not None, then
369+
``deserializer`` will override the default deserializer. The
370+
default deserializer is set by the ``predictor_cls``.
359371
candidate (CandidateEstimator or dict): a CandidateEstimator used for deploying
360372
to a SageMaker Inference Pipeline. If None, the best candidate will
361373
be used. If the candidate input is a dict, a CandidateEstimator will be
@@ -405,6 +417,8 @@ def deploy(
405417
return model.deploy(
406418
initial_instance_count=initial_instance_count,
407419
instance_type=instance_type,
420+
serializer=serializer,
421+
deserializer=deserializer,
408422
endpoint_name=endpoint_name,
409423
tags=tags,
410424
wait=wait,

src/sagemaker/cli/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying athis file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Tools for automating code updates"""
14+
from __future__ import absolute_import

src/sagemaker/cli/compatibility/v2/ast_transformer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
modifiers.renamed_params.SessionCreateEndpointImageURIRenamer(),
3636
modifiers.training_params.TrainPrefixRemover(),
3737
modifiers.training_input.TrainingInputConstructorRefactor(),
38+
modifiers.training_input.ShuffleConfigModuleRenamer(),
3839
modifiers.serde.SerdeConstructorRenamer(),
3940
]
4041

@@ -51,6 +52,7 @@
5152
modifiers.predictors.PredictorImportFromRenamer(),
5253
modifiers.tfs.TensorFlowServingImportFromRenamer(),
5354
modifiers.training_input.TrainingInputImportFromRenamer(),
55+
modifiers.training_input.ShuffleConfigImportFromRenamer(),
5456
modifiers.serde.SerdeImportFromAmazonCommonRenamer(),
5557
modifiers.serde.SerdeImportFromPredictorRenamer(),
5658
]

src/sagemaker/cli/compatibility/v2/modifiers/training_input.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,73 @@ def modify_node(self, node):
100100
if node.module == "sagemaker.session":
101101
node.module = "sagemaker.inputs"
102102
return node
103+
104+
105+
class ShuffleConfigModuleRenamer(Modifier):
106+
"""A class to change ``ShuffleConfig`` usage to use ``sagemaker.inputs.ShuffleConfig``."""
107+
108+
def node_should_be_modified(self, node):
109+
"""Checks if the ``ast.Call`` node instantiates a class of interest.
110+
111+
This looks for the following calls:
112+
113+
- ``sagemaker.session.ShuffleConfig``
114+
- ``session.ShuffleConfig``
115+
116+
Args:
117+
node (ast.Call): a node that represents a function call. For more,
118+
see https://docs.python.org/3/library/ast.html#abstract-grammar.
119+
120+
Returns:
121+
bool: If the ``ast.Call`` instantiates a class of interest.
122+
"""
123+
if isinstance(node.func, ast.Name):
124+
return False
125+
126+
return matching.matches_name_or_namespaces(
127+
node, "ShuffleConfig", ("sagemaker.session", "session")
128+
)
129+
130+
def modify_node(self, node):
131+
"""Modifies the ``ast.Call`` node to call ``sagemaker.inputs.ShuffleConfig``.
132+
133+
Args:
134+
node (ast.Call): a node that represents a ``sagemaker.session.ShuffleConfig``
135+
constructor.
136+
137+
Returns:
138+
ast.Call: the original node, with its namespace changed to use the ``inputs`` module.
139+
"""
140+
_rename_namespace(node, "session")
141+
return node
142+
143+
144+
class ShuffleConfigImportFromRenamer(Modifier):
145+
"""A class to update import statements of ``ShuffleConfig``."""
146+
147+
def node_should_be_modified(self, node):
148+
"""Checks if the import statement imports ``sagemaker.session.ShuffleConfig``.
149+
150+
Args:
151+
node (ast.ImportFrom): a node that represents a ``from ... import ... `` statement.
152+
For more, see https://docs.python.org/3/library/ast.html#abstract-grammar.
153+
154+
Returns:
155+
bool: If the import statement imports ``sagemaker.session.ShuffleConfig``.
156+
"""
157+
return node.module == "sagemaker.session" and any(
158+
name.name == "ShuffleConfig" for name in node.names
159+
)
160+
161+
def modify_node(self, node):
162+
"""Changes the ``ast.ImportFrom`` node's namespace to ``sagemaker.inputs``.
163+
164+
Args:
165+
node (ast.ImportFrom): a node that represents a ``from ... import ... `` statement.
166+
For more, see https://docs.python.org/3/library/ast.html#abstract-grammar.
167+
168+
Returns:
169+
ast.ImportFrom: the original node, with its module modified to ``"sagemaker.inputs"``.
170+
"""
171+
node.module = "sagemaker.inputs"
172+
return node

0 commit comments

Comments
 (0)