Skip to content

fix: update py2 warning message since python 2 is deprecated #1224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sagemaker/chainer/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@

LATEST_VERSION = "5.0.0"
"""The latest version of Chainer included in the SageMaker pre-built Docker images."""

LATEST_PY2_VERSION = "5.0.0"
4 changes: 2 additions & 2 deletions src/sagemaker/chainer/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
empty_framework_version_warning,
python_deprecation_warning,
)
from sagemaker.chainer.defaults import CHAINER_VERSION, LATEST_VERSION
from sagemaker.chainer.defaults import CHAINER_VERSION, LATEST_VERSION, LATEST_PY2_VERSION
from sagemaker.chainer.model import ChainerModel
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT

Expand Down Expand Up @@ -134,7 +134,7 @@ def __init__(
)

if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
logger.warning(python_deprecation_warning(self.__framework_name__, LATEST_PY2_VERSION))

self.py_version = py_version
self.use_mpi = use_mpi
Expand Down
5 changes: 3 additions & 2 deletions src/sagemaker/chainer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
empty_framework_version_warning,
)
from sagemaker.model import FrameworkModel, MODEL_SERVER_WORKERS_PARAM_NAME
from sagemaker.chainer.defaults import CHAINER_VERSION, LATEST_VERSION
from sagemaker.chainer.defaults import CHAINER_VERSION, LATEST_VERSION, LATEST_PY2_VERSION
from sagemaker.predictor import RealTimePredictor, npy_serializer, numpy_deserializer

logger = logging.getLogger("sagemaker")
Expand Down Expand Up @@ -111,7 +111,8 @@ def __init__(
model_data, image, role, entry_point, predictor_cls=predictor_cls, **kwargs
)
if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
logger.warning(python_deprecation_warning(self.__framework_name__, LATEST_PY2_VERSION))

if framework_version is None:
logger.warning(empty_framework_version_warning(CHAINER_VERSION, LATEST_VERSION))

Expand Down
11 changes: 7 additions & 4 deletions src/sagemaker/fw_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"please add framework_version={latest} to your constructor."
)
PYTHON_2_DEPRECATION_WARNING = (
"The Python 2 {framework} images will be soon deprecated and may not be "
"supported for newer upcoming versions of the {framework} images.\n"
"{latest_supported_version} is the latest version of {framework} that supports "
"Python 2. Newer versions of {framework} will only be available for Python 3."
"Please set the argument \"py_version='py3'\" to use the Python 3 {framework} image."
)

Expand Down Expand Up @@ -495,9 +495,12 @@ def get_unsupported_framework_version_error(
)


def python_deprecation_warning(framework):
def python_deprecation_warning(framework, latest_supported_version):
"""
Args:
framework:
latest_supported_version:
"""
return PYTHON_2_DEPRECATION_WARNING.format(framework=framework)
return PYTHON_2_DEPRECATION_WARNING.format(
framework=framework, latest_supported_version=latest_supported_version
)
2 changes: 2 additions & 0 deletions src/sagemaker/mxnet/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@

LATEST_VERSION = "1.6.0"
"""The latest version of MXNet included in the SageMaker pre-built Docker images."""

LATEST_PY2_VERSION = "1.6.0"
4 changes: 2 additions & 2 deletions src/sagemaker/mxnet/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
python_deprecation_warning,
is_version_equal_or_higher,
)
from sagemaker.mxnet.defaults import MXNET_VERSION, LATEST_VERSION
from sagemaker.mxnet.defaults import MXNET_VERSION, LATEST_VERSION, LATEST_PY2_VERSION
from sagemaker.mxnet.model import MXNetModel
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT

Expand Down Expand Up @@ -120,7 +120,7 @@ def __init__(
)

if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
logger.warning(python_deprecation_warning(self.__framework_name__, LATEST_PY2_VERSION))

self.py_version = py_version
self._configure_distribution(distributions)
Expand Down
5 changes: 3 additions & 2 deletions src/sagemaker/mxnet/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
empty_framework_version_warning,
)
from sagemaker.model import FrameworkModel, MODEL_SERVER_WORKERS_PARAM_NAME
from sagemaker.mxnet.defaults import MXNET_VERSION, LATEST_VERSION
from sagemaker.mxnet.defaults import MXNET_VERSION, LATEST_VERSION, LATEST_PY2_VERSION
from sagemaker.predictor import RealTimePredictor, json_serializer, json_deserializer

logger = logging.getLogger("sagemaker")
Expand Down Expand Up @@ -113,7 +113,8 @@ def __init__(
)

if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
logger.warning(python_deprecation_warning(self.__framework_name__, LATEST_PY2_VERSION))

if framework_version is None:
logger.warning(empty_framework_version_warning(MXNET_VERSION, LATEST_VERSION))

Expand Down
2 changes: 2 additions & 0 deletions src/sagemaker/pytorch/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
"""The latest version of PyTorch included in the SageMaker pre-built Docker images."""

PYTHON_VERSION = "py3"

LATEST_PY2_VERSION = "1.3.1"
9 changes: 7 additions & 2 deletions src/sagemaker/pytorch/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
python_deprecation_warning,
is_version_equal_or_higher,
)
from sagemaker.pytorch.defaults import PYTORCH_VERSION, PYTHON_VERSION, LATEST_VERSION
from sagemaker.pytorch.defaults import (
PYTORCH_VERSION,
PYTHON_VERSION,
LATEST_VERSION,
LATEST_PY2_VERSION,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at this point it might be worth starting to do from sagemaker.pytorch import defaults instead 😂

from sagemaker.pytorch.model import PyTorchModel
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT

Expand Down Expand Up @@ -116,7 +121,7 @@ def __init__(
)

if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
logger.warning(python_deprecation_warning(self.__framework_name__, LATEST_PY2_VERSION))

self.py_version = py_version

Expand Down
10 changes: 8 additions & 2 deletions src/sagemaker/pytorch/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
empty_framework_version_warning,
)
from sagemaker.model import FrameworkModel, MODEL_SERVER_WORKERS_PARAM_NAME
from sagemaker.pytorch.defaults import PYTORCH_VERSION, PYTHON_VERSION, LATEST_VERSION
from sagemaker.pytorch.defaults import (
PYTORCH_VERSION,
PYTHON_VERSION,
LATEST_VERSION,
LATEST_PY2_VERSION,
)
from sagemaker.predictor import RealTimePredictor, npy_serializer, numpy_deserializer

logger = logging.getLogger("sagemaker")
Expand Down Expand Up @@ -114,7 +119,8 @@ def __init__(
)

if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
logger.warning(python_deprecation_warning(self.__framework_name__, LATEST_PY2_VERSION))

if framework_version is None:
logger.warning(empty_framework_version_warning(PYTORCH_VERSION, LATEST_VERSION))

Expand Down
2 changes: 2 additions & 0 deletions src/sagemaker/sklearn/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
SKLEARN_NAME = "scikit-learn"

SKLEARN_VERSION = "0.20.0"

LATEST_PY2_VERSION = "0.20.0"
4 changes: 2 additions & 2 deletions src/sagemaker/sklearn/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
empty_framework_version_warning,
python_deprecation_warning,
)
from sagemaker.sklearn.defaults import SKLEARN_VERSION, SKLEARN_NAME
from sagemaker.sklearn.defaults import SKLEARN_VERSION, SKLEARN_NAME, LATEST_PY2_VERSION
from sagemaker.sklearn.model import SKLearnModel
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT

Expand Down Expand Up @@ -119,7 +119,7 @@ def __init__(
)

if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
logger.warning(python_deprecation_warning(self.__framework_name__, LATEST_PY2_VERSION))

self.py_version = py_version

Expand Down
4 changes: 2 additions & 2 deletions src/sagemaker/sklearn/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from sagemaker.fw_registry import default_framework_uri
from sagemaker.model import FrameworkModel, MODEL_SERVER_WORKERS_PARAM_NAME
from sagemaker.predictor import RealTimePredictor, npy_serializer, numpy_deserializer
from sagemaker.sklearn.defaults import SKLEARN_VERSION, SKLEARN_NAME
from sagemaker.sklearn.defaults import SKLEARN_VERSION, SKLEARN_NAME, LATEST_PY2_VERSION

logger = logging.getLogger("sagemaker")

Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(
)

if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
logger.warning(python_deprecation_warning(self.__framework_name__, LATEST_PY2_VERSION))

self.py_version = py_version
self.framework_version = framework_version
Expand Down
2 changes: 2 additions & 0 deletions src/sagemaker/tensorflow/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@

LATEST_VERSION = "2.0.0"
"""The latest version of TensorFlow included in the SageMaker pre-built Docker images."""

LATEST_PY2_VERSION = "2.0.0"
11 changes: 6 additions & 5 deletions src/sagemaker/tensorflow/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from sagemaker.debugger import DebuggerHookConfig
from sagemaker.estimator import Framework
import sagemaker.fw_utils as fw
from sagemaker.tensorflow.defaults import TF_VERSION, LATEST_VERSION
from sagemaker.tensorflow.defaults import TF_VERSION, LATEST_VERSION, LATEST_PY2_VERSION
from sagemaker.tensorflow.model import TensorFlowModel
from sagemaker.tensorflow.serving import Model
from sagemaker.transformer import Transformer
Expand Down Expand Up @@ -293,6 +293,10 @@ def __init__(

if not py_version:
py_version = "py3" if self._only_python_3_supported() else "py2"
if py_version == "py2":
logger.warning(
fw.python_deprecation_warning(self.__framework_name__, LATEST_PY2_VERSION)
)

if "enable_sagemaker_metrics" not in kwargs:
# enable sagemaker metrics for TF v1.15 or greater:
Expand All @@ -302,9 +306,6 @@ def __init__(
super(TensorFlow, self).__init__(image_name=image_name, **kwargs)
self.checkpoint_path = checkpoint_path

if py_version == "py2":
logger.warning("tensorflow py2 container will be deprecated soon.")

self.py_version = py_version
self.training_steps = training_steps
self.evaluation_steps = evaluation_steps
Expand Down Expand Up @@ -359,7 +360,7 @@ def _validate_args(

if py_version == "py2" and self._only_python_3_supported():
msg = (
"Python 2 containers are only available until January 1st, 2020. "
"Python 2 containers are only available before January 1st, 2020. "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not strictly true. someone can always use an outdated image if they really want Python 2. why not use the same kind wording as the other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an error message that py2 container is not available at all. If customer is trying to use a py2 container when self._only_python_3_supported()

A revisit of this line makes me think we should just say py2 containers are not available with this framework version instead of saying they are available until Jan 1st.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that sounds good. you could probably also add the latest version that is supported by Python 2 if you want

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"Please use a Python 3 container."
)
raise AttributeError(msg)
Expand Down
5 changes: 3 additions & 2 deletions src/sagemaker/tensorflow/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
from sagemaker.model import FrameworkModel, MODEL_SERVER_WORKERS_PARAM_NAME
from sagemaker.predictor import RealTimePredictor
from sagemaker.tensorflow.defaults import TF_VERSION, LATEST_VERSION
from sagemaker.tensorflow.defaults import TF_VERSION, LATEST_VERSION, LATEST_PY2_VERSION
from sagemaker.tensorflow.predictor import tf_json_serializer, tf_json_deserializer

logger = logging.getLogger("sagemaker")
Expand Down Expand Up @@ -111,7 +111,8 @@ def __init__(
)

if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
logger.warning(python_deprecation_warning(self.__framework_name__, LATEST_PY2_VERSION))

if framework_version is None:
logger.warning(empty_framework_version_warning(TF_VERSION, LATEST_VERSION))

Expand Down
3 changes: 1 addition & 2 deletions src/sagemaker/xgboost/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from sagemaker.fw_utils import (
framework_name_from_image,
framework_version_from_tag,
python_deprecation_warning,
get_unsupported_framework_version_error,
UploadedCode,
)
Expand Down Expand Up @@ -112,7 +111,7 @@ def __init__(
)

if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
raise AttributeError("XGBoost container does not support Python 2, please use Python 3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would happen before when someone tried XGBoost + Python 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They will get errors when Python SDK tries to pull the xgboost py2 image because 1p algorithm team do not release xgboost py2 images.

self.py_version = py_version

if framework_version in XGBOOST_SUPPORTED_VERSIONS:
Expand Down
4 changes: 2 additions & 2 deletions src/sagemaker/xgboost/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import logging

import sagemaker
from sagemaker.fw_utils import model_code_key_prefix, python_deprecation_warning
from sagemaker.fw_utils import model_code_key_prefix
from sagemaker.fw_registry import default_framework_uri
from sagemaker.model import FrameworkModel, MODEL_SERVER_WORKERS_PARAM_NAME
from sagemaker.predictor import RealTimePredictor, npy_serializer, csv_deserializer
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(
)

if py_version == "py2":
logger.warning(python_deprecation_warning(self.__framework_name__))
raise AttributeError("XGBoost container does not support Python 2, please use Python 3")

self.py_version = py_version
self.framework_version = framework_version
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test_chainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,34 @@ def test_attach_custom_image(sagemaker_session):
assert estimator.train_image() == training_image


@patch("sagemaker.chainer.estimator.python_deprecation_warning")
def test_estimator_py2_warning(warning, sagemaker_session):
estimator = Chainer(
entry_point=SCRIPT_PATH,
role=ROLE,
sagemaker_session=sagemaker_session,
train_instance_count=INSTANCE_COUNT,
train_instance_type=INSTANCE_TYPE,
py_version="py2",
)

assert estimator.py_version == "py2"
warning.assert_called_with(estimator.__framework_name__, defaults.LATEST_PY2_VERSION)


@patch("sagemaker.chainer.model.python_deprecation_warning")
def test_model_py2_warning(warning, sagemaker_session):
model = ChainerModel(
MODEL_DATA,
role=ROLE,
entry_point=SCRIPT_PATH,
sagemaker_session=sagemaker_session,
py_version="py2",
)
assert model.py_version == "py2"
warning.assert_called_with(model.__framework_name__, defaults.LATEST_PY2_VERSION)


@patch("sagemaker.chainer.estimator.empty_framework_version_warning")
def test_empty_framework_version(warning, sagemaker_session):
estimator = Chainer(
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test_mxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,34 @@ def test_estimator_wrong_version_launch_parameter_server(sagemaker_session):
assert "The distributions option is valid for only versions 1.3 and higher" in str(e)


@patch("sagemaker.mxnet.estimator.python_deprecation_warning")
def test_estimator_py2_warning(warning, sagemaker_session):
estimator = MXNet(
entry_point=SCRIPT_PATH,
role=ROLE,
sagemaker_session=sagemaker_session,
train_instance_count=INSTANCE_COUNT,
train_instance_type=INSTANCE_TYPE,
py_version="py2",
)

assert estimator.py_version == "py2"
warning.assert_called_with(estimator.__framework_name__, defaults.LATEST_PY2_VERSION)


@patch("sagemaker.mxnet.model.python_deprecation_warning")
def test_model_py2_warning(warning, sagemaker_session):
model = MXNetModel(
MODEL_DATA,
role=ROLE,
entry_point=SCRIPT_PATH,
sagemaker_session=sagemaker_session,
py_version="py2",
)
assert model.py_version == "py2"
warning.assert_called_with(model.__framework_name__, defaults.LATEST_PY2_VERSION)


@patch("sagemaker.mxnet.estimator.empty_framework_version_warning")
def test_empty_framework_version(warning, sagemaker_session):
mx = MXNet(
Expand Down
Loading