From 3a8697071f7c48b0db5b1aa6517cfe70e2a16d19 Mon Sep 17 00:00:00 2001 From: Eric Johnson <65414824+metrizable@users.noreply.github.com> Date: Wed, 29 Jul 2020 21:26:08 -0700 Subject: [PATCH] change: use _framework_name for 'protected' attribute --- src/sagemaker/chainer/estimator.py | 6 +++--- src/sagemaker/chainer/model.py | 6 +++--- src/sagemaker/estimator.py | 4 ++-- src/sagemaker/model.py | 2 +- src/sagemaker/mxnet/estimator.py | 6 +++--- src/sagemaker/mxnet/model.py | 6 +++--- src/sagemaker/pytorch/estimator.py | 6 +++--- src/sagemaker/pytorch/model.py | 6 +++--- src/sagemaker/sklearn/estimator.py | 4 ++-- src/sagemaker/sklearn/model.py | 4 ++-- src/sagemaker/tensorflow/estimator.py | 6 +++--- src/sagemaker/tensorflow/model.py | 4 ++-- src/sagemaker/xgboost/estimator.py | 6 +++--- src/sagemaker/xgboost/model.py | 4 ++-- tests/unit/sagemaker/tensorflow/test_estimator_init.py | 2 +- tests/unit/test_chainer.py | 4 ++-- tests/unit/test_estimator.py | 2 +- tests/unit/test_job.py | 2 +- tests/unit/test_mxnet.py | 4 ++-- tests/unit/test_pytorch.py | 4 ++-- 20 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/sagemaker/chainer/estimator.py b/src/sagemaker/chainer/estimator.py index e435caee1a..16a3a1e833 100644 --- a/src/sagemaker/chainer/estimator.py +++ b/src/sagemaker/chainer/estimator.py @@ -32,7 +32,7 @@ class Chainer(Framework): """Handle end-to-end training and deployment of custom Chainer code.""" - __framework_name__ = "chainer" + _framework_name = "chainer" # Hyperparameters _use_mpi = "sagemaker_use_mpi" @@ -131,7 +131,7 @@ def __init__( validate_version_or_image_args(framework_version, py_version, image_uri) if py_version == "py2": logger.warning( - python_deprecation_warning(self.__framework_name__, defaults.LATEST_PY2_VERSION) + python_deprecation_warning(self._framework_name, defaults.LATEST_PY2_VERSION) ) self.framework_version = framework_version self.py_version = py_version @@ -272,7 +272,7 @@ class constructor init_params["image_uri"] = image_uri return init_params - if framework != cls.__framework_name__: + if framework != cls._framework_name: raise ValueError( "Training job: {} didn't use image for requested framework".format( job_details["TrainingJobName"] diff --git a/src/sagemaker/chainer/model.py b/src/sagemaker/chainer/model.py index 86bbfe623e..48ca779257 100644 --- a/src/sagemaker/chainer/model.py +++ b/src/sagemaker/chainer/model.py @@ -59,7 +59,7 @@ class ChainerModel(FrameworkModel): ``Endpoint``. """ - __framework_name__ = "chainer" + _framework_name = "chainer" def __init__( self, @@ -116,7 +116,7 @@ def __init__( validate_version_or_image_args(framework_version, py_version, image_uri) if py_version == "py2": logger.warning( - python_deprecation_warning(self.__framework_name__, defaults.LATEST_PY2_VERSION) + python_deprecation_warning(self._framework_name, defaults.LATEST_PY2_VERSION) ) self.framework_version = framework_version self.py_version = py_version @@ -176,7 +176,7 @@ def serving_image_uri(self, region_name, instance_type, accelerator_type=None): """ return image_uris.retrieve( - self.__framework_name__, + self._framework_name, region_name, version=self.framework_version, py_version=self.py_version, diff --git a/src/sagemaker/estimator.py b/src/sagemaker/estimator.py index a107e27bf2..bb865268a2 100644 --- a/src/sagemaker/estimator.py +++ b/src/sagemaker/estimator.py @@ -1418,7 +1418,7 @@ class Framework(EstimatorBase): such as training/deployment images and predictor instances. """ - __framework_name__ = None + _framework_name = None LAUNCH_PS_ENV_NAME = "sagemaker_parameter_server_enabled" LAUNCH_MPI_ENV_NAME = "sagemaker_mpi_enabled" @@ -1816,7 +1816,7 @@ def train_image(self): if self.image_uri: return self.image_uri return image_uris.retrieve( - self.__framework_name__, + self._framework_name, self.sagemaker_session.boto_region_name, instance_type=self.instance_type, version=self.framework_version, # pylint: disable=no-member diff --git a/src/sagemaker/model.py b/src/sagemaker/model.py index 618b6baa68..286732a2f9 100644 --- a/src/sagemaker/model.py +++ b/src/sagemaker/model.py @@ -184,7 +184,7 @@ def _set_model_name_if_needed(self): def _framework(self): """Placeholder docstring""" - return getattr(self, "__framework_name__", None) + return getattr(self, "_framework_name", None) def _get_framework_version(self): """Placeholder docstring""" diff --git a/src/sagemaker/mxnet/estimator.py b/src/sagemaker/mxnet/estimator.py index 6e03308dcd..99932c569a 100644 --- a/src/sagemaker/mxnet/estimator.py +++ b/src/sagemaker/mxnet/estimator.py @@ -34,7 +34,7 @@ class MXNet(Framework): """Handle end-to-end training and deployment of custom MXNet code.""" - __framework_name__ = "mxnet" + _framework_name = "mxnet" _LOWEST_SCRIPT_MODE_VERSION = ["1", "3"] def __init__( @@ -114,7 +114,7 @@ def __init__( validate_version_or_image_args(framework_version, py_version, image_uri) if py_version == "py2": logger.warning( - python_deprecation_warning(self.__framework_name__, defaults.LATEST_PY2_VERSION) + python_deprecation_warning(self._framework_name, defaults.LATEST_PY2_VERSION) ) self.framework_version = framework_version self.py_version = py_version @@ -280,7 +280,7 @@ class constructor init_params["image_uri"] = image_uri return init_params - if framework != cls.__framework_name__: + if framework != cls._framework_name: raise ValueError( "Training job: {} didn't use image for requested framework".format( job_details["TrainingJobName"] diff --git a/src/sagemaker/mxnet/model.py b/src/sagemaker/mxnet/model.py index 402c68b7b5..2cc57d0d83 100644 --- a/src/sagemaker/mxnet/model.py +++ b/src/sagemaker/mxnet/model.py @@ -59,7 +59,7 @@ def __init__(self, endpoint_name, sagemaker_session=None): class MXNetModel(FrameworkModel): """An MXNet SageMaker ``Model`` that can be deployed to a SageMaker ``Endpoint``.""" - __framework_name__ = "mxnet" + _framework_name = "mxnet" _LOWEST_MMS_VERSION = "1.4.0" def __init__( @@ -119,7 +119,7 @@ def __init__( validate_version_or_image_args(framework_version, py_version, image_uri) if py_version == "py2": logger.warning( - python_deprecation_warning(self.__framework_name__, defaults.LATEST_PY2_VERSION) + python_deprecation_warning(self._framework_name, defaults.LATEST_PY2_VERSION) ) self.framework_version = framework_version self.py_version = py_version @@ -184,7 +184,7 @@ def serving_image_uri(self, region_name, instance_type, accelerator_type=None): """ return image_uris.retrieve( - self.__framework_name__, + self._framework_name, region_name, version=self.framework_version, py_version=self.py_version, diff --git a/src/sagemaker/pytorch/estimator.py b/src/sagemaker/pytorch/estimator.py index 4451fef0e2..39282e63d7 100644 --- a/src/sagemaker/pytorch/estimator.py +++ b/src/sagemaker/pytorch/estimator.py @@ -33,7 +33,7 @@ class PyTorch(Framework): """Handle end-to-end training and deployment of custom PyTorch code.""" - __framework_name__ = "pytorch" + _framework_name = "pytorch" def __init__( self, @@ -109,7 +109,7 @@ def __init__( validate_version_or_image_args(framework_version, py_version, image_uri) if py_version == "py2": logger.warning( - python_deprecation_warning(self.__framework_name__, defaults.LATEST_PY2_VERSION) + python_deprecation_warning(self._framework_name, defaults.LATEST_PY2_VERSION) ) self.framework_version = framework_version self.py_version = py_version @@ -221,7 +221,7 @@ class constructor init_params["image_uri"] = image_uri return init_params - if framework != cls.__framework_name__: + if framework != cls._framework_name: raise ValueError( "Training job: {} didn't use image for requested framework".format( job_details["TrainingJobName"] diff --git a/src/sagemaker/pytorch/model.py b/src/sagemaker/pytorch/model.py index cbd9b53000..ca49d5fca9 100644 --- a/src/sagemaker/pytorch/model.py +++ b/src/sagemaker/pytorch/model.py @@ -60,7 +60,7 @@ class PyTorchModel(FrameworkModel): ``Endpoint``. """ - __framework_name__ = "pytorch" + _framework_name = "pytorch" _LOWEST_MMS_VERSION = "1.2" def __init__( @@ -118,7 +118,7 @@ def __init__( validate_version_or_image_args(framework_version, py_version, image_uri) if py_version == "py2": logger.warning( - python_deprecation_warning(self.__framework_name__, defaults.LATEST_PY2_VERSION) + python_deprecation_warning(self._framework_name, defaults.LATEST_PY2_VERSION) ) self.framework_version = framework_version self.py_version = py_version @@ -183,7 +183,7 @@ def serving_image_uri(self, region_name, instance_type, accelerator_type=None): """ return image_uris.retrieve( - self.__framework_name__, + self._framework_name, region_name, version=self.framework_version, py_version=self.py_version, diff --git a/src/sagemaker/sklearn/estimator.py b/src/sagemaker/sklearn/estimator.py index 66a4e25e27..7ab5da6f36 100644 --- a/src/sagemaker/sklearn/estimator.py +++ b/src/sagemaker/sklearn/estimator.py @@ -32,7 +32,7 @@ class SKLearn(Framework): """Handle end-to-end training and deployment of custom Scikit-learn code.""" - __framework_name__ = defaults.SKLEARN_NAME + _framework_name = defaults.SKLEARN_NAME def __init__( self, @@ -138,7 +138,7 @@ def __init__( if image_uri is None: self.image_uri = image_uris.retrieve( - SKLearn.__framework_name__, + SKLearn._framework_name, self.sagemaker_session.boto_region_name, version=self.framework_version, py_version=self.py_version, diff --git a/src/sagemaker/sklearn/model.py b/src/sagemaker/sklearn/model.py index 7597e7bd53..2a505fe924 100644 --- a/src/sagemaker/sklearn/model.py +++ b/src/sagemaker/sklearn/model.py @@ -55,7 +55,7 @@ class SKLearnModel(FrameworkModel): ``Endpoint``. """ - __framework_name__ = defaults.SKLEARN_NAME + _framework_name = defaults.SKLEARN_NAME def __init__( self, @@ -175,7 +175,7 @@ def serving_image_uri(self, region_name, instance_type): """ return image_uris.retrieve( - self.__framework_name__, + self._framework_name, region_name, version=self.framework_version, py_version=self.py_version, diff --git a/src/sagemaker/tensorflow/estimator.py b/src/sagemaker/tensorflow/estimator.py index 41a8c95ca4..4c640c4ebc 100644 --- a/src/sagemaker/tensorflow/estimator.py +++ b/src/sagemaker/tensorflow/estimator.py @@ -33,7 +33,7 @@ class TensorFlow(Framework): """Handle end-to-end training and deployment of user-provided TensorFlow code.""" - __framework_name__ = "tensorflow" + _framework_name = "tensorflow" _HIGHEST_LEGACY_MODE_ONLY_VERSION = version.Version("1.10.0") _HIGHEST_PYTHON_2_VERSION = version.Version("2.1.0") @@ -116,7 +116,7 @@ def __init__( fw.validate_version_or_image_args(framework_version, py_version, image_uri) if py_version == "py2": logger.warning( - fw.python_deprecation_warning(self.__framework_name__, defaults.LATEST_PY2_VERSION) + fw.python_deprecation_warning(self._framework_name, defaults.LATEST_PY2_VERSION) ) self.framework_version = framework_version self.py_version = py_version @@ -221,7 +221,7 @@ def _prepare_init_params_from_job_description(cls, job_details, model_channel_na if not script_mode: init_params["image_uri"] = image_uri - if framework != cls.__framework_name__: + if framework != cls._framework_name: raise ValueError( "Training job: {} didn't use image for requested framework".format( job_details["TrainingJobName"] diff --git a/src/sagemaker/tensorflow/model.py b/src/sagemaker/tensorflow/model.py index 6e00777f86..c60c8d6bf7 100644 --- a/src/sagemaker/tensorflow/model.py +++ b/src/sagemaker/tensorflow/model.py @@ -121,7 +121,7 @@ def predict(self, data, initial_args=None): class TensorFlowModel(sagemaker.model.FrameworkModel): """A ``FrameworkModel`` implementation for inference with TensorFlow Serving.""" - __framework_name__ = "tensorflow" + _framework_name = "tensorflow" LOG_LEVEL_PARAM_NAME = "SAGEMAKER_TFS_NGINX_LOGLEVEL" LOG_LEVEL_MAP = { logging.DEBUG: "debug", @@ -286,7 +286,7 @@ def _get_image_uri(self, instance_type, accelerator_type=None): return self.image_uri return image_uris.retrieve( - self.__framework_name__, + self._framework_name, self.sagemaker_session.boto_region_name, version=self.framework_version, instance_type=instance_type, diff --git a/src/sagemaker/xgboost/estimator.py b/src/sagemaker/xgboost/estimator.py index 5b13bc95fd..9c32733331 100644 --- a/src/sagemaker/xgboost/estimator.py +++ b/src/sagemaker/xgboost/estimator.py @@ -34,7 +34,7 @@ class XGBoost(Framework): """Handle end-to-end training and deployment of XGBoost booster training or training using customer provided XGBoost entry point script.""" - __framework_name__ = defaults.XGBOOST_NAME + _framework_name = defaults.XGBOOST_NAME def __init__( self, @@ -103,7 +103,7 @@ def __init__( if image_uri is None: self.image_uri = image_uris.retrieve( - self.__framework_name__, + self._framework_name, self.sagemaker_session.boto_region_name, version=framework_version, py_version=self.py_version, @@ -252,7 +252,7 @@ def _prepare_init_params_from_job_description(cls, job_details, model_channel_na framework, py_version, tag, _ = framework_name_from_image(image_uri) init_params["py_version"] = py_version - if framework and framework != cls.__framework_name__: + if framework and framework != cls._framework_name: raise ValueError( "Training job: {} didn't use image for requested framework".format( job_details["TrainingJobName"] diff --git a/src/sagemaker/xgboost/model.py b/src/sagemaker/xgboost/model.py index 0c1cfcc0a9..44868b4d07 100644 --- a/src/sagemaker/xgboost/model.py +++ b/src/sagemaker/xgboost/model.py @@ -51,7 +51,7 @@ def __init__(self, endpoint_name, sagemaker_session=None): class XGBoostModel(FrameworkModel): """An XGBoost SageMaker ``Model`` that can be deployed to a SageMaker ``Endpoint``.""" - __framework_name__ = XGBOOST_NAME + _framework_name = XGBOOST_NAME def __init__( self, @@ -144,7 +144,7 @@ def serving_image_uri(self, region_name, instance_type): str: The appropriate image URI based on the given parameters. """ return image_uris.retrieve( - self.__framework_name__, + self._framework_name, region_name, version=self.framework_version, py_version=self.py_version, diff --git a/tests/unit/sagemaker/tensorflow/test_estimator_init.py b/tests/unit/sagemaker/tensorflow/test_estimator_init.py index fb77868fd7..84a82d4b36 100644 --- a/tests/unit/sagemaker/tensorflow/test_estimator_init.py +++ b/tests/unit/sagemaker/tensorflow/test_estimator_init.py @@ -65,7 +65,7 @@ def test_py2_version_is_not_deprecated(sagemaker_session): def test_framework_name(sagemaker_session): tf = _build_tf(sagemaker_session, framework_version="1.15.2", py_version="py3") - assert tf.__framework_name__ == "tensorflow" + assert tf._framework_name == "tensorflow" def test_enable_sm_metrics(sagemaker_session): diff --git a/tests/unit/test_chainer.py b/tests/unit/test_chainer.py index 5d5a763335..7a26d5216e 100644 --- a/tests/unit/test_chainer.py +++ b/tests/unit/test_chainer.py @@ -561,7 +561,7 @@ def test_estimator_py2_warning(warning, sagemaker_session, chainer_version): ) assert estimator.py_version == "py2" - warning.assert_called_with(estimator.__framework_name__, defaults.LATEST_PY2_VERSION) + warning.assert_called_with(estimator._framework_name, defaults.LATEST_PY2_VERSION) @patch("sagemaker.chainer.model.python_deprecation_warning") @@ -575,4 +575,4 @@ def test_model_py2_warning(warning, sagemaker_session, chainer_version): py_version="py2", ) assert model.py_version == "py2" - warning.assert_called_with(model.__framework_name__, defaults.LATEST_PY2_VERSION) + warning.assert_called_with(model._framework_name, defaults.LATEST_PY2_VERSION) diff --git a/tests/unit/test_estimator.py b/tests/unit/test_estimator.py index 0671195634..9796a6d63b 100644 --- a/tests/unit/test_estimator.py +++ b/tests/unit/test_estimator.py @@ -107,7 +107,7 @@ class DummyFramework(Framework): - __framework_name__ = "dummy" + _framework_name = "dummy" def train_image(self): return IMAGE_URI diff --git a/tests/unit/test_job.py b/tests/unit/test_job.py index 6d76f7636f..20a0561bb6 100644 --- a/tests/unit/test_job.py +++ b/tests/unit/test_job.py @@ -81,7 +81,7 @@ def sagemaker_session(): class DummyFramework(Framework): - __framework_name__ = "dummy" + _framework_name = "dummy" def train_image(self): return IMAGE_NAME diff --git a/tests/unit/test_mxnet.py b/tests/unit/test_mxnet.py index f59d8d8543..94a08caac2 100644 --- a/tests/unit/test_mxnet.py +++ b/tests/unit/test_mxnet.py @@ -715,7 +715,7 @@ def test_estimator_py2_warning(warning, sagemaker_session): ) assert estimator.py_version == "py2" - warning.assert_called_with(estimator.__framework_name__, defaults.LATEST_PY2_VERSION) + warning.assert_called_with(estimator._framework_name, defaults.LATEST_PY2_VERSION) @patch("sagemaker.mxnet.model.python_deprecation_warning") @@ -729,7 +729,7 @@ def test_model_py2_warning(warning, sagemaker_session): sagemaker_session=sagemaker_session, ) assert model.py_version == "py2" - warning.assert_called_with(model.__framework_name__, defaults.LATEST_PY2_VERSION) + warning.assert_called_with(model._framework_name, defaults.LATEST_PY2_VERSION) def test_create_model_with_custom_hosting_image(sagemaker_session): diff --git a/tests/unit/test_pytorch.py b/tests/unit/test_pytorch.py index 8a77a9edbd..202b06633b 100644 --- a/tests/unit/test_pytorch.py +++ b/tests/unit/test_pytorch.py @@ -553,7 +553,7 @@ def test_estimator_py2_warning(warning, sagemaker_session, pytorch_training_vers ) assert estimator.py_version == "py2" - warning.assert_called_with(estimator.__framework_name__, defaults.LATEST_PY2_VERSION) + warning.assert_called_with(estimator._framework_name, defaults.LATEST_PY2_VERSION) @patch("sagemaker.pytorch.model.python_deprecation_warning") @@ -567,7 +567,7 @@ def test_model_py2_warning(warning, sagemaker_session, pytorch_inference_version py_version="py2", ) assert model.py_version == "py2" - warning.assert_called_with(model.__framework_name__, defaults.LATEST_PY2_VERSION) + warning.assert_called_with(model._framework_name, defaults.LATEST_PY2_VERSION) def test_pt_enable_sm_metrics(