Skip to content

Commit 5dee4e4

Browse files
authored
breaking: rename image_name to image_uri (#1667)
1 parent 7342cc7 commit 5dee4e4

32 files changed

+276
-280
lines changed

src/sagemaker/chainer/estimator.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(
5151
hyperparameters=None,
5252
framework_version=None,
5353
py_version=None,
54-
image_name=None,
54+
image_uri=None,
5555
**kwargs
5656
):
5757
"""This ``Estimator`` executes an Chainer script in a managed Chainer
@@ -101,13 +101,13 @@ def __init__(
101101
and values, but ``str()`` will be called to convert them before
102102
training.
103103
py_version (str): Python version you want to use for executing your
104-
model training code. Defaults to ``None``. Required unless ``image_name``
104+
model training code. Defaults to ``None``. Required unless ``image_uri``
105105
is provided.
106106
framework_version (str): Chainer version you want to use for
107107
executing your model training code. Defaults to ``None``. Required unless
108-
``image_name`` is provided. List of supported versions:
108+
``image_uri`` is provided. List of supported versions:
109109
https://github.com/aws/sagemaker-python-sdk#chainer-sagemaker-estimators.
110-
image_name (str): If specified, the estimator will use this image
110+
image_uri (str): If specified, the estimator will use this image
111111
for training and hosting, instead of selecting the appropriate
112112
SageMaker official image based on framework_version and
113113
py_version. It can be an ECR url or dockerhub image and tag.
@@ -117,7 +117,7 @@ def __init__(
117117
* ``custom-image:latest``
118118
119119
If ``framework_version`` or ``py_version`` are ``None``, then
120-
``image_name`` is required. If also ``None``, then a ``ValueError``
120+
``image_uri`` is required. If also ``None``, then a ``ValueError``
121121
will be raised.
122122
**kwargs: Additional kwargs passed to the
123123
:class:`~sagemaker.estimator.Framework` constructor.
@@ -128,7 +128,7 @@ def __init__(
128128
:class:`~sagemaker.estimator.Framework` and
129129
:class:`~sagemaker.estimator.EstimatorBase`.
130130
"""
131-
validate_version_or_image_args(framework_version, py_version, image_name)
131+
validate_version_or_image_args(framework_version, py_version, image_uri)
132132
if py_version == "py2":
133133
logger.warning(
134134
python_deprecation_warning(self.__framework_name__, defaults.LATEST_PY2_VERSION)
@@ -137,7 +137,7 @@ def __init__(
137137
self.py_version = py_version
138138

139139
super(Chainer, self).__init__(
140-
entry_point, source_dir, hyperparameters, image_name=image_name, **kwargs
140+
entry_point, source_dir, hyperparameters, image_uri=image_uri, **kwargs
141141
)
142142

143143
self.use_mpi = use_mpi
@@ -209,7 +209,7 @@ def create_model(
209209
kwargs["name"] = self._get_or_create_name(kwargs.get("name"))
210210

211211
if "image" not in kwargs:
212-
kwargs["image"] = self.image_name
212+
kwargs["image"] = self.image_uri
213213

214214
return ChainerModel(
215215
self.model_data,
@@ -257,8 +257,8 @@ class constructor
257257
if value:
258258
init_params[argument[len("sagemaker_") :]] = value
259259

260-
image_name = init_params.pop("image")
261-
framework, py_version, tag, _ = framework_name_from_image(image_name)
260+
image_uri = init_params.pop("image")
261+
framework, py_version, tag, _ = framework_name_from_image(image_uri)
262262

263263
if tag is None:
264264
framework_version = None
@@ -270,7 +270,7 @@ class constructor
270270
if not framework:
271271
# If we were unable to parse the framework name from the image it is not one of our
272272
# officially supported images, in this case just add the image to the init params.
273-
init_params["image_name"] = image_name
273+
init_params["image_uri"] = image_uri
274274
return init_params
275275

276276
if framework != cls.__framework_name__:

src/sagemaker/estimator.py

+12-16
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
UploadedCode,
4040
validate_source_dir,
4141
_region_supports_debugger,
42-
parameter_v2_rename_warning,
4342
)
4443
from sagemaker.job import _Job
4544
from sagemaker.local import LocalSession
@@ -1131,7 +1130,7 @@ class Estimator(EstimatorBase):
11311130

11321131
def __init__(
11331132
self,
1134-
image_name,
1133+
image_uri,
11351134
role,
11361135
train_instance_count,
11371136
train_instance_type,
@@ -1164,7 +1163,7 @@ def __init__(
11641163
"""Initialize an ``Estimator`` instance.
11651164
11661165
Args:
1167-
image_name (str): The container image to use for training.
1166+
image_uri (str): The container image to use for training.
11681167
role (str): An AWS IAM role (either name or full ARN). The Amazon
11691168
SageMaker training jobs and APIs that create Amazon SageMaker
11701169
endpoints use this role to access training data and model
@@ -1273,8 +1272,7 @@ def __init__(
12731272
https://docs.aws.amazon.com/sagemaker/latest/dg/API_AlgorithmSpecification.html#SageMaker-Type-AlgorithmSpecification-EnableSageMakerMetricsTimeSeries
12741273
(default: ``None``).
12751274
"""
1276-
logging.warning(parameter_v2_rename_warning("image_name", "image_uri"))
1277-
self.image_name = image_name
1275+
self.image_uri = image_uri
12781276
self.hyperparam_dict = hyperparameters.copy() if hyperparameters else {}
12791277
super(Estimator, self).__init__(
12801278
role,
@@ -1312,7 +1310,7 @@ def train_image(self):
13121310
The fit() method, that does the model training, calls this method to
13131311
find the image to use for model training.
13141312
"""
1315-
return self.image_name
1313+
return self.image_uri
13161314

13171315
def set_hyperparameters(self, **kwargs):
13181316
"""
@@ -1422,7 +1420,7 @@ class constructor
14221420
job_details, model_channel_name
14231421
)
14241422

1425-
init_params["image_name"] = init_params.pop("image")
1423+
init_params["image_uri"] = init_params.pop("image")
14261424
return init_params
14271425

14281426

@@ -1449,7 +1447,7 @@ def __init__(
14491447
enable_cloudwatch_metrics=False,
14501448
container_log_level=logging.INFO,
14511449
code_location=None,
1452-
image_name=None,
1450+
image_uri=None,
14531451
dependencies=None,
14541452
enable_network_isolation=False,
14551453
git_config=None,
@@ -1515,7 +1513,7 @@ def __init__(
15151513
a string prepended with a "/" is appended to ``code_location``. The code
15161514
file uploaded to S3 is 'code_location/job-name/source/sourcedir.tar.gz'.
15171515
If not specified, the default ``code location`` is s3://output_bucket/job-name/.
1518-
image_name (str): An alternate image name to use instead of the
1516+
image_uri (str): An alternate image name to use instead of the
15191517
official Sagemaker image for the framework. This is useful to
15201518
run one of the Sagemaker supported frameworks with an image
15211519
containing custom dependencies.
@@ -1635,6 +1633,8 @@ def __init__(
16351633
self.git_config = git_config
16361634
self.source_dir = source_dir
16371635
self.dependencies = dependencies or []
1636+
self.uploaded_code = None
1637+
16381638
if enable_cloudwatch_metrics:
16391639
warnings.warn(
16401640
"enable_cloudwatch_metrics is now deprecated and will be removed in the future.",
@@ -1643,11 +1643,7 @@ def __init__(
16431643
self.enable_cloudwatch_metrics = False
16441644
self.container_log_level = container_log_level
16451645
self.code_location = code_location
1646-
self.image_name = image_name
1647-
if image_name is not None:
1648-
logging.warning(parameter_v2_rename_warning("image_name", "image_uri"))
1649-
1650-
self.uploaded_code = None
1646+
self.image_uri = image_uri
16511647

16521648
self._hyperparameters = hyperparameters or {}
16531649
self.checkpoint_s3_uri = checkpoint_s3_uri
@@ -1833,8 +1829,8 @@ def train_image(self):
18331829
Returns:
18341830
str: The URI of the Docker image.
18351831
"""
1836-
if self.image_name:
1837-
return self.image_name
1832+
if self.image_uri:
1833+
return self.image_uri
18381834
return create_image_uri(
18391835
self.sagemaker_session.boto_region_name,
18401836
self.__framework_name__,

src/sagemaker/fw_utils.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,11 @@ def _list_files_to_compress(script, directory):
490490
return [os.path.join(basedir, name) for name in os.listdir(basedir)]
491491

492492

493-
def framework_name_from_image(image_name):
493+
def framework_name_from_image(image_uri):
494494
# noinspection LongLine
495495
"""Extract the framework and Python version from the image name.
496496
Args:
497-
image_name (str): Image URI, which should be one of the following forms:
497+
image_uri (str): Image URI, which should be one of the following forms:
498498
legacy:
499499
'<account>.dkr.ecr.<region>.amazonaws.com/sagemaker-<fw>-<py_ver>-<device>:<container_version>'
500500
legacy:
@@ -509,7 +509,7 @@ def framework_name_from_image(image_name):
509509
str: If the image is script mode
510510
"""
511511
sagemaker_pattern = re.compile(ECR_URI_PATTERN)
512-
sagemaker_match = sagemaker_pattern.match(image_name)
512+
sagemaker_match = sagemaker_pattern.match(image_uri)
513513
if sagemaker_match is None:
514514
return None, None, None, None
515515
# extract framework, python version and image tag
@@ -691,22 +691,22 @@ def _region_supports_debugger(region_name):
691691
return region_name.lower() not in DEBUGGER_UNSUPPORTED_REGIONS
692692

693693

694-
def validate_version_or_image_args(framework_version, py_version, image_name):
694+
def validate_version_or_image_args(framework_version, py_version, image_uri):
695695
"""Checks if version or image arguments are specified.
696696
697697
Validates framework and model arguments to enforce version or image specification.
698698
699699
Args:
700700
framework_version (str): The version of the framework.
701701
py_version (str): The version of Python.
702-
image_name (str): The URI of the image.
702+
image_uri (str): The URI of the image.
703703
704704
Raises:
705-
ValueError: if `image_name` is None and either `framework_version` or `py_version` is
705+
ValueError: if `image_uri` is None and either `framework_version` or `py_version` is
706706
None.
707707
"""
708-
if (framework_version is None or py_version is None) and image_name is None:
708+
if (framework_version is None or py_version is None) and image_uri is None:
709709
raise ValueError(
710-
"framework_version or py_version was None, yet image_name was also None. "
711-
"Either specify both framework_version and py_version, or specify image_name."
710+
"framework_version or py_version was None, yet image_uri was also None. "
711+
"Either specify both framework_version and py_version, or specify image_uri."
712712
)

src/sagemaker/mxnet/estimator.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(
4444
py_version=None,
4545
source_dir=None,
4646
hyperparameters=None,
47-
image_name=None,
47+
image_uri=None,
4848
distribution=None,
4949
**kwargs
5050
):
@@ -72,11 +72,11 @@ def __init__(
7272
must point to a file located at the root of ``source_dir``.
7373
framework_version (str): MXNet version you want to use for executing
7474
your model training code. Defaults to `None`. Required unless
75-
``image_name`` is provided. List of supported versions.
75+
``image_uri`` is provided. List of supported versions.
7676
https://github.com/aws/sagemaker-python-sdk#mxnet-sagemaker-estimators.
7777
py_version (str): Python version you want to use for executing your
7878
model training code. One of 'py2' or 'py3'. Defaults to ``None``. Required
79-
unless ``image_name`` is provided.
79+
unless ``image_uri`` is provided.
8080
source_dir (str): Path (absolute, relative or an S3 URI) to a directory
8181
with any other training source code dependencies aside from the entry
8282
point file (default: None). If ``source_dir`` is an S3 URI, it must
@@ -88,7 +88,7 @@ def __init__(
8888
SageMaker. For convenience, this accepts other types for keys
8989
and values, but ``str()`` will be called to convert them before
9090
training.
91-
image_name (str): If specified, the estimator will use this image for training and
91+
image_uri (str): If specified, the estimator will use this image for training and
9292
hosting, instead of selecting the appropriate SageMaker official image based on
9393
framework_version and py_version. It can be an ECR url or dockerhub image and tag.
9494
@@ -97,7 +97,7 @@ def __init__(
9797
* ``custom-image:latest``
9898
9999
If ``framework_version`` or ``py_version`` are ``None``, then
100-
``image_name`` is required. If also ``None``, then a ``ValueError``
100+
``image_uri`` is required. If also ``None``, then a ``ValueError``
101101
will be raised.
102102
distribution (dict): A dictionary with information on how to run distributed
103103
training (default: None). To have parameter servers launched for training,
@@ -111,7 +111,7 @@ def __init__(
111111
:class:`~sagemaker.estimator.Framework` and
112112
:class:`~sagemaker.estimator.EstimatorBase`.
113113
"""
114-
validate_version_or_image_args(framework_version, py_version, image_name)
114+
validate_version_or_image_args(framework_version, py_version, image_uri)
115115
if py_version == "py2":
116116
logger.warning(
117117
python_deprecation_warning(self.__framework_name__, defaults.LATEST_PY2_VERSION)
@@ -127,7 +127,7 @@ def __init__(
127127
kwargs["enable_sagemaker_metrics"] = True
128128

129129
super(MXNet, self).__init__(
130-
entry_point, source_dir, hyperparameters, image_name=image_name, **kwargs
130+
entry_point, source_dir, hyperparameters, image_uri=image_uri, **kwargs
131131
)
132132

133133
if distribution is not None:
@@ -168,7 +168,7 @@ def create_model(
168168
entry_point=None,
169169
source_dir=None,
170170
dependencies=None,
171-
image_name=None,
171+
image_uri=None,
172172
**kwargs
173173
):
174174
"""Create a SageMaker ``MXNetModel`` object that can be deployed to an
@@ -198,7 +198,7 @@ def create_model(
198198
any additional libraries that will be exported to the container.
199199
If not specified, the dependencies from training are used.
200200
This is not supported with "local code" in Local Mode.
201-
image_name (str): If specified, the estimator will use this image for hosting, instead
201+
image_uri (str): If specified, the estimator will use this image for hosting, instead
202202
of selecting the appropriate SageMaker official image based on framework_version
203203
and py_version. It can be an ECR url or dockerhub image and tag.
204204
@@ -214,7 +214,7 @@ def create_model(
214214
See :func:`~sagemaker.mxnet.model.MXNetModel` for full details.
215215
"""
216216
if "image" not in kwargs:
217-
kwargs["image"] = image_name or self.image_name
217+
kwargs["image"] = image_uri or self.image_uri
218218

219219
kwargs["name"] = self._get_or_create_name(kwargs.get("name"))
220220

@@ -252,8 +252,8 @@ class constructor
252252
init_params = super(MXNet, cls)._prepare_init_params_from_job_description(
253253
job_details, model_channel_name
254254
)
255-
image_name = init_params.pop("image")
256-
framework, py_version, tag, _ = framework_name_from_image(image_name)
255+
image_uri = init_params.pop("image")
256+
framework, py_version, tag, _ = framework_name_from_image(image_uri)
257257

258258
# We switched image tagging scheme from regular image version (e.g. '1.0') to more
259259
# expressive containing framework version, device type and python version
@@ -271,7 +271,7 @@ class constructor
271271
if not framework:
272272
# If we were unable to parse the framework name from the image it is not one of our
273273
# officially supported images, in this case just add the image to the init params.
274-
init_params["image_name"] = image_name
274+
init_params["image_uri"] = image_uri
275275
return init_params
276276

277277
if framework != cls.__framework_name__:

0 commit comments

Comments
 (0)