




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



						def __init__( self  :      List[Any]				,       snake_case__  :      Any				,       snake_case__  :      List[Any]=13				,       snake_case__  :      Union[str, Any]=7				,       snake_case__  :      List[str]=True				,       snake_case__  :      List[Any]=True				,       snake_case__  :      Tuple=True				,       snake_case__  :      Any=True				,       snake_case__  :      Union[str, Any]=99				,       snake_case__  :      Union[str, Any]=16				,       snake_case__  :      Optional[int]=32				,       snake_case__  :      Tuple=2				,       snake_case__  :      Tuple=4				,       snake_case__  :      int=37				,       snake_case__  :      Optional[int]="gelu"				,       snake_case__  :      str=0.1				,       snake_case__  :      Dict=0.1				,       snake_case__  :      Any=5_12				,       snake_case__  :      List[Any]=16				,       snake_case__  :      Dict=2				,       snake_case__  :      Dict=0.02				,       snake_case__  :      Any=3				,       snake_case__  :      Any=4				,       snake_case__  :      Any=None				,       ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       parent
								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_							=       5_12
								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



						def   __a				( self  :      int     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       ids_tensor([self.batch_size, self.seq_length]				,       self.vocab_size     )

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

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

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

								SCREAMING_SNAKE_CASE_							=       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   __a				( self  :      Tuple				,       snake_case__  :      Union[str, Any]				,       snake_case__  :      Optional[Any]				,       snake_case__  :      str				,       snake_case__  :      Optional[Any]				,       snake_case__  :      str				,       snake_case__  :      str				,       snake_case__  :      Union[str, Any]     ):

								"""simple docstring"""

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

								SCREAMING_SNAKE_CASE_							=       [input_ids, input_mask]
								SCREAMING_SNAKE_CASE_							=       model(snake_case__     )

								SCREAMING_SNAKE_CASE_							=       model(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   __a				( self  :      int				,       snake_case__  :      Optional[Any]				,       snake_case__  :      int				,       snake_case__  :      List[str]				,       snake_case__  :      int				,       snake_case__  :      str				,       snake_case__  :      Tuple				,       snake_case__  :      Optional[int]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       self.num_labels
								SCREAMING_SNAKE_CASE_							=       TFAlbertForPreTraining(config=snake_case__     )
								SCREAMING_SNAKE_CASE_							=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								SCREAMING_SNAKE_CASE_							=       model(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   __a				( self  :      Tuple				,       snake_case__  :      Any				,       snake_case__  :      Optional[int]				,       snake_case__  :      str				,       snake_case__  :      int				,       snake_case__  :      Optional[int]				,       snake_case__  :      Dict				,       snake_case__  :      Union[str, Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       TFAlbertForMaskedLM(config=snake_case__     )
								SCREAMING_SNAKE_CASE_							=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								SCREAMING_SNAKE_CASE_							=       model(snake_case__     )
								self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.seq_length, self.vocab_size)     )



						def   __a				( self  :      Optional[int]				,       snake_case__  :      Dict				,       snake_case__  :      Optional[int]				,       snake_case__  :      Tuple				,       snake_case__  :      str				,       snake_case__  :      Dict				,       snake_case__  :      str				,       snake_case__  :      Optional[Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       self.num_labels
								SCREAMING_SNAKE_CASE_							=       TFAlbertForSequenceClassification(config=snake_case__     )
								SCREAMING_SNAKE_CASE_							=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								SCREAMING_SNAKE_CASE_							=       model(snake_case__     )
								self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.num_labels)     )



						def   __a				( self  :      Any				,       snake_case__  :      Any				,       snake_case__  :      Optional[int]				,       snake_case__  :      Dict				,       snake_case__  :      Optional[int]				,       snake_case__  :      str				,       snake_case__  :      Union[str, Any]				,       snake_case__  :      Any     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       TFAlbertForQuestionAnswering(config=snake_case__     )
								SCREAMING_SNAKE_CASE_							=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
								SCREAMING_SNAKE_CASE_							=       model(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   __a				( self  :      Optional[int]				,       snake_case__  :      Dict				,       snake_case__  :      Union[str, Any]				,       snake_case__  :      Tuple				,       snake_case__  :      List[str]				,       snake_case__  :      List[str]				,       snake_case__  :      Tuple				,       snake_case__  :      Optional[int]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       self.num_choices
								SCREAMING_SNAKE_CASE_							=       TFAlbertForMultipleChoice(config=snake_case__     )
								SCREAMING_SNAKE_CASE_							=       tf.tile(tf.expand_dims(snake_case__				,       1     )				,       (1, self.num_choices, 1)     )
								SCREAMING_SNAKE_CASE_							=       tf.tile(tf.expand_dims(snake_case__				,       1     )				,       (1, self.num_choices, 1)     )
								SCREAMING_SNAKE_CASE_							=       tf.tile(tf.expand_dims(snake_case__				,       1     )				,       (1, self.num_choices, 1)     )
								SCREAMING_SNAKE_CASE_							=       {
								    'input_ids': multiple_choice_inputs_ids,
								    'attention_mask': multiple_choice_input_mask,
								    'token_type_ids': multiple_choice_token_type_ids,
								}
								SCREAMING_SNAKE_CASE_							=       model(snake_case__     )
								self.parent.assertListEqual(list(result['logits'].shape     )				,       [self.batch_size, self.num_choices]     )



						def   __a				( self  :      str				,       snake_case__  :      Optional[Any]				,       snake_case__  :      Optional[int]				,       snake_case__  :      List[str]				,       snake_case__  :      Any				,       snake_case__  :      Any				,       snake_case__  :      Optional[int]				,       snake_case__  :      int     ):

								"""simple docstring"""

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






						def   __a				( self  :      str     ):

								"""simple docstring"""

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



@require_tf
class       lowercase_		(SCREAMING_SNAKE_CASE__       ,  SCREAMING_SNAKE_CASE__       ,  unittest.TestCase   ):
						lowerCAmelCase__ 			=(
						    (
						        TFAlbertModel,
						        TFAlbertForPreTraining,
						        TFAlbertForMaskedLM,
						        TFAlbertForSequenceClassification,
						        TFAlbertForQuestionAnswering,
						        TFAlbertForTokenClassification,
						        TFAlbertForMultipleChoice,
						    )
						    if is_tf_available()
						    else ()
						)
						lowerCAmelCase__ 			=(
						    {
						        "feature-extraction": TFAlbertModel,
						        "fill-mask": TFAlbertForMaskedLM,
						        "question-answering": TFAlbertForQuestionAnswering,
						        "text-classification": TFAlbertForSequenceClassification,
						        "token-classification": TFAlbertForTokenClassification,
						        "zero-shot": TFAlbertForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						lowerCAmelCase__ 			=False
						lowerCAmelCase__ 			=False



						def   __a				( self  :      str				,       snake_case__  :      Any				,       snake_case__  :      str				,       snake_case__  :      Any=False     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       super()._prepare_for_class(snake_case__				,       snake_case__				,       return_labels=snake_case__     )

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

								return inputs_dict



						def   __a				( self  :      List[str]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       TFAlbertModelTester(self     )
								SCREAMING_SNAKE_CASE_							=       ConfigTester(self				,       config_class=snake_case__				,       hidden_size=37     )



						def   __a				( self  :      Union[str, Any]     ):

								"""simple docstring"""

								self.config_tester.run_common_tests()



						def   __a				( self  :      Union[str, Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_model(*snake_case__     )



						def   __a				( self  :      List[Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_pretraining(*snake_case__     )



						def   __a				( self  :      Union[str, Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_masked_lm(*snake_case__     )



						def   __a				( self  :      int     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_multiple_choice(*snake_case__     )



						def   __a				( self  :      Optional[Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_sequence_classification(*snake_case__     )



						def   __a				( self  :      List[str]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_question_answering(*snake_case__     )






						@slow
						def   __a				( self  :      Optional[Any]     ):

								"""simple docstring"""

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



@require_tf
class       lowercase_		(unittest.TestCase   ):



						@slow
						def   __a				( self  :      str     ):

								"""simple docstring"""

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

								SCREAMING_SNAKE_CASE_							=       [1, 6, 3_00_00]
								self.assertEqual(output.shape				,       snake_case__     )

								SCREAMING_SNAKE_CASE_							=       tf.constant(
								    [
								        [
								            [4.59_56_68, 0.74_46_27_54, -1.81_81_47],
								            [4.5_95_43_47, 0.7_45_41_84, -1.8_18_82_58],
								            [4.5_95_49_05, 0.7_44_82_35, -1.8_18_23_16],
								        ]
								    ]     )
								tf.debugging.assert_near(output[:, :3, :3]				,       snake_case__				,       atol=1e-4     )





from __future__ import annotations


def 				_a       (				lowerCAmelCase						,	lowerCAmelCase   )->  int:
		SCREAMING_SNAKE_CASE_			,							SCREAMING_SNAKE_CASE_							=       0, len(lowerCAmelCase   ) - 1
		while start_ind <= end_ind:
				if array[start_ind] == search_item:
						return start_ind
				elif array[end_ind] == search_item:
						return end_ind
				else:
						start_ind += 1
						end_ind -= 1
    # returns -1 if search_item is not found in array
		return -1


if __name__ == "__main__":
						print(double_linear_search(list(range(1_0_0)), 4_0))