






"""simple docstring"""


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 						snake_case  :





    def __init__(							self     : Union[str, Any]    ,		A     : Tuple    ,		A     : Optional[int]=1_2    ,		A     : int=7    ,		A     : int=True    ,		A     : Optional[int]=True    ,		A     : Any=True    ,		A     : List[Any]=9_9    ,		A     : List[Any]=3_2    ,		A     : Tuple=3_2    ,		A     : int=2    ,		A     : Dict=4    ,		A     : List[Any]=3_7    ,		A     : Dict=0.1    ,		A     : Optional[int]=0.1    ,		A     : Any=5_1_2    ,		A     : List[str]=0.02    ,		A     : List[Any]=0    ,		A     : List[Any]=None    ,		):


      '''simple docstring'''




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





    def     lowerCamelCase__				(							self     : List[str]      ):


      '''simple docstring'''




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

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

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

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

      return config, input_ids, tf.convert_to_tensor(A      )





    def     lowerCamelCase__				(							self     : Union[str, 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     : str    ,		A     : List[str]    ,		A     : Tuple    ,		A     : str      ):


      '''simple docstring'''




      a					:      int    =       TFBlipTextModel(config=A      )
      a					:      List[Any]    =       model(A    ,		attention_mask=A    ,		training=A      )
      a					:      Dict    =       model(A    ,		training=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     lowerCamelCase__				(							self     : Union[str, Any]      ):


      '''simple docstring'''




      a					:      List[str]    =       self.prepare_config_and_inputs()
      a,					a,					a					:      Dict    =       config_and_inputs
      a					:      List[str]    =       {'input_ids': input_ids, 'attention_mask': input_mask}
      return config, inputs_dict






@require_tf
class 						snake_case  (  UpperCAmelCase       ,			unittest.TestCase	):
    __magic_name__   					=					(TFBlipTextModel,) if is_tf_available() else ()
    __magic_name__   					=					False
    __magic_name__   					=					False
    __magic_name__   					=					False





    def     lowerCamelCase__				(							self     : Optional[Any]      ):


      '''simple docstring'''




      a					:      List[str]    =       BlipTextModelTester(self      )
      a					:      str    =       ConfigTester(self    ,		config_class=A    ,		hidden_size=3_7      )





    def     lowerCamelCase__				(							self     : List[str]      ):


      '''simple docstring'''




      self.config_tester.run_common_tests()





    def     lowerCamelCase__				(							self     : List[Any]      ):


      '''simple docstring'''




      a					:      Optional[Any]    =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*A      )





    def     lowerCamelCase__				(							self     : int      ):


      '''simple docstring'''




      pass





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


      '''simple docstring'''




      pass





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


      '''simple docstring'''




      pass





    @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'      )
    def     lowerCamelCase__				(							self     : Any      ):


      '''simple docstring'''




      pass





    @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'      )
    def     lowerCamelCase__				(							self     : int      ):


      '''simple docstring'''




      pass





    @slow
    def     lowerCamelCase__				(							self     : Tuple      ):


      '''simple docstring'''




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





    def     lowerCamelCase__				(							self     : Optional[int]    ,		A     : Tuple=True      ):


      '''simple docstring'''




      super().test_pt_tf_model_equivalence(allow_missing_keys=A      )












"""simple docstring"""


from typing import TYPE_CHECKING

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


_UpperCamelCase    :   Optional[int]   			=						{
    'configuration_rag': ['RagConfig'],
    'retrieval_rag': ['RagRetriever'],
    'tokenization_rag': ['RagTokenizer'],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _UpperCamelCase    :   Dict   			=						[
       'RagModel',
       'RagPreTrainedModel',
       'RagSequenceForGeneration',
       'RagTokenForGeneration',
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _UpperCamelCase    :   Optional[int]   			=						[
       'TFRagModel',
       'TFRagPreTrainedModel',
       'TFRagSequenceForGeneration',
       'TFRagTokenForGeneration',
   ]


if TYPE_CHECKING:
   from .configuration_rag import RagConfig
   from .retrieval_rag import RagRetriever
   from .tokenization_rag import RagTokenizer

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_rag import RagModel, RagPreTrainedModel, RagSequenceForGeneration, RagTokenForGeneration

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_rag import (
          TFRagModel,
          TFRagPreTrainedModel,
          TFRagSequenceForGeneration,
          TFRagTokenForGeneration,
      )

else:
   import sys

   _UpperCamelCase    :   int   			=						_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




