





from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask


if is_tf_available():
	import tensorflow as tf

	from transformers import TFBlipTextModel
	from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST



class  __lowerCAmelCase	:






			def __init__(self ,							__magic_name__ ,							__magic_name__=12 ,							__magic_name__=7 ,							__magic_name__=True ,							__magic_name__=True ,							__magic_name__=True ,							__magic_name__=99 ,							__magic_name__=32 ,							__magic_name__=32 ,							__magic_name__=2 ,							__magic_name__=4 ,							__magic_name__=37 ,							__magic_name__=0.1 ,							__magic_name__=0.1 ,							__magic_name__=512 ,							__magic_name__=0.02 ,							__magic_name__=0 ,							__magic_name__=None ,							)					->       Tuple:


							'''simple docstring'''



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






			def       lowerCamelCase  (self   )					->       str:


							'''simple docstring'''



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

							snake_case_						:   Tuple           =  None
							if self.use_input_mask:
											snake_case_						:   Optional[Any]           =  random_attention_mask([self.batch_size, self.seq_length]   )

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

							snake_case_						:   str           =  self.get_config()

							return config, input_ids, tf.convert_to_tensor(__magic_name__   )






			def       lowerCamelCase  (self   )					->       List[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       lowerCamelCase  (self ,							__magic_name__ ,							__magic_name__ ,							__magic_name__   )					->       List[Any]:


							'''simple docstring'''



							snake_case_						:   Union[str, Any]           =  TFBlipTextModel(config=__magic_name__   )
							snake_case_						:   List[str]           =  model(__magic_name__ ,							attention_mask=__magic_name__ ,							training=__magic_name__   )
							snake_case_						:   Tuple           =  model(__magic_name__ ,							training=__magic_name__   )
							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   )					->       Any:


							'''simple docstring'''



							snake_case_						:   List[str]           =  self.prepare_config_and_inputs()
							snake_case_      ,							snake_case_      ,							snake_case_						:   Tuple           =  config_and_inputs
							snake_case_						:   Optional[int]           =  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
							return config, inputs_dict




@require_tf
class  __lowerCAmelCase	(      _a,					unittest.TestCase					):
			lowerCamelCase_					:					str	      =				(TFBlipTextModel,) if is_tf_available() else ()
			lowerCamelCase_					:					Optional[Any]	      =				False
			lowerCamelCase_					:					Any	      =				False
			lowerCamelCase_					:					List[Any]	      =				False






			def       lowerCamelCase  (self   )					->       int:


							'''simple docstring'''



							snake_case_						:   List[Any]           =  BlipTextModelTester(self   )
							snake_case_						:   Optional[int]           =  ConfigTester(self ,							config_class=__magic_name__ ,							hidden_size=37   )






			def       lowerCamelCase  (self   )					->       Dict:


							'''simple docstring'''



							self.config_tester.run_common_tests()






			def       lowerCamelCase  (self   )					->       Dict:


							'''simple docstring'''



							snake_case_						:   Dict           =  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__magic_name__   )






			def       lowerCamelCase  (self   )					->       Dict:


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






			@unittest.skip(reason='''Blip does not use inputs_embeds'''   )
			def       lowerCamelCase  (self   )					->       Optional[int]:


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






			@slow
			def       lowerCamelCase  (self   )					->       Union[str, Any]:


							'''simple docstring'''



							for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											snake_case_						:   Dict           =  TFBlipTextModel.from_pretrained(__magic_name__   )
											self.assertIsNotNone(__magic_name__   )






			def       lowerCamelCase  (self ,							__magic_name__=True   )					->       List[Any]:


							'''simple docstring'''



							super().test_pt_tf_model_equivalence(allow_missing_keys=__magic_name__   )







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


lowerCAmelCase_    =    logging.get_logger(__name__)

lowerCAmelCase_    =    {
    '''microsoft/biogpt''': '''https://huggingface.co/microsoft/biogpt/resolve/main/config.json''',
    # See all BioGPT models at https://huggingface.co/models?filter=biogpt
}



class  __lowerCAmelCase	(      _a					):
			lowerCamelCase_					:					Any	      =				'''biogpt'''






			def __init__(self ,							__magic_name__=4_2384 ,							__magic_name__=1024 ,							__magic_name__=24 ,							__magic_name__=16 ,							__magic_name__=4096 ,							__magic_name__="gelu" ,							__magic_name__=0.1 ,							__magic_name__=0.1 ,							__magic_name__=1024 ,							__magic_name__=0.02 ,							__magic_name__=1e-12 ,							__magic_name__=True ,							__magic_name__=True ,							__magic_name__=0.0 ,							__magic_name__=0.0 ,							__magic_name__=1 ,							__magic_name__=0 ,							__magic_name__=2 ,							**__magic_name__ ,							)					->       List[str]:


							'''simple docstring'''



							snake_case_						:   List[str]           =  vocab_size
							snake_case_						:   Dict           =  max_position_embeddings
							snake_case_						:   Optional[int]           =  hidden_size
							snake_case_						:   List[Any]           =  num_hidden_layers
							snake_case_						:   List[str]           =  num_attention_heads
							snake_case_						:   int           =  intermediate_size
							snake_case_						:   List[Any]           =  hidden_act
							snake_case_						:   List[Any]           =  hidden_dropout_prob
							snake_case_						:   Optional[int]           =  attention_probs_dropout_prob
							snake_case_						:   Optional[int]           =  initializer_range
							snake_case_						:   Optional[int]           =  layer_norm_eps
							snake_case_						:   str           =  scale_embedding
							snake_case_						:   Optional[Any]           =  use_cache
							snake_case_						:   Optional[Any]           =  layerdrop
							snake_case_						:   Optional[Any]           =  activation_dropout
							super().__init__(pad_token_id=__magic_name__ ,							bos_token_id=__magic_name__ ,							eos_token_id=__magic_name__ ,							**__magic_name__   )
