|
| 1 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | +from __future__ import absolute_import |
| 14 | + |
| 15 | +from mock.mock import patch |
| 16 | + |
| 17 | +from sagemaker import image_uris |
| 18 | +import pytest |
| 19 | + |
| 20 | +from tests.unit.sagemaker.jumpstart.utils import get_spec_from_base_spec |
| 21 | +from sagemaker.jumpstart.utils import get_jumpstart_content_bucket |
| 22 | +from sagemaker.jumpstart import constants as sagemaker_constants |
| 23 | + |
| 24 | + |
| 25 | +@patch("sagemaker.jumpstart.accessors.JumpStartModelsAccessor.get_model_specs") |
| 26 | +def test_jumpstart_script_uri(patched_get_model_specs): |
| 27 | + |
| 28 | + patched_get_model_specs.side_effect = get_spec_from_base_spec |
| 29 | + uri = image_uris.retrieve( |
| 30 | + framework=None, |
| 31 | + region="us-west-2", |
| 32 | + image_scope="inference", |
| 33 | + model_id="pytorch-ic-mobilenet-v2", |
| 34 | + model_version="*", |
| 35 | + instance_type="ml.p2.xlarge", |
| 36 | + ) |
| 37 | + assert uri == "763104351884.dkr.ecr.us-west-2.amazonaws.com/pytorch-inference:1.5.0-gpu-py3" |
| 38 | + patched_get_model_specs.assert_called_once_with("us-west-2", "pytorch-ic-mobilenet-v2", "*") |
| 39 | + |
| 40 | + patched_get_model_specs.reset_mock() |
| 41 | + |
| 42 | + uri = image_uris.retrieve( |
| 43 | + framework=None, |
| 44 | + region="us-west-2", |
| 45 | + image_scope="training", |
| 46 | + model_id="pytorch-ic-mobilenet-v2", |
| 47 | + model_version="*", |
| 48 | + instance_type="ml.p2.xlarge", |
| 49 | + ) |
| 50 | + assert uri == "763104351884.dkr.ecr.us-west-2.amazonaws.com/pytorch-training:1.5.0-gpu-py3" |
| 51 | + patched_get_model_specs.assert_called_once_with("us-west-2", "pytorch-ic-mobilenet-v2", "*") |
| 52 | + patched_get_model_specs.reset_mock() |
| 53 | + |
| 54 | + image_uris.retrieve( |
| 55 | + framework=None, |
| 56 | + region="us-west-2", |
| 57 | + image_scope="training", |
| 58 | + model_id="pytorch-ic-mobilenet-v2", |
| 59 | + model_version="*", |
| 60 | + instance_type="ml.p2.xlarge", |
| 61 | + ) |
| 62 | + patched_get_model_specs.assert_called_once_with( |
| 63 | + sagemaker_constants.JUMPSTART_DEFAULT_REGION_NAME, "pytorch-ic-mobilenet-v2", "*" |
| 64 | + ) |
| 65 | + |
| 66 | + with pytest.raises(ValueError) as e: |
| 67 | + image_uris.retrieve( |
| 68 | + framework=None, |
| 69 | + region="us-west-2", |
| 70 | + image_scope="BAD_SCOPE", |
| 71 | + model_id="pytorch-ic-mobilenet-v2", |
| 72 | + model_version="*", |
| 73 | + instance_type="ml.p2.xlarge", |
| 74 | + ) |
| 75 | + |
| 76 | + with pytest.raises(ValueError) as e: |
| 77 | + image_uris.retrieve( |
| 78 | + framework=None, |
| 79 | + region="mars-south-1", |
| 80 | + image_scope="training", |
| 81 | + model_id="pytorch-ic-mobilenet-v2", |
| 82 | + model_version="*", |
| 83 | + instance_type="ml.p2.xlarge", |
| 84 | + ) |
| 85 | + |
| 86 | + with pytest.raises(ValueError) as e: |
| 87 | + image_uris.retrieve( |
| 88 | + framework=None, |
| 89 | + region="us-west-2", |
| 90 | + model_id="pytorch-ic-mobilenet-v2", |
| 91 | + model_version="*", |
| 92 | + instance_type="ml.p2.xlarge", |
| 93 | + ) |
| 94 | + |
| 95 | + with pytest.raises(ValueError) as e: |
| 96 | + image_uris.retrieve( |
| 97 | + framework=None, |
| 98 | + region="us-west-2", |
| 99 | + image_scope="training", |
| 100 | + model_version="*", |
| 101 | + instance_type="ml.p2.xlarge", |
| 102 | + ) |
| 103 | + |
| 104 | + with pytest.raises(ValueError) as e: |
| 105 | + image_uris.retrieve( |
| 106 | + region="us-west-2", |
| 107 | + framework=None, |
| 108 | + image_scope="training", |
| 109 | + model_id="pytorch-ic-mobilenet-v2", |
| 110 | + instance_type="ml.p2.xlarge", |
| 111 | + ) |
0 commit comments