



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






							def snake_case_  (   self      ):
									a_     :      Any 						=     ids_tensor([self.batch_size, self.seq_length]			,     self.vocab_size      )

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

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

									a_     :      Any 						=     self.get_config()

									return config, input_ids, tf.convert_to_tensor(a_      )






							def snake_case_  (   self      ):
									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 snake_case_  (   self			,     a_			,     a_			,     a_      ):
									a_     :      Union[str, Any] 						=     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 snake_case_  (   self      ):
									a_     :      Optional[int] 						=     self.prepare_config_and_inputs()
									a_						,				a_						,				a_     :      str 						=     config_and_inputs
									a_     :      Dict 						=     {"input_ids": input_ids, "attention_mask": input_mask}
									return config, inputs_dict




@require_tf
class 			snake_case_						(						a_     ,unittest.TestCase				):
							__lowerCAmelCase    					=					(TFBlipTextModel,) if is_tf_available() else ()
							__lowerCAmelCase    					=					False
							__lowerCAmelCase    					=					False
							__lowerCAmelCase    					=					False






							def snake_case_  (   self      ):
									a_     :      int 						=     BlipTextModelTester(self      )
									a_     :      Optional[int] 						=     ConfigTester(self			,     config_class=a_			,     hidden_size=3_7      )






							def snake_case_  (   self      ):
									self.config_tester.run_common_tests()






							def snake_case_  (   self      ):
									a_     :      Union[str, Any] 						=     self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*a_      )






							def snake_case_  (   self      ):
									pass






							def snake_case_  (   self      ):
									pass






							@unittest.skip(reason="Blip does not use inputs_embeds"      )
							def snake_case_  (   self      ):
									pass






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






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






							@slow
							def snake_case_  (   self      ):
									for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											a_     :      Tuple 						=     TFBlipTextModel.from_pretrained(a_      )
											self.assertIsNotNone(a_      )






							def snake_case_  (   self			,     a_=True      ):
									super().test_pt_tf_model_equivalence(allow_missing_keys=a_      )




"""simple docstring"""
from typing import TYPE_CHECKING

from ..utils import _LazyModule


SCREAMING_SNAKE_CASE_				= {
    """config""": [
        """EXTERNAL_DATA_FORMAT_SIZE_LIMIT""",
        """OnnxConfig""",
        """OnnxConfigWithPast""",
        """OnnxSeq2SeqConfigWithPast""",
        """PatchingSpec""",
    ],
    """convert""": ["""export""", """validate_model_outputs"""],
    """features""": ["""FeaturesManager"""],
    """utils""": ["""ParameterFormat""", """compute_serialized_parameters_size"""],
}


if TYPE_CHECKING:
					from .config import (
					    EXTERNAL_DATA_FORMAT_SIZE_LIMIT,
					    OnnxConfig,
					    OnnxConfigWithPast,
					    OnnxSeqaSeqConfigWithPast,
					    PatchingSpec,
					)
					from .convert import export, validate_model_outputs
					from .features import FeaturesManager
					from .utils import ParameterFormat, compute_serialized_parameters_size

else:
					import sys

					SCREAMING_SNAKE_CASE_				= _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)