"""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      UpperCamelCase__:





						def __init__(							self		,__UpperCAmelCase		,__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=5_12		,__UpperCAmelCase=16		,__UpperCAmelCase=2		,__UpperCAmelCase=0.0_2		,__UpperCAmelCase=3		,__UpperCAmelCase=4		,__UpperCAmelCase=None		,)       ->					int:
													A__						  =				parent
													A__						  =				13
													A__						  =				7
													A__						  =				True
													A__						  =				True
													A__						  =				True
													A__						  =				True
													A__						  =				99
													A__						  =				16
													A__						  =				32
													A__						  =				2
													A__						  =				4
													A__						  =				37
													A__						  =				'''gelu'''
													A__						  =				0.1
													A__						  =				0.1
													A__						  =				5_12
													A__						  =				16
													A__						  =				2
													A__						  =				0.0_2
													A__						  =				3
													A__						  =				4
													A__						  =				None





						def 					snake_case__						(							self  )       ->					Tuple:
													A__						  =				ids_tensor([self.batch_size, self.seq_length]		,self.vocab_size  )

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

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

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

													A__						  =				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 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase  )       ->					Tuple:
													A__						  =				TFAlbertModel(config=a__  )
													# inputs = {'input_ids': input_ids,
													#           'attention_mask': input_mask,
													#           'token_type_ids': token_type_ids}
													# sequence_output, pooled_output = model(**inputs)
													A__						  =				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													A__						  =				model(a__  )

													A__						  =				[input_ids, input_mask]
													A__						  =				model(a__  )

													A__						  =				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 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase  )       ->					Optional[Any]:
													A__						  =				self.num_labels
													A__						  =				TFAlbertForPreTraining(config=a__  )
													A__						  =				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													A__						  =				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 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase  )       ->					List[Any]:
													A__						  =				TFAlbertForMaskedLM(config=a__  )
													A__						  =				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													A__						  =				model(a__  )
													self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.seq_length, self.vocab_size)  )





						def 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase  )       ->					Union[str, Any]:
													A__						  =				self.num_labels
													A__						  =				TFAlbertForSequenceClassification(config=a__  )
													A__						  =				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													A__						  =				model(a__  )
													self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.num_labels)  )





						def 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase  )       ->					Any:
													A__						  =				TFAlbertForQuestionAnswering(config=a__  )
													A__						  =				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													A__						  =				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 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase  )       ->					List[Any]:
													A__						  =				self.num_choices
													A__						  =				TFAlbertForMultipleChoice(config=a__  )
													A__						  =				tf.tile(tf.expand_dims(a__		,1  )		,(1, self.num_choices, 1)  )
													A__						  =				tf.tile(tf.expand_dims(a__		,1  )		,(1, self.num_choices, 1)  )
													A__						  =				tf.tile(tf.expand_dims(a__		,1  )		,(1, self.num_choices, 1)  )
													A__						  =				{
													    '''input_ids''': multiple_choice_inputs_ids,
													    '''attention_mask''': multiple_choice_input_mask,
													    '''token_type_ids''': multiple_choice_token_type_ids,
													}
													A__						  =				model(a__  )
													self.parent.assertListEqual(list(result['logits'].shape  )		,[self.batch_size, self.num_choices]  )





						def 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase  )       ->					Any:
													A__						  =				self.num_labels
													A__						  =				TFAlbertForTokenClassification(config=a__  )
													A__						  =				{
													    '''input_ids''': input_ids,
													    '''attention_mask''': input_mask,
													    '''token_type_ids''': token_type_ids,
													}
													A__						  =				model(a__  )
													self.parent.assertListEqual(list(result['logits'].shape  )		,[self.batch_size, self.seq_length, self.num_labels]  )





						def 					snake_case__						(							self  )       ->					List[str]:
													A__						  =				self.prepare_config_and_inputs()
													(
													    A__       
													)						  =				config_and_inputs
													A__						  =				{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
													return config, inputs_dict






@require_tf
class      UpperCamelCase__(      __A		,    __A		,    unittest.TestCase			):
						lowerCAmelCase__	:    int    				=		(
						    (
						        TFAlbertModel,
						        TFAlbertForPreTraining,
						        TFAlbertForMaskedLM,
						        TFAlbertForSequenceClassification,
						        TFAlbertForQuestionAnswering,
						        TFAlbertForTokenClassification,
						        TFAlbertForMultipleChoice,
						    )
						    if is_tf_available()
						    else ()
						)
						lowerCAmelCase__	:    Optional[int]    				=		(
						    {
						        'feature-extraction': TFAlbertModel,
						        'fill-mask': TFAlbertForMaskedLM,
						        'question-answering': TFAlbertForQuestionAnswering,
						        'text-classification': TFAlbertForSequenceClassification,
						        'token-classification': TFAlbertForTokenClassification,
						        'zero-shot': TFAlbertForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						lowerCAmelCase__	:    List[str]    				=		False
						lowerCAmelCase__	:    Dict    				=		False





						def 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase=False  )       ->					List[str]:
													A__						  =				super()._prepare_for_class(a__		,a__		,return_labels=a__  )

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

													return inputs_dict





						def 					snake_case__						(							self  )       ->					List[Any]:
													A__						  =				TFAlbertModelTester(self  )
													A__						  =				ConfigTester(self		,config_class=a__		,hidden_size=37  )





						def 					snake_case__						(							self  )       ->					str:
													self.config_tester.run_common_tests()





						def 					snake_case__						(							self  )       ->					Tuple:
													A__						  =				self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_model(*a__  )





						def 					snake_case__						(							self  )       ->					Any:
													A__						  =				self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_for_pretraining(*a__  )





						def 					snake_case__						(							self  )       ->					Optional[int]:
													A__						  =				self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_for_masked_lm(*a__  )





						def 					snake_case__						(							self  )       ->					List[Any]:
													A__						  =				self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_for_multiple_choice(*a__  )





						def 					snake_case__						(							self  )       ->					Dict:
													A__						  =				self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_for_sequence_classification(*a__  )





						def 					snake_case__						(							self  )       ->					Any:
													A__						  =				self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_albert_for_question_answering(*a__  )





						@slow
						def 					snake_case__						(							self  )       ->					Union[str, Any]:






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






@require_tf
class      UpperCamelCase__(      unittest.TestCase			):





						@slow
						def 					snake_case__						(							self  )       ->					List[Any]:
													A__						  =				TFAlbertForPreTraining.from_pretrained('albert-base-v2'  )
													A__						  =				tf.constant([[0, 1, 2, 3, 4, 5]]  )
													A__						  =				model(a__  )[0]

													A__						  =				[1, 6, 3_00_00]
													self.assertEqual(output.shape		,a__  )

													A__						  =				tf.constant(
													    [
													        [
													            [4.5_9_5_6_6_8, 0.7_4_4_6_2_7_5_4, -1.8_1_8_1_4_7],
													            [4.5_9_5_4_3_4_7, 0.7_4_5_4_1_8_4, -1.8_1_8_8_2_5_8],
													            [4.5_9_5_4_9_0_5, 0.7_4_4_8_2_3_5, -1.8_1_8_2_3_1_6],
													        ]
													    ]  )
													tf.debugging.assert_near(output[:, :3, :3]		,a__		,atol=1e-4  )









import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


a					:				Dict       =      logging.get_logger(__name__)

a					:				str       =      {
    'facebook/hubert-base-ls960': 'https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json',
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}

class   lowerCamelCase						(	SCREAMING_SNAKE_CASE  ):
       _UpperCamelCase     		=   """hubert"""

       def __init__(      self						,    a__=32						,    a__=7_68						,    a__=12						,    a__=12						,    a__=30_72						,    a__="gelu"						,    a__=0.1						,    a__=0.1						,    a__=0.1						,    a__=True						,    a__=0.0						,    a__=0.1						,    a__=0.1						,    a__=0.02						,    a__=1e-5						,    a__="group"						,    a__="gelu"						,    a__=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)						,    a__=(5, 2, 2, 2, 2, 2, 2)						,    a__=(10, 3, 3, 3, 3, 2, 2)						,    a__=False						,    a__=1_28						,    a__=16						,    a__=False						,    a__=True						,    a__=0.05						,    a__=10						,    a__=2						,    a__=0.0						,    a__=10						,    a__=0						,    a__="sum"						,    a__=False						,    a__=False						,    a__=2_56						,    a__=0						,    a__=1						,    a__=2						,    **a__						,    ):






        '''simple docstring'''






        super().__init__(**a__						,    pad_token_id=a__						,    bos_token_id=a__						,    eos_token_id=a__       )
        snake_case :			List[str]							=   hidden_size
        snake_case :			List[str]							=   feat_extract_norm
        snake_case :			List[str]							=   feat_extract_activation
        snake_case :			Dict							=   list(a__       )
        snake_case :			Tuple							=   list(a__       )
        snake_case :			Dict							=   list(a__       )
        snake_case :			str							=   conv_bias
        snake_case :			Dict							=   num_conv_pos_embeddings
        snake_case :			Union[str, Any]							=   num_conv_pos_embedding_groups
        snake_case :			Optional[int]							=   len(self.conv_dim       )
        snake_case :			Tuple							=   num_hidden_layers
        snake_case :			Any							=   intermediate_size
        snake_case :			Optional[Any]							=   hidden_act
        snake_case :			str							=   num_attention_heads
        snake_case :			List[Any]							=   hidden_dropout
        snake_case :			Union[str, Any]							=   attention_dropout
        snake_case :			Dict							=   activation_dropout
        snake_case :			List[str]							=   feat_proj_layer_norm
        snake_case :			List[str]							=   feat_proj_dropout
        snake_case :			Union[str, Any]							=   final_dropout
        snake_case :			List[str]							=   layerdrop
        snake_case :			str							=   layer_norm_eps
        snake_case :			Tuple							=   initializer_range
        snake_case :			str							=   vocab_size
        snake_case :			Tuple							=   do_stable_layer_norm
        snake_case :			Dict							=   use_weighted_layer_sum
        snake_case :			Optional[Any]							=   classifier_proj_size

        if (
            (len(self.conv_stride       ) != self.num_feat_extract_layers)
            or (len(self.conv_kernel       ) != self.num_feat_extract_layers)
            or (len(self.conv_dim       ) != self.num_feat_extract_layers)
        ):
         raise ValueError(
             '''Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='''
             ''' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='''
             f''' {len(self.conv_dim       )}`, `len(config.conv_stride) = {len(self.conv_stride       )}`,'''
             f''' `len(config.conv_kernel) = {len(self.conv_kernel       )}`.'''       )

        # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
        snake_case :			Optional[int]							=   apply_spec_augment
        snake_case :			int							=   mask_time_prob
        snake_case :			Dict							=   mask_time_length
        snake_case :			Any							=   mask_time_min_masks
        snake_case :			Any							=   mask_feature_prob
        snake_case :			Union[str, Any]							=   mask_feature_length
        snake_case :			List[Any]							=   mask_feature_min_masks

        # ctc loss
        snake_case :			List[str]							=   ctc_loss_reduction
        snake_case :			Dict							=   ctc_zero_infinity



       @property
       def 					UpperCAmelCase					(      self       ):






        '''simple docstring'''






        return functools.reduce(operator.mul						,    self.conv_stride						,    1       )






