Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sagemaker-core/src/sagemaker/core/image_uris.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def retrieve(
pt_or_tf_version = (
re.compile("^(pytorch|tensorflow)(.*)$").match(base_framework_version).group(2)
)
_version = original_version
_version = _version_for_config(version, config)

if repo in [
"huggingface-pytorch-trcomp-training",
Expand Down
84 changes: 82 additions & 2 deletions sagemaker-core/tests/unit/image_uris/test_retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def test_retrieve_huggingface(config_for_framework):
)
assert (
"564829616587.dkr.ecr.us-east-1.amazonaws.com/huggingface-pytorch-training:"
"1.6-transformers4.2-gpu-py37-cu110-ubuntu18.04" == pt_uri_mv
"1.6-transformers4.2.1-gpu-py37-cu110-ubuntu18.04" == pt_uri_mv
)

pt_uri = image_uris.retrieve(
Expand Down Expand Up @@ -760,7 +760,7 @@ def test_retrieve_huggingface(config_for_framework):
)
assert (
"564829616587.dkr.ecr.us-east-1.amazonaws.com/huggingface-pytorch-training:"
"1.6.0-transformers4.3.1-gpu-py37-cu110-ubuntu18.04" == pt_new_version
"1.6.0-transformers4.2.1-gpu-py37-cu110-ubuntu18.04" == pt_new_version

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Low: This updated assertion is worth a sanity check. The call passes version="4.3.1", which is not present in this test's single-version config (only 4.2.1 exists). Because _validate_version_and_set_if_needed takes the single-version shortcut (len(available_versions) == 1 and 4.3.1 is not an alias), version is silently coerced to 4.2.1, so after this fix the tag correctly becomes transformers4.2.1. The expectation is right, but the test name/value pt_new_version with input 4.3.1 is now misleading since the input version is effectively ignored. Consider using a value that is actually a defined alias (or adding 4.3.1 to the config) so the test clearly demonstrates alias resolution rather than the single-version fallback.

)


Expand Down Expand Up @@ -832,6 +832,86 @@ def test_get_latest_version_function_with_no_framework(config_for_framework):
assert "No framework config for framework" in str(e.exception)


def _get_huggingface_alias_test_cases():
"""Build parametrized test cases for every HuggingFace version alias."""
config = image_uris.config_for_framework("huggingface")
cases = []
for scope in ("training", "inference"):
section = config[scope]
aliases = section.get("version_aliases", {})
for alias, resolved in aliases.items():
ver_cfg = section["versions"][resolved]
base_fws = [k for k in ver_cfg if k != "version_aliases"]
base_fw = base_fws[0]
py_ver = ver_cfg[base_fw]["py_versions"][0]
inst = "ml.p3.2xlarge" if scope == "training" else "ml.c5.xlarge"
cases.append(
pytest.param(
scope, alias, resolved, base_fw, py_ver, inst, id=f"{scope}-{alias}->{resolved}"
)
)
return cases


def _get_huggingface_full_version_test_cases():
"""Build parametrized test cases for every non-aliased HuggingFace version."""
config = image_uris.config_for_framework("huggingface")
cases = []
for scope in ("training", "inference"):
section = config[scope]
for full_ver, ver_cfg in section["versions"].items():
base_fws = [k for k in ver_cfg if k != "version_aliases"]
base_fw = base_fws[0]
py_ver = ver_cfg[base_fw]["py_versions"][0]
inst = "ml.p3.2xlarge" if scope == "training" else "ml.c5.xlarge"
cases.append(
pytest.param(scope, full_ver, base_fw, py_ver, inst, id=f"{scope}-{full_ver}")
)
return cases


@pytest.mark.parametrize(
"scope,alias,resolved,base_fw,py_ver,instance_type",
_get_huggingface_alias_test_cases(),
)
def test_huggingface_version_alias_resolves_in_tag(
scope, alias, resolved, base_fw, py_ver, instance_type
):
"""Version aliases must be resolved to full versions in image URI tags."""
uri = image_uris.retrieve(
framework="huggingface",
region="us-east-1",
version=alias,
py_version=py_ver,
image_scope=scope,
base_framework_version=base_fw,
instance_type=instance_type,
)
assert (
f"transformers{resolved}-" in uri
), f"Expected resolved version 'transformers{resolved}-' in URI, got: {uri}"


@pytest.mark.parametrize(
"scope,full_version,base_fw,py_ver,instance_type",
_get_huggingface_full_version_test_cases(),
)
def test_huggingface_full_version_in_tag(scope, full_version, base_fw, py_ver, instance_type):
"""Full (non-aliased) versions must appear unchanged in image URI tags."""
uri = image_uris.retrieve(
framework="huggingface",
region="us-east-1",
version=full_version,
py_version=py_ver,
image_scope=scope,
base_framework_version=base_fw,
instance_type=instance_type,
)
assert (
f"transformers{full_version}-" in uri
), f"Expected full version 'transformers{full_version}-' in URI, got: {uri}"


@pytest.mark.parametrize(
"framework",
[
Expand Down
Loading