42
42
BASE_MANIFEST ,
43
43
BASE_SPEC ,
44
44
)
45
+ from sagemaker .jumpstart .utils import get_jumpstart_content_bucket
45
46
46
47
47
48
@patch .object (JumpStartModelsCache , "_retrieval_function" , patched_retrieval_function )
@@ -525,11 +526,14 @@ def test_jumpstart_cache_evaluates_md5_hash(mock_boto3_client):
525
526
)
526
527
527
528
529
+ @patch ("sagemaker.jumpstart.cache.utils.emit_logs_based_on_model_specs" )
528
530
@patch ("boto3.client" )
529
- def test_jumpstart_cache_makes_correct_s3_calls (mock_boto3_client ):
531
+ def test_jumpstart_cache_makes_correct_s3_calls (
532
+ mock_boto3_client , mock_emit_logs_based_on_model_specs
533
+ ):
530
534
531
535
# test get_header
532
- mock_json = json .dumps (
536
+ mock_manifest_json = json .dumps (
533
537
[
534
538
{
535
539
"model_id" : "pytorch-ic-imagenet-inception-v3-classification-4" ,
@@ -542,17 +546,17 @@ def test_jumpstart_cache_makes_correct_s3_calls(mock_boto3_client):
542
546
)
543
547
mock_boto3_client .return_value .get_object .return_value = {
544
548
"Body" : botocore .response .StreamingBody (
545
- io .BytesIO (bytes (mock_json , "utf-8" )), content_length = len (mock_json )
549
+ io .BytesIO (bytes (mock_manifest_json , "utf-8" )), content_length = len (mock_manifest_json )
546
550
),
547
551
"ETag" : "etag" ,
548
552
}
549
553
550
554
mock_boto3_client .return_value .head_object .return_value = {"ETag" : "some-hash" }
551
555
552
- bucket_name = "bucket_name"
556
+ bucket_name = get_jumpstart_content_bucket ( "us-west-2" )
553
557
client_config = botocore .config .Config (signature_version = "my_signature_version" )
554
558
cache = JumpStartModelsCache (
555
- s3_bucket_name = bucket_name , s3_client_config = client_config , region = "my_region "
559
+ s3_bucket_name = bucket_name , s3_client_config = client_config , region = "us-west-2 "
556
560
)
557
561
cache .get_header (
558
562
model_id = "pytorch-ic-imagenet-inception-v3-classification-4" , semantic_version_str = "*"
@@ -563,7 +567,7 @@ def test_jumpstart_cache_makes_correct_s3_calls(mock_boto3_client):
563
567
)
564
568
mock_boto3_client .return_value .head_object .assert_not_called ()
565
569
566
- mock_boto3_client .assert_called_with ("s3" , region_name = "my_region " , config = client_config )
570
+ mock_boto3_client .assert_called_with ("s3" , region_name = "us-west-2 " , config = client_config )
567
571
568
572
# test get_specs. manifest already in cache, so only s3 call will be to get specs.
569
573
mock_json = json .dumps (BASE_SPEC )
@@ -576,9 +580,22 @@ def test_jumpstart_cache_makes_correct_s3_calls(mock_boto3_client):
576
580
),
577
581
"ETag" : "etag" ,
578
582
}
579
- cache .get_specs (
580
- model_id = "pytorch-ic-imagenet-inception-v3-classification-4" , semantic_version_str = "*"
581
- )
583
+
584
+ with patch ("logging.Logger.warning" ) as mocked_warning_log :
585
+ cache .get_specs (
586
+ model_id = "pytorch-ic-imagenet-inception-v3-classification-4" , semantic_version_str = "*"
587
+ )
588
+ mocked_warning_log .assert_called_once_with (
589
+ "Using model 'pytorch-ic-imagenet-inception-v3-classification-4' with wildcard "
590
+ "version identifier '*'. Please consider pinning to version '2.0.0' to "
591
+ "ensure stable results. Note that models may have different input/output "
592
+ "signatures after a major version upgrade."
593
+ )
594
+ mocked_warning_log .reset_mock ()
595
+ cache .get_specs (
596
+ model_id = "pytorch-ic-imagenet-inception-v3-classification-4" , semantic_version_str = "*"
597
+ )
598
+ mocked_warning_log .assert_not_called ()
582
599
583
600
mock_boto3_client .return_value .get_object .assert_called_with (
584
601
Bucket = bucket_name ,
@@ -595,10 +612,18 @@ def test_jumpstart_cache_handles_bad_semantic_version_manifest_key_cache():
595
612
cache .clear = MagicMock ()
596
613
cache ._model_id_semantic_version_manifest_key_cache = MagicMock ()
597
614
cache ._model_id_semantic_version_manifest_key_cache .get .side_effect = [
598
- JumpStartVersionedModelId (
599
- "tensorflow-ic-imagenet-inception-v3-classification-4" , "999.0.0"
615
+ (
616
+ JumpStartVersionedModelId (
617
+ "tensorflow-ic-imagenet-inception-v3-classification-4" , "999.0.0"
618
+ ),
619
+ True ,
620
+ ),
621
+ (
622
+ JumpStartVersionedModelId (
623
+ "tensorflow-ic-imagenet-inception-v3-classification-4" , "1.0.0"
624
+ ),
625
+ True ,
600
626
),
601
- JumpStartVersionedModelId ("tensorflow-ic-imagenet-inception-v3-classification-4" , "1.0.0" ),
602
627
]
603
628
604
629
assert JumpStartModelHeader (
@@ -616,11 +641,17 @@ def test_jumpstart_cache_handles_bad_semantic_version_manifest_key_cache():
616
641
cache .clear .reset_mock ()
617
642
618
643
cache ._model_id_semantic_version_manifest_key_cache .get .side_effect = [
619
- JumpStartVersionedModelId (
620
- "tensorflow-ic-imagenet-inception-v3-classification-4" , "999.0.0"
644
+ (
645
+ JumpStartVersionedModelId (
646
+ "tensorflow-ic-imagenet-inception-v3-classification-4" , "999.0.0"
647
+ ),
648
+ True ,
621
649
),
622
- JumpStartVersionedModelId (
623
- "tensorflow-ic-imagenet-inception-v3-classification-4" , "987.0.0"
650
+ (
651
+ JumpStartVersionedModelId (
652
+ "tensorflow-ic-imagenet-inception-v3-classification-4" , "987.0.0"
653
+ ),
654
+ True ,
624
655
),
625
656
]
626
657
with pytest .raises (KeyError ):
@@ -735,6 +766,7 @@ def test_jumpstart_local_metadata_override_header(
735
766
mocked_get_json_file_and_etag_from_s3 .assert_not_called ()
736
767
737
768
769
+ @patch ("sagemaker.jumpstart.cache.utils.emit_logs_based_on_model_specs" )
738
770
@patch .object (JumpStartModelsCache , "_get_json_file_and_etag_from_s3" )
739
771
@patch ("sagemaker.jumpstart.utils.get_sagemaker_version" , lambda : "2.68.3" )
740
772
@patch .dict (
@@ -747,7 +779,10 @@ def test_jumpstart_local_metadata_override_header(
747
779
@patch ("sagemaker.jumpstart.cache.os.path.isdir" )
748
780
@patch ("builtins.open" )
749
781
def test_jumpstart_local_metadata_override_specs (
750
- mocked_open : Mock , mocked_is_dir : Mock , mocked_get_json_file_and_etag_from_s3 : Mock
782
+ mocked_open : Mock ,
783
+ mocked_is_dir : Mock ,
784
+ mocked_get_json_file_and_etag_from_s3 : Mock ,
785
+ mock_emit_logs_based_on_model_specs ,
751
786
):
752
787
753
788
mocked_open .side_effect = [
@@ -776,6 +811,7 @@ def test_jumpstart_local_metadata_override_specs(
776
811
mocked_get_json_file_and_etag_from_s3 .assert_not_called ()
777
812
778
813
814
+ @patch ("sagemaker.jumpstart.cache.utils.emit_logs_based_on_model_specs" )
779
815
@patch .object (JumpStartModelsCache , "_get_json_file_and_etag_from_s3" )
780
816
@patch ("sagemaker.jumpstart.utils.get_sagemaker_version" , lambda : "2.68.3" )
781
817
@patch .dict (
@@ -791,6 +827,7 @@ def test_jumpstart_local_metadata_override_specs_not_exist_both_directories(
791
827
mocked_open : Mock ,
792
828
mocked_is_dir : Mock ,
793
829
mocked_get_json_file_and_etag_from_s3 : Mock ,
830
+ mocked_emit_logs_based_on_model_specs ,
794
831
):
795
832
model_id , version = "tensorflow-ic-imagenet-inception-v3-classification-4" , "2.0.0"
796
833
0 commit comments