code: 
  
  
  
  import unittest
  
  import numpy as np
  
  from transformers import BlipTextConfig
  from transformers.testing_utils import require_torch, slow, torch_device
  from transformers.utils import is_torch_available
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
  
  
  if is_torch_available():
      import torch
  
      from transformers import BlipTextModel
      from transformers.models.blip.modeling_blip import BLIP_PRETRAINED_MODEL_ARCHIVE_LIST
  
  
  
  class        lowerCAmelCase_	:
         def __init__(    self,    SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_=12,    SCREAMING_SNAKE_CASE_=7,    SCREAMING_SNAKE_CASE_=True,    SCREAMING_SNAKE_CASE_=True,    SCREAMING_SNAKE_CASE_=True,    SCREAMING_SNAKE_CASE_=99,    SCREAMING_SNAKE_CASE_=32,    SCREAMING_SNAKE_CASE_=32,    SCREAMING_SNAKE_CASE_=5,    SCREAMING_SNAKE_CASE_=4,    SCREAMING_SNAKE_CASE_=37,    SCREAMING_SNAKE_CASE_=0.1,    SCREAMING_SNAKE_CASE_=0.1,    SCREAMING_SNAKE_CASE_=512,    SCREAMING_SNAKE_CASE_=0.02,    SCREAMING_SNAKE_CASE_=0,    SCREAMING_SNAKE_CASE_=None,    )  ->	Tuple:
            UpperCamelCase					:						Dict					=			parent
            UpperCamelCase					:						Union[str, Any]					=			batch_size
            UpperCamelCase					:						Optional[int]					=			seq_length
            UpperCamelCase					:						str					=			is_training
            UpperCamelCase					:						str					=			use_input_mask
            UpperCamelCase					:						Dict					=			use_labels
            UpperCamelCase					:						List[str]					=			vocab_size
            UpperCamelCase					:						Union[str, Any]					=			hidden_size
            UpperCamelCase					:						Optional[int]					=			projection_dim
            UpperCamelCase					:						Dict					=			num_hidden_layers
            UpperCamelCase					:						str					=			num_attention_heads
            UpperCamelCase					:						Union[str, Any]					=			intermediate_size
            UpperCamelCase					:						List[Any]					=			dropout
            UpperCamelCase					:						Optional[Any]					=			attention_dropout
            UpperCamelCase					:						Dict					=			max_position_embeddings
            UpperCamelCase					:						List[str]					=			initializer_range
            UpperCamelCase					:						str					=			scope
            UpperCamelCase					:						Union[str, Any]					=			bos_token_id
         def       snake_case_ (    self )  ->	Optional[int]:
            UpperCamelCase					:						str					=			ids_tensor([self.batch_size, self.seq_length],    self.vocab_size )
  
            UpperCamelCase					:						Union[str, Any]					=			None
            if self.use_input_mask:
               UpperCamelCase					:						List[str]					=			random_attention_mask([self.batch_size, self.seq_length] )
  
            if input_mask is not None:
               UpperCamelCase			,  UpperCamelCase					:						Any					=			input_mask.shape
               UpperCamelCase					:						Optional[int]					=			np.random.randint(1,    seq_length - 1,    size=(batch_size,) )
               for batch_idx, start_index in enumerate(a_ ):
                  UpperCamelCase					:						int					=			1
                  UpperCamelCase					:						Dict					=			0
  
            UpperCamelCase					:						Any					=			self.get_config()
  
            return config, input_ids, input_mask
         def       snake_case_ (    self )  ->	int:
            return BlipTextConfig(
                vocab_size=self.vocab_size,    hidden_size=self.hidden_size,    projection_dim=self.projection_dim,    num_hidden_layers=self.num_hidden_layers,    num_attention_heads=self.num_attention_heads,    intermediate_size=self.intermediate_size,    dropout=self.dropout,    attention_dropout=self.attention_dropout,    max_position_embeddings=self.max_position_embeddings,    initializer_range=self.initializer_range,    bos_token_id=self.bos_token_id,    )
         def       snake_case_ (    self,    SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_ )  ->	str:
            UpperCamelCase					:						Union[str, Any]					=			BlipTextModel(config=a_ )
            model.to(a_ )
            model.eval()
            with torch.no_grad():
               UpperCamelCase					:						Dict					=			model(a_,    attention_mask=a_ )
               UpperCamelCase					:						Tuple					=			model(a_ )
            self.parent.assertEqual(result.last_hidden_state.shape,    (self.batch_size, self.seq_length, self.hidden_size) )
            self.parent.assertEqual(result.pooler_output.shape,    (self.batch_size, self.hidden_size) )
  
  
  
  
  
  
         def       snake_case_ (    self )  ->	Tuple:
            UpperCamelCase					:						Optional[Any]					=			self.prepare_config_and_inputs()
            UpperCamelCase			,  UpperCamelCase			,  UpperCamelCase					:						Optional[Any]					=			config_and_inputs
            UpperCamelCase					:						Any					=			{'input_ids': input_ids, 'attention_mask': input_mask}
            return config, inputs_dict
  
  
  
  
  
  
  @require_torch
  class        lowerCAmelCase_	(						SCREAMING_SNAKE_CASE__ ,					unittest.TestCase							):
         UpperCAmelCase__       :      Any       =						(BlipTextModel,) if is_torch_available() else ()
         UpperCAmelCase__       :      List[Any]       =						False
         UpperCAmelCase__       :      Dict       =						False
         UpperCAmelCase__       :      int       =						False
         def       snake_case_ (    self )  ->	str:
            UpperCamelCase					:						str					=			BlipTextModelTester(self )
            UpperCamelCase					:						Union[str, Any]					=			ConfigTester(self,    config_class=a_,    hidden_size=37 )
         def       snake_case_ (    self )  ->	List[Any]:
            self.config_tester.run_common_tests()
         def       snake_case_ (    self )  ->	str:
            UpperCamelCase					:						int					=			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(*a_ )
         def       snake_case_ (    self )  ->	str:
            pass
         def       snake_case_ (    self )  ->	Union[str, Any]:
            pass
         @unittest.skip(reason='Blip does not use inputs_embeds' )
         def       snake_case_ (    self )  ->	Union[str, Any]:
            pass
         @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING' )
         def       snake_case_ (    self )  ->	List[Any]:
            pass
         @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING' )
         def       snake_case_ (    self )  ->	Any:
            pass
         @slow
         def       snake_case_ (    self )  ->	Union[str, Any]:
  
  
  
            for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               UpperCamelCase					:						List[str]					=			BlipTextModel.from_pretrained(a_ )
               self.assertIsNotNone(a_ )
  
  
  
  
  
  
         def       snake_case_ (    self )  ->	int:
            super().test_pt_tf_model_equivalence(allow_missing_keys=a_ )
  
  
  
  
style_context: 
  
  
  
  import unittest
  
  import numpy as np
  
  from transformers.testing_utils import require_torch, require_vision
  from transformers.utils import is_torch_available, is_vision_available
  
  from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs
  
  
  if is_torch_available():
      import torch
  
  if is_vision_available():
      from PIL import Image
  
      from transformers import ViltImageProcessor
  
  
  
  class        lowerCAmelCase_	(						unittest.TestCase							):
         def __init__(    self,    SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_=7,    SCREAMING_SNAKE_CASE_=3,    SCREAMING_SNAKE_CASE_=18,    SCREAMING_SNAKE_CASE_=30,    SCREAMING_SNAKE_CASE_=400,    SCREAMING_SNAKE_CASE_=True,    SCREAMING_SNAKE_CASE_=None,    SCREAMING_SNAKE_CASE_=2,    SCREAMING_SNAKE_CASE_=True,    SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5],    SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5],    )  ->	List[Any]:
            UpperCamelCase					:						Optional[int]					=			size if size is not None else {'shortest_edge': 30}
            UpperCamelCase					:						Dict					=			parent
            UpperCamelCase					:						str					=			batch_size
            UpperCamelCase					:						str					=			num_channels
            UpperCamelCase					:						Optional[int]					=			image_size
            UpperCamelCase					:						List[Any]					=			min_resolution
            UpperCamelCase					:						Tuple					=			max_resolution
            UpperCamelCase					:						Tuple					=			do_resize
            UpperCamelCase					:						Any					=			size
            UpperCamelCase					:						int					=			size_divisor
            UpperCamelCase					:						str					=			do_normalize
            UpperCamelCase					:						Optional[int]					=			image_mean
            UpperCamelCase					:						List[str]					=			image_std
         def       snake_case_ (    self )  ->	List[Any]:
            return {
                "image_mean": self.image_mean,
                "image_std": self.image_std,
                "do_normalize": self.do_normalize,
                "do_resize": self.do_resize,
                "size": self.size,
                "size_divisor": self.size_divisor,
            }
  
  
  
  
  
  
         def       snake_case_ (    self,    SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_=False )  ->	Union[str, Any]:
            if not batched:
               UpperCamelCase					:						Optional[Any]					=			self.size['shortest_edge']
               UpperCamelCase					:						int					=			image_inputs[0]
               if isinstance(SCREAMING_SNAKE_CASE_,    Image.Image ):
                  UpperCamelCase			,  UpperCamelCase					:						List[Any]					=			image.size
               else:
                  UpperCamelCase			,  UpperCamelCase					:						List[Any]					=			image.shape[1], image.shape[2]
               UpperCamelCase					:						Any					=			size / min(SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_ )
               if h < w:
                  UpperCamelCase			,  UpperCamelCase					:						Optional[int]					=			size, scale * w
               else:
                  UpperCamelCase			,  UpperCamelCase					:						List[str]					=			scale * h, size
  
               UpperCamelCase					:						int					=			int((1333 / 800) * size )
               if max(SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_ ) > max_size:
                  UpperCamelCase					:						Any					=			max_size / max(SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_ )
                  UpperCamelCase					:						List[Any]					=			newh * scale
                  UpperCamelCase					:						Optional[int]					=			neww * scale
  
               UpperCamelCase			,  UpperCamelCase					:						List[Any]					=			int(newh + 0.5 ), int(neww + 0.5 )
               UpperCamelCase			,  UpperCamelCase					:						int					=			(
                   newh // self.size_divisor * self.size_divisor,
                   neww // self.size_divisor * self.size_divisor,
               )
  
            else:
               UpperCamelCase					:						Dict					=			[]
               for image in image_inputs:
                  UpperCamelCase			,  UpperCamelCase					:						Union[str, Any]					=			self.get_expected_values([image] )
                  expected_values.append((expected_height, expected_width) )
               UpperCamelCase					:						List[str]					=			max(SCREAMING_SNAKE_CASE_,    key=lambda SCREAMING_SNAKE_CASE_ : item[0] )[0]
               UpperCamelCase					:						List[str]					=			max(SCREAMING_SNAKE_CASE_,    key=lambda SCREAMING_SNAKE_CASE_ : item[1] )[1]
  
            return expected_height, expected_width
  
  
  
  
  
  
  @require_torch
  @require_vision
  class        lowerCAmelCase_	(						a__ ,					unittest.TestCase							):
         UpperCAmelCase__       :      List[Any]       =						ViltImageProcessor if is_vision_available() else None
         def       snake_case_ (    self )  ->	Union[str, Any]:
            UpperCamelCase					:						Dict					=			ViltImageProcessingTester(self )
         @property
         def       snake_case_ (    self )  ->	Dict:
            return self.image_processor_tester.prepare_image_processor_dict()
         def       snake_case_ (    self )  ->	Union[str, Any]:
            UpperCamelCase					:						List[str]					=			self.image_processing_class(**self.image_processor_dict )
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,    'image_mean' ) )
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,    'image_std' ) )
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,    'do_normalize' ) )
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,    'do_resize' ) )
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,    'size' ) )
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,    'size_divisor' ) )
         def       snake_case_ (    self )  ->	List[Any]:
            UpperCamelCase					:						Union[str, Any]					=			self.image_processing_class.from_dict(self.image_processor_dict )
            self.assertEqual(image_processor.size,    {'shortest_edge': 30} )
  
            UpperCamelCase					:						Union[str, Any]					=			self.image_processing_class.from_dict(self.image_processor_dict,    size=42 )
            self.assertEqual(image_processor.size,    {'shortest_edge': 42} )
         def       snake_case_ (    self )  ->	Dict:
            pass
         def       snake_case_ (    self )  ->	str:
            # Initialize image_processing
            UpperCamelCase					:						int					=			self.image_processing_class(**self.image_processor_dict )
            # create random PIL images
            UpperCamelCase					:						Any					=			prepare_image_inputs(self.image_processor_tester,    equal_resolution=SCREAMING_SNAKE_CASE_ )
            for image in image_inputs:
               self.assertIsInstance(SCREAMING_SNAKE_CASE_,    Image.Image )
  
            # Test not batched input
            UpperCamelCase					:						int					=			image_processing(image_inputs[0],    return_tensors='pt' ).pixel_values
  
            UpperCamelCase			,  UpperCamelCase					:						Dict					=			self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE_ )
            self.assertEqual(
                encoded_images.shape,    (1, self.image_processor_tester.num_channels, expected_height, expected_width),    )
  
            # Test batched
            UpperCamelCase					:						str					=			image_processing(SCREAMING_SNAKE_CASE_,    return_tensors='pt' ).pixel_values
  
            UpperCamelCase			,  UpperCamelCase					:						Tuple					=			self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE_,    batched=SCREAMING_SNAKE_CASE_ )
            self.assertEqual(
                encoded_images.shape,    (
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_channels,
                    expected_height,
                    expected_width,
                ),    )
         def       snake_case_ (    self )  ->	List[str]:
            # Initialize image_processing
            UpperCamelCase					:						Optional[int]					=			self.image_processing_class(**self.image_processor_dict )
            # create random numpy tensors
            UpperCamelCase					:						Optional[Any]					=			prepare_image_inputs(self.image_processor_tester,    equal_resolution=SCREAMING_SNAKE_CASE_,    numpify=SCREAMING_SNAKE_CASE_ )
            for image in image_inputs:
               self.assertIsInstance(SCREAMING_SNAKE_CASE_,    np.ndarray )
  
            # Test not batched input
            UpperCamelCase					:						Optional[Any]					=			image_processing(image_inputs[0],    return_tensors='pt' ).pixel_values
  
            UpperCamelCase			,  UpperCamelCase					:						str					=			self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE_ )
            self.assertEqual(
                encoded_images.shape,    (1, self.image_processor_tester.num_channels, expected_height, expected_width),    )
  
            # Test batched
            UpperCamelCase					:						Dict					=			image_processing(SCREAMING_SNAKE_CASE_,    return_tensors='pt' ).pixel_values
  
            UpperCamelCase			,  UpperCamelCase					:						Optional[Any]					=			self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE_,    batched=SCREAMING_SNAKE_CASE_ )
            self.assertEqual(
                encoded_images.shape,    (
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_channels,
                    expected_height,
                    expected_width,
                ),    )
  
  
  
  
  
  
         def       snake_case_ (    self )  ->	Optional[Any]:
            # Initialize image_processing
            UpperCamelCase					:						Optional[int]					=			self.image_processing_class(**self.image_processor_dict )
            # create random PyTorch tensors
            UpperCamelCase					:						Dict					=			prepare_image_inputs(self.image_processor_tester,    equal_resolution=SCREAMING_SNAKE_CASE_,    torchify=SCREAMING_SNAKE_CASE_ )
            for image in image_inputs:
               self.assertIsInstance(SCREAMING_SNAKE_CASE_,    torch.Tensor )
  
            # Test not batched input
            UpperCamelCase					:						List[str]					=			image_processing(image_inputs[0],    return_tensors='pt' ).pixel_values
  
            UpperCamelCase			,  UpperCamelCase					:						Union[str, Any]					=			self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE_ )
            self.assertEqual(
                encoded_images.shape,    (1, self.image_processor_tester.num_channels, expected_height, expected_width),    )
  
            # Test batched
            UpperCamelCase					:						List[Any]					=			image_processing(SCREAMING_SNAKE_CASE_,    return_tensors='pt' ).pixel_values
  
            UpperCamelCase			,  UpperCamelCase					:						Dict					=			self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE_,    batched=SCREAMING_SNAKE_CASE_ )
            self.assertEqual(
                encoded_images.shape,    (
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_channels,
                    expected_height,
                    expected_width,
                ),    )
  
  
  
  