


'''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      lowerCamelCase_  :






      def __init__(   self							:       Optional[Any]		,		_A							:       List[Any]		,		_A							:       Tuple=12		,		_A							:       Tuple=7		,		_A							:       str=True		,		_A							:       List[Any]=True		,		_A							:       Any=True		,		_A							:       Optional[Any]=99		,		_A							:       Tuple=32		,		_A							:       Dict=32		,		_A							:       Tuple=2		,		_A							:       Any=4		,		_A							:       Dict=37		,		_A							:       int=0.1		,		_A							:       List[str]=0.1		,		_A							:       Optional[int]=512		,		_A							:       int=0.0_2		,		_A							:       List[Any]=0		,		_A							:       Union[str, Any]=None		,		):


          '''simple docstring'''


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






      def lowercase_				(   self							:       int					):


          '''simple docstring'''


          UpperCAmelCase__     :						Union[str, Any]						=							ids_tensor([self.batch_size, self.seq_length]		,		self.vocab_size					)

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

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

          UpperCAmelCase__     :						Optional[int]						=							self.get_config()

          return config, input_ids, tf.convert_to_tensor(_A					)






      def lowercase_				(   self							:       Optional[int]					):


          '''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 lowercase_				(   self							:       Optional[Any]		,		_A							:       int		,		_A							:       Dict		,		_A							:       List[Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						str						=							TFBlipTextModel(config=_A					)
          UpperCAmelCase__     :						Optional[int]						=							model(_A		,		attention_mask=_A		,		training=_A					)
          UpperCAmelCase__     :						List[Any]						=							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 lowercase_				(   self							:       Dict					):


          '''simple docstring'''


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




@require_tf
class      lowerCamelCase_  (      __a	,			unittest.TestCase ):
      lowerCAmelCase__							=	(TFBlipTextModel,) if is_tf_available() else ()
      lowerCAmelCase__							=	False
      lowerCAmelCase__							=	False
      lowerCAmelCase__							=	False






      def lowercase_				(   self							:       List[Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						Optional[int]						=							BlipTextModelTester(self					)
          UpperCAmelCase__     :						str						=							ConfigTester(self		,		config_class=_A		,		hidden_size=37					)






      def lowercase_				(   self							:       List[str]					):


          '''simple docstring'''


          self.config_tester.run_common_tests()






      def lowercase_				(   self							:       int					):


          '''simple docstring'''


          UpperCAmelCase__     :						Optional[int]						=							self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*_A					)






      def lowercase_				(   self							:       Any					):


          '''simple docstring'''


          pass






      def lowercase_				(   self							:       int					):


          '''simple docstring'''


          pass






      @unittest.skip(reason='''Blip does not use inputs_embeds'''					)
      def lowercase_				(   self							:       str					):


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






      @slow
      def lowercase_				(   self							:       Optional[Any]					):


          '''simple docstring'''


          for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCAmelCase__     :						Any						=							TFBlipTextModel.from_pretrained(_A					)
              self.assertIsNotNone(_A					)






      def lowercase_				(   self							:       Any		,		_A							:       Tuple=True					):


          '''simple docstring'''


          super().test_pt_tf_model_equivalence(allow_missing_keys=_A					)





'''simple docstring'''

import os


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_doctest_list.py
a							   =				'.'


if __name__ == "__main__":
	a							   =				os.path.join(REPO_PATH, 'utils/documentation_tests.txt')
	a							   =				[]
	a							   =				[]
	with open(doctest_file_path) as fp:
		for line in fp:
			a							   =				line.strip()
			a							   =				os.path.join(REPO_PATH, line)
			if not (os.path.isfile(path) or os.path.isdir(path)):
				non_existent_paths.append(line)
			all_paths.append(path)
	if len(non_existent_paths) > 0:
		a							   =				'\n'.join(non_existent_paths)
		raise ValueError(F"""`utils/documentation_tests.txt` contains non-existent paths:\n{non_existent_paths}""")
	if all_paths != sorted(all_paths):
		raise ValueError('Files in `utils/documentation_tests.txt` are not in alphabetical order.')




