






"""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 				__SCREAMING_SNAKE_CASE    :


							def __init__(      self   :    Optional[Any]      ,     snake_case   :    List[Any]      ,     snake_case   :    List[Any]=12      ,     snake_case   :    Optional[int]=7      ,     snake_case   :    int=True      ,     snake_case   :    Union[str, Any]=True      ,     snake_case   :    Union[str, Any]=True      ,     snake_case   :    int=99      ,     snake_case   :    List[str]=32      ,     snake_case   :    Tuple=32      ,     snake_case   :    str=5      ,     snake_case   :    Union[str, Any]=4      ,     snake_case   :    Optional[int]=37      ,     snake_case   :    List[Any]=0.1      ,     snake_case   :    Optional[Any]=0.1      ,     snake_case   :    Optional[Any]=512      ,     snake_case   :    Any=0.02      ,     snake_case   :    int=0      ,     snake_case   :    Any=None      ,     ):
													'''simple docstring'''





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


							def     _UpperCamelCase							(      self   :    Optional[int]				):
													'''simple docstring'''





													A__    :	List[Any]			=	ids_tensor([self.batch_size, self.seq_length]      ,     self.vocab_size				)

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

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

													A__    :	int			=	self.get_config()

													return config, input_ids, input_mask


							def     _UpperCamelCase							(      self   :    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     _UpperCamelCase							(      self   :    Any      ,     snake_case   :    Any      ,     snake_case   :    List[str]      ,     snake_case   :    Optional[int]				):
													'''simple docstring'''





													A__    :	List[Any]			=	BlipTextModel(config=snake_case				)
													model.to(snake_case				)
													model.eval()
													with torch.no_grad():
																			A__    :	Tuple			=	model(snake_case      ,     attention_mask=snake_case				)
																			A__    :	Any			=	model(snake_case				)
													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     _UpperCamelCase							(      self   :    Union[str, Any]				):
													'''simple docstring'''





													A__    :	Dict			=	self.prepare_config_and_inputs()
													A__	,	A__	,	A__    :	Any			=	config_and_inputs
													A__    :	Optional[int]			=	{"""input_ids""": input_ids, """attention_mask""": input_mask}
													return config, inputs_dict






@require_torch
class 				__SCREAMING_SNAKE_CASE    (					UpperCamelCase							,		unittest.TestCase		):
							snake_case_  =				(BlipTextModel,) if is_torch_available() else ()
							snake_case_  =				False
							snake_case_  =				False
							snake_case_  =				False


							def     _UpperCamelCase							(      self   :    Any				):
													'''simple docstring'''





													A__    :	int			=	BlipTextModelTester(self				)
													A__    :	int			=	ConfigTester(self      ,     config_class=snake_case      ,     hidden_size=37				)


							def     _UpperCamelCase							(      self   :    str				):
													'''simple docstring'''





													self.config_tester.run_common_tests()


							def     _UpperCamelCase							(      self   :    Tuple				):
													'''simple docstring'''





													A__    :	Any			=	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*snake_case				)


							def     _UpperCamelCase							(      self   :    List[Any]				):
													'''simple docstring'''





													pass


							def     _UpperCamelCase							(      self   :    Dict				):
													'''simple docstring'''





													pass


							@unittest.skip(reason="""Blip does not use inputs_embeds"""				)
							def     _UpperCamelCase							(      self   :    Tuple				):
													'''simple docstring'''





													pass


							@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""				)
							def     _UpperCamelCase							(      self   :    Optional[int]				):
													'''simple docstring'''





													pass


							@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""				)
							def     _UpperCamelCase							(      self   :    List[str]				):
													'''simple docstring'''





													pass


							@slow
							def     _UpperCamelCase							(      self   :    Optional[Any]				):
													'''simple docstring'''





													for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			A__    :	Dict			=	BlipTextModel.from_pretrained(snake_case				)
																			self.assertIsNotNone(snake_case				)


							def     _UpperCamelCase							(      self   :    Union[str, Any]				):
													'''simple docstring'''





													super().test_pt_tf_model_equivalence(allow_missing_keys=snake_case				)














"""simple docstring"""



from typing import TYPE_CHECKING

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


A_     =				{
    '''configuration_deformable_detr''': ['''DEFORMABLE_DETR_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DeformableDetrConfig'''],
}

try:
						if not is_vision_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A_     =				['''DeformableDetrFeatureExtractor''']
						A_     =				['''DeformableDetrImageProcessor''']

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A_     =				[
						    '''DEFORMABLE_DETR_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''DeformableDetrForObjectDetection''',
						    '''DeformableDetrModel''',
						    '''DeformableDetrPreTrainedModel''',
						]


if TYPE_CHECKING:
						from .configuration_deformable_detr import DEFORMABLE_DETR_PRETRAINED_CONFIG_ARCHIVE_MAP, DeformableDetrConfig

						try:
												if not is_vision_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .feature_extraction_deformable_detr import DeformableDetrFeatureExtractor
												from .image_processing_deformable_detr import DeformableDetrImageProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_deformable_detr import (
												    DEFORMABLE_DETR_PRETRAINED_MODEL_ARCHIVE_LIST,
												    DeformableDetrForObjectDetection,
												    DeformableDetrModel,
												    DeformableDetrPreTrainedModel,
												)

else:
						import sys

						A_     =				_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






