Skip to content

Commit c97b3ce

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

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-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-form: "315553699071.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost:1.5-1-cpu-py3"
458+
# 2. Short-form: "315553699071.dkr.ecr.us-west-2.amazonaws.com/sagemaker-xgboost:1.5-1"
459+
# Both tags point to the same image
460+
# Sidenote: both tags have full GPU capabilities, despite "cpu" delineation
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

+30
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,36 @@ 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", 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_result = ("xgboost", "py3", "1.5-1", None)
537+
assert (
538+
expected_result
539+
== fw_utils.framework_name_from_image(short_image_uri)
540+
== fw_utils.framework_name_from_image(long_image_uri)
541+
)
542+
543+
514544
def test_model_code_key_prefix_with_all_values_present():
515545
key_prefix = fw_utils.model_code_key_prefix("prefix", "model_name", "image_uri")
516546
assert key_prefix == "prefix/model_name"

0 commit comments

Comments
 (0)