Use Version 2.0 of the SageMaker Python SDK (experimental)

Development on v2.0.0 of the SageMaker Python SDK is underway. For more info on our plans, see https://github.com/aws/sagemaker-python-sdk/issues/1459.

Installation

Warning

Version 2.0.0 is currently experimental, so proceed with caution. If you do run into issues or have any other feedback, please let us know by opening an issue or commenting on our planning issue.

To install the latest release candidate:

pip install git+git@github.com:aws/sagemaker-python-sdk.git@v2.0.0.rc0

To install the latest version of v2:

pip install git+git@github.com:aws/sagemaker-python-sdk.git@zwei

If you are executing this pip install command in a notebook, make sure to restart your kernel.

Changes

This section is for major changes that may require updates to your SageMaker Python SDK code. You can also see what changes have been made in the CHANGELOG.

Require framework_version and py_version for Frameworks

Framework estimator and model classes now require framework_version and py_version instead of supplying defaults, unless an image URI is explicitly supplied.

For example:

from sagemaker.tensorflow import TensorFlow

TensorFlow(
    entry_point="script.py",
    framework_version="2.2.0",  # now required
    py_version="py37",  # now required
    role="my-role",
    train_instance_type="ml.m5.xlarge",
    train_instance_count=1,
)

from sagemaker.mxnet import MXNetModel

MXNetModel(
    model_data="s3://bucket/model.tar.gz",
    role="my-role",
    entry_point="inference.py",
    framework_version="1.6.0",  # now required
    py_version="py3",  # now required
)

Deprecate Legacy TensorFlow

TensorFlow versions 1.4-1.10 and some variations of versions 1.11-1.12 (see What Constitutes “Legacy TensorFlow Support”) are no longer natively supported by the SageMaker Python SDK.

To use those versions of TensorFlow, you must specify the Docker image URI explicitly, and configure settings via hyperparameters or environment variables rather than using SDK parameters. For more information, see Upgrade from Legacy TensorFlow Support.

Parameter Changes for sagemaker.model.Model

The parameter order for sagemaker.model.Model changed: instead of model_data being first, image now is first. As a result, model_data has now been made into an optional parameter.

If you are using the sagemaker.model.Model class, your code should be changed as follows:

# v1.x
Model("s3://bucket/path/model.tar.gz", "my-image:latest")

# v2.0 and later
Model("my-image:latest", model_data="s3://bucket/path/model.tar.gz")

Dependency Changes

SciPy

SciPy is no longer a required dependency of the SageMaker Python SDK.

If you use sagemaker.amazon.common.write_spmatrix_to_sparse_tensor() and don’t already install SciPy in your environment, you can use our scipy installation target:

pip install sagemaker[scipy]

TensorFlow

The tensorflow installation target has been removed, as it is no longer needed for any SageMaker Python SDK functionality.

If you want to install TensorFlow, see the TensorFlow documentation.

Automatically Upgrade Your Code

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. It automates as much as possible, but there are still syntactical and stylistic changes that cannot be performed by the script.

Warning

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.

Usage

Currently, the tool supports only converting one file at a time:

$ sagemaker-upgrade-v2 --in-file input.py --out-file output.py
$ sagemaker-upgrade-v2 --in-file input.ipynb --out-file output.ipynb

You can apply it to a set of files using a loop:

$ for file in $(find input-dir); do sagemaker-upgrade-v2 --in-file $file --out-file output-dir/$file; done

Limitations

Aliased Imports

The tool checks for a limited number of patterns when looking for constructors. For example, if you are using a TensorFlow estimator, only the following invocation styles are handled:

TensorFlow()
sagemaker.tensorflow.TensorFlow()
sagemaker.tensorflow.estimator.TensorFlow()

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.

TensorFlow Serving

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.

sagemaker.model.Model

If you are using the sagemaker.model.Model class, the tool does not take care of switching the order between model_data and image.