Skip to content

Commit 459fd54

Browse files
committed
Address comments
1 parent 62effe3 commit 459fd54

File tree

4 files changed

+90
-76
lines changed

4 files changed

+90
-76
lines changed

src/sagemaker/amazon/amazon_estimator.py

Lines changed: 69 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from sagemaker.amazon.common import write_numpy_to_dense_tensor
2424
from sagemaker.estimator import EstimatorBase, _TrainingJob
2525
from sagemaker.session import s3_input
26-
from sagemaker.utils import sagemaker_timestamp
26+
from sagemaker.utils import sagemaker_timestamp, get_ecr_image_uri_prefix
2727

2828
logger = logging.getLogger(__name__)
2929

@@ -283,79 +283,79 @@ def registry(region_name, algorithm=None):
283283
284284
https://github.com/aws/sagemaker-python-sdk/tree/master/src/sagemaker/amazon
285285
"""
286-
if algorithm in [None, "pca", "kmeans", "linear-learner", "factorization-machines", "ntm",
287-
"randomcutforest", "knn", "object2vec", "ipinsights"]:
286+
if algorithm in [None, 'pca', 'kmeans', 'linear-learner', 'factorization-machines', 'ntm',
287+
'randomcutforest', 'knn', 'object2vec', 'ipinsights']:
288288
account_id = {
289-
"us-east-1": "382416733822",
290-
"us-east-2": "404615174143",
291-
"us-west-2": "174872318107",
292-
"eu-west-1": "438346466558",
293-
"eu-central-1": "664544806723",
294-
"ap-northeast-1": "351501993468",
295-
"ap-northeast-2": "835164637446",
296-
"ap-southeast-2": "712309505854",
297-
"us-gov-west-1": "226302683700",
298-
"ap-southeast-1": "475088953585",
299-
"ap-south-1": "991648021394",
300-
"ca-central-1": "469771592824",
301-
"eu-west-2": "644912444149",
302-
"us-west-1": "632365934929",
303-
"us-iso-east-1": "490574956308",
289+
'us-east-1': '382416733822',
290+
'us-east-2': '404615174143',
291+
'us-west-2': '174872318107',
292+
'eu-west-1': '438346466558',
293+
'eu-central-1': '664544806723',
294+
'ap-northeast-1': '351501993468',
295+
'ap-northeast-2': '835164637446',
296+
'ap-southeast-2': '712309505854',
297+
'us-gov-west-1': '226302683700',
298+
'ap-southeast-1': '475088953585',
299+
'ap-south-1': '991648021394',
300+
'ca-central-1': '469771592824',
301+
'eu-west-2': '644912444149',
302+
'us-west-1': '632365934929',
303+
'us-iso-east-1': '490574956308',
304304
}[region_name]
305-
elif algorithm in ["lda"]:
305+
elif algorithm in ['lda']:
306306
account_id = {
307-
"us-east-1": "766337827248",
308-
"us-east-2": "999911452149",
309-
"us-west-2": "266724342769",
310-
"eu-west-1": "999678624901",
311-
"eu-central-1": "353608530281",
312-
"ap-northeast-1": "258307448986",
313-
"ap-northeast-2": "293181348795",
314-
"ap-southeast-2": "297031611018",
315-
"us-gov-west-1": "226302683700",
316-
"ap-southeast-1": "475088953585",
317-
"ap-south-1": "991648021394",
318-
"ca-central-1": "469771592824",
319-
"eu-west-2": "644912444149",
320-
"us-west-1": "632365934929",
321-
"us-iso-east-1": "490574956308",
307+
'us-east-1': '766337827248',
308+
'us-east-2': '999911452149',
309+
'us-west-2': '266724342769',
310+
'eu-west-1': '999678624901',
311+
'eu-central-1': '353608530281',
312+
'ap-northeast-1': '258307448986',
313+
'ap-northeast-2': '293181348795',
314+
'ap-southeast-2': '297031611018',
315+
'us-gov-west-1': '226302683700',
316+
'ap-southeast-1': '475088953585',
317+
'ap-south-1': '991648021394',
318+
'ca-central-1': '469771592824',
319+
'eu-west-2': '644912444149',
320+
'us-west-1': '632365934929',
321+
'us-iso-east-1': '490574956308',
322322
}[region_name]
323-
elif algorithm in ["forecasting-deepar"]:
323+
elif algorithm in ['forecasting-deepar']:
324324
account_id = {
325-
"us-east-1": "522234722520",
326-
"us-east-2": "566113047672",
327-
"us-west-2": "156387875391",
328-
"eu-west-1": "224300973850",
329-
"eu-central-1": "495149712605",
330-
"ap-northeast-1": "633353088612",
331-
"ap-northeast-2": "204372634319",
332-
"ap-southeast-2": "514117268639",
333-
"us-gov-west-1": "226302683700",
334-
"ap-southeast-1": "475088953585",
335-
"ap-south-1": "991648021394",
336-
"ca-central-1": "469771592824",
337-
"eu-west-2": "644912444149",
338-
"us-west-1": "632365934929",
339-
"us-iso-east-1": "490574956308",
325+
'us-east-1': '522234722520',
326+
'us-east-2': '566113047672',
327+
'us-west-2': '156387875391',
328+
'eu-west-1': '224300973850',
329+
'eu-central-1': '495149712605',
330+
'ap-northeast-1': '633353088612',
331+
'ap-northeast-2': '204372634319',
332+
'ap-southeast-2': '514117268639',
333+
'us-gov-west-1': '226302683700',
334+
'ap-southeast-1': '475088953585',
335+
'ap-south-1': '991648021394',
336+
'ca-central-1': '469771592824',
337+
'eu-west-2': '644912444149',
338+
'us-west-1': '632365934929',
339+
'us-iso-east-1': '490574956308',
340340
}[region_name]
341-
elif algorithm in ["xgboost", "seq2seq", "image-classification", "blazingtext",
342-
"object-detection", "semantic-segmentation"]:
341+
elif algorithm in ['xgboost', 'seq2seq', 'image-classification', 'blazingtext',
342+
'object-detection', 'semantic-segmentation']:
343343
account_id = {
344-
"us-east-1": "811284229777",
345-
"us-east-2": "825641698319",
346-
"us-west-2": "433757028032",
347-
"eu-west-1": "685385470294",
348-
"eu-central-1": "813361260812",
349-
"ap-northeast-1": "501404015308",
350-
"ap-northeast-2": "306986355934",
351-
"ap-southeast-2": "544295431143",
352-
"us-gov-west-1": "226302683700",
353-
"ap-southeast-1": "475088953585",
354-
"ap-south-1": "991648021394",
355-
"ca-central-1": "469771592824",
356-
"eu-west-2": "644912444149",
357-
"us-west-1": "632365934929",
358-
"us-iso-east-1": "490574956308",
344+
'us-east-1': '811284229777',
345+
'us-east-2': '825641698319',
346+
'us-west-2': '433757028032',
347+
'eu-west-1': '685385470294',
348+
'eu-central-1': '813361260812',
349+
'ap-northeast-1': '501404015308',
350+
'ap-northeast-2': '306986355934',
351+
'ap-southeast-2': '544295431143',
352+
'us-gov-west-1': '226302683700',
353+
'ap-southeast-1': '475088953585',
354+
'ap-south-1': '991648021394',
355+
'ca-central-1': '469771592824',
356+
'eu-west-2': '644912444149',
357+
'us-west-1': '632365934929',
358+
'us-iso-east-1': '490574956308',
359359
}[region_name]
360360
elif algorithm in ['image-classification-neo', 'xgboost-neo']:
361361
account_id = {
@@ -365,10 +365,9 @@ def registry(region_name, algorithm=None):
365365
'us-east-2': '007439368137',
366366
}[region_name]
367367
else:
368-
raise ValueError("Algorithm class:{} doesn't have mapping to account_id with images".format(algorithm))
368+
raise ValueError('Algorithm class:{} does not have mapping to account_id with images'.format(algorithm))
369369

370-
domain_name = "c2s.ic.gov" if region_name == "us-iso-east-1" else "amazonaws.com"
371-
return "{}.dkr.ecr.{}.{}".format(account_id, region_name, domain_name)
370+
return get_ecr_image_uri_prefix(account_id, region_name)
372371

373372

374373
def get_image_uri(region_name, repo_name, repo_version=1):

src/sagemaker/fw_registry.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from __future__ import absolute_import
1414
import logging
1515

16+
from sagemaker.utils import get_ecr_image_uri_prefix
17+
1618
image_registry_map = {
1719
"us-west-1": {
1820
"sparkml-serving": "746614075791",
@@ -84,8 +86,7 @@ def registry(region_name, framework=None):
8486
"""
8587
try:
8688
account_id = image_registry_map[region_name][framework]
87-
domain_name = "c2s.ic.gov" if region_name == "us-iso-east-1" else "amazonaws.com"
88-
return "{}.dkr.ecr.{}.{}".format(account_id, region_name, domain_name)
89+
return get_ecr_image_uri_prefix(account_id, region_name)
8990
except KeyError:
9091
logging.error("The specific image or region does not exist")
9192
raise

src/sagemaker/fw_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import tempfile
2222
from six.moves.urllib.parse import urlparse
2323

24+
from sagemaker.utils import get_ecr_image_uri_prefix
25+
2426
_TAR_SOURCE_FILENAME = 'source.tar.gz'
2527

2628
UploadedCode = namedtuple('UserCode', ['s3_prefix', 'script_name'])
@@ -97,10 +99,8 @@ def create_image_uri(region, framework, instance_type, framework_version, py_ver
9799
optimized_families=optimized_families):
98100
framework += '-eia'
99101

100-
domain_name = "c2s.ic.gov" if region == "us-iso-east-1" else "amazonaws.com"
101-
102-
return "{}.dkr.ecr.{}.{}/sagemaker-{}:{}" \
103-
.format(account, region, domain_name, framework, tag)
102+
return "{}/sagemaker-{}:{}" \
103+
.format(get_ecr_image_uri_prefix(account, region), framework, tag)
104104

105105

106106
def _accelerator_type_valid_for_framework(framework, accelerator_type=None, optimized_families=None):

src/sagemaker/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,20 @@ def download_file(bucket_name, path, target, sagemaker_session):
292292
bucket.download_file(path, target)
293293

294294

295+
def get_ecr_image_uri_prefix(account, region):
296+
"""get prefix of ECR image URI
297+
298+
Args:
299+
account (str): AWS account number
300+
region (str): AWS region name
301+
302+
Returns:
303+
(str): URI prefix of ECR image
304+
"""
305+
domain = 'c2s.ic.gov' if region == 'us-iso-east-1' else 'amazonaws.com'
306+
return '{}.dkr.ecr.{}.{}'.format(account, region, domain)
307+
308+
295309
class DeferredError(object):
296310
"""Stores an exception and raises it at a later time if this
297311
object is accessed in any way. Useful to allow soft-dependencies on imports,

0 commit comments

Comments
 (0)