






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							(  __A						):





		'''simple docstring'''



		UpperCAmelCase__      :				Tuple				    =						"""wav2vec2"""


		def __init__(						self ,    UpperCamelCase__=32 ,    UpperCamelCase__=768 ,    UpperCamelCase__=12 ,    UpperCamelCase__=12 ,    UpperCamelCase__=3072 ,    UpperCamelCase__="gelu" ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=0.0 ,    UpperCamelCase__=0.0 ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=0.02 ,    UpperCamelCase__=1E-5 ,    UpperCamelCase__="group" ,    UpperCamelCase__="gelu" ,    UpperCamelCase__=(512, 512, 512, 512, 512, 512, 512) ,    UpperCamelCase__=(5, 2, 2, 2, 2, 2, 2) ,    UpperCamelCase__=(10, 3, 3, 3, 3, 2, 2) ,    UpperCamelCase__=False ,    UpperCamelCase__=128 ,    UpperCamelCase__=16 ,    UpperCamelCase__=False ,    UpperCamelCase__=True ,    UpperCamelCase__=0.05 ,    UpperCamelCase__=10 ,    UpperCamelCase__=2 ,    UpperCamelCase__=0.0 ,    UpperCamelCase__=10 ,    UpperCamelCase__=0 ,    UpperCamelCase__=320 ,    UpperCamelCase__=2 ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=100 ,    UpperCamelCase__=256 ,    UpperCamelCase__=256 ,    UpperCamelCase__=0.1 ,    UpperCamelCase__="sum" ,    UpperCamelCase__=False ,    UpperCamelCase__=False ,    UpperCamelCase__=256 ,    UpperCamelCase__=(512, 512, 512, 512, 1500) ,    UpperCamelCase__=(5, 3, 3, 1, 1) ,    UpperCamelCase__=(1, 2, 3, 1, 1) ,    UpperCamelCase__=512 ,    UpperCamelCase__=0 ,    UpperCamelCase__=1 ,    UpperCamelCase__=2 ,    UpperCamelCase__=False ,    UpperCamelCase__=3 ,    UpperCamelCase__=2 ,    UpperCamelCase__=3 ,    UpperCamelCase__=None ,    UpperCamelCase__=None ,    **UpperCamelCase__ ,    ):
						super().__init__(**UpperCamelCase__ ,    pad_token_id=UpperCamelCase__ ,    bos_token_id=UpperCamelCase__ ,    eos_token_id=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   hidden_size
						SCREAMING_SNAKE_CASE_   :	Dict													=   feat_extract_norm
						SCREAMING_SNAKE_CASE_   :	Any													=   feat_extract_activation
						SCREAMING_SNAKE_CASE_   :	List[str]													=   list(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	List[str]													=   list(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   list(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	List[str]													=   conv_bias
						SCREAMING_SNAKE_CASE_   :	int													=   num_conv_pos_embeddings
						SCREAMING_SNAKE_CASE_   :	str													=   num_conv_pos_embedding_groups
						SCREAMING_SNAKE_CASE_   :	List[str]													=   len(self.conv_dim       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   num_hidden_layers
						SCREAMING_SNAKE_CASE_   :	Tuple													=   intermediate_size
						SCREAMING_SNAKE_CASE_   :	int													=   hidden_act
						SCREAMING_SNAKE_CASE_   :	Dict													=   num_attention_heads
						SCREAMING_SNAKE_CASE_   :	List[str]													=   hidden_dropout
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   attention_dropout
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   activation_dropout
						SCREAMING_SNAKE_CASE_   :	Dict													=   feat_proj_dropout
						SCREAMING_SNAKE_CASE_   :	List[str]													=   final_dropout
						SCREAMING_SNAKE_CASE_   :	Tuple													=   layerdrop
						SCREAMING_SNAKE_CASE_   :	str													=   layer_norm_eps
						SCREAMING_SNAKE_CASE_   :	List[str]													=   initializer_range
						SCREAMING_SNAKE_CASE_   :	List[str]													=   vocab_size
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   do_stable_layer_norm
						SCREAMING_SNAKE_CASE_   :	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
						SCREAMING_SNAKE_CASE_   :	int													=   apply_spec_augment
						SCREAMING_SNAKE_CASE_   :	int													=   mask_time_prob
						SCREAMING_SNAKE_CASE_   :	Dict													=   mask_time_length
						SCREAMING_SNAKE_CASE_   :	Any													=   mask_time_min_masks
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   mask_feature_prob
						SCREAMING_SNAKE_CASE_   :	int													=   mask_feature_length
						SCREAMING_SNAKE_CASE_   :	int													=   mask_feature_min_masks

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

						# ctc loss
						SCREAMING_SNAKE_CASE_   :	Dict													=   ctc_loss_reduction
						SCREAMING_SNAKE_CASE_   :	Dict													=   ctc_zero_infinity

						# adapter
						SCREAMING_SNAKE_CASE_   :	int													=   add_adapter
						SCREAMING_SNAKE_CASE_   :	Tuple													=   adapter_kernel_size
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   adapter_stride
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   num_adapter_layers
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   output_hidden_size or hidden_size
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   adapter_attn_dim

						# SequenceClassification-specific parameter. Feel free to ignore for other classes.
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   classifier_proj_size

						# XVector-specific parameters. Feel free to ignore for other classes.
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   list(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Tuple													=   list(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	str													=   list(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	List[str]													=   xvector_output_dim






		@property
		def   __snake_case			(						self       ):
						return functools.reduce(operator.mul ,    self.conv_stride ,    1       )







from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch


@require_torch
@require_tf
class 							__a							(  __A						):





		'''simple docstring'''



		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Any													=   SMALL_MODEL_IDENTIFIER
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   'pt'
						SCREAMING_SNAKE_CASE_   :	Tuple													=   'tf'


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   AutoModel.from_pretrained(self.test_model       )
						model_pt.save_pretrained(UpperCamelCase__       )


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	int													=   TFAutoModel.from_pretrained(self.test_model ,    from_pt=UpperCamelCase__       )
						model_tf.save_pretrained(UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   'mock_framework'

						# Framework provided - return whatever the user provides
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   FeaturesManager.determine_framework(self.test_model ,    UpperCamelCase__       )
						self.assertEqual(UpperCamelCase__ ,    UpperCamelCase__       )

						# Local checkpoint and framework provided - return provided framework
						# PyTorch checkpoint
						with TemporaryDirectory() as local_pt_ckpt:
										self._setup_pt_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Dict													=   FeaturesManager.determine_framework(UpperCamelCase__ ,    UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    UpperCamelCase__       )

						# TensorFlow checkpoint
						with TemporaryDirectory() as local_tf_ckpt:
										self._setup_tf_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	List[str]													=   FeaturesManager.determine_framework(UpperCamelCase__ ,    UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    UpperCamelCase__       )


		def   __snake_case			(						self       ):
						# PyTorch checkpoint
						with TemporaryDirectory() as local_pt_ckpt:
										self._setup_pt_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   FeaturesManager.determine_framework(UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_pt       )

						# TensorFlow checkpoint
						with TemporaryDirectory() as local_tf_ckpt:
										self._setup_tf_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   FeaturesManager.determine_framework(UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_tf       )

						# Invalid local checkpoint
						with TemporaryDirectory() as local_invalid_ckpt:
										with self.assertRaises(UpperCamelCase__       ):
														SCREAMING_SNAKE_CASE_   :	Any													=   FeaturesManager.determine_framework(UpperCamelCase__       )






		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_tf_available' ,    UpperCamelCase__       ):
										SCREAMING_SNAKE_CASE_   :	str													=   FeaturesManager.determine_framework(self.test_model       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_pt       )

						# PyTorch not in environment -> use TensorFlow
						SCREAMING_SNAKE_CASE_   :	List[str]													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_torch_available' ,    UpperCamelCase__       ):
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   FeaturesManager.determine_framework(self.test_model       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_tf       )

						# Both in environment -> use PyTorch
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   MagicMock(return_value=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Tuple													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_tf_available' ,    UpperCamelCase__       ), patch(
						    'transformers.onnx.features.is_torch_available' ,    UpperCamelCase__       ):
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   FeaturesManager.determine_framework(self.test_model       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_pt       )

						# Both not in environment -> raise error
						SCREAMING_SNAKE_CASE_   :	Tuple													=   MagicMock(return_value=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Any													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_tf_available' ,    UpperCamelCase__       ), patch(
						    'transformers.onnx.features.is_torch_available' ,    UpperCamelCase__       ):
										with self.assertRaises(UpperCamelCase__       ):
														SCREAMING_SNAKE_CASE_   :	Optional[int]													=   FeaturesManager.determine_framework(self.test_model       )