




import functools
import operator

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


A   =       logging.get_logger(__name__)

A   =       {
    """facebook/wav2vec2-base-960h""": """https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json""",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}



class      a__				(	__magic_name__   ):
			lowercase_    =	"wav2vec2"


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


						"""simple docstring"""




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

						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	: Union[str, Any]		=					apply_spec_augment
						__UpperCAmelCase	: Optional[Any]		=					mask_time_prob
						__UpperCAmelCase	: List[str]		=					mask_time_length
						__UpperCAmelCase	: str		=					mask_time_min_masks
						__UpperCAmelCase	: Optional[int]		=					mask_feature_prob
						__UpperCAmelCase	: Union[str, Any]		=					mask_feature_length
						__UpperCAmelCase	: str		=					mask_feature_min_masks

						# parameters for pretraining with codevector quantized representations
						__UpperCAmelCase	: int		=					num_codevectors_per_group
						__UpperCAmelCase	: Dict		=					num_codevector_groups
						__UpperCAmelCase	: List[str]		=					contrastive_logits_temperature
						__UpperCAmelCase	: int		=					feat_quantizer_dropout
						__UpperCAmelCase	: Optional[Any]		=					num_negatives
						__UpperCAmelCase	: str		=					codevector_dim
						__UpperCAmelCase	: Dict		=					proj_codevector_dim
						__UpperCAmelCase	: Union[str, Any]		=					diversity_loss_weight

						# ctc loss
						__UpperCAmelCase	: Optional[int]		=					ctc_loss_reduction
						__UpperCAmelCase	: Optional[int]		=					ctc_zero_infinity

						# adapter
						__UpperCAmelCase	: Tuple		=					add_adapter
						__UpperCAmelCase	: Any		=					adapter_kernel_size
						__UpperCAmelCase	: Union[str, Any]		=					adapter_stride
						__UpperCAmelCase	: Union[str, Any]		=					num_adapter_layers
						__UpperCAmelCase	: Dict		=					output_hidden_size or hidden_size
						__UpperCAmelCase	: str		=					adapter_attn_dim

						# SequenceClassification-specific parameter. Feel free to ignore for other classes.
						__UpperCAmelCase	: List[str]		=					classifier_proj_size

						# XVector-specific parameters. Feel free to ignore for other classes.
						__UpperCAmelCase	: List[str]		=					list(UpperCamelCase_)
						__UpperCAmelCase	: Optional[int]		=					list(UpperCamelCase_)
						__UpperCAmelCase	: Tuple		=					list(UpperCamelCase_)
						__UpperCAmelCase	: Dict		=					xvector_output_dim


			@property
			def       a_     (      self      :    List[str]):


						"""simple docstring"""




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








"""simple docstring"""





import json
import os
import tempfile

from transformers.testing_utils import check_json_file_has_correct_format



class      a__				:
			lowercase_    =	None


			def       a_     (      self      :    List[Any]):


						"""simple docstring"""




						__UpperCAmelCase	: Optional[Any]		=					self.feature_extraction_class(**self.feat_extract_dict)
						__UpperCAmelCase	: Any		=					json.loads(feat_extract.to_json_string())
						for key, value in self.feat_extract_dict.items():
									self.assertEqual(obj[key]      ,  UpperCamelCase_)


			def       a_     (      self      :    Tuple):


						"""simple docstring"""




						__UpperCAmelCase	: Optional[Any]		=					self.feature_extraction_class(**self.feat_extract_dict)

						with tempfile.TemporaryDirectory() as tmpdirname:
									__UpperCAmelCase	: Dict		=					os.path.join(UpperCamelCase_      ,  "feat_extract.json")
									feat_extract_first.to_json_file(UpperCamelCase_)
									__UpperCAmelCase	: Optional[Any]		=					self.feature_extraction_class.from_json_file(UpperCamelCase_)

						self.assertEqual(feat_extract_second.to_dict()      ,  feat_extract_first.to_dict())


			def       a_     (      self      :    List[str]):


						"""simple docstring"""




						__UpperCAmelCase	: Optional[Any]		=					self.feature_extraction_class(**self.feat_extract_dict)

						with tempfile.TemporaryDirectory() as tmpdirname:
									__UpperCAmelCase	: Tuple		=					feat_extract_first.save_pretrained(UpperCamelCase_)[0]
									check_json_file_has_correct_format(UpperCamelCase_)
									__UpperCAmelCase	: List[Any]		=					self.feature_extraction_class.from_pretrained(UpperCamelCase_)

						self.assertEqual(feat_extract_second.to_dict()      ,  feat_extract_first.to_dict())


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


						"""simple docstring"""




						__UpperCAmelCase	: Union[str, Any]		=					self.feature_extraction_class()
						self.assertIsNotNone(UpperCamelCase_)


