From 82adb10313a0dff1c6628df82fbf3b965057e569 Mon Sep 17 00:00:00 2001 From: Lauren Yu <6631887+laurenyu@users.noreply.github.com> Date: Mon, 8 Jun 2020 15:28:02 -0700 Subject: [PATCH 1/2] doc: change "v2" to "version 2.0 or later" --- .../tensorflow/upgrade_from_legacy.rst | 22 +++++++++---------- .../cli/compatibility/v2/__init__.py | 2 +- src/sagemaker/cli/compatibility/v2/files.py | 21 +++++++++--------- .../v2/modifiers/tf_legacy_mode.py | 4 +++- .../cli/compatibility/v2/modifiers/tfs.py | 9 +++++--- .../compatibility/v2/sagemaker_upgrade_v2.py | 7 +++--- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/doc/frameworks/tensorflow/upgrade_from_legacy.rst b/doc/frameworks/tensorflow/upgrade_from_legacy.rst index 7beec18dda..de6c8cd69b 100644 --- a/doc/frameworks/tensorflow/upgrade_from_legacy.rst +++ b/doc/frameworks/tensorflow/upgrade_from_legacy.rst @@ -2,7 +2,7 @@ Upgrade from Legacy TensorFlow Support ###################################### -With v2 of the SageMaker Python SDK, support for legacy SageMaker TensorFlow images has been deprecated. +With version 2.0 or later of the SageMaker Python SDK, support for legacy SageMaker TensorFlow images has been deprecated. This guide explains how to upgrade your SageMaker Python SDK usage. For more information about using TensorFlow with the SageMaker Python SDK, see `Use TensorFlow with the SageMaker Python SDK `_. @@ -67,13 +67,13 @@ For more information about implementing your own handlers, see `How to implement Continue with Legacy Versions ***************************** -While not recommended, you can still use a legacy TensorFlow version with v2 of the SageMaker Python SDK. +While not recommended, you can still use a legacy TensorFlow version with version 2.0 or later of the SageMaker Python SDK. In order to do so, you need to change how a few parameters are defined. Training ======== -When creating an estimator, v2 requires the following changes: +When creating an estimator, the Python SDK version 2.0 or later requires the following changes: #. Explicitly specify the ECR image URI via ``image_name``. 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: from sagemaker.tensorflow import TensorFlow - # v1 + # v1.x estimator = TensorFlow( ... source_dir="code", @@ -99,7 +99,7 @@ the difference in code would be as follows: requirements_file="requirements.txt", ) - # v2 + # v2.0 or later estimator = TensorFlow( ... source_dir="code", @@ -123,7 +123,7 @@ To provide a requirements file, define a hyperparameter named "sagemaker_require Inference ========= -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. +Using a legacy TensorFlow version for endpoints and batch transform can be achieved with version 2.0 or later of the SageMaker Python SDK with some minor changes to your code. From an Estimator ----------------- @@ -134,16 +134,16 @@ To specify the number of model server workers, you need to set it through an env .. code:: python - # v1 + # v1.x estimator.deploy(..., model_server_workers=4) - # v2 + # v2.0 or later estimator.deploy(..., env={"MODEL_SERVER_WORKERS": 4}) From a Trained Model -------------------- -If you are starting with a trained model, v2 requires the following changes: +If you are starting with a trained model, the Python SDK version 2.0 or later requires the following changes: #. Use the the :class:`sagemaker.model.FrameworkModel` class. #. Explicitly specify the ECR image URI via ``image``. @@ -155,7 +155,7 @@ the difference in code would be as follows: .. code:: python - # v1 + # v1.x from sagemaker.tensorflow import TensorFlowModel model = TensorFlowModel( @@ -165,7 +165,7 @@ the difference in code would be as follows: model_server_workers=4, ) - # v2 + # v2.0 or later from sagemaker.model import FrameworkModel model = FrameworkModel( diff --git a/src/sagemaker/cli/compatibility/v2/__init__.py b/src/sagemaker/cli/compatibility/v2/__init__.py index b44e22749e..678f685e79 100644 --- a/src/sagemaker/cli/compatibility/v2/__init__.py +++ b/src/sagemaker/cli/compatibility/v2/__init__.py @@ -10,5 +10,5 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -"""Tools to assist with upgrading to v2 of the SageMaker Python SDK.""" +"""Tools to assist with upgrading to version 2.0 or later of the SageMaker Python SDK.""" from __future__ import absolute_import diff --git a/src/sagemaker/cli/compatibility/v2/files.py b/src/sagemaker/cli/compatibility/v2/files.py index bfed230f98..649839e037 100644 --- a/src/sagemaker/cli/compatibility/v2/files.py +++ b/src/sagemaker/cli/compatibility/v2/files.py @@ -30,7 +30,7 @@ class FileUpdater(object): def __init__(self, input_path, output_path): """Creates a ``FileUpdater`` for updating a file so that - it is compatible with v2 of the SageMaker Python SDK. + it is compatible with version 2.0 or later of the SageMaker Python SDK. Args: input_path (str): Location of the input file. @@ -44,8 +44,8 @@ def __init__(self, input_path, output_path): @abstractmethod def update(self): """Reads the input file, updates the code so that it is - compatible with v2 of the SageMaker Python SDK, and writes the - updated code to an output file. + compatible with version 2.0 or later of the SageMaker Python SDK, + and writes the updated code to an output file. """ def _make_output_dirs_if_needed(self): @@ -66,21 +66,22 @@ class PyFileUpdater(FileUpdater): def update(self): """Reads the input Python file, updates the code so that it is - compatible with v2 of the SageMaker Python SDK, and writes the - updated code to an output file. + compatible with version 2.0 or later of the SageMaker Python SDK, + and writes the updated code to an output file. """ output = self._update_ast(self._read_input_file()) self._write_output_file(output) def _update_ast(self, input_ast): """Updates an abstract syntax tree (AST) so that it is compatible - with v2 of the SageMaker Python SDK. + with version 2.0 or later of the SageMaker Python SDK. Args: - input_ast (ast.Module): AST to be updated for use with Python SDK v2. + input_ast (ast.Module): AST to be updated for use with + the Python SDK version 2.0 or later. Returns: - ast.Module: Updated AST that is compatible with Python SDK v2. + ast.Module: Updated AST that is compatible with the Python SDK version 2.0 or later. """ return ASTTransformer().visit(input_ast) @@ -115,7 +116,7 @@ class JupyterNotebookFileUpdater(FileUpdater): def update(self): """Reads the input Jupyter notebook file, updates the code so that it is - compatible with v2 of the SageMaker Python SDK, and writes the + compatible with version 2.0 or later of the SageMaker Python SDK, and writes the updated code to an output file. """ nb_json = self._read_input_file() @@ -128,7 +129,7 @@ def update(self): def _update_code_from_cell(self, cell): """Updates the code from a code cell so that it is - compatible with v2 of the SageMaker Python SDK. + compatible with version 2.0 or later of the SageMaker Python SDK. Args: cell (dict): A dictionary representation of a code cell from diff --git a/src/sagemaker/cli/compatibility/v2/modifiers/tf_legacy_mode.py b/src/sagemaker/cli/compatibility/v2/modifiers/tf_legacy_mode.py index 554150b253..d94b1a54a4 100644 --- a/src/sagemaker/cli/compatibility/v2/modifiers/tf_legacy_mode.py +++ b/src/sagemaker/cli/compatibility/v2/modifiers/tf_legacy_mode.py @@ -10,7 +10,9 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -"""Classes to modify TensorFlow legacy mode code to be compatible with SageMaker Python SDK v2.""" +"""Classes to modify TensorFlow legacy mode code to be compatible +with version 2.0 or later of the SageMaker Python SDK. +""" from __future__ import absolute_import import ast diff --git a/src/sagemaker/cli/compatibility/v2/modifiers/tfs.py b/src/sagemaker/cli/compatibility/v2/modifiers/tfs.py index 2bf36d6898..857894e262 100644 --- a/src/sagemaker/cli/compatibility/v2/modifiers/tfs.py +++ b/src/sagemaker/cli/compatibility/v2/modifiers/tfs.py @@ -10,7 +10,9 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -"""Classes to modify TensorFlow Serving code to be compatible with SageMaker Python SDK v2.""" +"""Classes to modify TensorFlow Serving code to be compatible +with version 2.0 or later of the SageMaker Python SDK. +""" from __future__ import absolute_import import ast @@ -57,7 +59,8 @@ def node_should_be_modified(self, node): ) def modify_node(self, node): - """Modifies the ``ast.Call`` node to use the v2 classes for TensorFlow Serving: + """Modifies the ``ast.Call`` node to use the classes for TensorFlow Serving available in + version 2.0 or later of the Python SDK: - ``sagemaker.tensorflow.TensorFlowModel`` - ``sagemaker.tensorflow.TensorFlowPredictor`` @@ -72,7 +75,7 @@ def modify_node(self, node): node.func.value = node.func.value.value def _new_cls_name(self, cls_name): - """Returns the v2 class name.""" + """Returns the updated class name.""" return "TensorFlow{}".format(cls_name) diff --git a/src/sagemaker/cli/compatibility/v2/sagemaker_upgrade_v2.py b/src/sagemaker/cli/compatibility/v2/sagemaker_upgrade_v2.py index e00f96cc0b..434d228721 100644 --- a/src/sagemaker/cli/compatibility/v2/sagemaker_upgrade_v2.py +++ b/src/sagemaker/cli/compatibility/v2/sagemaker_upgrade_v2.py @@ -10,7 +10,7 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -"""A tool to upgrade SageMaker Python SDK code to be compatible with v2.""" +"""A tool to upgrade SageMaker Python SDK code to be compatible with version 2.0 or later.""" from __future__ import absolute_import import argparse @@ -22,7 +22,7 @@ def _update_file(input_file, output_file): - """Updates a file to be compatible with v2 of the SageMaker Python SDK, + """Updates a file to be compatible with version 2.0 or later of the SageMaker Python SDK, and write the updated source to the output file. Args: @@ -53,7 +53,8 @@ def _update_file(input_file, output_file): def _parse_args(): """Parses CLI arguments.""" parser = argparse.ArgumentParser( - description="A tool to convert files to be compatible with v2 of the SageMaker Python SDK. " + description="A tool to convert files to be compatible with " + "version 2.0 or later of the SageMaker Python SDK. " "Simple usage: sagemaker-upgrade-v2 --in-file foo.py --out-file bar.py" ) parser.add_argument( From 7156292ed29d89e3a49ac43b4efdb3441fe2d88d Mon Sep 17 00:00:00 2001 From: Lauren Yu <6631887+laurenyu@users.noreply.github.com> Date: Tue, 9 Jun 2020 09:43:20 -0700 Subject: [PATCH 2/2] s/or/and --- .../tensorflow/upgrade_from_legacy.rst | 16 ++++++++-------- src/sagemaker/cli/compatibility/v2/__init__.py | 2 +- src/sagemaker/cli/compatibility/v2/files.py | 16 ++++++++-------- .../compatibility/v2/modifiers/tf_legacy_mode.py | 2 +- .../cli/compatibility/v2/modifiers/tfs.py | 4 ++-- .../cli/compatibility/v2/sagemaker_upgrade_v2.py | 6 +++--- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/doc/frameworks/tensorflow/upgrade_from_legacy.rst b/doc/frameworks/tensorflow/upgrade_from_legacy.rst index de6c8cd69b..7805c9579b 100644 --- a/doc/frameworks/tensorflow/upgrade_from_legacy.rst +++ b/doc/frameworks/tensorflow/upgrade_from_legacy.rst @@ -2,7 +2,7 @@ Upgrade from Legacy TensorFlow Support ###################################### -With version 2.0 or later of the SageMaker Python SDK, support for legacy SageMaker TensorFlow images has been deprecated. +With version 2.0 and later of the SageMaker Python SDK, support for legacy SageMaker TensorFlow images has been deprecated. This guide explains how to upgrade your SageMaker Python SDK usage. For more information about using TensorFlow with the SageMaker Python SDK, see `Use TensorFlow with the SageMaker Python SDK `_. @@ -67,13 +67,13 @@ For more information about implementing your own handlers, see `How to implement Continue with Legacy Versions ***************************** -While not recommended, you can still use a legacy TensorFlow version with version 2.0 or later of the SageMaker Python SDK. +While not recommended, you can still use a legacy TensorFlow version with version 2.0 and later of the SageMaker Python SDK. In order to do so, you need to change how a few parameters are defined. Training ======== -When creating an estimator, the Python SDK version 2.0 or later requires the following changes: +When creating an estimator, the Python SDK version 2.0 and later requires the following changes: #. Explicitly specify the ECR image URI via ``image_name``. To determine the URI, you can use :func:`sagemaker.fw_utils.create_image_uri`. @@ -99,7 +99,7 @@ the difference in code would be as follows: requirements_file="requirements.txt", ) - # v2.0 or later + # v2.0 and later estimator = TensorFlow( ... source_dir="code", @@ -123,7 +123,7 @@ To provide a requirements file, define a hyperparameter named "sagemaker_require Inference ========= -Using a legacy TensorFlow version for endpoints and batch transform can be achieved with version 2.0 or later of the SageMaker Python SDK with some minor changes to your code. +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. From an Estimator ----------------- @@ -137,13 +137,13 @@ To specify the number of model server workers, you need to set it through an env # v1.x estimator.deploy(..., model_server_workers=4) - # v2.0 or later + # v2.0 and later estimator.deploy(..., env={"MODEL_SERVER_WORKERS": 4}) From a Trained Model -------------------- -If you are starting with a trained model, the Python SDK version 2.0 or later requires the following changes: +If you are starting with a trained model, the Python SDK version 2.0 and later requires the following changes: #. Use the the :class:`sagemaker.model.FrameworkModel` class. #. Explicitly specify the ECR image URI via ``image``. @@ -165,7 +165,7 @@ the difference in code would be as follows: model_server_workers=4, ) - # v2.0 or later + # v2.0 and later from sagemaker.model import FrameworkModel model = FrameworkModel( diff --git a/src/sagemaker/cli/compatibility/v2/__init__.py b/src/sagemaker/cli/compatibility/v2/__init__.py index 678f685e79..a19ed16295 100644 --- a/src/sagemaker/cli/compatibility/v2/__init__.py +++ b/src/sagemaker/cli/compatibility/v2/__init__.py @@ -10,5 +10,5 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -"""Tools to assist with upgrading to version 2.0 or later of the SageMaker Python SDK.""" +"""Tools to assist with upgrading to version 2.0 and later of the SageMaker Python SDK.""" from __future__ import absolute_import diff --git a/src/sagemaker/cli/compatibility/v2/files.py b/src/sagemaker/cli/compatibility/v2/files.py index 649839e037..35b436f1af 100644 --- a/src/sagemaker/cli/compatibility/v2/files.py +++ b/src/sagemaker/cli/compatibility/v2/files.py @@ -30,7 +30,7 @@ class FileUpdater(object): def __init__(self, input_path, output_path): """Creates a ``FileUpdater`` for updating a file so that - it is compatible with version 2.0 or later of the SageMaker Python SDK. + it is compatible with version 2.0 and later of the SageMaker Python SDK. Args: input_path (str): Location of the input file. @@ -44,7 +44,7 @@ def __init__(self, input_path, output_path): @abstractmethod def update(self): """Reads the input file, updates the code so that it is - compatible with version 2.0 or later of the SageMaker Python SDK, + compatible with version 2.0 and later of the SageMaker Python SDK, and writes the updated code to an output file. """ @@ -66,7 +66,7 @@ class PyFileUpdater(FileUpdater): def update(self): """Reads the input Python file, updates the code so that it is - compatible with version 2.0 or later of the SageMaker Python SDK, + compatible with version 2.0 and later of the SageMaker Python SDK, and writes the updated code to an output file. """ output = self._update_ast(self._read_input_file()) @@ -74,14 +74,14 @@ def update(self): def _update_ast(self, input_ast): """Updates an abstract syntax tree (AST) so that it is compatible - with version 2.0 or later of the SageMaker Python SDK. + with version 2.0 and later of the SageMaker Python SDK. Args: input_ast (ast.Module): AST to be updated for use with - the Python SDK version 2.0 or later. + the Python SDK version 2.0 and later. Returns: - ast.Module: Updated AST that is compatible with the Python SDK version 2.0 or later. + ast.Module: Updated AST that is compatible with the Python SDK version 2.0 and later. """ return ASTTransformer().visit(input_ast) @@ -116,7 +116,7 @@ class JupyterNotebookFileUpdater(FileUpdater): def update(self): """Reads the input Jupyter notebook file, updates the code so that it is - compatible with version 2.0 or later of the SageMaker Python SDK, and writes the + compatible with version 2.0 and later of the SageMaker Python SDK, and writes the updated code to an output file. """ nb_json = self._read_input_file() @@ -129,7 +129,7 @@ def update(self): def _update_code_from_cell(self, cell): """Updates the code from a code cell so that it is - compatible with version 2.0 or later of the SageMaker Python SDK. + compatible with version 2.0 and later of the SageMaker Python SDK. Args: cell (dict): A dictionary representation of a code cell from diff --git a/src/sagemaker/cli/compatibility/v2/modifiers/tf_legacy_mode.py b/src/sagemaker/cli/compatibility/v2/modifiers/tf_legacy_mode.py index d94b1a54a4..77dc0f1286 100644 --- a/src/sagemaker/cli/compatibility/v2/modifiers/tf_legacy_mode.py +++ b/src/sagemaker/cli/compatibility/v2/modifiers/tf_legacy_mode.py @@ -11,7 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. """Classes to modify TensorFlow legacy mode code to be compatible -with version 2.0 or later of the SageMaker Python SDK. +with version 2.0 and later of the SageMaker Python SDK. """ from __future__ import absolute_import diff --git a/src/sagemaker/cli/compatibility/v2/modifiers/tfs.py b/src/sagemaker/cli/compatibility/v2/modifiers/tfs.py index 857894e262..9a98d0de6e 100644 --- a/src/sagemaker/cli/compatibility/v2/modifiers/tfs.py +++ b/src/sagemaker/cli/compatibility/v2/modifiers/tfs.py @@ -11,7 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. """Classes to modify TensorFlow Serving code to be compatible -with version 2.0 or later of the SageMaker Python SDK. +with version 2.0 and later of the SageMaker Python SDK. """ from __future__ import absolute_import @@ -60,7 +60,7 @@ def node_should_be_modified(self, node): def modify_node(self, node): """Modifies the ``ast.Call`` node to use the classes for TensorFlow Serving available in - version 2.0 or later of the Python SDK: + version 2.0 and later of the Python SDK: - ``sagemaker.tensorflow.TensorFlowModel`` - ``sagemaker.tensorflow.TensorFlowPredictor`` diff --git a/src/sagemaker/cli/compatibility/v2/sagemaker_upgrade_v2.py b/src/sagemaker/cli/compatibility/v2/sagemaker_upgrade_v2.py index 434d228721..e72fc8226f 100644 --- a/src/sagemaker/cli/compatibility/v2/sagemaker_upgrade_v2.py +++ b/src/sagemaker/cli/compatibility/v2/sagemaker_upgrade_v2.py @@ -10,7 +10,7 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -"""A tool to upgrade SageMaker Python SDK code to be compatible with version 2.0 or later.""" +"""A tool to upgrade SageMaker Python SDK code to be compatible with version 2.0 and later.""" from __future__ import absolute_import import argparse @@ -22,7 +22,7 @@ def _update_file(input_file, output_file): - """Updates a file to be compatible with version 2.0 or later of the SageMaker Python SDK, + """Updates a file to be compatible with version 2.0 and later of the SageMaker Python SDK, and write the updated source to the output file. Args: @@ -54,7 +54,7 @@ def _parse_args(): """Parses CLI arguments.""" parser = argparse.ArgumentParser( description="A tool to convert files to be compatible with " - "version 2.0 or later of the SageMaker Python SDK. " + "version 2.0 and later of the SageMaker Python SDK. " "Simple usage: sagemaker-upgrade-v2 --in-file foo.py --out-file bar.py" ) parser.add_argument(