|
28 | 28 | from sagemaker.session import s3_input
|
29 | 29 | from sagemaker.utils import sagemaker_timestamp, get_ecr_image_uri_prefix
|
30 | 30 | from sagemaker.xgboost.defaults import (
|
| 31 | + XGBOOST_1P_VERSIONS, |
31 | 32 | XGBOOST_LATEST_VERSION,
|
| 33 | + XGBOOST_NAME, |
32 | 34 | XGBOOST_SUPPORTED_VERSIONS,
|
33 |
| - XGBOOST_VERSION_0_90_1, |
34 |
| - XGBOOST_VERSION_0_90, |
35 | 35 | XGBOOST_VERSION_EQUIVALENTS,
|
36 | 36 | )
|
37 | 37 | from sagemaker.xgboost.estimator import get_xgboost_image_uri
|
@@ -616,41 +616,67 @@ def get_image_uri(region_name, repo_name, repo_version=1):
|
616 | 616 | repo_name:
|
617 | 617 | repo_version:
|
618 | 618 | """
|
619 |
| - if repo_name == "xgboost": |
620 |
| - if not _is_latest_xgboost_version(repo_version): |
621 |
| - logging.warning( |
622 |
| - "There is a more up to date SageMaker XGBoost image. " |
623 |
| - "To use the newer image, please set 'repo_version'=" |
624 |
| - "'%s'. For example:\n" |
625 |
| - "\tget_image_uri(region, 'xgboost', '%s').", |
626 |
| - XGBOOST_LATEST_VERSION, |
627 |
| - XGBOOST_LATEST_VERSION, |
628 |
| - ) |
629 |
| - |
630 |
| - if repo_version in [XGBOOST_VERSION_0_90] + _generate_version_equivalents( |
631 |
| - XGBOOST_VERSION_0_90_1 |
632 |
| - ): |
633 |
| - return get_xgboost_image_uri(region_name, XGBOOST_VERSION_0_90_1) |
634 |
| - |
635 |
| - supported_version = [ |
| 619 | + repo_version = str(repo_version) |
| 620 | + |
| 621 | + if repo_name == XGBOOST_NAME: |
| 622 | + |
| 623 | + if repo_version in XGBOOST_1P_VERSIONS: |
| 624 | + _warn_newer_xgboost_image() |
| 625 | + return "{}/{}:{}".format(registry(region_name, repo_name), repo_name, repo_version) |
| 626 | + |
| 627 | + if "-" not in repo_version: |
| 628 | + xgboost_version_matches = [ |
| 629 | + version |
| 630 | + for version in XGBOOST_SUPPORTED_VERSIONS |
| 631 | + if repo_version == version.split("-")[0] |
| 632 | + ] |
| 633 | + if xgboost_version_matches: |
| 634 | + # Assumes that XGBOOST_SUPPORTED_VERSION is sorted from oldest version to latest, |
| 635 | + # and the latest version is at the end of the list. |
| 636 | + repo_version = xgboost_version_matches[-1] |
| 637 | + |
| 638 | + supported_framework_versions = [ |
636 | 639 | version
|
637 | 640 | for version in XGBOOST_SUPPORTED_VERSIONS
|
638 | 641 | if repo_version in _generate_version_equivalents(version)
|
639 | 642 | ]
|
640 |
| - if supported_version: |
641 |
| - return get_xgboost_image_uri(region_name, supported_version[0]) |
| 643 | + |
| 644 | + if not supported_framework_versions: |
| 645 | + raise ValueError( |
| 646 | + "SageMaker XGBoost version {} is not supported. Supported versions: {}".format( |
| 647 | + repo_version, ", ".join(XGBOOST_SUPPORTED_VERSIONS) |
| 648 | + ) |
| 649 | + ) |
| 650 | + |
| 651 | + if not _is_latest_xgboost_version(repo_version): |
| 652 | + _warn_newer_xgboost_image() |
| 653 | + |
| 654 | + return get_xgboost_image_uri(region_name, supported_framework_versions[-1]) |
642 | 655 |
|
643 | 656 | repo = "{}:{}".format(repo_name, repo_version)
|
644 | 657 | return "{}/{}".format(registry(region_name, repo_name), repo)
|
645 | 658 |
|
646 | 659 |
|
| 660 | +def _warn_newer_xgboost_image(): |
| 661 | + """Print a warning when there is a newer XGBoost image""" |
| 662 | + logging.warning( |
| 663 | + "There is a more up to date SageMaker XGBoost image. " |
| 664 | + "To use the newer image, please set 'repo_version'=" |
| 665 | + "'%s'. For example:\n" |
| 666 | + "\tget_image_uri(region, '%s', '%s').", |
| 667 | + XGBOOST_LATEST_VERSION, |
| 668 | + XGBOOST_NAME, |
| 669 | + XGBOOST_LATEST_VERSION, |
| 670 | + ) |
| 671 | + |
| 672 | + |
647 | 673 | def _is_latest_xgboost_version(repo_version):
|
648 | 674 | """Compare xgboost image version with latest version
|
649 | 675 |
|
650 | 676 | Args:
|
651 | 677 | repo_version:
|
652 | 678 | """
|
653 |
| - if repo_version in (1, "latest"): |
| 679 | + if repo_version in XGBOOST_1P_VERSIONS: |
654 | 680 | return False
|
655 | 681 | return repo_version in _generate_version_equivalents(XGBOOST_LATEST_VERSION)
|
656 | 682 |
|
|
0 commit comments