Skip to content

Commit e495012

Browse files
author
Mark Bunday
committed
fix: Add regex for short-form sagemaker-xgboost tags in framework_name_from_image
1 parent ace07d7 commit e495012

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/sagemaker/fw_utils.py

+12
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ def framework_name_from_image(image_uri):
410410
'<account>.dkr.ecr.<region>.amazonaws.com/sagemaker-rl-<fw>:<rl_toolkit><rl_version>-<device>-<py_ver>'
411411
current:
412412
'<account>.dkr.ecr.<region>.amazonaws.com/<fw>-<image_scope>:<fw_version>-<device>-<py_ver>'
413+
current:
414+
'<account>.dkr.ecr.<region>.amazonaws.com/sagemaker-xgboost:<fw_version>-<container_version>'
413415
414416
Returns:
415417
tuple: A tuple containing:
@@ -450,6 +452,16 @@ def framework_name_from_image(image_uri):
450452
legacy_match = legacy_name_pattern.match(sagemaker_match.group(9))
451453
if legacy_match is not None:
452454
return (legacy_match.group(1), legacy_match.group(2), legacy_match.group(4), None)
455+
456+
# sagemaker-xgboost images are tagged with two aliases, e.g.:
457+
# 1. Long tag: "315553699071.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost:1.5-1-cpu-py3"
458+
# 2. Short tag: "315553699071.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost:1.5-1"
459+
# Note 1: Both tags point to the same image
460+
# Note 2: Both tags have full GPU capabilities, despite "cpu" delineation in the long tag
461+
short_xgboost_tag_pattern = re.compile(r"^sagemaker-(xgboost):(.*)$")
462+
short_xgboost_tag_match = short_xgboost_tag_pattern.match(sagemaker_match.group(9))
463+
if short_xgboost_tag_match is not None:
464+
return (short_xgboost_tag_match.group(1), "py3", short_xgboost_tag_match.group(2), None)
453465
return None, None, None, None
454466

455467

tests/unit/test_fw_utils.py

+33
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,39 @@ def test_framework_version_from_tag_other():
511511
assert version is None
512512

513513

514+
def test_framework_name_from_xgboost_image_short_tag():
515+
ecr_uri = "246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost"
516+
image_tag = "1.5-1"
517+
image_uri = f"{ecr_uri}:{image_tag}"
518+
expected_result = ("xgboost", "py3", "1.5-1", None)
519+
assert expected_result == fw_utils.framework_name_from_image(image_uri)
520+
521+
522+
def test_framework_name_from_xgboost_image_long_tag():
523+
ecr_uri = "246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost"
524+
image_tag = "1.5-1-cpu-py3"
525+
image_uri = f"{ecr_uri}:{image_tag}"
526+
expected_result = ("xgboost", "py3", "1.5-1-cpu-py3", None)
527+
assert expected_result == fw_utils.framework_name_from_image(image_uri)
528+
529+
530+
def test_framework_name_from_xgboost_image_short_long_tag_equal():
531+
ecr_uri = "246618743249.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost"
532+
short_image_tag = "1.5-1"
533+
long_image_tag = "1.5-1-cpu-py3"
534+
short_image_uri = f"{ecr_uri}:{short_image_tag}"
535+
long_image_uri = f"{ecr_uri}:{long_image_tag}"
536+
expected_framework = "xgboost"
537+
expected_py = "py3"
538+
539+
short_framework, short_py, short_tag, _ = fw_utils.framework_name_from_image(short_image_uri)
540+
long_framework, long_py, long_tag, _ = fw_utils.framework_name_from_image(long_image_uri)
541+
assert expected_framework == short_framework == long_framework
542+
assert expected_py == short_py == long_py
543+
assert short_image_tag == short_tag
544+
assert long_image_tag == long_tag
545+
546+
514547
def test_model_code_key_prefix_with_all_values_present():
515548
key_prefix = fw_utils.model_code_key_prefix("prefix", "model_name", "image_uri")
516549
assert key_prefix == "prefix/model_name"

0 commit comments

Comments
 (0)