




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   :	List[str]   ,     __UpperCAmelCase   :	Dict   ,     __UpperCAmelCase   :	Optional[Any]=13   ,     __UpperCAmelCase   :	Dict=7   ,     __UpperCAmelCase   :	Dict=True   ,     __UpperCAmelCase   :	Any=True   ,     __UpperCAmelCase   :	Any=True   ,     __UpperCAmelCase   :	List[str]=True   ,     __UpperCAmelCase   :	Union[str, Any]=99   ,     __UpperCAmelCase   :	Optional[int]=16   ,     __UpperCAmelCase   :	Tuple=32   ,     __UpperCAmelCase   :	Optional[int]=2   ,     __UpperCAmelCase   :	Dict=4   ,     __UpperCAmelCase   :	Dict=37   ,     __UpperCAmelCase   :	Any="gelu"   ,     __UpperCAmelCase   :	Union[str, Any]=0.1   ,     __UpperCAmelCase   :	List[str]=0.1   ,     __UpperCAmelCase   :	Any=512   ,     __UpperCAmelCase   :	Optional[Any]=16   ,     __UpperCAmelCase   :	List[str]=2   ,     __UpperCAmelCase   :	List[str]=0.02   ,     __UpperCAmelCase   :	List[str]=3   ,     __UpperCAmelCase   :	Dict=4   ,     __UpperCAmelCase   :	List[str]=None   ,     )		->					int:

										"""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        lowercase__							(    self   :	Optional[int]				)		->					int:

										"""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        lowercase__							(    self   :	Optional[Any]   ,     __UpperCAmelCase   :	Optional[Any]   ,     __UpperCAmelCase   :	Tuple   ,     __UpperCAmelCase   :	List[Any]   ,     __UpperCAmelCase   :	Tuple   ,     __UpperCAmelCase   :	Dict   ,     __UpperCAmelCase   :	Optional[int]   ,     __UpperCAmelCase   :	List[Any]				)		->					Optional[int]:

										"""simple docstring"""



										UpperCamelCase_     				= TFAlbertModel(config=__A				)
										# 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(__A				)

										UpperCamelCase_     				= [input_ids, input_mask]
										UpperCamelCase_     				= model(__A				)

										UpperCamelCase_     				= model(__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   :	List[str]   ,     __UpperCAmelCase   :	Optional[int]   ,     __UpperCAmelCase   :	Any   ,     __UpperCAmelCase   :	List[str]   ,     __UpperCAmelCase   :	Optional[int]   ,     __UpperCAmelCase   :	List[Any]   ,     __UpperCAmelCase   :	Optional[int]   ,     __UpperCAmelCase   :	Union[str, Any]				)		->					Any:

										"""simple docstring"""



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

										"""simple docstring"""



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







							def        lowercase__							(    self   :	Dict   ,     __UpperCAmelCase   :	List[Any]   ,     __UpperCAmelCase   :	Union[str, Any]   ,     __UpperCAmelCase   :	Union[str, Any]   ,     __UpperCAmelCase   :	Optional[Any]   ,     __UpperCAmelCase   :	Optional[Any]   ,     __UpperCAmelCase   :	str   ,     __UpperCAmelCase   :	List[str]				)		->					List[Any]:

										"""simple docstring"""



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







							def        lowercase__							(    self   :	Dict   ,     __UpperCAmelCase   :	Any   ,     __UpperCAmelCase   :	Tuple   ,     __UpperCAmelCase   :	Union[str, Any]   ,     __UpperCAmelCase   :	List[Any]   ,     __UpperCAmelCase   :	List[Any]   ,     __UpperCAmelCase   :	Any   ,     __UpperCAmelCase   :	Any				)		->					Dict:

										"""simple docstring"""



										UpperCamelCase_     				= TFAlbertForQuestionAnswering(config=__A				)
										UpperCamelCase_     				= {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
										UpperCamelCase_     				= model(__A				)
										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   :	List[Any]   ,     __UpperCAmelCase   :	Union[str, Any]   ,     __UpperCAmelCase   :	List[Any]   ,     __UpperCAmelCase   :	Tuple   ,     __UpperCAmelCase   :	Dict   ,     __UpperCAmelCase   :	Tuple   ,     __UpperCAmelCase   :	List[str]   ,     __UpperCAmelCase   :	Dict				)		->					List[Any]:

										"""simple docstring"""



										UpperCamelCase_     				= self.num_choices
										UpperCamelCase_     				= TFAlbertForMultipleChoice(config=__A				)
										UpperCamelCase_     				= tf.tile(tf.expand_dims(__A   ,     1				)   ,     (1, self.num_choices, 1)				)
										UpperCamelCase_     				= tf.tile(tf.expand_dims(__A   ,     1				)   ,     (1, self.num_choices, 1)				)
										UpperCamelCase_     				= tf.tile(tf.expand_dims(__A   ,     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(__A				)
										self.parent.assertListEqual(list(result['logits'].shape				)   ,     [self.batch_size, self.num_choices]				)







							def        lowercase__							(    self   :	int   ,     __UpperCAmelCase   :	Tuple   ,     __UpperCAmelCase   :	Optional[Any]   ,     __UpperCAmelCase   :	Any   ,     __UpperCAmelCase   :	Union[str, Any]   ,     __UpperCAmelCase   :	Tuple   ,     __UpperCAmelCase   :	str   ,     __UpperCAmelCase   :	Optional[Any]				)		->					str:

										"""simple docstring"""



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







							def        lowercase__							(    self   :	List[Any]				)		->					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					(				_A  ,						_A  ,						unittest.TestCase       ):
							_SCREAMING_SNAKE_CASE  :		Dict			  =       (
							    (
							        TFAlbertModel,
							        TFAlbertForPreTraining,
							        TFAlbertForMaskedLM,
							        TFAlbertForSequenceClassification,
							        TFAlbertForQuestionAnswering,
							        TFAlbertForTokenClassification,
							        TFAlbertForMultipleChoice,
							    )
							    if is_tf_available()
							    else ()
							)
							_SCREAMING_SNAKE_CASE  :		Optional[Any]			  =       (
							    {
							        '''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  :		Union[str, Any]			  =       False
							_SCREAMING_SNAKE_CASE  :		Union[str, Any]			  =       False







							def        lowercase__							(    self   :	Any   ,     __UpperCAmelCase   :	List[str]   ,     __UpperCAmelCase   :	int   ,     __UpperCAmelCase   :	Union[str, Any]=False				)		->					Optional[int]:

										"""simple docstring"""



										UpperCamelCase_     				= super()._prepare_for_class(__A   ,     __A   ,     return_labels=__A				)

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

										return inputs_dict







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

										"""simple docstring"""



										UpperCamelCase_     				= TFAlbertModelTester(self				)
										UpperCamelCase_     				= ConfigTester(self   ,     config_class=__A   ,     hidden_size=37				)







							def        lowercase__							(    self   :	List[str]				)		->					str:

										"""simple docstring"""



										self.config_tester.run_common_tests()







							def        lowercase__							(    self   :	Any				)		->					List[str]:

										"""simple docstring"""



										UpperCamelCase_     				= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_albert_model(*__A				)







							def        lowercase__							(    self   :	Optional[int]				)		->					str:

										"""simple docstring"""



										UpperCamelCase_     				= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_albert_for_pretraining(*__A				)







							def        lowercase__							(    self   :	List[Any]				)		->					Dict:

										"""simple docstring"""



										UpperCamelCase_     				= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_albert_for_masked_lm(*__A				)







							def        lowercase__							(    self   :	Optional[int]				)		->					Any:

										"""simple docstring"""



										UpperCamelCase_     				= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_albert_for_multiple_choice(*__A				)







							def        lowercase__							(    self   :	str				)		->					List[Any]:

										"""simple docstring"""



										UpperCamelCase_     				= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_albert_for_sequence_classification(*__A				)







							def        lowercase__							(    self   :	Any				)		->					Any:

										"""simple docstring"""



										UpperCamelCase_     				= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_albert_for_question_answering(*__A				)







							@slow
							def        lowercase__							(    self   :	Tuple				)		->					Dict:

										"""simple docstring"""



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







@require_tf
class     A					(				unittest.TestCase       ):







							@slow
							def        lowercase__							(    self   :	Optional[int]				)		->					str:

										"""simple docstring"""



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

										UpperCamelCase_     				= [1, 6, 30000]
										self.assertEqual(output.shape   ,     __A				)

										UpperCamelCase_     				= 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]   ,     __A   ,     atol=1E-4				)





'''simple docstring'''







from ..utils import DummyObject, requires_backends

class      lowerCamelCase__     (     metaclass=_A				):






	'''simple docstring'''

	A__		=	['''torch''', '''librosa''']




	def __init__(  self		:  Optional[Any]   ,		*__A		:  Tuple   ,		**__A		:  Tuple					)     ->			Union[str, Any]:




								'''simple docstring'''





								requires_backends(self   ,		["""torch""", """librosa"""]					)




	@classmethod
	def      lowercase__							(  cls		:  Dict   ,		*__A		:  List[Any]   ,		**__A		:  List[str]					)     ->			Union[str, Any]:




								'''simple docstring'''





								requires_backends(cls   ,		["""torch""", """librosa"""]					)




	@classmethod
	def      lowercase__							(  cls		:  Optional[int]   ,		*__A		:  List[str]   ,		**__A		:  Tuple					)     ->			Any:




								'''simple docstring'''





								requires_backends(cls   ,		["""torch""", """librosa"""]					)





class      lowerCamelCase__     (     metaclass=_A				):






	'''simple docstring'''

	A__		=	['''torch''', '''librosa''']




	def __init__(  self		:  int   ,		*__A		:  Dict   ,		**__A		:  List[Any]					)     ->			List[Any]:




								'''simple docstring'''





								requires_backends(self   ,		["""torch""", """librosa"""]					)




	@classmethod
	def      lowercase__							(  cls		:  Optional[int]   ,		*__A		:  Optional[int]   ,		**__A		:  List[Any]					)     ->			Union[str, Any]:




								'''simple docstring'''





								requires_backends(cls   ,		["""torch""", """librosa"""]					)




	@classmethod
	def      lowercase__							(  cls		:  List[str]   ,		*__A		:  List[str]   ,		**__A		:  int					)     ->			List[str]:




								'''simple docstring'''





								requires_backends(cls   ,		["""torch""", """librosa"""]					)





