


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				:    List[Any]    ,				_lowerCamelCase				:    str    ,				_lowerCamelCase				:    Any=1_2    ,				_lowerCamelCase				:    Dict=7    ,				_lowerCamelCase				:    str=True    ,				_lowerCamelCase				:    str=True    ,				_lowerCamelCase				:    List[Any]=True    ,				_lowerCamelCase				:    int=9_9    ,				_lowerCamelCase				:    int=3_2    ,				_lowerCamelCase				:    int=3_2    ,				_lowerCamelCase				:    Union[str, Any]=2    ,				_lowerCamelCase				:    Union[str, Any]=4    ,				_lowerCamelCase				:    Any=3_7    ,				_lowerCamelCase				:    Optional[int]=0.1    ,				_lowerCamelCase				:    Tuple=0.1    ,				_lowerCamelCase				:    str=5_1_2    ,				_lowerCamelCase				:    Union[str, Any]=0.02    ,				_lowerCamelCase				:    List[Any]=0    ,				_lowerCamelCase				:    List[str]=None    ,				):
              snake_case__ :       List[str]	   =							parent
              snake_case__ :       Dict	   =							batch_size
              snake_case__ :       Any	   =							seq_length
              snake_case__ :       str	   =							is_training
              snake_case__ :       int	   =							use_input_mask
              snake_case__ :       int	   =							use_labels
              snake_case__ :       str	   =							vocab_size
              snake_case__ :       Tuple	   =							hidden_size
              snake_case__ :       Union[str, Any]	   =							projection_dim
              snake_case__ :       Tuple	   =							num_hidden_layers
              snake_case__ :       Any	   =							num_attention_heads
              snake_case__ :       List[Any]	   =							intermediate_size
              snake_case__ :       Tuple	   =							dropout
              snake_case__ :       str	   =							attention_dropout
              snake_case__ :       int	   =							max_position_embeddings
              snake_case__ :       List[Any]	   =							initializer_range
              snake_case__ :       Union[str, Any]	   =							scope
              snake_case__ :       Dict	   =							bos_token_id




       def     UpperCAmelCase__    ( self				:    Tuple			):
              snake_case__ :       Dict	   =							ids_tensor([self.batch_size, self.seq_length]    ,				self.vocab_size			)

              snake_case__ :       Tuple	   =							None
              if self.use_input_mask:
                     snake_case__ :       int	   =							random_attention_mask([self.batch_size, self.seq_length]			)

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

              snake_case__ :       Union[str, Any]	   =							self.get_config()

              return config, input_ids, tf.convert_to_tensor(snake_case__			)




       def     UpperCAmelCase__    ( self				:    Optional[Any]			):
              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				:    Tuple    ,				_lowerCamelCase				:    Tuple    ,				_lowerCamelCase				:    Tuple    ,				_lowerCamelCase				:    Tuple			):
              snake_case__ :       str	   =							TFBlipTextModel(config=snake_case__			)
              snake_case__ :       Optional[Any]	   =							model(snake_case__    ,				attention_mask=snake_case__    ,				training=snake_case__			)
              snake_case__ :       List[str]	   =							model(snake_case__    ,				training=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				:    int			):
              snake_case__ :       List[Any]	   =							self.prepare_config_and_inputs()
              snake_case__ :       Any	   =							config_and_inputs
              snake_case__ :       Any	   =							{"input_ids": input_ids, "attention_mask": input_mask}
              return config, inputs_dict


@require_tf
class snake_case__			(    UpperCamelCase_    ,   unittest.TestCase					):
       _lowerCAmelCase   =(TFBlipTextModel,) if is_tf_available() else ()
       _lowerCAmelCase   =False
       _lowerCAmelCase   =False
       _lowerCAmelCase   =False




       def     UpperCAmelCase__    ( self				:    Optional[Any]			):
              snake_case__ :       Optional[int]	   =							BlipTextModelTester(self			)
              snake_case__ :       Dict	   =							ConfigTester(self    ,				config_class=snake_case__    ,				hidden_size=3_7			)




       def     UpperCAmelCase__    ( self				:    Union[str, Any]			):
              self.config_tester.run_common_tests()




       def     UpperCAmelCase__    ( self				:    Union[str, Any]			):
              snake_case__ :       List[str]	   =							self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_model(*snake_case__			)




       def     UpperCAmelCase__    ( self				:    List[str]			):
              pass




       def     UpperCAmelCase__    ( self				:    Any			):
              pass




       @unittest.skip(reason='Blip does not use inputs_embeds'			)
       def     UpperCAmelCase__    ( self				:    Union[str, Any]			):
              pass




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




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




       @slow
       def     UpperCAmelCase__    ( self				:    Union[str, Any]			):
              for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                     snake_case__ :       int	   =							TFBlipTextModel.from_pretrained(snake_case__			)
                     self.assertIsNotNone(snake_case__			)




       def     UpperCAmelCase__    ( self				:    Dict    ,				_lowerCamelCase				:    int=True			):
              super().test_pt_tf_model_equivalence(allow_missing_keys=snake_case__			)













"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_lowerCAmelCase	:	Tuple				=      {
    """configuration_lxmert""": ["""LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LxmertConfig"""],
    """tokenization_lxmert""": ["""LxmertTokenizer"""],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase	:	int				=      ["""LxmertTokenizerFast"""]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase	:	Tuple				=      [
     """LxmertEncoder""",
     """LxmertForPreTraining""",
     """LxmertForQuestionAnswering""",
     """LxmertModel""",
     """LxmertPreTrainedModel""",
     """LxmertVisualFeatureEncoder""",
     """LxmertXLayer""",
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase	:	Optional[int]				=      [
     """TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
     """TFLxmertForPreTraining""",
     """TFLxmertMainLayer""",
     """TFLxmertModel""",
     """TFLxmertPreTrainedModel""",
     """TFLxmertVisualFeatureEncoder""",
 ]


if TYPE_CHECKING:
 from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
 from .tokenization_lxmert import LxmertTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_lxmert_fast import LxmertTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_lxmert import (
      LxmertEncoder,
      LxmertForPreTraining,
      LxmertForQuestionAnswering,
      LxmertModel,
      LxmertPreTrainedModel,
      LxmertVisualFeatureEncoder,
      LxmertXLayer,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_lxmert import (
      TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFLxmertForPreTraining,
      TFLxmertMainLayer,
      TFLxmertModel,
      TFLxmertPreTrainedModel,
      TFLxmertVisualFeatureEncoder,
  )

else:
 import sys

 _lowerCAmelCase	:	Any				=      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


