
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   : Optional[Any]       ,	a   : Optional[int]       ,	a   : Tuple=12       ,	a   : int=7       ,	a   : Dict=True       ,	a   : Optional[Any]=True       ,	a   : Optional[int]=True       ,	a   : List[str]=99       ,	a   : Tuple=32       ,	a   : Tuple=32       ,	a   : str=5       ,	a   : Union[str, Any]=4       ,	a   : Tuple=37       ,	a   : Any=0.1       ,	a   : List[Any]=0.1       ,	a   : Any=512       ,	a   : str=0.0_2       ,	a   : Any=0       ,	a   : Any=None       ,	):






							'''simple docstring'''







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






				def 				_lowerCamelCase						(		self   : List[str]  ):






							'''simple docstring'''







							lowerCAmelCase__ : Optional[Any]   =						ids_tensor([self.batch_size, self.seq_length]       ,	self.vocab_size  )

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

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

							lowerCAmelCase__ : Optional[Any]   =						self.get_config()

							return config, input_ids, input_mask






				def 				_lowerCamelCase						(		self   : List[str]  ):






							'''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 				_lowerCamelCase						(		self   : Optional[Any]       ,	a   : str       ,	a   : int       ,	a   : List[Any]  ):






							'''simple docstring'''







							lowerCAmelCase__ : Any   =						BlipTextModel(config=snake_case__  )
							model.to(snake_case__  )
							model.eval()
							with torch.no_grad():
										lowerCAmelCase__ : Optional[Any]   =						model(snake_case__       ,	attention_mask=snake_case__  )
										lowerCAmelCase__ : Dict   =						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 				_lowerCamelCase						(		self   : int  ):






							'''simple docstring'''







							lowerCAmelCase__ : List[str]   =						self.prepare_config_and_inputs()
							lowerCAmelCase__ : Union[str, Any]   =						config_and_inputs
							lowerCAmelCase__ : Any   =						{"""input_ids""": input_ids, """attention_mask""": input_mask}
							return config, inputs_dict







@require_torch
class 	A__				(	_lowercase		,  unittest.TestCase      ):
				lowercase            =    (BlipTextModel,) if is_torch_available() else ()
				lowercase            =    False
				lowercase            =    False
				lowercase            =    False






				def 				_lowerCamelCase						(		self   : Union[str, Any]  ):






							'''simple docstring'''







							lowerCAmelCase__ : Any   =						BlipTextModelTester(self  )
							lowerCAmelCase__ : int   =						ConfigTester(self       ,	config_class=snake_case__       ,	hidden_size=37  )






				def 				_lowerCamelCase						(		self   : Any  ):






							'''simple docstring'''







							self.config_tester.run_common_tests()






				def 				_lowerCamelCase						(		self   : List[str]  ):






							'''simple docstring'''







							lowerCAmelCase__ : Any   =						self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*snake_case__  )






				def 				_lowerCamelCase						(		self   : Optional[int]  ):






							'''simple docstring'''







							pass






				def 				_lowerCamelCase						(		self   : List[str]  ):






							'''simple docstring'''







							pass






				@unittest.skip(reason='Blip does not use inputs_embeds'  )
				def 				_lowerCamelCase						(		self   : Optional[Any]  ):






							'''simple docstring'''







							pass






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






							'''simple docstring'''







							pass






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






							'''simple docstring'''







							pass






				@slow
				def 				_lowerCamelCase						(		self   : Optional[int]  ):






							'''simple docstring'''







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






				def 				_lowerCamelCase						(		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_tokenizers_available, is_torch_available


lowercase		:    Tuple			=       {
    'configuration_codegen': ['CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CodeGenConfig', 'CodeGenOnnxConfig'],
    'tokenization_codegen': ['CodeGenTokenizer'],
}

try:
			if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowercase		:    int			=       ['CodeGenTokenizerFast']

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowercase		:    Optional[int]			=       [
			    'CODEGEN_PRETRAINED_MODEL_ARCHIVE_LIST',
			    'CodeGenForCausalLM',
			    'CodeGenModel',
			    'CodeGenPreTrainedModel',
			]

if TYPE_CHECKING:
			from .configuration_codegen import CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP, CodeGenConfig, CodeGenOnnxConfig
			from .tokenization_codegen import CodeGenTokenizer

			try:
						if not is_tokenizers_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_codegen_fast import CodeGenTokenizerFast

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_codegen import (
						    CODEGEN_PRETRAINED_MODEL_ARCHIVE_LIST,
						    CodeGenForCausalLM,
						    CodeGenModel,
						    CodeGenPreTrainedModel,
						)

else:
			import sys

			lowercase		:    Optional[Any]			=       _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
