42
42
mock_s3_model_data_url = "sample s3 data url"
43
43
mock_secret_key = "mock_secret_key"
44
44
mock_instance_type = "mock instance type"
45
- MOCK_HF_MODEL_METADATA_JSON = {"mock_key" : "mock_value" }
46
45
47
46
supported_model_server = {
48
47
ModelServer .TORCHSERVE ,
55
54
56
55
class TestModelBuilder (unittest .TestCase ):
57
56
@patch ("sagemaker.serve.builder.model_builder._ServeSettings" )
58
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
59
- @patch ("sagemaker.huggingface.llm_utils.json" )
60
- def test_validation_in_progress_mode_not_supported (
61
- self , mock_serveSettings , mock_urllib , mock_json
62
- ):
63
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
64
- mock_hf_model_metadata_url = Mock ()
65
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
66
-
57
+ def test_validation_in_progress_mode_not_supported (self , mock_serveSettings ):
67
58
builder = ModelBuilder ()
68
59
self .assertRaisesRegex (
69
60
Exception ,
@@ -75,15 +66,7 @@ def test_validation_in_progress_mode_not_supported(
75
66
)
76
67
77
68
@patch ("sagemaker.serve.builder.model_builder._ServeSettings" )
78
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
79
- @patch ("sagemaker.huggingface.llm_utils.json" )
80
- def test_validation_cannot_set_both_model_and_inference_spec (
81
- self , mock_serveSettings , mock_urllib , mock_json
82
- ):
83
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
84
- mock_hf_model_metadata_url = Mock ()
85
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
86
-
69
+ def test_validation_cannot_set_both_model_and_inference_spec (self , mock_serveSettings ):
87
70
builder = ModelBuilder (inference_spec = "some value" , model = Mock (spec = object ))
88
71
self .assertRaisesRegex (
89
72
Exception ,
@@ -95,15 +78,7 @@ def test_validation_cannot_set_both_model_and_inference_spec(
95
78
)
96
79
97
80
@patch ("sagemaker.serve.builder.model_builder._ServeSettings" )
98
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
99
- @patch ("sagemaker.huggingface.llm_utils.json" )
100
- def test_validation_unsupported_model_server_type (
101
- self , mock_serveSettings , mock_urllib , mock_json
102
- ):
103
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
104
- mock_hf_model_metadata_url = Mock ()
105
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
106
-
81
+ def test_validation_unsupported_model_server_type (self , mock_serveSettings ):
107
82
builder = ModelBuilder (model_server = "invalid_model_server" )
108
83
self .assertRaisesRegex (
109
84
Exception ,
@@ -116,15 +91,7 @@ def test_validation_unsupported_model_server_type(
116
91
)
117
92
118
93
@patch ("sagemaker.serve.builder.model_builder._ServeSettings" )
119
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
120
- @patch ("sagemaker.huggingface.llm_utils.json" )
121
- def test_validation_model_server_not_set_with_image_uri (
122
- self , mock_serveSettings , mock_urllib , mock_json
123
- ):
124
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
125
- mock_hf_model_metadata_url = Mock ()
126
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
127
-
94
+ def test_validation_model_server_not_set_with_image_uri (self , mock_serveSettings ):
128
95
builder = ModelBuilder (image_uri = "image_uri" )
129
96
self .assertRaisesRegex (
130
97
Exception ,
@@ -137,15 +104,9 @@ def test_validation_model_server_not_set_with_image_uri(
137
104
)
138
105
139
106
@patch ("sagemaker.serve.builder.model_builder._ServeSettings" )
140
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
141
- @patch ("sagemaker.huggingface.llm_utils.json" )
142
107
def test_save_model_throw_exception_when_none_of_model_and_inference_spec_is_set (
143
- self , mock_serveSettings , mock_urllib , mock_json
108
+ self , mock_serveSettings
144
109
):
145
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
146
- mock_hf_model_metadata_url = Mock ()
147
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
148
-
149
110
builder = ModelBuilder (inference_spec = None , model = None )
150
111
self .assertRaisesRegex (
151
112
Exception ,
@@ -165,12 +126,8 @@ def test_save_model_throw_exception_when_none_of_model_and_inference_spec_is_set
165
126
@patch ("sagemaker.serve.builder.model_builder.SageMakerEndpointMode" )
166
127
@patch ("sagemaker.serve.builder.model_builder.Model" )
167
128
@patch ("os.path.exists" )
168
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
169
- @patch ("sagemaker.huggingface.llm_utils.json" )
170
129
def test_build_happy_path_with_sagemaker_endpoint_mode_and_byoc (
171
130
self ,
172
- mock_urllib ,
173
- mock_json ,
174
131
mock_path_exists ,
175
132
mock_sdk_model ,
176
133
mock_sageMakerEndpointMode ,
@@ -189,10 +146,6 @@ def test_build_happy_path_with_sagemaker_endpoint_mode_and_byoc(
189
146
else None
190
147
)
191
148
192
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
193
- mock_hf_model_metadata_url = Mock ()
194
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
195
-
196
149
mock_detect_fw_version .return_value = framework , version
197
150
198
151
mock_prepare_for_torchserve .side_effect = (
@@ -273,12 +226,8 @@ def test_build_happy_path_with_sagemaker_endpoint_mode_and_byoc(
273
226
@patch ("sagemaker.serve.builder.model_builder.SageMakerEndpointMode" )
274
227
@patch ("sagemaker.serve.builder.model_builder.Model" )
275
228
@patch ("os.path.exists" )
276
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
277
- @patch ("sagemaker.huggingface.llm_utils.json" )
278
229
def test_build_happy_path_with_sagemaker_endpoint_mode_and_1p_dlc_as_byoc (
279
230
self ,
280
- mock_urllib ,
281
- mock_json ,
282
231
mock_path_exists ,
283
232
mock_sdk_model ,
284
233
mock_sageMakerEndpointMode ,
@@ -296,11 +245,6 @@ def test_build_happy_path_with_sagemaker_endpoint_mode_and_1p_dlc_as_byoc(
296
245
and instance_type == "ml.c5.xlarge"
297
246
else None
298
247
)
299
-
300
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
301
- mock_hf_model_metadata_url = Mock ()
302
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
303
-
304
248
mock_detect_fw_version .return_value = framework , version
305
249
306
250
mock_prepare_for_torchserve .side_effect = (
@@ -381,12 +325,8 @@ def test_build_happy_path_with_sagemaker_endpoint_mode_and_1p_dlc_as_byoc(
381
325
@patch ("sagemaker.serve.builder.model_builder.SageMakerEndpointMode" )
382
326
@patch ("sagemaker.serve.builder.model_builder.Model" )
383
327
@patch ("os.path.exists" )
384
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
385
- @patch ("sagemaker.huggingface.llm_utils.json" )
386
328
def test_build_happy_path_with_sagemaker_endpoint_mode_and_inference_spec (
387
329
self ,
388
- mock_urllib ,
389
- mock_json ,
390
330
mock_path_exists ,
391
331
mock_sdk_model ,
392
332
mock_sageMakerEndpointMode ,
@@ -402,10 +342,6 @@ def test_build_happy_path_with_sagemaker_endpoint_mode_and_inference_spec(
402
342
lambda model_path : mock_native_model if model_path == MODEL_PATH else None
403
343
)
404
344
405
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
406
- mock_hf_model_metadata_url = Mock ()
407
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
408
-
409
345
mock_detect_fw_version .return_value = framework , version
410
346
411
347
mock_detect_container .side_effect = (
@@ -490,12 +426,8 @@ def test_build_happy_path_with_sagemaker_endpoint_mode_and_inference_spec(
490
426
@patch ("sagemaker.serve.builder.model_builder.SageMakerEndpointMode" )
491
427
@patch ("sagemaker.serve.builder.model_builder.Model" )
492
428
@patch ("os.path.exists" )
493
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
494
- @patch ("sagemaker.huggingface.llm_utils.json" )
495
429
def test_build_happy_path_with_sagemakerEndpoint_mode_and_model (
496
430
self ,
497
- mock_urllib ,
498
- mock_json ,
499
431
mock_path_exists ,
500
432
mock_sdk_model ,
501
433
mock_sageMakerEndpointMode ,
@@ -514,10 +446,6 @@ def test_build_happy_path_with_sagemakerEndpoint_mode_and_model(
514
446
else None
515
447
)
516
448
517
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
518
- mock_hf_model_metadata_url = Mock ()
519
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
520
-
521
449
mock_detect_fw_version .return_value = framework , version
522
450
523
451
mock_prepare_for_torchserve .side_effect = (
@@ -601,12 +529,8 @@ def test_build_happy_path_with_sagemakerEndpoint_mode_and_model(
601
529
@patch ("sagemaker.serve.builder.model_builder.SageMakerEndpointMode" )
602
530
@patch ("sagemaker.serve.builder.model_builder.Model" )
603
531
@patch ("os.path.exists" )
604
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
605
- @patch ("sagemaker.huggingface.llm_utils.json" )
606
532
def test_build_happy_path_with_sagemakerEndpoint_mode_and_xgboost_model (
607
533
self ,
608
- mock_urllib ,
609
- mock_json ,
610
534
mock_path_exists ,
611
535
mock_sdk_model ,
612
536
mock_sageMakerEndpointMode ,
@@ -626,10 +550,6 @@ def test_build_happy_path_with_sagemakerEndpoint_mode_and_xgboost_model(
626
550
else None
627
551
)
628
552
629
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
630
- mock_hf_model_metadata_url = Mock ()
631
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
632
-
633
553
mock_detect_fw_version .return_value = "xgboost" , version
634
554
635
555
mock_prepare_for_torchserve .side_effect = (
@@ -714,12 +634,8 @@ def test_build_happy_path_with_sagemakerEndpoint_mode_and_xgboost_model(
714
634
@patch ("sagemaker.serve.builder.model_builder.LocalContainerMode" )
715
635
@patch ("sagemaker.serve.builder.model_builder.Model" )
716
636
@patch ("os.path.exists" )
717
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
718
- @patch ("sagemaker.huggingface.llm_utils.json" )
719
637
def test_build_happy_path_with_local_container_mode (
720
638
self ,
721
- mock_urllib ,
722
- mock_json ,
723
639
mock_path_exists ,
724
640
mock_sdk_model ,
725
641
mock_localContainerMode ,
@@ -734,10 +650,6 @@ def test_build_happy_path_with_local_container_mode(
734
650
lambda model_path : mock_native_model if model_path == MODEL_PATH else None
735
651
)
736
652
737
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
738
- mock_hf_model_metadata_url = Mock ()
739
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
740
-
741
653
mock_detect_container .side_effect = (
742
654
lambda model , region , instance_type : mock_image_uri
743
655
if model == mock_native_model
@@ -816,12 +728,8 @@ def test_build_happy_path_with_local_container_mode(
816
728
@patch ("sagemaker.serve.builder.model_builder.LocalContainerMode" )
817
729
@patch ("sagemaker.serve.builder.model_builder.Model" )
818
730
@patch ("os.path.exists" )
819
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
820
- @patch ("sagemaker.huggingface.llm_utils.json" )
821
731
def test_build_happy_path_with_localContainer_mode_overwritten_with_sagemaker_mode (
822
732
self ,
823
- mock_urllib ,
824
- mock_json ,
825
733
mock_path_exists ,
826
734
mock_sdk_model ,
827
735
mock_localContainerMode ,
@@ -838,10 +746,6 @@ def test_build_happy_path_with_localContainer_mode_overwritten_with_sagemaker_mo
838
746
lambda model_path : mock_native_model if model_path == MODEL_PATH else None
839
747
)
840
748
841
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
842
- mock_hf_model_metadata_url = Mock ()
843
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
844
-
845
749
mock_detect_fw_version .return_value = framework , version
846
750
847
751
mock_detect_container .side_effect = (
@@ -965,12 +869,8 @@ def test_build_happy_path_with_localContainer_mode_overwritten_with_sagemaker_mo
965
869
@patch ("sagemaker.serve.builder.model_builder.LocalContainerMode" )
966
870
@patch ("sagemaker.serve.builder.model_builder.Model" )
967
871
@patch ("os.path.exists" )
968
- @patch ("sagemaker.huggingface.llm_utils.urllib" )
969
- @patch ("sagemaker.huggingface.llm_utils.json" )
970
872
def test_build_happy_path_with_sagemaker_endpoint_mode_overwritten_with_local_container (
971
873
self ,
972
- mock_urllib ,
973
- mock_json ,
974
874
mock_path_exists ,
975
875
mock_sdk_model ,
976
876
mock_localContainerMode ,
@@ -984,10 +884,6 @@ def test_build_happy_path_with_sagemaker_endpoint_mode_overwritten_with_local_co
984
884
# setup mocks
985
885
mock_detect_fw_version .return_value = framework , version
986
886
987
- mock_json .load .return_value = MOCK_HF_MODEL_METADATA_JSON
988
- mock_hf_model_metadata_url = Mock ()
989
- mock_urllib .request .Request .side_effect = mock_hf_model_metadata_url
990
-
991
887
mock_detect_container .side_effect = (
992
888
lambda model , region , instance_type : mock_image_uri
993
889
if model == mock_fw_model
0 commit comments