|
16 | 16 |
|
17 | 17 | from mock.mock import patch
|
18 | 18 |
|
| 19 | +import copy |
19 | 20 | from sagemaker.jumpstart import artifacts
|
| 21 | +from sagemaker.jumpstart.artifacts.model_uris import ( |
| 22 | + _retrieve_hosting_prepacked_artifact_key, |
| 23 | + _retrieve_hosting_artifact_key, |
| 24 | + _retrieve_training_artifact_key, |
| 25 | +) |
| 26 | +from sagemaker.jumpstart.types import JumpStartModelSpecs |
| 27 | +from tests.unit.sagemaker.jumpstart.constants import ( |
| 28 | + BASE_SPEC, |
| 29 | +) |
| 30 | + |
20 | 31 |
|
21 | 32 | from tests.unit.sagemaker.jumpstart.utils import get_spec_from_base_spec
|
22 | 33 |
|
23 | 34 |
|
| 35 | +class ModelArtifactVariantsTest(unittest.TestCase): |
| 36 | + def test_retrieve_hosting_prepacked_artifact_key(self): |
| 37 | + |
| 38 | + test_spec = copy.deepcopy(BASE_SPEC) |
| 39 | + |
| 40 | + test_spec["hosting_prepacked_artifact_key"] = "some/thing" |
| 41 | + |
| 42 | + test_spec["hosting_instance_type_variants"] = { |
| 43 | + "regional_aliases": { |
| 44 | + "us-west-2": { |
| 45 | + "alias_ecr_uri_1": "763104351884.dkr.ecr.us-west-2.ama" |
| 46 | + "zonaws.com/djl-inference:0.23.0-deepspeed0.9.5-cu118" |
| 47 | + } |
| 48 | + }, |
| 49 | + "variants": { |
| 50 | + "c4": { |
| 51 | + "regional_properties": { |
| 52 | + "image_uri": "$alias_ecr_uri_1", |
| 53 | + }, |
| 54 | + "properties": { |
| 55 | + "prepacked_artifact_key": "in/the/way", |
| 56 | + }, |
| 57 | + } |
| 58 | + }, |
| 59 | + } |
| 60 | + |
| 61 | + self.assertEqual( |
| 62 | + _retrieve_hosting_prepacked_artifact_key( |
| 63 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 64 | + ), |
| 65 | + "in/the/way", |
| 66 | + ) |
| 67 | + |
| 68 | + test_spec["hosting_prepacked_artifact_key"] = None |
| 69 | + |
| 70 | + self.assertEqual( |
| 71 | + _retrieve_hosting_prepacked_artifact_key( |
| 72 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 73 | + ), |
| 74 | + "in/the/way", |
| 75 | + ) |
| 76 | + |
| 77 | + test_spec["hosting_instance_type_variants"] = None |
| 78 | + |
| 79 | + self.assertEqual( |
| 80 | + _retrieve_hosting_prepacked_artifact_key( |
| 81 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 82 | + ), |
| 83 | + None, |
| 84 | + ) |
| 85 | + |
| 86 | + test_spec["hosting_prepacked_artifact_key"] = "shemoves" |
| 87 | + |
| 88 | + self.assertEqual( |
| 89 | + _retrieve_hosting_prepacked_artifact_key( |
| 90 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 91 | + ), |
| 92 | + "shemoves", |
| 93 | + ) |
| 94 | + |
| 95 | + def test_retrieve_hosting_artifact_key(self): |
| 96 | + |
| 97 | + test_spec = copy.deepcopy(BASE_SPEC) |
| 98 | + |
| 99 | + test_spec["hosting_artifact_key"] = "some/thing" |
| 100 | + |
| 101 | + test_spec["hosting_instance_type_variants"] = { |
| 102 | + "regional_aliases": { |
| 103 | + "us-west-2": { |
| 104 | + "alias_ecr_uri_1": "763104351884.dkr.ecr.us-west-2.ama" |
| 105 | + "zonaws.com/djl-inference:0.23.0-deepspeed0.9.5-cu118" |
| 106 | + } |
| 107 | + }, |
| 108 | + "variants": { |
| 109 | + "c4": { |
| 110 | + "regional_properties": { |
| 111 | + "image_uri": "$alias_ecr_uri_1", |
| 112 | + }, |
| 113 | + "properties": { |
| 114 | + "artifact_key": "in/the/way", |
| 115 | + }, |
| 116 | + } |
| 117 | + }, |
| 118 | + } |
| 119 | + |
| 120 | + self.assertEqual( |
| 121 | + _retrieve_hosting_artifact_key( |
| 122 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 123 | + ), |
| 124 | + "in/the/way", |
| 125 | + ) |
| 126 | + |
| 127 | + test_spec["hosting_artifact_key"] = None |
| 128 | + |
| 129 | + self.assertEqual( |
| 130 | + _retrieve_hosting_artifact_key( |
| 131 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 132 | + ), |
| 133 | + "in/the/way", |
| 134 | + ) |
| 135 | + |
| 136 | + test_spec["hosting_instance_type_variants"] = None |
| 137 | + |
| 138 | + self.assertEqual( |
| 139 | + _retrieve_hosting_artifact_key( |
| 140 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 141 | + ), |
| 142 | + None, |
| 143 | + ) |
| 144 | + |
| 145 | + test_spec["hosting_artifact_key"] = "shemoves" |
| 146 | + |
| 147 | + self.assertEqual( |
| 148 | + _retrieve_hosting_artifact_key( |
| 149 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 150 | + ), |
| 151 | + "shemoves", |
| 152 | + ) |
| 153 | + |
| 154 | + def test_retrieve_training_artifact_key(self): |
| 155 | + |
| 156 | + test_spec = copy.deepcopy(BASE_SPEC) |
| 157 | + |
| 158 | + test_spec["training_artifact_key"] = "some/thing" |
| 159 | + |
| 160 | + test_spec["training_instance_type_variants"] = { |
| 161 | + "regional_aliases": { |
| 162 | + "us-west-2": { |
| 163 | + "alias_ecr_uri_1": "763104351884.dkr.ecr.us-west-2." |
| 164 | + "amazonaws.com/djl-inference:0.23.0-deepspeed0.9.5-cu118" |
| 165 | + } |
| 166 | + }, |
| 167 | + "variants": { |
| 168 | + "c4": { |
| 169 | + "regional_properties": { |
| 170 | + "image_uri": "$alias_ecr_uri_1", |
| 171 | + }, |
| 172 | + "properties": { |
| 173 | + "artifact_key": "in/the/way", |
| 174 | + }, |
| 175 | + } |
| 176 | + }, |
| 177 | + } |
| 178 | + |
| 179 | + self.assertEqual( |
| 180 | + _retrieve_training_artifact_key( |
| 181 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 182 | + ), |
| 183 | + "in/the/way", |
| 184 | + ) |
| 185 | + |
| 186 | + test_spec["training_artifact_key"] = None |
| 187 | + |
| 188 | + self.assertEqual( |
| 189 | + _retrieve_training_artifact_key( |
| 190 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 191 | + ), |
| 192 | + "in/the/way", |
| 193 | + ) |
| 194 | + |
| 195 | + test_spec["training_instance_type_variants"] = None |
| 196 | + |
| 197 | + self.assertEqual( |
| 198 | + _retrieve_training_artifact_key( |
| 199 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 200 | + ), |
| 201 | + None, |
| 202 | + ) |
| 203 | + |
| 204 | + test_spec["training_artifact_key"] = "shemoves" |
| 205 | + |
| 206 | + self.assertEqual( |
| 207 | + _retrieve_training_artifact_key( |
| 208 | + JumpStartModelSpecs(test_spec), instance_type="ml.c4.xlarge" |
| 209 | + ), |
| 210 | + "shemoves", |
| 211 | + ) |
| 212 | + |
| 213 | + |
24 | 214 | @patch("sagemaker.jumpstart.accessors.JumpStartModelsAccessor.get_model_specs")
|
25 | 215 | class RetrieveKwargsTest(unittest.TestCase):
|
26 | 216 |
|
|
0 commit comments