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




				def __init__(     self		,     _snake_case		,     _snake_case=12		,     _snake_case=7		,     _snake_case=True		,     _snake_case=True		,     _snake_case=True		,     _snake_case=99		,     _snake_case=32		,     _snake_case=32		,     _snake_case=2		,     _snake_case=4		,     _snake_case=37		,     _snake_case=0.1		,     _snake_case=0.1		,     _snake_case=512		,     _snake_case=0.02		,     _snake_case=0		,     _snake_case=None		,     )    ->      Dict:


								'''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 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Union[str, Any]:


								'''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 				SCREAMING_SNAKE_CASE_		(     self				)    ->      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 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case		,     _snake_case		,     _snake_case				)    ->      Optional[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 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Dict:


								'''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 			__A( a  ,   unittest.TestCase			):
				snake_case_						   =    (TFBlipTextModel,) if is_tf_available() else ()
				snake_case_						   =    False
				snake_case_						   =    False
				snake_case_						   =    False




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[int]:


								'''simple docstring'''




								__a										=    BlipTextModelTester(self				)
								__a										=    ConfigTester(self		,     config_class=_snake_case		,     hidden_size=37				)




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


								'''simple docstring'''




								self.config_tester.run_common_tests()




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Tuple:


								'''simple docstring'''




								__a										=    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_snake_case				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      str:


								'''simple docstring'''




								pass




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[Any]:


								'''simple docstring'''




								pass




				@unittest.skip(reason='''Blip does not use inputs_embeds'''				)
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Dict:


								'''simple docstring'''




								pass




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


								'''simple docstring'''




								pass




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


								'''simple docstring'''




								pass




				@slow
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      str:


								'''simple docstring'''




								for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												__a										=    TFBlipTextModel.from_pretrained(_snake_case				)
												self.assertIsNotNone(_snake_case				)




				def 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case=True				)    ->      Optional[Any]:


								'''simple docstring'''




								super().test_pt_tf_model_equivalence(allow_missing_keys=_snake_case				)





snake_case_ : Dict    		=       {
    "Pillow": "Pillow",
    "accelerate": "accelerate>=0.11.0",
    "compel": "compel==0.1.8",
    "black": "black~=23.1",
    "datasets": "datasets",
    "filelock": "filelock",
    "flax": "flax>=0.4.1",
    "hf-doc-builder": "hf-doc-builder>=0.3.0",
    "huggingface-hub": "huggingface-hub>=0.13.2",
    "requests-mock": "requests-mock==1.10.0",
    "importlib_metadata": "importlib_metadata",
    "invisible-watermark": "invisible-watermark",
    "isort": "isort>=5.5.4",
    "jax": "jax>=0.2.8,!=0.3.2",
    "jaxlib": "jaxlib>=0.1.65",
    "Jinja2": "Jinja2",
    "k-diffusion": "k-diffusion>=0.0.12",
    "torchsde": "torchsde",
    "note_seq": "note_seq",
    "librosa": "librosa",
    "numpy": "numpy",
    "omegaconf": "omegaconf",
    "parameterized": "parameterized",
    "protobuf": "protobuf>=3.20.3,<4",
    "pytest": "pytest",
    "pytest-timeout": "pytest-timeout",
    "pytest-xdist": "pytest-xdist",
    "ruff": "ruff>=0.0.241",
    "safetensors": "safetensors",
    "sentencepiece": "sentencepiece>=0.1.91,!=0.1.92",
    "scipy": "scipy",
    "onnx": "onnx",
    "regex": "regex!=2019.12.17",
    "requests": "requests",
    "tensorboard": "tensorboard",
    "torch": "torch>=1.4",
    "torchvision": "torchvision",
    "transformers": "transformers>=4.25.1",
    "urllib3": "urllib3<=2.0.0",
}






