



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    ,	lowerCAmelCase    ,	lowerCAmelCase=12    ,	lowerCAmelCase=7    ,	lowerCAmelCase=True    ,	lowerCAmelCase=True    ,	lowerCAmelCase=True    ,	lowerCAmelCase=99    ,	lowerCAmelCase=32    ,	lowerCAmelCase=32    ,	lowerCAmelCase=2    ,	lowerCAmelCase=4    ,	lowerCAmelCase=37    ,	lowerCAmelCase=0.1    ,	lowerCAmelCase=0.1    ,	lowerCAmelCase=512    ,	lowerCAmelCase=0.02    ,	lowerCAmelCase=0    ,	lowerCAmelCase=None    ,	):
							UpperCAmelCase_						=				parent
							UpperCAmelCase_						=				batch_size
							UpperCAmelCase_						=				seq_length
							UpperCAmelCase_						=				is_training
							UpperCAmelCase_						=				use_input_mask
							UpperCAmelCase_						=				use_labels
							UpperCAmelCase_						=				vocab_size
							UpperCAmelCase_						=				hidden_size
							UpperCAmelCase_						=				projection_dim
							UpperCAmelCase_						=				num_hidden_layers
							UpperCAmelCase_						=				num_attention_heads
							UpperCAmelCase_						=				intermediate_size
							UpperCAmelCase_						=				dropout
							UpperCAmelCase_						=				attention_dropout
							UpperCAmelCase_						=				max_position_embeddings
							UpperCAmelCase_						=				initializer_range
							UpperCAmelCase_						=				scope
							UpperCAmelCase_						=				bos_token_id



					def    A__		(			self     ):
							UpperCAmelCase_						=				ids_tensor([self.batch_size, self.seq_length]    ,	self.vocab_size     )

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

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

							UpperCAmelCase_						=				self.get_config()

							return config, input_ids, tf.convert_to_tensor(lowerCAmelCase     )



					def    A__		(			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    A__		(			self    ,	lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase     ):
							UpperCAmelCase_						=				TFBlipTextModel(config=lowerCAmelCase     )
							UpperCAmelCase_						=				model(lowerCAmelCase    ,	attention_mask=lowerCAmelCase    ,	training=lowerCAmelCase     )
							UpperCAmelCase_						=				model(lowerCAmelCase    ,	training=lowerCAmelCase     )
							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    A__		(			self     ):
							UpperCAmelCase_						=				self.prepare_config_and_inputs()
							UpperCAmelCase_					,						UpperCAmelCase_					,						UpperCAmelCase_						=				config_and_inputs
							UpperCAmelCase_						=				{"input_ids": input_ids, "attention_mask": input_mask}
							return config, inputs_dict





@require_tf
class 	lowerCamelCase      (						lowercase__,     unittest.TestCase  ):







					'''simple docstring'''







					lowerCAmelCase_				:    str									=  (TFBlipTextModel,) if is_tf_available() else ()
					lowerCAmelCase_				:    Dict									=  False
					lowerCAmelCase_				:    Optional[int]									=  False
					lowerCAmelCase_				:    List[Any]									=  False



					def    A__		(			self     ):
							UpperCAmelCase_						=				BlipTextModelTester(self     )
							UpperCAmelCase_						=				ConfigTester(self    ,	config_class=lowerCAmelCase    ,	hidden_size=37     )



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



					def    A__		(			self     ):
							UpperCAmelCase_						=				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowerCAmelCase     )



					def    A__		(			self     ):
							pass



					def    A__		(			self     ):
							pass



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



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



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



					@slow
					def    A__		(			self     ):
							for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									UpperCAmelCase_						=				TFBlipTextModel.from_pretrained(lowerCAmelCase     )
									self.assertIsNotNone(lowerCAmelCase     )



					def    A__		(			self    ,	lowerCAmelCase=True     ):
							super().test_pt_tf_model_equivalence(allow_missing_keys=lowerCAmelCase     )






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available


SCREAMING_SNAKE_CASE     				=						{"tokenization_herbert": ["HerbertTokenizer"]}

try:
			if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			SCREAMING_SNAKE_CASE     				=						["HerbertTokenizerFast"]


if TYPE_CHECKING:
			from .tokenization_herbert import HerbertTokenizer

			try:
						if not is_tokenizers_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_herbert_fast import HerbertTokenizerFast

else:
			import sys

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

