

"""simple docstring"""




import functools
import operator

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


A_				:      str           =			logging.get_logger(__name__)

A_				:      Dict           =			{
    "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  lowerCamelCase    (A__      ):
			lowerCamelCase__ :		List[str]       		=				'wav2vec2'

			def __init__(       self					:    List[str]     ,					__UpperCAmelCase					:    Union[str, Any]=3_2     ,					__UpperCAmelCase					:    Any=7_6_8     ,					__UpperCAmelCase					:    List[str]=1_2     ,					__UpperCAmelCase					:    Dict=1_2     ,					__UpperCAmelCase					:    str=3_0_7_2     ,					__UpperCAmelCase					:    str="gelu"     ,					__UpperCAmelCase					:    Optional[Any]=0.1     ,					__UpperCAmelCase					:    List[Any]=0.1     ,					__UpperCAmelCase					:    Any=0.1     ,					__UpperCAmelCase					:    List[str]=0.0     ,					__UpperCAmelCase					:    str=0.0     ,					__UpperCAmelCase					:    List[str]=0.1     ,					__UpperCAmelCase					:    int=0.1     ,					__UpperCAmelCase					:    Union[str, Any]=0.02     ,					__UpperCAmelCase					:    List[Any]=1e-5     ,					__UpperCAmelCase					:    int="group"     ,					__UpperCAmelCase					:    Tuple="gelu"     ,					__UpperCAmelCase					:    int=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)     ,					__UpperCAmelCase					:    Dict=(5, 2, 2, 2, 2, 2, 2)     ,					__UpperCAmelCase					:    List[Any]=(1_0, 3, 3, 3, 3, 2, 2)     ,					__UpperCAmelCase					:    Optional[Any]=False     ,					__UpperCAmelCase					:    List[str]=1_2_8     ,					__UpperCAmelCase					:    Tuple=1_6     ,					__UpperCAmelCase					:    Any=False     ,					__UpperCAmelCase					:    Union[str, Any]=True     ,					__UpperCAmelCase					:    List[Any]=0.05     ,					__UpperCAmelCase					:    List[str]=1_0     ,					__UpperCAmelCase					:    Optional[int]=2     ,					__UpperCAmelCase					:    int=0.0     ,					__UpperCAmelCase					:    Dict=1_0     ,					__UpperCAmelCase					:    List[Any]=0     ,					__UpperCAmelCase					:    int=3_2_0     ,					__UpperCAmelCase					:    Any=2     ,					__UpperCAmelCase					:    Dict=0.1     ,					__UpperCAmelCase					:    Any=1_0_0     ,					__UpperCAmelCase					:    List[Any]=2_5_6     ,					__UpperCAmelCase					:    Any=2_5_6     ,					__UpperCAmelCase					:    str=0.1     ,					__UpperCAmelCase					:    int="sum"     ,					__UpperCAmelCase					:    int=False     ,					__UpperCAmelCase					:    str=False     ,					__UpperCAmelCase					:    Dict=2_5_6     ,					__UpperCAmelCase					:    Optional[Any]=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 1_5_0_0)     ,					__UpperCAmelCase					:    Any=(5, 3, 3, 1, 1)     ,					__UpperCAmelCase					:    Dict=(1, 2, 3, 1, 1)     ,					__UpperCAmelCase					:    Optional[Any]=5_1_2     ,					__UpperCAmelCase					:    int=0     ,					__UpperCAmelCase					:    Tuple=1     ,					__UpperCAmelCase					:    int=2     ,					__UpperCAmelCase					:    int=False     ,					__UpperCAmelCase					:    int=3     ,					__UpperCAmelCase					:    Optional[int]=2     ,					__UpperCAmelCase					:    Any=3     ,					__UpperCAmelCase					:    Optional[Any]=None     ,					__UpperCAmelCase					:    List[Any]=None     ,					**__UpperCAmelCase					:    List[Any]     ,					) ->     Optional[Any]:
						super().__init__(**__UpperCAmelCase     ,					pad_token_id=__UpperCAmelCase     ,					bos_token_id=__UpperCAmelCase     ,					eos_token_id=__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   hidden_size
						SCREAMING_SNAKE_CASE__										=   feat_extract_norm
						SCREAMING_SNAKE_CASE__										=   feat_extract_activation
						SCREAMING_SNAKE_CASE__										=   list(__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   list(__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   list(__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   conv_bias
						SCREAMING_SNAKE_CASE__										=   num_conv_pos_embeddings
						SCREAMING_SNAKE_CASE__										=   num_conv_pos_embedding_groups
						SCREAMING_SNAKE_CASE__										=   len(self.conv_dim							)
						SCREAMING_SNAKE_CASE__										=   num_hidden_layers
						SCREAMING_SNAKE_CASE__										=   intermediate_size
						SCREAMING_SNAKE_CASE__										=   hidden_act
						SCREAMING_SNAKE_CASE__										=   num_attention_heads
						SCREAMING_SNAKE_CASE__										=   hidden_dropout
						SCREAMING_SNAKE_CASE__										=   attention_dropout
						SCREAMING_SNAKE_CASE__										=   activation_dropout
						SCREAMING_SNAKE_CASE__										=   feat_proj_dropout
						SCREAMING_SNAKE_CASE__										=   final_dropout
						SCREAMING_SNAKE_CASE__										=   layerdrop
						SCREAMING_SNAKE_CASE__										=   layer_norm_eps
						SCREAMING_SNAKE_CASE__										=   initializer_range
						SCREAMING_SNAKE_CASE__										=   vocab_size
						SCREAMING_SNAKE_CASE__										=   do_stable_layer_norm
						SCREAMING_SNAKE_CASE__										=   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__										=   apply_spec_augment
						SCREAMING_SNAKE_CASE__										=   mask_time_prob
						SCREAMING_SNAKE_CASE__										=   mask_time_length
						SCREAMING_SNAKE_CASE__										=   mask_time_min_masks
						SCREAMING_SNAKE_CASE__										=   mask_feature_prob
						SCREAMING_SNAKE_CASE__										=   mask_feature_length
						SCREAMING_SNAKE_CASE__										=   mask_feature_min_masks

						# parameters for pretraining with codevector quantized representations
						SCREAMING_SNAKE_CASE__										=   num_codevectors_per_group
						SCREAMING_SNAKE_CASE__										=   num_codevector_groups
						SCREAMING_SNAKE_CASE__										=   contrastive_logits_temperature
						SCREAMING_SNAKE_CASE__										=   feat_quantizer_dropout
						SCREAMING_SNAKE_CASE__										=   num_negatives
						SCREAMING_SNAKE_CASE__										=   codevector_dim
						SCREAMING_SNAKE_CASE__										=   proj_codevector_dim
						SCREAMING_SNAKE_CASE__										=   diversity_loss_weight

						# ctc loss
						SCREAMING_SNAKE_CASE__										=   ctc_loss_reduction
						SCREAMING_SNAKE_CASE__										=   ctc_zero_infinity

						# adapter
						SCREAMING_SNAKE_CASE__										=   add_adapter
						SCREAMING_SNAKE_CASE__										=   adapter_kernel_size
						SCREAMING_SNAKE_CASE__										=   adapter_stride
						SCREAMING_SNAKE_CASE__										=   num_adapter_layers
						SCREAMING_SNAKE_CASE__										=   output_hidden_size or hidden_size
						SCREAMING_SNAKE_CASE__										=   adapter_attn_dim

						# SequenceClassification-specific parameter. Feel free to ignore for other classes.
						SCREAMING_SNAKE_CASE__										=   classifier_proj_size

						# XVector-specific parameters. Feel free to ignore for other classes.
						SCREAMING_SNAKE_CASE__										=   list(__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   list(__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   list(__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   xvector_output_dim





			@property
			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[Any]							) ->     Optional[Any]:
						return functools.reduce(operator.mul     ,					self.conv_stride     ,					1							)





"""simple docstring"""




import pickle
import unittest

import torch

from accelerate import Accelerator
from accelerate.state import AcceleratorState
from accelerate.test_utils import require_cpu





@require_cpu
class  lowerCamelCase    (unittest.TestCase      ):

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     str:
						SCREAMING_SNAKE_CASE__										=   torch.nn.Linear(1_0     ,					1_0							)
						SCREAMING_SNAKE_CASE__										=   torch.optim.SGD(model.parameters()     ,					0.1							)
						SCREAMING_SNAKE_CASE__										=   Accelerator()
						SCREAMING_SNAKE_CASE__										=   accelerator.prepare(__UpperCAmelCase							)
						try:
									pickle.loads(pickle.dumps(__UpperCAmelCase							)							)
						except Exception as e:
									self.fail(F"""Accelerated optimizer pickling failed with {e}"""							)
						AcceleratorState._reset_state()


