




import functools
import operator

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


a__		    =    logging.get_logger(__name__)

a__		    =    {
    """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       SCREAMING_SNAKE_CASE_							(					a__      ):



	"""simple docstring"""


	__magic_name__      :					List[str]			  =		'hubert'






	def __init__(				self		:	Any				,    lowerCAmelCase		:	Optional[int]=32				,    lowerCAmelCase		:	int=768				,    lowerCAmelCase		:	Union[str, Any]=12				,    lowerCAmelCase		:	Union[str, Any]=12				,    lowerCAmelCase		:	Union[str, Any]=3072				,    lowerCAmelCase		:	List[Any]="gelu"				,    lowerCAmelCase		:	Optional[Any]=0.1				,    lowerCAmelCase		:	Optional[int]=0.1				,    lowerCAmelCase		:	Tuple=0.1				,    lowerCAmelCase		:	List[str]=True				,    lowerCAmelCase		:	Tuple=0.0				,    lowerCAmelCase		:	Union[str, Any]=0.1				,    lowerCAmelCase		:	List[Any]=0.1				,    lowerCAmelCase		:	Optional[int]=0.02				,    lowerCAmelCase		:	List[str]=1E-5				,    lowerCAmelCase		:	Dict="group"				,    lowerCAmelCase		:	Optional[int]="gelu"				,    lowerCAmelCase		:	Tuple=(512, 512, 512, 512, 512, 512, 512)				,    lowerCAmelCase		:	Tuple=(5, 2, 2, 2, 2, 2, 2)				,    lowerCAmelCase		:	List[Any]=(10, 3, 3, 3, 3, 2, 2)				,    lowerCAmelCase		:	str=False				,    lowerCAmelCase		:	List[Any]=128				,    lowerCAmelCase		:	int=16				,    lowerCAmelCase		:	List[Any]=False				,    lowerCAmelCase		:	Dict=True				,    lowerCAmelCase		:	List[str]=0.05				,    lowerCAmelCase		:	List[Any]=10				,    lowerCAmelCase		:	Optional[int]=2				,    lowerCAmelCase		:	str=0.0				,    lowerCAmelCase		:	Union[str, Any]=10				,    lowerCAmelCase		:	Dict=0				,    lowerCAmelCase		:	Union[str, Any]="sum"				,    lowerCAmelCase		:	Any=False				,    lowerCAmelCase		:	Any=False				,    lowerCAmelCase		:	Optional[Any]=256				,    lowerCAmelCase		:	List[str]=0				,    lowerCAmelCase		:	Optional[int]=1				,    lowerCAmelCase		:	Optional[Any]=2				,    **lowerCAmelCase		:	Optional[Any]				,    )  ->					Union[str, Any]:







						"""simple docstring"""







						super().__init__(**__A				,    pad_token_id=__A				,    bos_token_id=__A				,    eos_token_id=__A  )
						__UpperCamelCase				:  Tuple								=			hidden_size
						__UpperCamelCase				:  Any								=			feat_extract_norm
						__UpperCamelCase				:  Optional[int]								=			feat_extract_activation
						__UpperCamelCase				:  Dict								=			list(__A  )
						__UpperCamelCase				:  Tuple								=			list(__A  )
						__UpperCamelCase				:  Any								=			list(__A  )
						__UpperCamelCase				:  List[str]								=			conv_bias
						__UpperCamelCase				:  Tuple								=			num_conv_pos_embeddings
						__UpperCamelCase				:  Tuple								=			num_conv_pos_embedding_groups
						__UpperCamelCase				:  Union[str, Any]								=			len(self.conv_dim  )
						__UpperCamelCase				:  str								=			num_hidden_layers
						__UpperCamelCase				:  Optional[int]								=			intermediate_size
						__UpperCamelCase				:  Any								=			hidden_act
						__UpperCamelCase				:  Optional[Any]								=			num_attention_heads
						__UpperCamelCase				:  List[Any]								=			hidden_dropout
						__UpperCamelCase				:  List[str]								=			attention_dropout
						__UpperCamelCase				:  Optional[Any]								=			activation_dropout
						__UpperCamelCase				:  str								=			feat_proj_layer_norm
						__UpperCamelCase				:  Dict								=			feat_proj_dropout
						__UpperCamelCase				:  str								=			final_dropout
						__UpperCamelCase				:  Any								=			layerdrop
						__UpperCamelCase				:  Any								=			layer_norm_eps
						__UpperCamelCase				:  Optional[int]								=			initializer_range
						__UpperCamelCase				:  Union[str, Any]								=			vocab_size
						__UpperCamelCase				:  int								=			do_stable_layer_norm
						__UpperCamelCase				:  str								=			use_weighted_layer_sum
						__UpperCamelCase				:  int								=			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
						__UpperCamelCase				:  Optional[Any]								=			apply_spec_augment
						__UpperCamelCase				:  Optional[int]								=			mask_time_prob
						__UpperCamelCase				:  Union[str, Any]								=			mask_time_length
						__UpperCamelCase				:  str								=			mask_time_min_masks
						__UpperCamelCase				:  Tuple								=			mask_feature_prob
						__UpperCamelCase				:  Dict								=			mask_feature_length
						__UpperCamelCase				:  Tuple								=			mask_feature_min_masks

						# ctc loss
						__UpperCamelCase				:  Dict								=			ctc_loss_reduction
						__UpperCamelCase				:  Tuple								=			ctc_zero_infinity






	@property
	def 				lowerCamelCase__    (				self		:	Union[str, Any]  )  ->					Optional[Any]:







						"""simple docstring"""







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












from __future__ import annotations

import unittest

from transformers import DebertaConfig, is_tf_available
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 (
	    TFDebertaForMaskedLM,
	    TFDebertaForQuestionAnswering,
	    TFDebertaForSequenceClassification,
	    TFDebertaForTokenClassification,
	    TFDebertaModel,
	)


class       SCREAMING_SNAKE_CASE_							:



	"""simple docstring"""


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







						"""simple docstring"""







						__UpperCamelCase				:  Union[str, Any]								=			parent
						__UpperCamelCase				:  Any								=			13
						__UpperCamelCase				:  Union[str, Any]								=			7
						__UpperCamelCase				:  List[str]								=			True
						__UpperCamelCase				:  List[Any]								=			True
						__UpperCamelCase				:  Union[str, Any]								=			True
						__UpperCamelCase				:  Any								=			True
						__UpperCamelCase				:  Optional[int]								=			99
						__UpperCamelCase				:  int								=			32
						__UpperCamelCase				:  List[str]								=			2
						__UpperCamelCase				:  List[Any]								=			4
						__UpperCamelCase				:  Any								=			37
						__UpperCamelCase				:  str								=			"""gelu"""
						__UpperCamelCase				:  Any								=			0.1
						__UpperCamelCase				:  List[str]								=			0.1
						__UpperCamelCase				:  Optional[Any]								=			512
						__UpperCamelCase				:  Dict								=			16
						__UpperCamelCase				:  Tuple								=			False
						__UpperCamelCase				:  Optional[Any]								=			-1
						__UpperCamelCase				:  Optional[int]								=			True
						__UpperCamelCase				:  Optional[Any]								=			2
						__UpperCamelCase				:  List[str]								=			0.02
						__UpperCamelCase				:  Union[str, Any]								=			3
						__UpperCamelCase				:  Optional[int]								=			4
						__UpperCamelCase				:  List[Any]								=			None






	def 				lowerCamelCase__    (				self		:	Optional[Any]  )  ->					Dict:







						"""simple docstring"""







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

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

						__UpperCamelCase				:  Optional[int]								=			None
						if self.use_token_type_ids:
											__UpperCamelCase				:  Optional[Any]								=			ids_tensor([self.batch_size, self.seq_length]				,    self.type_vocab_size  )

						__UpperCamelCase				:  Union[str, Any]								=			None
						__UpperCamelCase				:  List[Any]								=			None
						__UpperCamelCase				:  Tuple								=			None
						if self.use_labels:
											__UpperCamelCase				:  str								=			ids_tensor([self.batch_size]				,    self.type_sequence_label_size  )
											__UpperCamelCase				:  Dict								=			ids_tensor([self.batch_size, self.seq_length]				,    self.num_labels  )

						__UpperCamelCase				:  Optional[Any]								=			DebertaConfig(
						    vocab_size=self.vocab_size				,    hidden_size=self.hidden_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				,    relative_attention=self.relative_attention				,    max_relative_positions=self.max_relative_positions				,    position_biased_input=self.position_biased_input				,    initializer_range=self.initializer_range				,    return_dict=lowerCAmelCase				,    )

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






	def 				lowerCamelCase__    (				self		:	str				,    lowerCAmelCase		:	Any				,    lowerCAmelCase		:	Optional[int]				,    lowerCAmelCase		:	Optional[Any]				,    lowerCAmelCase		:	Dict				,    lowerCAmelCase		:	Optional[Any]				,    lowerCAmelCase		:	Dict				,    lowerCAmelCase		:	List[Any]  )  ->					Any:







						"""simple docstring"""







						__UpperCamelCase				:  str								=			TFDebertaModel(config=lowerCAmelCase  )
						__UpperCamelCase				:  Optional[Any]								=			{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

						__UpperCamelCase				:  Optional[int]								=			[input_ids, input_mask]
						__UpperCamelCase				:  Any								=			model(lowerCAmelCase  )

						__UpperCamelCase				:  int								=			model(lowerCAmelCase  )

						self.parent.assertEqual(result.last_hidden_state.shape				,    (self.batch_size, self.seq_length, self.hidden_size)  )






	def 				lowerCamelCase__    (				self		:	Dict				,    lowerCAmelCase		:	Optional[int]				,    lowerCAmelCase		:	Any				,    lowerCAmelCase		:	Union[str, Any]				,    lowerCAmelCase		:	Optional[Any]				,    lowerCAmelCase		:	Optional[int]				,    lowerCAmelCase		:	List[str]				,    lowerCAmelCase		:	int  )  ->					List[Any]:







						"""simple docstring"""







						__UpperCamelCase				:  Tuple								=			TFDebertaForMaskedLM(config=lowerCAmelCase  )
						__UpperCamelCase				:  Dict								=			{
						    """input_ids""": input_ids,
						    """attention_mask""": input_mask,
						    """token_type_ids""": token_type_ids,
						}
						__UpperCamelCase				:  Union[str, Any]								=			model(lowerCAmelCase  )
						self.parent.assertEqual(result.logits.shape				,    (self.batch_size, self.seq_length, self.vocab_size)  )






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







						"""simple docstring"""







						__UpperCamelCase				:  List[Any]								=			self.num_labels
						__UpperCamelCase				:  Optional[Any]								=			TFDebertaForSequenceClassification(config=lowerCAmelCase  )
						__UpperCamelCase				:  Any								=			{
						    """input_ids""": input_ids,
						    """attention_mask""": input_mask,
						    """token_type_ids""": token_type_ids,
						}

						__UpperCamelCase				:  Any								=			model(lowerCAmelCase  )
						self.parent.assertEqual(result.logits.shape				,    (self.batch_size, self.num_labels)  )






	def 				lowerCamelCase__    (				self		:	List[str]				,    lowerCAmelCase		:	str				,    lowerCAmelCase		:	Dict				,    lowerCAmelCase		:	List[str]				,    lowerCAmelCase		:	List[str]				,    lowerCAmelCase		:	List[Any]				,    lowerCAmelCase		:	Optional[int]				,    lowerCAmelCase		:	Dict  )  ->					List[Any]:







						"""simple docstring"""







						__UpperCamelCase				:  List[Any]								=			self.num_labels
						__UpperCamelCase				:  Optional[Any]								=			TFDebertaForTokenClassification(config=lowerCAmelCase  )
						__UpperCamelCase				:  List[Any]								=			{
						    """input_ids""": input_ids,
						    """attention_mask""": input_mask,
						    """token_type_ids""": token_type_ids,
						}
						__UpperCamelCase				:  int								=			model(lowerCAmelCase  )
						self.parent.assertEqual(result.logits.shape				,    (self.batch_size, self.seq_length, self.num_labels)  )






	def 				lowerCamelCase__    (				self		:	int				,    lowerCAmelCase		:	Optional[int]				,    lowerCAmelCase		:	int				,    lowerCAmelCase		:	Any				,    lowerCAmelCase		:	Dict				,    lowerCAmelCase		:	Dict				,    lowerCAmelCase		:	int				,    lowerCAmelCase		:	List[str]  )  ->					Optional[int]:







						"""simple docstring"""







						__UpperCamelCase				:  Optional[Any]								=			TFDebertaForQuestionAnswering(config=lowerCAmelCase  )
						__UpperCamelCase				:  int								=			{
						    """input_ids""": input_ids,
						    """attention_mask""": input_mask,
						    """token_type_ids""": token_type_ids,
						}

						__UpperCamelCase				:  Tuple								=			model(lowerCAmelCase  )
						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 				lowerCamelCase__    (				self		:	Optional[Any]  )  ->					Optional[int]:







						"""simple docstring"""







						__UpperCamelCase				:  Tuple								=			self.prepare_config_and_inputs()
						(
						    (
						    __UpperCamelCase
						)			, (
						    __UpperCamelCase
						)			, (
						    __UpperCamelCase
						)			, (
						    __UpperCamelCase
						)			, (
						    __UpperCamelCase
						)			, (
						    __UpperCamelCase
						)			, (
						    __UpperCamelCase
						)			, 
						)				:  int								=			config_and_inputs
						__UpperCamelCase				:  str								=			{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
						return config, inputs_dict






@require_tf
class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase  ,     _UpperCamelCase  ,     unittest.TestCase      ):



	"""simple docstring"""


	__magic_name__      :					str			  =		(
	    (
	        TFDebertaModel,
	        TFDebertaForMaskedLM,
	        TFDebertaForQuestionAnswering,
	        TFDebertaForSequenceClassification,
	        TFDebertaForTokenClassification,
	    )
	    if is_tf_available()
	    else ()
	)
	__magic_name__      :					Optional[Any]			  =		(
	    {
	        'feature-extraction': TFDebertaModel,
	        'fill-mask': TFDebertaForMaskedLM,
	        'question-answering': TFDebertaForQuestionAnswering,
	        'text-classification': TFDebertaForSequenceClassification,
	        'token-classification': TFDebertaForTokenClassification,
	        'zero-shot': TFDebertaForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)

	__magic_name__      :					int			  =		False
	__magic_name__      :					List[str]			  =		False






	def 				lowerCamelCase__    (				self		:	Tuple  )  ->					int:







						"""simple docstring"""







						__UpperCamelCase				:  str								=			TFDebertaModelTester(self  )
						__UpperCamelCase				:  Union[str, Any]								=			ConfigTester(self				,    config_class=lowerCAmelCase				,    hidden_size=37  )






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







						"""simple docstring"""







						self.config_tester.run_common_tests()






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







						"""simple docstring"""







						__UpperCamelCase				:  List[Any]								=			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*lowerCAmelCase  )






	def 				lowerCamelCase__    (				self		:	List[Any]  )  ->					Optional[Any]:







						"""simple docstring"""







						__UpperCamelCase				:  Dict								=			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase  )






	def 				lowerCamelCase__    (				self		:	Dict  )  ->					int:







						"""simple docstring"""







						__UpperCamelCase				:  Any								=			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase  )






	def 				lowerCamelCase__    (				self		:	Tuple  )  ->					Any:







						"""simple docstring"""







						__UpperCamelCase				:  Dict								=			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase  )






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







						"""simple docstring"""







						__UpperCamelCase				:  str								=			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase  )






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







						"""simple docstring"""







						__UpperCamelCase				:  List[str]								=			TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""  )
						self.assertIsNotNone(lowerCAmelCase  )






@require_tf
class       SCREAMING_SNAKE_CASE_							(					unittest.TestCase      ):



	"""simple docstring"""


	@unittest.skip(reason="""Model not available yet"""  )
	def 				lowerCamelCase__    (				self		:	Optional[int]  )  ->					Tuple:







						"""simple docstring"""







						pass






	@slow
	def 				lowerCamelCase__    (				self		:	Tuple  )  ->					List[Any]:







						"""simple docstring"""







						__UpperCamelCase				:  str								=			TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""  )
						__UpperCamelCase				:  Optional[int]								=			tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]  )
						__UpperCamelCase				:  int								=			tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
						__UpperCamelCase				:  Tuple								=			model(lowerCAmelCase				,    attention_mask=lowerCAmelCase  )[0]

						__UpperCamelCase				:  Any								=			tf.constant(
						    [
						        [
						            [-0.59_85_58_96, -0.80_55_25_66, -0.8_46_21_35],
						            [1.4_48_40_25, -0.93_48_37_94, -0.80_59_30_85],
						            [0.3_12_27_41, 0.00_31_60_59, -1.4_13_13_77],
						        ]
						    ]  )
						tf.debugging.assert_near(output[:, 1:4, 1:4]				,    lowerCAmelCase				,    atol=1E-4  )






