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






							def __init__(					self						:			int						, snake_case__						:			Union[str, Any]						, snake_case__						:			int=1_3						, snake_case__						:			Dict=7						, snake_case__						:			Optional[Any]=True						, snake_case__						:			int=True						, snake_case__						:			List[Any]=True						, snake_case__						:			Optional[int]=True						, snake_case__						:			Optional[int]=9_9						, snake_case__						:			Dict=1_6						, snake_case__						:			Optional[Any]=3_2						, snake_case__						:			Tuple=2						, snake_case__						:			Union[str, Any]=4						, snake_case__						:			str=3_7						, snake_case__						:			Union[str, Any]="gelu"						, snake_case__						:			Tuple=0.1						, snake_case__						:			Optional[Any]=0.1						, snake_case__						:			List[Any]=5_1_2						, snake_case__						:			Any=1_6						, snake_case__						:			Dict=2						, snake_case__						:			Optional[Any]=0.02						, snake_case__						:			List[Any]=3						, snake_case__						:			Optional[int]=4						, snake_case__						:			int=None						, ):






												"""simple docstring"""



												__a:						int		    =					parent
												__a:						Dict		    =					1_3
												__a:						Any		    =					7
												__a:						Dict		    =					True
												__a:						Any		    =					True
												__a:						Optional[int]		    =					True
												__a:						Union[str, Any]		    =					True
												__a:						Optional[Any]		    =					9_9
												__a:						List[str]		    =					1_6
												__a:						Union[str, Any]		    =					3_2
												__a:						List[str]		    =					2
												__a:						List[Any]		    =					4
												__a:						Tuple		    =					3_7
												__a:						Dict		    =					"""gelu"""
												__a:						Optional[Any]		    =					0.1
												__a:						Union[str, Any]		    =					0.1
												__a:						List[str]		    =					5_1_2
												__a:						Union[str, Any]		    =					1_6
												__a:						Union[str, Any]		    =					2
												__a:						Optional[Any]		    =					0.02
												__a:						Tuple		    =					3
												__a:						List[Any]		    =					4
												__a:						Tuple		    =					None






							def 							__lowercase  (					self						:			int    ):






												"""simple docstring"""



												__a:						Dict		    =					ids_tensor([self.batch_size, self.seq_length]						, self.vocab_size    )

												__a:						List[Any]		    =					None
												if self.use_input_mask:
																	__a:						Tuple		    =					random_attention_mask([self.batch_size, self.seq_length]    )

												__a:						List[str]		    =					None
												if self.use_token_type_ids:
																	__a:						Tuple		    =					ids_tensor([self.batch_size, self.seq_length]						, self.type_vocab_size    )

												__a:						int		    =					None
												__a:						Tuple		    =					None
												__a:						Dict		    =					None
												if self.use_labels:
																	__a:						Dict		    =					ids_tensor([self.batch_size]						, self.type_sequence_label_size    )
																	__a:						List[Any]		    =					ids_tensor([self.batch_size, self.seq_length]						, self.num_labels    )
																	__a:						List[Any]		    =					ids_tensor([self.batch_size]						, self.num_choices    )

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






												"""simple docstring"""



												__a:						List[str]		    =					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)
												__a:						Optional[Any]		    =					{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
												__a:						Union[str, Any]		    =					model(snake_case__    )

												__a:						Dict		    =					[input_ids, input_mask]
												__a:						Any		    =					model(snake_case__    )

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






												"""simple docstring"""



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






												"""simple docstring"""



												__a:						Dict		    =					TFAlbertForMaskedLM(config=snake_case__    )
												__a:						int		    =					{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
												__a:						List[str]		    =					model(snake_case__    )
												self.parent.assertEqual(result.logits.shape						, (self.batch_size, self.seq_length, self.vocab_size)    )






							def 							__lowercase  (					self						:			Union[str, Any]						, snake_case__						:			Optional[Any]						, snake_case__						:			int						, snake_case__						:			List[Any]						, snake_case__						:			Tuple						, snake_case__						:			Any						, snake_case__						:			Tuple						, snake_case__						:			List[Any]    ):






												"""simple docstring"""



												__a:						List[Any]		    =					self.num_labels
												__a:						str		    =					TFAlbertForSequenceClassification(config=snake_case__    )
												__a:						List[str]		    =					{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
												__a:						Optional[Any]		    =					model(snake_case__    )
												self.parent.assertEqual(result.logits.shape						, (self.batch_size, self.num_labels)    )






							def 							__lowercase  (					self						:			Optional[int]						, snake_case__						:			int						, snake_case__						:			Optional[Any]						, snake_case__						:			List[Any]						, snake_case__						:			Tuple						, snake_case__						:			Optional[int]						, snake_case__						:			Tuple						, snake_case__						:			Any    ):






												"""simple docstring"""



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






												"""simple docstring"""



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






							def 							__lowercase  (					self						:			Any						, snake_case__						:			int						, snake_case__						:			Union[str, Any]						, snake_case__						:			Optional[Any]						, snake_case__						:			str						, snake_case__						:			List[Any]						, snake_case__						:			Tuple						, snake_case__						:			Union[str, Any]    ):






												"""simple docstring"""



												__a:						Any		    =					self.num_labels
												__a:						Union[str, Any]		    =					TFAlbertForTokenClassification(config=snake_case__    )
												__a:						Dict		    =					{
												    """input_ids""": input_ids,
												    """attention_mask""": input_mask,
												    """token_type_ids""": token_type_ids,
												}
												__a:						str		    =					model(snake_case__    )
												self.parent.assertListEqual(list(result["""logits"""].shape    )						, [self.batch_size, self.seq_length, self.num_labels]    )






							def 							__lowercase  (					self						:			Optional[Any]    ):






												"""simple docstring"""



												__a:						List[str]		    =					self.prepare_config_and_inputs()
												(
												    (
												    __a
												)    ,				(
												    __a
												)    ,				(
												    __a
												)    ,				(
												    __a
												)    ,				(
												    __a
												)    ,				(
												    __a
												)    ,				(
												    __a
												)    ,				
												):						Optional[Any]		    =					config_and_inputs
												__a:						Dict		    =					{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
												return config, inputs_dict






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






							def 							__lowercase  (					self						:			List[Any]						, snake_case__						:			Optional[Any]						, snake_case__						:			Union[str, Any]						, snake_case__						:			int=False    ):






												"""simple docstring"""



												__a:						int		    =					super()._prepare_for_class(snake_case__						, snake_case__						, return_labels=snake_case__    )

												if return_labels:
																	if model_class in get_values(snake_case__    ):
																						__a:						Optional[Any]		    =					tf.zeros(self.model_tester.batch_size						, dtype=tf.intaa    )

												return inputs_dict






							def 							__lowercase  (					self						:			Any    ):






												"""simple docstring"""



												__a:						Union[str, Any]		    =					TFAlbertModelTester(self    )
												__a:						Optional[Any]		    =					ConfigTester(self						, config_class=snake_case__						, hidden_size=3_7    )






							def 							__lowercase  (					self						:			Any    ):






												"""simple docstring"""



												self.config_tester.run_common_tests()






							def 							__lowercase  (					self						:			Optional[Any]    ):






												"""simple docstring"""



												__a:						Union[str, Any]		    =					self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_albert_model(*snake_case__    )






							def 							__lowercase  (					self						:			str    ):






												"""simple docstring"""



												__a:						List[str]		    =					self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_albert_for_pretraining(*snake_case__    )






							def 							__lowercase  (					self						:			Optional[Any]    ):






												"""simple docstring"""



												__a:						str		    =					self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_albert_for_masked_lm(*snake_case__    )






							def 							__lowercase  (					self						:			Optional[Any]    ):






												"""simple docstring"""



												__a:						Optional[Any]		    =					self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_albert_for_multiple_choice(*snake_case__    )






							def 							__lowercase  (					self						:			Dict    ):






												"""simple docstring"""



												__a:						Union[str, Any]		    =					self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_albert_for_sequence_classification(*snake_case__    )






							def 							__lowercase  (					self						:			Optional[Any]    ):






												"""simple docstring"""



												__a:						Dict		    =					self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_albert_for_question_answering(*snake_case__    )






							@slow
							def 							__lowercase  (					self						:			Union[str, Any]    ):






												"""simple docstring"""



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






@require_tf
class    _snake_case  (						unittest.TestCase       ):






							@slow
							def 							__lowercase  (					self						:			Union[str, Any]    ):






												"""simple docstring"""



												__a:						List[Any]		    =					TFAlbertForPreTraining.from_pretrained("""albert-base-v2"""    )
												__a:						str		    =					tf.constant([[0, 1, 2, 3, 4, 5]]    )
												__a:						List[Any]		    =					model(snake_case__    )[0]

												__a:						Optional[int]		    =					[1, 6, 3_0_0_0_0]
												self.assertEqual(output.shape						, snake_case__    )

												__a:						Any		    =					tf.constant(
												    [
												        [
												            [4.595_668, 0.74_462_754, -1.818_147],
												            [4.5_954_347, 0.7_454_184, -1.8_188_258],
												            [4.5_954_905, 0.7_448_235, -1.8_182_316],
												        ]
												    ]    )
												tf.debugging.assert_near(output[:, :3, :3]						, snake_case__						, atol=1e-4    )


"""simple docstring"""
lowercase		:						str =					{
    '0000': '0',
    '0001': '1',
    '0010': '2',
    '0011': '3',
    '0100': '4',
    '0101': '5',
    '0110': '6',
    '0111': '7',
    '1000': '8',
    '1001': '9',
    '1010': 'a',
    '1011': 'b',
    '1100': 'c',
    '1101': 'd',
    '1110': 'e',
    '1111': 'f',
}


def     lowerCamelCase_    (	lowerCamelCase_ )     ->			str:


					'''simple docstring'''
					__a:						Optional[int]		    =					str(lowerCamelCase_ ).strip()

					# Exceptions
					if not binary_str:
										raise ValueError("""Empty string was passed to the function""" )
					__a:						List[Any]		    =					binary_str[0] == """-"""
					__a:						List[str]		    =					binary_str[1:] if is_negative else binary_str
					if not all(char in """01""" for char in binary_str ):
										raise ValueError("""Non-binary value was passed to the function""" )

					__a:						Any		    =					(
					    """0""" * (4 * (divmod(len(lowerCamelCase_ )	,				4 )[0] + 1) - len(lowerCamelCase_ )) + binary_str
					)

					__a:						int		    =					[]
					for x in range(0	,				len(lowerCamelCase_ )	,				4 ):
										hexadecimal.append(BITS_TO_HEX[binary_str[x : x + 4]] )
					__a:						Tuple		    =					"""0x""" + """""".join(lowerCamelCase_ )

					return "-" + hexadecimal_str if is_negative else hexadecimal_str


if __name__ == "__main__":
			from doctest import testmod

			testmod()
