code: 
  
  
  
  """simple docstring"""
  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 							_UpperCAmelCase							:
  
  
  
  
  
       '''simple docstring'''
  
  
  
       def __init__(      self ,			A ,			A=1_2 ,			A=7 ,			A=True ,			A=True ,			A=True ,			A=9_9 ,			A=3_2 ,			A=3_2 ,			A=5 ,			A=4 ,			A=3_7 ,			A=0.1 ,			A=0.1 ,			A=5_1_2 ,			A=0.02 ,			A=0 ,			A=None ,			)							->      Optional[int]:
           _UpperCAmelCase							:						Optional[int]       							=					parent
           _UpperCAmelCase							:						Dict       							=					batch_size
           _UpperCAmelCase							:						Tuple       							=					seq_length
           _UpperCAmelCase							:						Optional[int]       							=					is_training
           _UpperCAmelCase							:						List[str]       							=					use_input_mask
           _UpperCAmelCase							:						Any       							=					use_labels
           _UpperCAmelCase							:						str       							=					vocab_size
           _UpperCAmelCase							:						List[Any]       							=					hidden_size
           _UpperCAmelCase							:						str       							=					projection_dim
           _UpperCAmelCase							:						List[str]       							=					num_hidden_layers
           _UpperCAmelCase							:						Union[str, Any]       							=					num_attention_heads
           _UpperCAmelCase							:						int       							=					intermediate_size
           _UpperCAmelCase							:						str       							=					dropout
           _UpperCAmelCase							:						Dict       							=					attention_dropout
           _UpperCAmelCase							:						Dict       							=					max_position_embeddings
           _UpperCAmelCase							:						int       							=					initializer_range
           _UpperCAmelCase							:						Optional[Any]       							=					scope
           _UpperCAmelCase							:						Dict       							=					bos_token_id
  
  
  
  
  
       def 				__lowerCAmelCase			(      self	)							->      Dict:
           _UpperCAmelCase							:						Optional[int]       							=					ids_tensor([self.batch_size, self.seq_length] ,			self.vocab_size	)
  
           _UpperCAmelCase							:						List[Any]       							=					None
           if self.use_input_mask:
               _UpperCAmelCase							:						Tuple       							=					random_attention_mask([self.batch_size, self.seq_length]	)
  
           if input_mask is not None:
               _UpperCAmelCase							,       _UpperCAmelCase							:						Tuple       							=					input_mask.shape
               _UpperCAmelCase							:						List[Any]       							=					np.random.randint(1 ,			seq_length - 1 ,			size=(batch_size,)	)
               for batch_idx, start_index in enumerate(A	):
                   _UpperCAmelCase							:						Any       							=					1
                   _UpperCAmelCase							:						Dict       							=					0
  
           _UpperCAmelCase							:						int       							=					self.get_config()
  
           return config, input_ids, input_mask
  
  
  
  
  
       def 				__lowerCAmelCase			(      self	)							->      Optional[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 				__lowerCAmelCase			(      self ,			A ,			A ,			A	)							->      Optional[int]:
           _UpperCAmelCase							:						List[Any]       							=					BlipTextModel(config=A	)
           model.to(A	)
           model.eval()
           with torch.no_grad():
               _UpperCAmelCase							:						Any       							=					model(A ,			attention_mask=A	)
               _UpperCAmelCase							:						Any       							=					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 				__lowerCAmelCase			(      self	)							->      int:
           _UpperCAmelCase							:						Any       							=					self.prepare_config_and_inputs()
           _UpperCAmelCase							,       _UpperCAmelCase							,       _UpperCAmelCase							:						Tuple       							=					config_and_inputs
           _UpperCAmelCase							:						str       							=					{'''input_ids''': input_ids, '''attention_mask''': input_mask}
           return config, inputs_dict
  
  
  
  @require_torch
  class 							_UpperCAmelCase							(				a	,unittest.TestCase   ):
  
  
  
  
  
       '''simple docstring'''
  
  
  
       a__             =(BlipTextModel,) if is_torch_available() else ()
       a__             =False
       a__             =False
       a__             =False
  
  
  
  
  
       def 				__lowerCAmelCase			(      self	)							->      Tuple:
           _UpperCAmelCase							:						Union[str, Any]       							=					BlipTextModelTester(self	)
           _UpperCAmelCase							:						Union[str, Any]       							=					ConfigTester(self ,			config_class=A ,			hidden_size=3_7	)
  
  
  
  
  
       def 				__lowerCAmelCase			(      self	)							->      Any:
           self.config_tester.run_common_tests()
  
  
  
  
  
       def 				__lowerCAmelCase			(      self	)							->      int:
           _UpperCAmelCase							:						int       							=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*A	)
  
  
  
  
  
       def 				__lowerCAmelCase			(      self	)							->      Dict:
           pass
  
  
  
  
  
       def 				__lowerCAmelCase			(      self	)							->      Dict:
           pass
  
  
  
  
  
       @unittest.skip(reason='''Blip does not use inputs_embeds'''	)
       def 				__lowerCAmelCase			(      self	)							->      List[str]:
           pass
  
  
  
  
  
       @unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''	)
       def 				__lowerCAmelCase			(      self	)							->      Dict:
           pass
  
  
  
  
  
       @unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''	)
       def 				__lowerCAmelCase			(      self	)							->      Dict:
           pass
  
  
  
  
  
       @slow
       def 				__lowerCAmelCase			(      self	)							->      Dict:
           for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               _UpperCAmelCase							:						Union[str, Any]       							=					BlipTextModel.from_pretrained(A	)
               self.assertIsNotNone(A	)
  
  
  
  
  
       def 				__lowerCAmelCase			(      self	)							->      Optional[int]:
           super().test_pt_tf_model_equivalence(allow_missing_keys=A	)
  
  
  
style_context: 
  
  
  
  """simple docstring"""
  # Lint as: python3
  import sys
  from collections.abc import Mapping
  from typing import TYPE_CHECKING
  
  import numpy as np
  import pyarrow as pa
  
  from .. import config
  from ..utils.py_utils import map_nested
  from .formatting import TensorFormatter
  
  
  if TYPE_CHECKING:
    import tensorflow as tf
  class 							_UpperCAmelCase							(				TensorFormatter[Mapping, '''tf.Tensor''', Mapping]   ):
  
  
  
  
  
       '''simple docstring'''
  
  
  
       def __init__(      self ,			A=None ,			**A	)							->      List[str]:
           super().__init__(features=A	)
           _UpperCAmelCase							:						Any       							=					tf_tensor_kwargs
           import tensorflow as tf  # noqa: import tf at initialization
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A	)							->      Optional[Any]:
           import tensorflow as tf
  
           if isinstance(A ,			A	) and column:
               if all(
                   isinstance(A ,			tf.Tensor	) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column	):
                   return tf.stack(A	)
               elif all(
                   isinstance(A ,			(tf.Tensor, tf.RaggedTensor)	) and x.ndim == 1 and x.dtype == column[0].dtype
                   for x in column	):
                   # only rag 1-D tensors, otherwise some dimensions become ragged even though they were consolidated
                   return tf.ragged.stack(A	)
  
           return column
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A	)							->      int:
           import tensorflow as tf
  
           if value is None:
               return value
  
           _UpperCAmelCase							:						Any       							=					{}
  
           if isinstance(A ,			(np.number, np.ndarray)	) and np.issubdtype(value.dtype ,			np.integer	):
               _UpperCAmelCase							:						Union[str, Any]       							=					{'''dtype''': tf.intaa}
           elif isinstance(A ,			(np.number, np.ndarray)	) and np.issubdtype(value.dtype ,			np.floating	):
               _UpperCAmelCase							:						Dict       							=					{'''dtype''': tf.floataa}
           elif config.PIL_AVAILABLE and "PIL" in sys.modules:
               import PIL.Image
  
               if isinstance(A ,			PIL.Image.Image	):
                   _UpperCAmelCase							:						Optional[int]       							=					np.asarray(A	)
  
           return tf.convert_to_tensor(A ,			**{**default_dtype, **self.tf_tensor_kwargs}	)
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A	)							->      Tuple:
           import tensorflow as tf
  
           # support for torch, tf, jax etc.
           if config.TORCH_AVAILABLE and "torch" in sys.modules:
               import torch
  
               if isinstance(A ,			torch.Tensor	):
                   return self._tensorize(data_struct.detach().cpu().numpy()[()]	)
           if hasattr(A ,			'''__array__'''	) and not isinstance(A ,			tf.Tensor	):
               _UpperCAmelCase							:						List[str]       							=					data_struct.__array__()
           # support for nested types like struct of list of struct
           if isinstance(A ,			np.ndarray	):
               if data_struct.dtype == object:  # tf tensors cannot be instantied from an array of objects
                   return self._consolidate([self.recursive_tensorize(A	) for substruct in data_struct]	)
           elif isinstance(A ,			(list, tuple)	):
               return self._consolidate([self.recursive_tensorize(A	) for substruct in data_struct]	)
           return self._tensorize(A	)
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A	)							->      Optional[int]:
           return map_nested(self._recursive_tensorize ,			A ,			map_list=A	)
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A	)							->      Mapping:
           _UpperCAmelCase							:						str       							=					self.numpy_arrow_extractor().extract_row(A	)
           _UpperCAmelCase							:						List[Any]       							=					self.python_features_decoder.decode_row(A	)
           return self.recursive_tensorize(A	)
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A	)							->      "tf.Tensor":
           _UpperCAmelCase							:						Union[str, Any]       							=					self.numpy_arrow_extractor().extract_column(A	)
           _UpperCAmelCase							:						Tuple       							=					self.python_features_decoder.decode_column(A ,			pa_table.column_names[0]	)
           _UpperCAmelCase							:						str       							=					self.recursive_tensorize(A	)
           _UpperCAmelCase							:						Optional[Any]       							=					self._consolidate(A	)
           return column
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A	)							->      Mapping:
           _UpperCAmelCase							:						Dict       							=					self.numpy_arrow_extractor().extract_batch(A	)
           _UpperCAmelCase							:						Tuple       							=					self.python_features_decoder.decode_batch(A	)
           _UpperCAmelCase							:						Union[str, Any]       							=					self.recursive_tensorize(A	)
           for column_name in batch:
               _UpperCAmelCase							:						str       							=					self._consolidate(batch[column_name]	)
           return batch
  
  
  