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




			"""simple docstring"""







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







								"""simple docstring"""
								A_								=    parent
								A_								=    batch_size
								A_								=    seq_length
								A_								=    is_training
								A_								=    use_input_mask
								A_								=    use_labels
								A_								=    vocab_size
								A_								=    hidden_size
								A_								=    projection_dim
								A_								=    num_hidden_layers
								A_								=    num_attention_heads
								A_								=    intermediate_size
								A_								=    dropout
								A_								=    attention_dropout
								A_								=    max_position_embeddings
								A_								=    initializer_range
								A_								=    scope
								A_								=    bos_token_id




			def   lowerCamelCase__  (					self    :       List[Any]						)   ->			str:







								"""simple docstring"""
								A_								=    ids_tensor([self.batch_size, self.seq_length]							, self.vocab_size						)

								A_								=    None
								if self.use_input_mask:
													A_								=    random_attention_mask([self.batch_size, self.seq_length]						)

								if input_mask is not None:
													A_								=    input_mask.numpy()
													A_			,     A_								=    input_mask.shape
													A_								=    np.random.randint(1							, seq_length - 1							, size=(batch_size,)						)
													for batch_idx, start_index in enumerate(_snake_case						):
																		A_								=    1
																		A_								=    0

								A_								=    self.get_config()

								return config, input_ids, tf.convert_to_tensor(_snake_case						)




			def   lowerCamelCase__  (					self    :       str						)   ->			Dict:







								"""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    :       Tuple							, _snake_case    :       List[str]							, _snake_case    :       List[Any]							, _snake_case    :       List[str]						)   ->			Union[str, Any]:







								"""simple docstring"""
								A_								=    TFBlipTextModel(config=_snake_case						)
								A_								=    model(_snake_case							, attention_mask=_snake_case							, training=_snake_case						)
								A_								=    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   lowerCamelCase__  (					self    :       int						)   ->			Optional[int]:







								"""simple docstring"""
								A_								=    self.prepare_config_and_inputs()
								A_			,     A_			,     A_								=    config_and_inputs
								A_								=    {"input_ids": input_ids, "attention_mask": input_mask}
								return config, inputs_dict





@require_tf
class __lowerCAmelCase					(       _lowercase  ,					unittest.TestCase   ):




			"""simple docstring"""







			snake_case						   =					(TFBlipTextModel,) if is_tf_available() else ()
			snake_case						   =					False
			snake_case						   =					False
			snake_case						   =					False




			def   lowerCamelCase__  (					self    :       Optional[Any]						)   ->			List[Any]:







								"""simple docstring"""
								A_								=    BlipTextModelTester(self						)
								A_								=    ConfigTester(self							, config_class=_snake_case							, hidden_size=37						)




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







								"""simple docstring"""
								self.config_tester.run_common_tests()




			def   lowerCamelCase__  (					self    :       int						)   ->			str:







								"""simple docstring"""
								A_								=    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_snake_case						)




			def   lowerCamelCase__  (					self    :       List[Any]						)   ->			Dict:







								"""simple docstring"""
								pass




			def   lowerCamelCase__  (					self    :       List[str]						)   ->			Tuple:







								"""simple docstring"""
								pass




			@unittest.skip(reason="Blip does not use inputs_embeds"						)
			def   lowerCamelCase__  (					self    :       Optional[Any]						)   ->			Union[str, Any]:







								"""simple docstring"""
								pass




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







								"""simple docstring"""
								pass




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







								"""simple docstring"""
								pass




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







								"""simple docstring"""
								for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													A_								=    TFBlipTextModel.from_pretrained(_snake_case						)
													self.assertIsNotNone(_snake_case						)






			def   lowerCamelCase__  (					self    :       List[str]							, _snake_case    :       str=True						)   ->			Optional[int]:







								"""simple docstring"""
								super().test_pt_tf_model_equivalence(allow_missing_keys=_snake_case						)






"""simple docstring"""





from typing import TYPE_CHECKING

from ..utils import _LazyModule


UpperCamelCase_       :    Dict						      =			{
    '''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

		UpperCamelCase_       :    List[Any]						      =			_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




