Skip to content

Commit f383e88

Browse files
committed
pysdk upgrade for python 3.10 and version mapping
1 parent 4c8814b commit f383e88

File tree

6 files changed

+226
-9
lines changed

6 files changed

+226
-9
lines changed

src/sagemaker/image_uri_config/sklearn.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,54 @@
192192
"us-west-2": "246618743249"
193193
},
194194
"repository": "sagemaker-scikit-learn"
195+
},
196+
"1.2-1-1": {
197+
"processors": [
198+
"cpu"
199+
],
200+
"py_versions": [
201+
"py3"
202+
],
203+
"registries": {
204+
"af-south-1": "510948584623",
205+
"ap-east-1": "651117190479",
206+
"ap-northeast-1": "354813040037",
207+
"ap-northeast-2": "366743142698",
208+
"ap-northeast-3": "867004704886",
209+
"ap-south-1": "720646828776",
210+
"ap-south-2": "628508329040",
211+
"ap-southeast-1": "121021644041",
212+
"ap-southeast-2": "783357654285",
213+
"ap-southeast-3": "951798379941",
214+
"ap-southeast-4": "106583098589",
215+
"ca-central-1": "341280168497",
216+
"ca-west-1": "190319476487",
217+
"cn-north-1": "450853457545",
218+
"cn-northwest-1": "451049120500",
219+
"eu-central-1": "492215442770",
220+
"eu-central-2": "680994064768",
221+
"eu-north-1": "662702820516",
222+
"eu-south-1": "978288397137",
223+
"eu-south-2": "104374241257",
224+
"eu-west-1": "141502667606",
225+
"eu-west-2": "764974769150",
226+
"eu-west-3": "659782779980",
227+
"il-central-1": "898809789911",
228+
"me-central-1": "272398656194",
229+
"me-south-1": "801668240914",
230+
"sa-east-1": "737474898029",
231+
"us-east-1": "683313688378",
232+
"us-east-2": "257758044811",
233+
"us-gov-east-1": "237065988967",
234+
"us-gov-west-1": "414596584902",
235+
"us-iso-east-1": "833128469047",
236+
"us-isob-east-1": "281123927165",
237+
"us-isof-east-1": "108575199400",
238+
"us-isof-south-1": "124985052026",
239+
"us-west-1": "746614075791",
240+
"us-west-2": "246618743249"
241+
},
242+
"repository": "sagemaker-scikit-learn"
195243
}
196244
}
197245
},
@@ -388,6 +436,54 @@
388436
"us-west-2": "246618743249"
389437
},
390438
"repository": "sagemaker-scikit-learn"
439+
},
440+
"1.2-1-1": {
441+
"processors": [
442+
"cpu"
443+
],
444+
"py_versions": [
445+
"py3"
446+
],
447+
"registries": {
448+
"af-south-1": "510948584623",
449+
"ap-east-1": "651117190479",
450+
"ap-northeast-1": "354813040037",
451+
"ap-northeast-2": "366743142698",
452+
"ap-northeast-3": "867004704886",
453+
"ap-south-1": "720646828776",
454+
"ap-south-2": "628508329040",
455+
"ap-southeast-1": "121021644041",
456+
"ap-southeast-2": "783357654285",
457+
"ap-southeast-3": "951798379941",
458+
"ap-southeast-4": "106583098589",
459+
"ca-central-1": "341280168497",
460+
"ca-west-1": "190319476487",
461+
"cn-north-1": "450853457545",
462+
"cn-northwest-1": "451049120500",
463+
"eu-central-1": "492215442770",
464+
"eu-central-2": "680994064768",
465+
"eu-north-1": "662702820516",
466+
"eu-south-1": "978288397137",
467+
"eu-south-2": "104374241257",
468+
"eu-west-1": "141502667606",
469+
"eu-west-2": "764974769150",
470+
"eu-west-3": "659782779980",
471+
"il-central-1": "898809789911",
472+
"me-central-1": "272398656194",
473+
"me-south-1": "801668240914",
474+
"sa-east-1": "737474898029",
475+
"us-east-1": "683313688378",
476+
"us-east-2": "257758044811",
477+
"us-gov-east-1": "237065988967",
478+
"us-gov-west-1": "414596584902",
479+
"us-iso-east-1": "833128469047",
480+
"us-isob-east-1": "281123927165",
481+
"us-isof-east-1": "108575199400",
482+
"us-isof-south-1": "124985052026",
483+
"us-west-1": "746614075791",
484+
"us-west-2": "246618743249"
485+
},
486+
"repository": "sagemaker-scikit-learn"
391487
}
392488
}
393489
},

src/sagemaker/image_uri_config/xgboost.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,48 @@
395395
"us-west-2": "246618743249"
396396
},
397397
"repository": "sagemaker-xgboost"
398+
},
399+
"1.7-1-1": {
400+
"registries": {
401+
"af-south-1": "510948584623",
402+
"ap-east-1": "651117190479",
403+
"ap-northeast-1": "354813040037",
404+
"ap-northeast-2": "366743142698",
405+
"ap-northeast-3": "867004704886",
406+
"ap-south-1": "720646828776",
407+
"ap-south-2": "628508329040",
408+
"ap-southeast-1": "121021644041",
409+
"ap-southeast-2": "783357654285",
410+
"ap-southeast-3": "951798379941",
411+
"ap-southeast-4": "106583098589",
412+
"ca-central-1": "341280168497",
413+
"ca-west-1": "190319476487",
414+
"cn-north-1": "450853457545",
415+
"cn-northwest-1": "451049120500",
416+
"eu-central-1": "492215442770",
417+
"eu-central-2": "680994064768",
418+
"eu-north-1": "662702820516",
419+
"eu-south-1": "978288397137",
420+
"eu-south-2": "104374241257",
421+
"eu-west-1": "141502667606",
422+
"eu-west-2": "764974769150",
423+
"eu-west-3": "659782779980",
424+
"il-central-1": "898809789911",
425+
"me-central-1": "272398656194",
426+
"me-south-1": "801668240914",
427+
"sa-east-1": "737474898029",
428+
"us-east-1": "683313688378",
429+
"us-east-2": "257758044811",
430+
"us-gov-east-1": "237065988967",
431+
"us-gov-west-1": "414596584902",
432+
"us-iso-east-1": "833128469047",
433+
"us-isob-east-1": "281123927165",
434+
"us-isof-east-1": "108575199400",
435+
"us-isof-south-1": "124985052026",
436+
"us-west-1": "746614075791",
437+
"us-west-2": "246618743249"
438+
},
439+
"repository": "sagemaker-xgboost"
398440
}
399441
}
400442
},
@@ -794,6 +836,48 @@
794836
"us-west-2": "246618743249"
795837
},
796838
"repository": "sagemaker-xgboost"
839+
},
840+
"1.7-1-1": {
841+
"registries": {
842+
"af-south-1": "510948584623",
843+
"ap-east-1": "651117190479",
844+
"ap-northeast-1": "354813040037",
845+
"ap-northeast-2": "366743142698",
846+
"ap-northeast-3": "867004704886",
847+
"ap-south-1": "720646828776",
848+
"ap-south-2": "628508329040",
849+
"ap-southeast-1": "121021644041",
850+
"ap-southeast-2": "783357654285",
851+
"ap-southeast-3": "951798379941",
852+
"ap-southeast-4": "106583098589",
853+
"ca-central-1": "341280168497",
854+
"ca-west-1": "190319476487",
855+
"cn-north-1": "450853457545",
856+
"cn-northwest-1": "451049120500",
857+
"eu-central-1": "492215442770",
858+
"eu-central-2": "680994064768",
859+
"eu-north-1": "662702820516",
860+
"eu-south-1": "978288397137",
861+
"eu-south-2": "104374241257",
862+
"eu-west-1": "141502667606",
863+
"eu-west-2": "764974769150",
864+
"eu-west-3": "659782779980",
865+
"il-central-1": "898809789911",
866+
"me-central-1": "272398656194",
867+
"me-south-1": "801668240914",
868+
"sa-east-1": "737474898029",
869+
"us-east-1": "683313688378",
870+
"us-east-2": "257758044811",
871+
"us-gov-east-1": "237065988967",
872+
"us-gov-west-1": "414596584902",
873+
"us-iso-east-1": "833128469047",
874+
"us-isob-east-1": "281123927165",
875+
"us-isof-east-1": "108575199400",
876+
"us-isof-south-1": "124985052026",
877+
"us-west-1": "746614075791",
878+
"us-west-2": "246618743249"
879+
},
880+
"repository": "sagemaker-xgboost"
797881
}
798882
}
799883
},

src/sagemaker/image_uris.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import os
1919
import re
2020
from typing import Optional
21-
from packaging.version import Version
21+
from sagemaker.utils import parse_sagemaker_version
2222

2323
from sagemaker import utils
2424
from sagemaker.jumpstart.constants import DEFAULT_JUMPSTART_SAGEMAKER_SESSION, JUMPSTART_LOGGER
@@ -403,8 +403,12 @@ def _config_for_framework_and_scope(framework, image_scope, accelerator_type=Non
403403
def _validate_instance_deprecation(framework, instance_type, version):
404404
"""Check if instance type is deprecated for a certain framework with a certain version"""
405405
if utils.get_instance_type_family(instance_type) == "p2":
406-
if (framework == "pytorch" and Version(version) >= Version("1.13")) or (
407-
framework == "tensorflow" and Version(version) >= Version("2.12")
406+
if (
407+
framework == "pytorch"
408+
and parse_sagemaker_version(version) >= parse_sagemaker_version("1.13")
409+
) or (
410+
framework == "tensorflow"
411+
and parse_sagemaker_version(version) >= parse_sagemaker_version("2.12")
408412
):
409413
raise ValueError(
410414
"P2 instances have been deprecated for sagemaker jobs starting PyTorch 1.13 and TensorFlow 2.12"
@@ -804,7 +808,7 @@ def _fetch_latest_version_from_config( # pylint: disable=R0911
804808
bottom_number = int(bottom_version[:-2])
805809
max_version = max(top_number, bottom_number)
806810
return f"{max_version}.x"
807-
if Version(top_version) >= Version(bottom_version):
811+
if parse_sagemaker_version(top_version) >= parse_sagemaker_version(bottom_version):
808812
return top_version
809813
return bottom_version
810814

src/sagemaker/serve/detector/image_detector.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import platform
66
import re
77
import logging
8-
from packaging import version
8+
from sagemaker.utils import parse_sagemaker_version
99
from sagemaker import image_uris
1010

1111
logger = logging.getLogger(__name__)
@@ -74,15 +74,15 @@ def auto_detect_container(model, region: str, instance_type: str) -> str:
7474
def _cast_to_compatible_version(framework: str, fw_version: str) -> Tuple[str]:
7575
"""Given fw_version, detect the available versions"""
7676
config = image_uris._config_for_framework_and_scope(framework, "inference", None)
77-
available_versions = [version.parse(ver) for ver in list(config["versions"].keys())]
77+
available_versions = [parse_sagemaker_version(ver) for ver in list(config["versions"].keys())]
7878
available_versions.sort()
7979

8080
earliest_upcast_version = None
8181
exact_match_version = None
8282
latest_downcast_version = None
8383

8484
major_version_pattern = r"^(\d+)"
85-
parsed_fw_version = version.parse(fw_version)
85+
parsed_fw_version = parse_sagemaker_version(fw_version)
8686
major_verson = int(re.match(major_version_pattern, str(parsed_fw_version)).group(1))
8787

8888
for available_version in available_versions:
@@ -119,7 +119,7 @@ def _cast_to_compatible_version(framework: str, fw_version: str) -> Tuple[str]:
119119
return (exact_match_version, latest_downcast_version, earliest_upcast_version)
120120

121121

122-
def _process_version(ver: version.Version) -> str:
122+
def _process_version(ver) -> str:
123123
"""Placeholder docstring"""
124124
if not ver:
125125
return None

src/sagemaker/utils.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
from sagemaker.workflow import is_pipeline_parameter_string, is_pipeline_variable
5454
from sagemaker.workflow.entities import PipelineVariable
5555

56+
try:
57+
from packaging.version import Version, InvalidVersion
58+
except ImportError:
59+
Version = None
60+
InvalidVersion = None
61+
5662
ALTERNATE_DOMAINS = {
5763
"cn-north-1": "amazonaws.com.cn",
5864
"cn-northwest-1": "amazonaws.com.cn",
@@ -1959,3 +1965,29 @@ def get_domain_for_region(region: str) -> str:
19591965
region (str): AWS region name.
19601966
"""
19611967
return ALTERNATE_DOMAINS.get(region, "amazonaws.com")
1968+
1969+
1970+
def parse_sagemaker_version(version_str):
1971+
"""Parse SageMaker version strings, handling custom formats like '1.7-1-1'
1972+
1973+
Args:
1974+
version_str (str): Version string to parse
1975+
1976+
Returns:
1977+
packaging.version.Version: Parsed version object
1978+
1979+
Raises:
1980+
InvalidVersion: If the version string cannot be parsed
1981+
ImportError: If packaging library is not available
1982+
"""
1983+
if Version is None or InvalidVersion is None:
1984+
raise ImportError("packaging library is required for version parsing")
1985+
1986+
try:
1987+
return Version(version_str)
1988+
except InvalidVersion:
1989+
# Handle SageMaker custom format: '1.7-1-1' -> '1.7.1.1'
1990+
if version_str.count("-") >= 2:
1991+
normalized = version_str.replace("-", ".", 2)
1992+
return Version(normalized)
1993+
raise

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from botocore.config import Config
2424
from packaging.version import Version
2525
from packaging.specifiers import SpecifierSet
26+
from sagemaker.utils import parse_sagemaker_version
2627

2728
from sagemaker import Session, image_uris, utils, get_execution_role
2829
from sagemaker.local import LocalSession
@@ -790,7 +791,7 @@ def _parametrize_framework_version_fixtures(metafunc, fixture_prefix, config):
790791
versions = list(config["versions"].keys()) + list(config.get("version_aliases", {}).keys())
791792
metafunc.parametrize(fixture_name, versions, scope="session")
792793

793-
latest_version = sorted(config["versions"].keys(), key=lambda v: Version(v))[-1]
794+
latest_version = sorted(config["versions"].keys(), key=parse_sagemaker_version)[-1]
794795

795796
fixture_name = "{}_latest_version".format(fixture_prefix)
796797
if fixture_name in metafunc.fixturenames:

0 commit comments

Comments
 (0)