


from __future__ import annotations

import unittest

from transformers import AlbertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
		import tensorflow as tf

		from transformers import TF_MODEL_FOR_PRETRAINING_MAPPING
		from transformers.models.albert.modeling_tf_albert import (
		    TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFAlbertForMaskedLM,
		    TFAlbertForMultipleChoice,
		    TFAlbertForPreTraining,
		    TFAlbertForQuestionAnswering,
		    TFAlbertForSequenceClassification,
		    TFAlbertForTokenClassification,
		    TFAlbertModel,
		)

class 	__a   :
		def __init__(    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE=13    ,					_SCREAMING_SNAKE_CASE=7    ,					_SCREAMING_SNAKE_CASE=True    ,					_SCREAMING_SNAKE_CASE=True    ,					_SCREAMING_SNAKE_CASE=True    ,					_SCREAMING_SNAKE_CASE=True    ,					_SCREAMING_SNAKE_CASE=99    ,					_SCREAMING_SNAKE_CASE=16    ,					_SCREAMING_SNAKE_CASE=32    ,					_SCREAMING_SNAKE_CASE=2    ,					_SCREAMING_SNAKE_CASE=4    ,					_SCREAMING_SNAKE_CASE=37    ,					_SCREAMING_SNAKE_CASE="gelu"    ,					_SCREAMING_SNAKE_CASE=0.1    ,					_SCREAMING_SNAKE_CASE=0.1    ,					_SCREAMING_SNAKE_CASE=512    ,					_SCREAMING_SNAKE_CASE=16    ,					_SCREAMING_SNAKE_CASE=2    ,					_SCREAMING_SNAKE_CASE=0.02    ,					_SCREAMING_SNAKE_CASE=3    ,					_SCREAMING_SNAKE_CASE=4    ,					_SCREAMING_SNAKE_CASE=None    ,					)				-> Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    parent
									_UpperCAmelCase					=    13
									_UpperCAmelCase					=    7
									_UpperCAmelCase					=    True
									_UpperCAmelCase					=    True
									_UpperCAmelCase					=    True
									_UpperCAmelCase					=    True
									_UpperCAmelCase					=    99
									_UpperCAmelCase					=    16
									_UpperCAmelCase					=    32
									_UpperCAmelCase					=    2
									_UpperCAmelCase					=    4
									_UpperCAmelCase					=    37
									_UpperCAmelCase					=    'gelu'
									_UpperCAmelCase					=    0.1
									_UpperCAmelCase					=    0.1
									_UpperCAmelCase					=    512
									_UpperCAmelCase					=    16
									_UpperCAmelCase					=    2
									_UpperCAmelCase					=    0.02
									_UpperCAmelCase					=    3
									_UpperCAmelCase					=    4
									_UpperCAmelCase					=    None
		def 			UpperCAmelCase__       (    self		)				-> Dict:




									"""simple docstring"""





									_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]		)

									_UpperCAmelCase					=    None
									if self.use_token_type_ids:
																_UpperCAmelCase					=    ids_tensor([self.batch_size, self.seq_length]    ,					self.type_vocab_size		)

									_UpperCAmelCase					=    None
									_UpperCAmelCase					=    None
									_UpperCAmelCase					=    None
									if self.use_labels:
																_UpperCAmelCase					=    ids_tensor([self.batch_size]    ,					self.type_sequence_label_size		)
																_UpperCAmelCase					=    ids_tensor([self.batch_size, self.seq_length]    ,					self.num_labels		)
																_UpperCAmelCase					=    ids_tensor([self.batch_size]    ,					self.num_choices		)

									_UpperCAmelCase					=    AlbertConfig(
									    vocab_size=self.vocab_size    ,					hidden_size=self.hidden_size    ,					embedding_size=self.embedding_size    ,					num_hidden_layers=self.num_hidden_layers    ,					num_attention_heads=self.num_attention_heads    ,					intermediate_size=self.intermediate_size    ,					hidden_act=self.hidden_act    ,					hidden_dropout_prob=self.hidden_dropout_prob    ,					attention_probs_dropout_prob=self.attention_probs_dropout_prob    ,					max_position_embeddings=self.max_position_embeddings    ,					type_vocab_size=self.type_vocab_size    ,					initializer_range=self.initializer_range    ,					)

									return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=    TFAlbertModel(config=_SCREAMING_SNAKE_CASE		)
									# inputs = {'input_ids': input_ids,
									#           'attention_mask': input_mask,
									#           'token_type_ids': token_type_ids}
									# sequence_output, pooled_output = model(**inputs)
									_UpperCAmelCase					=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									_UpperCAmelCase					=    model(_SCREAMING_SNAKE_CASE		)

									_UpperCAmelCase					=    [input_ids, input_mask]
									_UpperCAmelCase					=    model(_SCREAMING_SNAKE_CASE		)

									_UpperCAmelCase					=    model(_SCREAMING_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 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> List[Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.num_labels
									_UpperCAmelCase					=    TFAlbertForPreTraining(config=_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase					=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									_UpperCAmelCase					=    model(_SCREAMING_SNAKE_CASE		)
									self.parent.assertEqual(result.prediction_logits.shape    ,					(self.batch_size, self.seq_length, self.vocab_size)		)
									self.parent.assertEqual(result.sop_logits.shape    ,					(self.batch_size, self.num_labels)		)
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> str:




									"""simple docstring"""





									_UpperCAmelCase					=    TFAlbertForMaskedLM(config=_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase					=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									_UpperCAmelCase					=    model(_SCREAMING_SNAKE_CASE		)
									self.parent.assertEqual(result.logits.shape    ,					(self.batch_size, self.seq_length, self.vocab_size)		)
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.num_labels
									_UpperCAmelCase					=    TFAlbertForSequenceClassification(config=_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase					=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									_UpperCAmelCase					=    model(_SCREAMING_SNAKE_CASE		)
									self.parent.assertEqual(result.logits.shape    ,					(self.batch_size, self.num_labels)		)
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> List[str]:




									"""simple docstring"""





									_UpperCAmelCase					=    TFAlbertForQuestionAnswering(config=_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase					=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									_UpperCAmelCase					=    model(_SCREAMING_SNAKE_CASE		)
									self.parent.assertEqual(result.start_logits.shape    ,					(self.batch_size, self.seq_length)		)
									self.parent.assertEqual(result.end_logits.shape    ,					(self.batch_size, self.seq_length)		)
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> Dict:




									"""simple docstring"""





									_UpperCAmelCase					=    self.num_choices
									_UpperCAmelCase					=    TFAlbertForMultipleChoice(config=_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase					=    tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE    ,					1		)    ,					(1, self.num_choices, 1)		)
									_UpperCAmelCase					=    tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE    ,					1		)    ,					(1, self.num_choices, 1)		)
									_UpperCAmelCase					=    tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE    ,					1		)    ,					(1, self.num_choices, 1)		)
									_UpperCAmelCase					=    {
									    'input_ids': multiple_choice_inputs_ids,
									    'attention_mask': multiple_choice_input_mask,
									    'token_type_ids': multiple_choice_token_type_ids,
									}
									_UpperCAmelCase					=    model(_SCREAMING_SNAKE_CASE		)
									self.parent.assertListEqual(list(result['logits'].shape		)    ,					[self.batch_size, self.num_choices]		)
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> Any:




									"""simple docstring"""





									_UpperCAmelCase					=    self.num_labels
									_UpperCAmelCase					=    TFAlbertForTokenClassification(config=_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase					=    {
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									    'token_type_ids': token_type_ids,
									}
									_UpperCAmelCase					=    model(_SCREAMING_SNAKE_CASE		)
									self.parent.assertListEqual(list(result['logits'].shape		)    ,					[self.batch_size, self.seq_length, self.num_labels]		)






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




									"""simple docstring"""





									_UpperCAmelCase					=    self.prepare_config_and_inputs()
									(
									    (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, 
									)					=    config_and_inputs
									_UpperCAmelCase					=    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
									return config, inputs_dict



@require_tf
class 	__a   (       UpperCAmelCase					,   UpperCAmelCase					,   unittest.TestCase    ):
		_a			:						Dict    			=			(
		    (
		        TFAlbertModel,
		        TFAlbertForPreTraining,
		        TFAlbertForMaskedLM,
		        TFAlbertForSequenceClassification,
		        TFAlbertForQuestionAnswering,
		        TFAlbertForTokenClassification,
		        TFAlbertForMultipleChoice,
		    )
		    if is_tf_available()
		    else ()
		)
		_a			:						Union[str, Any]    			=			(
		    {
		        'feature-extraction': TFAlbertModel,
		        'fill-mask': TFAlbertForMaskedLM,
		        'question-answering': TFAlbertForQuestionAnswering,
		        'text-classification': TFAlbertForSequenceClassification,
		        'token-classification': TFAlbertForTokenClassification,
		        'zero-shot': TFAlbertForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)
		_a			:						int    			=			False
		_a			:						Optional[Any]    			=			False
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE=False		)				-> str:




									"""simple docstring"""





									_UpperCAmelCase					=    super()._prepare_for_class(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					return_labels=_SCREAMING_SNAKE_CASE		)

									if return_labels:
																if model_class in get_values(_SCREAMING_SNAKE_CASE		):
																							_UpperCAmelCase					=    tf.zeros(self.model_tester.batch_size    ,					dtype=tf.intaa		)

									return inputs_dict
		def 			UpperCAmelCase__       (    self		)				-> Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    TFAlbertModelTester(self		)
									_UpperCAmelCase					=    ConfigTester(self    ,					config_class=_SCREAMING_SNAKE_CASE    ,					hidden_size=37		)
		def 			UpperCAmelCase__       (    self		)				-> List[Any]:




									"""simple docstring"""





									self.config_tester.run_common_tests()
		def 			UpperCAmelCase__       (    self		)				-> Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_model(*_SCREAMING_SNAKE_CASE		)
		def 			UpperCAmelCase__       (    self		)				-> Dict:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_for_pretraining(*_SCREAMING_SNAKE_CASE		)
		def 			UpperCAmelCase__       (    self		)				-> str:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_for_masked_lm(*_SCREAMING_SNAKE_CASE		)
		def 			UpperCAmelCase__       (    self		)				-> List[str]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_for_multiple_choice(*_SCREAMING_SNAKE_CASE		)
		def 			UpperCAmelCase__       (    self		)				-> str:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_for_sequence_classification(*_SCREAMING_SNAKE_CASE		)
		def 			UpperCAmelCase__       (    self		)				-> Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_for_question_answering(*_SCREAMING_SNAKE_CASE		)






		@slow
		def 			UpperCAmelCase__       (    self		)				-> Dict:




									"""simple docstring"""





									for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																_UpperCAmelCase					=    TFAlbertModel.from_pretrained(_SCREAMING_SNAKE_CASE		)
																self.assertIsNotNone(_SCREAMING_SNAKE_CASE		)



@require_tf
class 	__a   (       unittest.TestCase    ):
		@slow
		def 			UpperCAmelCase__       (    self		)				-> Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    TFAlbertForPreTraining.from_pretrained('albert-base-v2'		)
									_UpperCAmelCase					=    tf.constant([[0, 1, 2, 3, 4, 5]]		)
									_UpperCAmelCase					=    model(_SCREAMING_SNAKE_CASE		)[0]

									_UpperCAmelCase					=    [1, 6, 30000]
									self.assertEqual(output.shape    ,					_SCREAMING_SNAKE_CASE		)

									_UpperCAmelCase					=    tf.constant(
									    [
									        [
									            [4.595668, 0.74462754, -1.818147],
									            [4.5954347, 0.7454184, -1.8188258],
									            [4.5954905, 0.7448235, -1.8182316],
									        ]
									    ]		)
									tf.debugging.assert_near(output[:, :3, :3]    ,					_SCREAMING_SNAKE_CASE    ,					atol=1e-4		)




from __future__ import annotations

def  lowerCAmelCase__				(    a__:	list[int]    ,						a__:	int )						->	list[int]:


							'''simple docstring'''





							_UpperCAmelCase					=    {}
							for index, val in enumerate(a__ ):
														_UpperCAmelCase					=    target - val
														if compl in chk_map:
																					return [chk_map[compl], index]
														_UpperCAmelCase					=    index
							return []


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		print(f'''{two_sum([2, 7, 1_1, 1_5], 9) = }''')
