28
28
29
29
UploadedCode = namedtuple ("UserCode" , ["s3_prefix" , "script_name" ])
30
30
"""sagemaker.fw_utils.UserCode: An object containing the S3 prefix and script name.
31
-
32
31
This is for the source code used for the entry point with an ``Estimator``. It can be
33
32
instantiated with positional or keyword arguments.
34
33
"""
54
53
VALID_PY_VERSIONS = ["py2" , "py3" ]
55
54
VALID_EIA_FRAMEWORKS = ["tensorflow" , "tensorflow-serving" , "mxnet" , "mxnet-serving" ]
56
55
VALID_ACCOUNTS_BY_REGION = {"us-gov-west-1" : "246785580436" , "us-iso-east-1" : "744548109606" }
56
+ OPT_IN_ACCOUNTS_BY_REGION = {"ap-east-1" : "057415533634" }
57
+ ASIMOV_OPT_IN_ACCOUNTS_BY_REGION = {"ap-east-1" : "871362719292" }
57
58
58
59
MERGED_FRAMEWORKS_REPO_MAP = {
59
60
"tensorflow-scriptmode" : "tensorflow-training" ,
73
74
def is_version_equal_or_higher (lowest_version , framework_version ):
74
75
"""Determine whether the ``framework_version`` is equal to or higher than
75
76
``lowest_version``
76
-
77
77
Args:
78
78
lowest_version (List[int]): lowest version represented in an integer
79
79
list
80
80
framework_version (str): framework version string
81
-
82
81
Returns:
83
82
bool: Whether or not framework_version is equal to or higher than
84
83
lowest_version
@@ -125,7 +124,11 @@ def _registry_id(region, framework, py_version, account, accelerator_type, frame
125
124
framework_version:
126
125
"""
127
126
if _using_merged_images (region , framework , py_version , accelerator_type , framework_version ):
127
+ if region in ASIMOV_OPT_IN_ACCOUNTS_BY_REGION :
128
+ return ASIMOV_OPT_IN_ACCOUNTS_BY_REGION .get (region )
128
129
return "763104351884"
130
+ if region in OPT_IN_ACCOUNTS_BY_REGION :
131
+ return OPT_IN_ACCOUNTS_BY_REGION .get (region )
129
132
return VALID_ACCOUNTS_BY_REGION .get (region , account )
130
133
131
134
@@ -140,7 +143,6 @@ def create_image_uri(
140
143
optimized_families = None ,
141
144
):
142
145
"""Return the ECR URI of an image.
143
-
144
146
Args:
145
147
region (str): AWS region where the image is uploaded.
146
148
framework (str): framework used by the image.
@@ -155,7 +157,6 @@ def create_image_uri(
155
157
accelerator_type (str): SageMaker Elastic Inference accelerator type.
156
158
optimized_families (str): Instance families for which there exist
157
159
specific optimized images.
158
-
159
160
Returns:
160
161
str: The appropriate image URI based on the given parameters.
161
162
"""
@@ -249,11 +250,9 @@ def _accelerator_type_valid_for_framework(
249
250
250
251
def validate_source_dir (script , directory ):
251
252
"""Validate that the source directory exists and it contains the user script
252
-
253
253
Args:
254
254
script (str): Script filename.
255
255
directory (str): Directory containing the source file.
256
-
257
256
Raises:
258
257
ValueError: If ``directory`` does not exist, is not a directory, or does
259
258
not contain ``script``.
@@ -272,18 +271,14 @@ def tar_and_upload_dir(
272
271
):
273
272
"""Package source files and upload a compress tar file to S3. The S3
274
273
location will be ``s3://<bucket>/s3_key_prefix/sourcedir.tar.gz``.
275
-
276
274
If directory is an S3 URI, an UploadedCode object will be returned, but
277
275
nothing will be uploaded to S3 (this allow reuse of code already in S3).
278
-
279
276
If directory is None, the script will be added to the archive at
280
277
``./<basename of script>``.
281
-
282
278
If directory is not None, the (recursive) contents of the directory will
283
279
be added to the archive. directory is treated as the base path of the
284
280
archive, and the script name is assumed to be a filename or relative path
285
281
inside the directory.
286
-
287
282
Args:
288
283
session (boto3.Session): Boto session used to access S3.
289
284
bucket (str): S3 bucket to which the compressed file is uploaded.
@@ -296,7 +291,6 @@ def tar_and_upload_dir(
296
291
copied into /opt/ml/lib
297
292
kms_key (str): Optional. KMS key ID used to upload objects to the bucket
298
293
(default: None).
299
-
300
294
Returns:
301
295
sagemaker.fw_utils.UserCode: An object with the S3 bucket and key (S3 prefix) and
302
296
script name.
@@ -343,7 +337,6 @@ def _list_files_to_compress(script, directory):
343
337
def framework_name_from_image (image_name ):
344
338
# noinspection LongLine
345
339
"""Extract the framework and Python version from the image name.
346
-
347
340
Args:
348
341
image_name (str): Image URI, which should be one of the following forms:
349
342
legacy:
@@ -354,7 +347,6 @@ def framework_name_from_image(image_name):
354
347
'<account>.dkr.ecr.<region>.amazonaws.com/sagemaker-<fw>:<fw_version>-<device>-<py_ver>'
355
348
current:
356
349
'<account>.dkr.ecr.<region>.amazonaws.com/sagemaker-rl-<fw>:<rl_toolkit><rl_version>-<device>-<py_ver>'
357
-
358
350
Returns:
359
351
tuple: A tuple containing:
360
352
str: The framework name str: The Python version str: The image tag
@@ -390,11 +382,9 @@ def framework_name_from_image(image_name):
390
382
391
383
def framework_version_from_tag (image_tag ):
392
384
"""Extract the framework version from the image tag.
393
-
394
385
Args:
395
386
image_tag (str): Image tag, which should take the form
396
387
'<framework_version>-<device>-<py_version>'
397
-
398
388
Returns:
399
389
str: The framework version.
400
390
"""
@@ -406,10 +396,8 @@ def framework_version_from_tag(image_tag):
406
396
def parse_s3_url (url ):
407
397
"""Returns an (s3 bucket, key name/prefix) tuple from a url with an s3
408
398
scheme
409
-
410
399
Args:
411
400
url (str):
412
-
413
401
Returns:
414
402
tuple: A tuple containing:
415
403
str: S3 bucket name str: S3 key
@@ -422,16 +410,13 @@ def parse_s3_url(url):
422
410
423
411
def model_code_key_prefix (code_location_key_prefix , model_name , image ):
424
412
"""Returns the s3 key prefix for uploading code during model deployment
425
-
426
413
The location returned is a potential concatenation of 2 parts
427
414
1. code_location_key_prefix if it exists
428
415
2. model_name or a name derived from the image
429
-
430
416
Args:
431
417
code_location_key_prefix (str): the s3 key prefix from code_location
432
418
model_name (str): the name of the model
433
419
image (str): the image from which a default name can be extracted
434
-
435
420
Returns:
436
421
str: the key prefix to be used in uploading code
437
422
"""
0 commit comments