
'''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 			A							:



			def __init__(					self       ,     lowerCamelCase__       ,     lowerCamelCase__=12       ,     lowerCamelCase__=7       ,     lowerCamelCase__=True       ,     lowerCamelCase__=True       ,     lowerCamelCase__=True       ,     lowerCamelCase__=99       ,     lowerCamelCase__=32       ,     lowerCamelCase__=32       ,     lowerCamelCase__=5       ,     lowerCamelCase__=4       ,     lowerCamelCase__=37       ,     lowerCamelCase__=0.1       ,     lowerCamelCase__=0.1       ,     lowerCamelCase__=512       ,     lowerCamelCase__=0.02       ,     lowerCamelCase__=0       ,     lowerCamelCase__=None       ,     )			->		str:




									'''simple docstring'''



									lowercase__							 =       parent
									lowercase__							 =       batch_size
									lowercase__							 =       seq_length
									lowercase__							 =       is_training
									lowercase__							 =       use_input_mask
									lowercase__							 =       use_labels
									lowercase__							 =       vocab_size
									lowercase__							 =       hidden_size
									lowercase__							 =       projection_dim
									lowercase__							 =       num_hidden_layers
									lowercase__							 =       num_attention_heads
									lowercase__							 =       intermediate_size
									lowercase__							 =       dropout
									lowercase__							 =       attention_dropout
									lowercase__							 =       max_position_embeddings
									lowercase__							 =       initializer_range
									lowercase__							 =       scope
									lowercase__							 =       bos_token_id



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




									'''simple docstring'''



									lowercase__							 =       ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size       )

									lowercase__							 =       None
									if self.use_input_mask:
															lowercase__							 =       random_attention_mask([self.batch_size, self.seq_length]       )

									if input_mask is not None:
															lowercase__ ,						lowercase__							 =       input_mask.shape
															lowercase__							 =       np.random.randint(1       ,     seq_length - 1       ,     size=(batch_size,)       )
															for batch_idx, start_index in enumerate(lowerCamelCase__       ):
																					lowercase__							 =       1
																					lowercase__							 =       0

									lowercase__							 =       self.get_config()

									return config, input_ids, input_mask



			def A__ (					self       )			->		Tuple:




									'''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       ,     lowerCamelCase__       ,     lowerCamelCase__       ,     lowerCamelCase__       )			->		Any:




									'''simple docstring'''



									lowercase__							 =       BlipTextModel(config=lowerCamelCase__       )
									model.to(lowerCamelCase__       )
									model.eval()
									with torch.no_grad():
															lowercase__							 =       model(lowerCamelCase__       ,     attention_mask=lowerCamelCase__       )
															lowercase__							 =       model(lowerCamelCase__       )
									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       )			->		int:




									'''simple docstring'''



									lowercase__							 =       self.prepare_config_and_inputs()
									lowercase__ ,						lowercase__ ,						lowercase__							 =       config_and_inputs
									lowercase__							 =       {"""input_ids""": input_ids, """attention_mask""": input_mask}
									return config, inputs_dict





@require_torch
class 			A							(       __UpperCAmelCase		,						unittest.TestCase				):
			lowerCamelCase							:							List[Any]       		=  (BlipTextModel,) if is_torch_available() else ()
			lowerCamelCase							:							Optional[int]       		=  False
			lowerCamelCase							:							str       		=  False
			lowerCamelCase							:							Optional[int]       		=  False



			def A__ (					self       )			->		Dict:




									'''simple docstring'''



									lowercase__							 =       BlipTextModelTester(self       )
									lowercase__							 =       ConfigTester(self       ,     config_class=lowerCamelCase__       ,     hidden_size=37       )



			def A__ (					self       )			->		Dict:




									'''simple docstring'''



									self.config_tester.run_common_tests()



			def A__ (					self       )			->		Optional[Any]:




									'''simple docstring'''



									lowercase__							 =       self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*lowerCamelCase__       )



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




									'''simple docstring'''



									pass



			def A__ (					self       )			->		Dict:




									'''simple docstring'''



									pass



			@unittest.skip(reason="""Blip does not use inputs_embeds"""       )
			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       )			->		int:




									'''simple docstring'''



									pass



			@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""       )
			def A__ (					self       )			->		Union[str, Any]:




									'''simple docstring'''



									pass



			@slow
			def A__ (					self       )			->		Any:




									'''simple docstring'''



									for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															lowercase__							 =       BlipTextModel.from_pretrained(lowerCamelCase__       )
															self.assertIsNotNone(lowerCamelCase__       )



			def A__ (					self       )			->		Any:




									'''simple docstring'''



									super().test_pt_tf_model_equivalence(allow_missing_keys=lowerCamelCase__       )








'''simple docstring'''



from typing import TYPE_CHECKING

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


__A          =    {"configuration_detr": ["DETR_PRETRAINED_CONFIG_ARCHIVE_MAP", "DetrConfig", "DetrOnnxConfig"]}

try:
				if not is_vision_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__A          =    ["DetrFeatureExtractor"]
				__A          =    ["DetrImageProcessor"]

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__A          =    [
				    "DETR_PRETRAINED_MODEL_ARCHIVE_LIST",
				    "DetrForObjectDetection",
				    "DetrForSegmentation",
				    "DetrModel",
				    "DetrPreTrainedModel",
				]


if TYPE_CHECKING:
				from .configuration_detr import DETR_PRETRAINED_CONFIG_ARCHIVE_MAP, DetrConfig, DetrOnnxConfig

				try:
								if not is_vision_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .feature_extraction_detr import DetrFeatureExtractor
								from .image_processing_detr import DetrImageProcessor

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_detr import (
								    DETR_PRETRAINED_MODEL_ARCHIVE_LIST,
								    DetrForObjectDetection,
								    DetrForSegmentation,
								    DetrModel,
								    DetrPreTrainedModel,
								)

else:
				import sys

				__A          =    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






