



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 :







							'''simple docstring'''






							def __init__(							self					,					a_					,					a_=12					,					a_=7					,					a_=True					,					a_=True					,					a_=True					,					a_=99					,					a_=32					,					a_=32					,					a_=5					,					a_=4					,					a_=37					,					a_=0.1					,					a_=0.1					,					a_=512					,					a_=0.02					,					a_=0					,					a_=None					,					):
											a__			 =						parent
											a__			 =						batch_size
											a__			 =						seq_length
											a__			 =						is_training
											a__			 =						use_input_mask
											a__			 =						use_labels
											a__			 =						vocab_size
											a__			 =						hidden_size
											a__			 =						projection_dim
											a__			 =						num_hidden_layers
											a__			 =						num_attention_heads
											a__			 =						intermediate_size
											a__			 =						dropout
											a__			 =						attention_dropout
											a__			 =						max_position_embeddings
											a__			 =						initializer_range
											a__			 =						scope
											a__			 =						bos_token_id


							def _a (							self						):
											a__			 =						ids_tensor([self.batch_size, self.seq_length]					,					self.vocab_size						)

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

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

											a__			 =						self.get_config()

											return config, input_ids, input_mask


							def _a (							self						):
											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					,					a_					,					a_					,					a_						):
											a__			 =						BlipTextModel(config=a_						)
											model.to(a_						)
											model.eval()
											with torch.no_grad():
															a__			 =						model(a_					,					attention_mask=a_						)
															a__			 =						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 _a (							self						):
											a__			 =						self.prepare_config_and_inputs()
											a__ ,     a__ ,     a__			 =						config_and_inputs
											a__			 =						{"""input_ids""": input_ids, """attention_mask""": input_mask}
											return config, inputs_dict




@require_torch
class 	__snake_case (				SCREAMING_SNAKE_CASE     ,unittest.TestCase):







							'''simple docstring'''






							UpperCamelCase__			: List[Any]             =   (BlipTextModel,) if is_torch_available() else ()
							UpperCamelCase__			: Optional[Any]             =   False
							UpperCamelCase__			: int             =   False
							UpperCamelCase__			: str             =   False


							def _a (							self						):
											a__			 =						BlipTextModelTester(self						)
											a__			 =						ConfigTester(self					,					config_class=a_					,					hidden_size=37						)


							def _a (							self						):
											self.config_tester.run_common_tests()


							def _a (							self						):
											a__			 =						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*a_						)


							def _a (							self						):
											pass


							def _a (							self						):
											pass


							@unittest.skip(reason="""Blip does not use inputs_embeds"""						)
							def _a (							self						):
											pass


							@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""						)
							def _a (							self						):
											pass


							@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""						)
							def _a (							self						):
											pass


							@slow
							def _a (							self						):
											for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															a__			 =						BlipTextModel.from_pretrained(a_						)
															self.assertIsNotNone(a_						)







							def _a (							self						):
											super().test_pt_tf_model_equivalence(allow_missing_keys=a_						)






from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase								=   logging.get_logger(__name__)

UpperCAmelCase								=   {
    """facebook/regnet-y-040""": """https://huggingface.co/facebook/regnet-y-040/blob/main/config.json""",
}

class 	__snake_case (				SCREAMING_SNAKE_CASE):







							'''simple docstring'''






							UpperCamelCase__			: Tuple             =   """regnet"""
							UpperCamelCase__			: int             =   ["""x""", """y"""]


							def __init__(							self					,					a_=3					,					a_=32					,					a_=[128, 192, 512, 1_088]					,					a_=[2, 6, 12, 2]					,					a_=64					,					a_="y"					,					a_="relu"					,					**a_					,					):
											super().__init__(**a_						)
											if layer_type not in self.layer_types:
															raise ValueError(F'''layer_type={layer_type} is not one of {",".join(self.layer_types						)}'''						)
											a__			 =						num_channels
											a__			 =						embedding_size
											a__			 =						hidden_sizes
											a__			 =						depths
											a__			 =						groups_width
											a__			 =						layer_type
											a__			 =						hidden_act
											# always downsample in the first stage
											a__			 =						True

