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 					__snake_case    :




					def __init__(  self       ,			__UpperCamelCase       ,			__UpperCamelCase=12       ,			__UpperCamelCase=7       ,			__UpperCamelCase=True       ,			__UpperCamelCase=True       ,			__UpperCamelCase=True       ,			__UpperCamelCase=99       ,			__UpperCamelCase=32       ,			__UpperCamelCase=32       ,			__UpperCamelCase=5       ,			__UpperCamelCase=4       ,			__UpperCamelCase=37       ,			__UpperCamelCase=0.1       ,			__UpperCamelCase=0.1       ,			__UpperCamelCase=512       ,			__UpperCamelCase=0.0_2       ,			__UpperCamelCase=0       ,			__UpperCamelCase=None       ,			)	->    List[Any]:



									'''simple docstring'''







									snake_case__   :      int   				= parent
									snake_case__   :      Dict   				= batch_size
									snake_case__   :      Dict   				= seq_length
									snake_case__   :      str   				= is_training
									snake_case__   :      Dict   				= use_input_mask
									snake_case__   :      Optional[int]   				= use_labels
									snake_case__   :      List[Any]   				= vocab_size
									snake_case__   :      str   				= hidden_size
									snake_case__   :      str   				= projection_dim
									snake_case__   :      List[Any]   				= num_hidden_layers
									snake_case__   :      int   				= num_attention_heads
									snake_case__   :      Optional[int]   				= intermediate_size
									snake_case__   :      Union[str, Any]   				= dropout
									snake_case__   :      str   				= attention_dropout
									snake_case__   :      str   				= max_position_embeddings
									snake_case__   :      Dict   				= initializer_range
									snake_case__   :      Any   				= scope
									snake_case__   :      str   				= bos_token_id




					def      __a     (  self						)	->    str:



									'''simple docstring'''







									snake_case__   :      Optional[int]   				= ids_tensor([self.batch_size, self.seq_length]       ,			self.vocab_size						)

									snake_case__   :      str   				= None
									if self.use_input_mask:
													snake_case__   :      Any   				= random_attention_mask([self.batch_size, self.seq_length]						)

									if input_mask is not None:
													snake_case__				,    snake_case__   :      Dict   				= input_mask.shape
													snake_case__   :      Any   				= np.random.randint(1       ,			seq_length - 1       ,			size=(batch_size,)						)
													for batch_idx, start_index in enumerate(__UpperCamelCase						):
																	snake_case__   :      List[str]   				= 1
																	snake_case__   :      Optional[int]   				= 0

									snake_case__   :      str   				= self.get_config()

									return config, input_ids, input_mask




					def      __a     (  self						)	->    Union[str, Any]:



									'''simple docstring'''







									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      __a     (  self       ,			__UpperCamelCase       ,			__UpperCamelCase       ,			__UpperCamelCase						)	->    Any:



									'''simple docstring'''







									snake_case__   :      Tuple   				= BlipTextModel(config=__UpperCamelCase						)
									model.to(__UpperCamelCase						)
									model.eval()
									with torch.no_grad():
													snake_case__   :      List[str]   				= model(__UpperCamelCase       ,			attention_mask=__UpperCamelCase						)
													snake_case__   :      str   				= model(__UpperCamelCase						)
									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      __a     (  self						)	->    List[str]:



									'''simple docstring'''







									snake_case__   :      Tuple   				= self.prepare_config_and_inputs()
									snake_case__				,    snake_case__				,    snake_case__   :      int   				= config_and_inputs
									snake_case__   :      Union[str, Any]   				= {'input_ids': input_ids, 'attention_mask': input_mask}
									return config, inputs_dict





@require_torch
class 					__snake_case    (     _lowerCamelCase       ,unittest.TestCase      ):
					__lowerCamelCase			   =  (BlipTextModel,) if is_torch_available() else ()
					__lowerCamelCase			   =  False
					__lowerCamelCase			   =  False
					__lowerCamelCase			   =  False




					def      __a     (  self						)	->    str:



									'''simple docstring'''







									snake_case__   :      Optional[Any]   				= BlipTextModelTester(self						)
									snake_case__   :      Dict   				= ConfigTester(self       ,			config_class=__UpperCamelCase       ,			hidden_size=37						)




					def      __a     (  self						)	->    Tuple:



									'''simple docstring'''







									self.config_tester.run_common_tests()




					def      __a     (  self						)	->    List[Any]:



									'''simple docstring'''







									snake_case__   :      List[str]   				= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*__UpperCamelCase						)




					def      __a     (  self						)	->    Union[str, Any]:



									'''simple docstring'''







									pass




					def      __a     (  self						)	->    List[str]:



									'''simple docstring'''







									pass




					@unittest.skip(reason='Blip does not use inputs_embeds'						)
					def      __a     (  self						)	->    Tuple:



									'''simple docstring'''







									pass




					@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'						)
					def      __a     (  self						)	->    Optional[Any]:



									'''simple docstring'''







									pass




					@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'						)
					def      __a     (  self						)	->    List[str]:



									'''simple docstring'''







									pass




					@slow
					def      __a     (  self						)	->    str:



									'''simple docstring'''







									for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													snake_case__   :      Union[str, Any]   				= BlipTextModel.from_pretrained(__UpperCamelCase						)
													self.assertIsNotNone(__UpperCamelCase						)




					def      __a     (  self						)	->    Union[str, Any]:



									'''simple docstring'''







									super().test_pt_tf_model_equivalence(allow_missing_keys=__UpperCamelCase						)



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


lowerCAmelCase__	:  int						=  {
    '''configuration_deta''': ['''DETA_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DetaConfig'''],
}

try:
				if not is_vision_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowerCAmelCase__	:  Union[str, Any]						=  ['''DetaImageProcessor''']

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowerCAmelCase__	:  Optional[int]						=  [
				    '''DETA_PRETRAINED_MODEL_ARCHIVE_LIST''',
				    '''DetaForObjectDetection''',
				    '''DetaModel''',
				    '''DetaPreTrainedModel''',
				]


if TYPE_CHECKING:
				from .configuration_deta import DETA_PRETRAINED_CONFIG_ARCHIVE_MAP, DetaConfig

				try:
								if not is_vision_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .image_processing_deta import DetaImageProcessor

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_deta import (
								    DETA_PRETRAINED_MODEL_ARCHIVE_LIST,
								    DetaForObjectDetection,
								    DetaModel,
								    DetaPreTrainedModel,
								)

else:
				import sys

				lowerCAmelCase__	:  int						=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


