code: def test_jumpstart_instance_types(patched_get_model_specs):
      patched_get_model_specs.side_effect = get_spec_from_base_spec
  
      model_id, model_version = "huggingface-eqa-bert-base-cased", "*"
      region = "us-west-2"
  
      mock_client = boto3.client("s3")
      mock_session = Mock(s3_client=mock_client)
  
      default_training_instance_types = instance_types.retrieve_default(
          region=region,
          model_id=model_id,
          model_version=model_version,
          scope="training",
          sagemaker_session=mock_session,
      )
      assert default_training_instance_types == "ml.p3.2xlarge"
  
      patched_get_model_specs.assert_called_once_with(
          region=region,
          model_id=model_id,
          version=model_version,
          s3_client=mock_client,
      )
  
      patched_get_model_specs.reset_mock()
  
      default_inference_instance_types = (
          instance_types.retrieve_default(
              region=region,
              model_id=model_id,
              model_version=model_version,
              scope="inference",
              sagemaker_session=mock_session,
          )
      )
      assert default_inference_instance_types == "ml.p2.xlarge"
  
      patched_get_model_specs.assert_called_once_with(
          region=region,
          model_id=model_id,
          version=model_version,
          s3_client=mock_client,
      )
  
      patched_get_model_specs.reset_mock()
  
      default_training_instance_types = instance_types.retrieve(
          region=region,
          model_id=model_id,
          model_version=model_version,
          scope="training",
          sagemaker_session=mock_session,
      )
      assert default_training_instance_types == [
          "ml.p3.2xlarge",
          "ml.p2.xlarge",
          "ml.g4dn.2xlarge",
          "ml.m5.xlarge",
          "ml.c5.2xlarge",
      ]
  
      patched_get_model_specs.assert_called_once_with(
          region=region,
          model_id=model_id,
          version=model_version,
          s3_client=mock_client,
      )
  
      patched_get_model_specs.reset_mock()
  
      default_inference_instance_types = instance_types.retrieve(
          region=region,
          model_id=model_id,
          model_version=model_version,
          scope="inference",
          sagemaker_session=mock_session,
      )
      assert default_inference_instance_types == [
          "ml.p2.xlarge",
          "ml.p3.2xlarge",
          "ml.g4dn.xlarge",
          "ml.m5.large",
          "ml.m5.xlarge",
          "ml.c5.xlarge",
          "ml.c5.2xlarge",
      ]
  
      patched_get_model_specs.assert_called_once_with(
          region=region,
          model_id=model_id,
          version=model_version,
          s3_client=mock_client,
      )
  
      patched_get_model_specs.reset_mock()
  
      with pytest.raises(ValueError):
          instance_types.retrieve_default(
              region=region,
              model_id=model_id,
              model_version="*",
          )
  
      with pytest.raises(ValueError):
          instance_types.retrieve(
              region=region,
              model_id=model_id,
              model_version="*",
          )
  
      with pytest.raises(KeyError):
          instance_types.retrieve_default(
              region=region,
              model_id="blah",
              model_version="*",
              scope="inference",
          )
  
      with pytest.raises(ValueError):
          instance_types.retrieve_default(
              region="mars-south-1",
              model_id=model_id,
              model_version="*",
              scope="training",
          )
  
      with pytest.raises(ValueError):
          instance_types.retrieve_default(
              model_version="*", scope="inference"
          )
  
      with pytest.raises(ValueError):
          instance_types.retrieve_default(
              model_id=model_id, scope="training"
          )
  
      with pytest.raises(KeyError):
          instance_types.retrieve(
              region=region,
              model_id="blah",
              model_version="*",
              scope="inference",
          )
  
      with pytest.raises(ValueError):
          instance_types.retrieve(
              region="mars-south-1",
              model_id=model_id,
              model_version="*",
              scope="training",
          )
  
      with pytest.raises(ValueError):
          instance_types.retrieve(model_version="*", scope="inference")
  
      with pytest.raises(ValueError):
          instance_types.retrieve(model_id=model_id, scope="training")
  
file_path: sagemaker-python-sdk/tests/unit/sagemaker/instance_types/jumpstart/test_instance_types.py
imports: from __future__ import absolute_import
  from unittest.mock import Mock
  import boto3
  from mock.mock import patch
  import pytest
  from sagemaker import instance_types
  from tests.unit.sagemaker.jumpstart.utils import get_spec_from_base_spec, get_special_model_spec
label_desc: Use image node_id 1 for calling a global function with example usage: test_jumpstart_instance_types(patched_get_model_specs) without return types