

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 							UpperCAmelCase_						:
							"""simple docstring"""







							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			,				)       ->       Optional[Any]:
												_a      :       Optional[Any]   =						parent
												_a      :       int   =						batch_size
												_a      :       Optional[int]   =						seq_length
												_a      :       List[Any]   =						is_training
												_a      :       Dict   =						use_input_mask
												_a      :       Optional[Any]   =						use_labels
												_a      :       Tuple   =						vocab_size
												_a      :       List[Any]   =						hidden_size
												_a      :       str   =						projection_dim
												_a      :       Optional[int]   =						num_hidden_layers
												_a      :       Union[str, Any]   =						num_attention_heads
												_a      :       Union[str, Any]   =						intermediate_size
												_a      :       int   =						dropout
												_a      :       List[Any]   =						attention_dropout
												_a      :       Tuple   =						max_position_embeddings
												_a      :       Dict   =						initializer_range
												_a      :       Union[str, Any]   =						scope
												_a      :       Tuple   =						bos_token_id


							def 							__lowercase							(     self			)       ->       List[str]:
												_a      :       Union[str, Any]   =						ids_tensor([self.batch_size, self.seq_length]			,				self.vocab_size			)

												_a      :       Optional[int]   =						None
												if self.use_input_mask:
																	_a      :       Tuple   =						random_attention_mask([self.batch_size, self.seq_length]			)

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

												_a      :       str   =						self.get_config()

												return config, input_ids, tf.convert_to_tensor(_a			)


							def 							__lowercase							(     self			)       ->       List[str]:
												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			,				_a			,				_a			,				_a			)       ->       Dict:
												_a      :       int   =						TFBlipTextModel(config=_a			)
												_a      :       str   =						model(_a			,				attention_mask=_a			,				training=_a			)
												_a      :       int   =						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			)       ->       str:
												_a      :       Optional[Any]   =						self.prepare_config_and_inputs()
												_a ,   _a ,   _a      :       Union[str, Any]   =						config_and_inputs
												_a      :       Tuple   =						{'''input_ids''': input_ids, '''attention_mask''': input_mask}
												return config, inputs_dict



@require_tf
class 							UpperCAmelCase_						(     __lowercase							,			unittest.TestCase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		Union[str, Any]             =       (TFBlipTextModel,) if is_tf_available() else ()
							UpperCAmelCase__			:		str             =       False
							UpperCAmelCase__			:		List[str]             =       False
							UpperCAmelCase__			:		Dict             =       False


							def 							__lowercase							(     self			)       ->       Any:
												_a      :       int   =						BlipTextModelTester(self			)
												_a      :       Optional[Any]   =						ConfigTester(self			,				config_class=_a			,				hidden_size=3_7			)


							def 							__lowercase							(     self			)       ->       Any:
												self.config_tester.run_common_tests()


							def 							__lowercase							(     self			)       ->       Union[str, Any]:
												_a      :       Dict   =						self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*_a			)


							def 							__lowercase							(     self			)       ->       Optional[Any]:
												pass


							def 							__lowercase							(     self			)       ->       int:
												pass


							@unittest.skip(reason='''Blip does not use inputs_embeds'''			)
							def 							__lowercase							(     self			)       ->       int:
												pass


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


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


							@slow
							def 							__lowercase							(     self			)       ->       Any:
												for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_a      :       Dict   =						TFBlipTextModel.from_pretrained(_a			)
																	self.assertIsNotNone(_a			)




							def 							__lowercase							(     self			,				_a=True			)       ->       List[str]:
												super().test_pt_tf_model_equivalence(allow_missing_keys=_a			)






import os
import unittest

from transformers import LxmertTokenizer, LxmertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin

@require_tokenizers
class 							UpperCAmelCase_						(     __lowercase							,			unittest.TestCase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		Any             =       LxmertTokenizer
							UpperCAmelCase__			:		Optional[Any]             =       LxmertTokenizerFast
							UpperCAmelCase__			:		Any             =       True
							UpperCAmelCase__			:		Dict             =       True


							def 							__lowercase							(     self			)       ->       Union[str, Any]:
												super().setUp()

												_a      :       int   =						[
												    '''[UNK]''',
												    '''[CLS]''',
												    '''[SEP]''',
												    '''want''',
												    '''##want''',
												    '''##ed''',
												    '''wa''',
												    '''un''',
												    '''runn''',
												    '''##ing''',
												    ''',''',
												    '''low''',
												    '''lowest''',
												]
												_a      :       Any   =						os.path.join(self.tmpdirname			,				VOCAB_FILES_NAMES['''vocab_file''']			)
												with open(self.vocab_file			,				'''w'''			,				encoding='''utf-8'''			) as vocab_writer:
																	vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]			)			)


							def 							__lowercase							(     self			,				_a			)       ->       List[str]:
												_a      :       Tuple   =						'''UNwant\u00E9d,running'''
												_a      :       str   =						'''unwanted, running'''
												return input_text, output_text


							def 							__lowercase							(     self			)       ->       List[Any]:
												_a      :       str   =						self.tokenizer_class(self.vocab_file			)

												_a      :       str   =						tokenizer.tokenize('''UNwant\u00E9d,running'''			)
												self.assertListEqual(_a			,				['''un''', '''##want''', '''##ed''', ''',''', '''runn''', '''##ing''']			)
												self.assertListEqual(tokenizer.convert_tokens_to_ids(_a			)			,				[7, 4, 5, 1_0, 8, 9]			)




							def 							__lowercase							(     self			)       ->       List[Any]:
												if not self.test_rust_tokenizer:
																	return

												_a      :       Optional[Any]   =						self.get_tokenizer()
												_a      :       str   =						self.get_rust_tokenizer()

												_a      :       Optional[Any]   =						'''I was born in 92000, and this is falsé.'''

												_a      :       Optional[Any]   =						tokenizer.tokenize(_a			)
												_a      :       List[Any]   =						rust_tokenizer.tokenize(_a			)
												self.assertListEqual(_a			,				_a			)

												_a      :       List[Any]   =						tokenizer.encode(_a			,				add_special_tokens=_a			)
												_a      :       Any   =						rust_tokenizer.encode(_a			,				add_special_tokens=_a			)
												self.assertListEqual(_a			,				_a			)

												_a      :       Dict   =						self.get_rust_tokenizer()
												_a      :       Optional[int]   =						tokenizer.encode(_a			)
												_a      :       Dict   =						rust_tokenizer.encode(_a			)
												self.assertListEqual(_a			,				_a			)



