Skip to content

Commit 00b4b48

Browse files
committed
Merge remote-tracking branch 'aws/zwei' into require-framework-version
2 parents 032789c + 18e402c commit 00b4b48

File tree

8 files changed

+123
-29
lines changed

8 files changed

+123
-29
lines changed

doc/frameworks/tensorflow/upgrade_from_legacy.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Upgrade from Legacy TensorFlow Support
33
######################################
44

5-
With v2 of the SageMaker Python SDK, support for legacy SageMaker TensorFlow images has been deprecated.
5+
With version 2.0 and later of the SageMaker Python SDK, support for legacy SageMaker TensorFlow images has been deprecated.
66
This guide explains how to upgrade your SageMaker Python SDK usage.
77

88
For more information about using TensorFlow with the SageMaker Python SDK, see `Use TensorFlow with the SageMaker Python SDK <using_tf.html>`_.
@@ -67,13 +67,13 @@ For more information about implementing your own handlers, see `How to implement
6767
Continue with Legacy Versions
6868
*****************************
6969

70-
While not recommended, you can still use a legacy TensorFlow version with v2 of the SageMaker Python SDK.
70+
While not recommended, you can still use a legacy TensorFlow version with version 2.0 and later of the SageMaker Python SDK.
7171
In order to do so, you need to change how a few parameters are defined.
7272

7373
Training
7474
========
7575

76-
When creating an estimator, v2 requires the following changes:
76+
When creating an estimator, the Python SDK version 2.0 and later requires the following changes:
7777

7878
#. Explicitly specify the ECR image URI via ``image_name``.
7979
To determine the URI, you can use :func:`sagemaker.fw_utils.create_image_uri`.
@@ -87,7 +87,7 @@ the difference in code would be as follows:
8787
8888
from sagemaker.tensorflow import TensorFlow
8989
90-
# v1
90+
# v1.x
9191
estimator = TensorFlow(
9292
...
9393
source_dir="code",
@@ -99,7 +99,7 @@ the difference in code would be as follows:
9999
requirements_file="requirements.txt",
100100
)
101101
102-
# v2
102+
# v2.0 and later
103103
estimator = TensorFlow(
104104
...
105105
source_dir="code",
@@ -123,7 +123,7 @@ To provide a requirements file, define a hyperparameter named "sagemaker_require
123123
Inference
124124
=========
125125

126-
Using a legacy TensorFlow version for endpoints and batch transform can be achieved with v2 of the SageMaker Python SDK with some minor changes to your code.
126+
Using a legacy TensorFlow version for endpoints and batch transform can be achieved with version 2.0 and later of the SageMaker Python SDK with some minor changes to your code.
127127

128128
From an Estimator
129129
-----------------
@@ -134,16 +134,16 @@ To specify the number of model server workers, you need to set it through an env
134134

135135
.. code:: python
136136
137-
# v1
137+
# v1.x
138138
estimator.deploy(..., model_server_workers=4)
139139
140-
# v2
140+
# v2.0 and later
141141
estimator.deploy(..., env={"MODEL_SERVER_WORKERS": 4})
142142
143143
From a Trained Model
144144
--------------------
145145

146-
If you are starting with a trained model, v2 requires the following changes:
146+
If you are starting with a trained model, the Python SDK version 2.0 and later requires the following changes:
147147

148148
#. Use the the :class:`sagemaker.model.FrameworkModel` class.
149149
#. Explicitly specify the ECR image URI via ``image``.
@@ -155,7 +155,7 @@ the difference in code would be as follows:
155155

156156
.. code:: python
157157
158-
# v1
158+
# v1.x
159159
from sagemaker.tensorflow import TensorFlowModel
160160
161161
model = TensorFlowModel(
@@ -165,7 +165,7 @@ the difference in code would be as follows:
165165
model_server_workers=4,
166166
)
167167
168-
# v2
168+
# v2.0 and later
169169
from sagemaker.model import FrameworkModel
170170
171171
model = FrameworkModel(

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Overview
2020
:maxdepth: 2
2121

2222
overview
23+
v2
2324

2425
The SageMaker Python SDK APIs:
2526

doc/v2.rst

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.
7+
8+
.. contents::
9+
:local:
10+
11+
************
12+
Installation
13+
************
14+
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+
25+
26+
To install the latest version of v2:
27+
28+
.. code:: bash
29+
30+
pip install [email protected]:aws/sagemaker-python-sdk.git@zwei
31+
32+
If you are executing this pip install command in a notebook, make sure to restart your kernel.
33+
34+
*******
35+
Changes
36+
*******
37+
38+
To see what changes have been made, see the `CHANGELOG <https://github.com/aws/sagemaker-python-sdk/blob/zwei/CHANGELOG.md>`_.
39+
40+
*******************************
41+
Automatically Upgrade Your Code
42+
*******************************
43+
44+
To help make your transition as seamless as possible, v2 of the SageMaker Python SDK comes with a command-line tool to automate updating your code.
45+
It automates as much as possible, but there are still syntactical and stylistic changes that cannot be performed by the script.
46+
47+
.. warning::
48+
While the tool is intended to be easy to use, we recommend using it as part of a process that includes testing before and after you run the tool.
49+
50+
Usage
51+
=====
52+
53+
Currently, the tool supports only converting one file at a time:
54+
55+
.. code::
56+
57+
$ sagemaker-upgrade-v2 --in-file input.py --out-file output.py
58+
$ sagemaker-upgrade-v2 --in-file input.ipynb --out-file output.ipynb
59+
60+
You can apply it to a set of files using a loop:
61+
62+
.. code:: bash
63+
64+
$ for file in $(find input-dir); do sagemaker-upgrade-v2 --in-file $file --out-file output-dir/$file; done
65+
66+
Limitations
67+
===========
68+
69+
Aliased Imports
70+
---------------
71+
72+
The tool checks for a limited number of patterns when looking for constructors.
73+
For example, if you are using a TensorFlow estimator, only the following invocation styles are handled:
74+
75+
.. code:: python
76+
77+
TensorFlow()
78+
sagemaker.tensorflow.TensorFlow()
79+
sagemaker.tensorflow.estimator.TensorFlow()
80+
81+
If you have aliased an import, e.g. ``from sagemaker.tensorflow import TensorFlow as TF``, the tool does not take care of updating its parameters.
82+
83+
TensorFlow Serving
84+
------------------
85+
86+
If you are using the ``sagemaker.tensorflow.serving.Model`` class, the tool does not take care of adding a framework version or changing it to ``sagemaker.tensorflow.TensorFlowModel``.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""Tools to assist with upgrading to v2 of the SageMaker Python SDK."""
13+
"""Tools to assist with upgrading to version 2.0 and later of the SageMaker Python SDK."""
1414
from __future__ import absolute_import

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FileUpdater(object):
3030

3131
def __init__(self, input_path, output_path):
3232
"""Creates a ``FileUpdater`` for updating a file so that
33-
it is compatible with v2 of the SageMaker Python SDK.
33+
it is compatible with version 2.0 and later of the SageMaker Python SDK.
3434
3535
Args:
3636
input_path (str): Location of the input file.
@@ -44,8 +44,8 @@ def __init__(self, input_path, output_path):
4444
@abstractmethod
4545
def update(self):
4646
"""Reads the input file, updates the code so that it is
47-
compatible with v2 of the SageMaker Python SDK, and writes the
48-
updated code to an output file.
47+
compatible with version 2.0 and later of the SageMaker Python SDK,
48+
and writes the updated code to an output file.
4949
"""
5050

5151
def _make_output_dirs_if_needed(self):
@@ -66,21 +66,22 @@ class PyFileUpdater(FileUpdater):
6666

6767
def update(self):
6868
"""Reads the input Python file, updates the code so that it is
69-
compatible with v2 of the SageMaker Python SDK, and writes the
70-
updated code to an output file.
69+
compatible with version 2.0 and later of the SageMaker Python SDK,
70+
and writes the updated code to an output file.
7171
"""
7272
output = self._update_ast(self._read_input_file())
7373
self._write_output_file(output)
7474

7575
def _update_ast(self, input_ast):
7676
"""Updates an abstract syntax tree (AST) so that it is compatible
77-
with v2 of the SageMaker Python SDK.
77+
with version 2.0 and later of the SageMaker Python SDK.
7878
7979
Args:
80-
input_ast (ast.Module): AST to be updated for use with Python SDK v2.
80+
input_ast (ast.Module): AST to be updated for use with
81+
the Python SDK version 2.0 and later.
8182
8283
Returns:
83-
ast.Module: Updated AST that is compatible with Python SDK v2.
84+
ast.Module: Updated AST that is compatible with the Python SDK version 2.0 and later.
8485
"""
8586
return ASTTransformer().visit(input_ast)
8687

@@ -115,7 +116,7 @@ class JupyterNotebookFileUpdater(FileUpdater):
115116

116117
def update(self):
117118
"""Reads the input Jupyter notebook file, updates the code so that it is
118-
compatible with v2 of the SageMaker Python SDK, and writes the
119+
compatible with version 2.0 and later of the SageMaker Python SDK, and writes the
119120
updated code to an output file.
120121
"""
121122
nb_json = self._read_input_file()
@@ -128,7 +129,7 @@ def update(self):
128129

129130
def _update_code_from_cell(self, cell):
130131
"""Updates the code from a code cell so that it is
131-
compatible with v2 of the SageMaker Python SDK.
132+
compatible with version 2.0 and later of the SageMaker Python SDK.
132133
133134
Args:
134135
cell (dict): A dictionary representation of a code cell from

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""Classes to modify TensorFlow legacy mode code to be compatible with SageMaker Python SDK v2."""
13+
"""Classes to modify TensorFlow legacy mode code to be compatible
14+
with version 2.0 and later of the SageMaker Python SDK.
15+
"""
1416
from __future__ import absolute_import
1517

1618
import ast

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""Classes to modify TensorFlow Serving code to be compatible with SageMaker Python SDK v2."""
13+
"""Classes to modify TensorFlow Serving code to be compatible
14+
with version 2.0 and later of the SageMaker Python SDK.
15+
"""
1416
from __future__ import absolute_import
1517

1618
import ast
@@ -57,7 +59,8 @@ def node_should_be_modified(self, node):
5759
)
5860

5961
def modify_node(self, node):
60-
"""Modifies the ``ast.Call`` node to use the v2 classes for TensorFlow Serving:
62+
"""Modifies the ``ast.Call`` node to use the classes for TensorFlow Serving available in
63+
version 2.0 and later of the Python SDK:
6164
6265
- ``sagemaker.tensorflow.TensorFlowModel``
6366
- ``sagemaker.tensorflow.TensorFlowPredictor``
@@ -72,7 +75,7 @@ def modify_node(self, node):
7275
node.func.value = node.func.value.value
7376

7477
def _new_cls_name(self, cls_name):
75-
"""Returns the v2 class name."""
78+
"""Returns the updated class name."""
7679
return "TensorFlow{}".format(cls_name)
7780

7881

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""A tool to upgrade SageMaker Python SDK code to be compatible with v2."""
13+
"""A tool to upgrade SageMaker Python SDK code to be compatible with version 2.0 and later."""
1414
from __future__ import absolute_import
1515

1616
import argparse
@@ -22,7 +22,7 @@
2222

2323

2424
def _update_file(input_file, output_file):
25-
"""Updates a file to be compatible with v2 of the SageMaker Python SDK,
25+
"""Updates a file to be compatible with version 2.0 and later of the SageMaker Python SDK,
2626
and write the updated source to the output file.
2727
2828
Args:
@@ -53,7 +53,8 @@ def _update_file(input_file, output_file):
5353
def _parse_args():
5454
"""Parses CLI arguments."""
5555
parser = argparse.ArgumentParser(
56-
description="A tool to convert files to be compatible with v2 of the SageMaker Python SDK. "
56+
description="A tool to convert files to be compatible with "
57+
"version 2.0 and later of the SageMaker Python SDK. "
5758
"Simple usage: sagemaker-upgrade-v2 --in-file foo.py --out-file bar.py"
5859
)
5960
parser.add_argument(

0 commit comments

Comments
 (0)