



"""simple docstring"""

import functools
import operator

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


lowercase__			   =  logging.get_logger(__name__)

lowercase__			   =  {
    "microsoft/unispeech-large-1500h-cv": (
        "https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json"
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}




class SCREAMING_SNAKE_CASE__					(		__snake_case      ):
						_lowerCAmelCase							=					"unispeech"



						def __init__(self						,     _lowercase=32						,     _lowercase=768						,     _lowercase=12						,     _lowercase=12						,     _lowercase=3072						,     _lowercase="gelu"						,     _lowercase=0.1						,     _lowercase=0.1						,     _lowercase=0.1						,     _lowercase=0.0						,     _lowercase=0.0						,     _lowercase=0.1						,     _lowercase=0.1						,     _lowercase=0.02						,     _lowercase=1e-5						,     _lowercase="group"						,     _lowercase="gelu"						,     _lowercase=(512, 512, 512, 512, 512, 512, 512)						,     _lowercase=(5, 2, 2, 2, 2, 2, 2)						,     _lowercase=(10, 3, 3, 3, 3, 2, 2)						,     _lowercase=False						,     _lowercase=128						,     _lowercase=16						,     _lowercase=False						,     _lowercase=True						,     _lowercase=0.05						,     _lowercase=10						,     _lowercase=2						,     _lowercase=0.0						,     _lowercase=10						,     _lowercase=0						,     _lowercase=320						,     _lowercase=2						,     _lowercase=0.1						,     _lowercase=100						,     _lowercase=256						,     _lowercase=256						,     _lowercase=0.1						,     _lowercase="mean"						,     _lowercase=False						,     _lowercase=False						,     _lowercase=256						,     _lowercase=80						,     _lowercase=0						,     _lowercase=1						,     _lowercase=2						,     _lowercase=0.5						,     **_lowercase						,     ):





													'''simple docstring'''

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

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

													# ctc loss
													__a		:		Any									=       ctc_loss_reduction
													__a		:		List[str]									=       ctc_zero_infinity

													# pretraining loss
													__a		:		Tuple									=       replace_prob





						@property
						def     lowerCAmelCase__(self							):





													'''simple docstring'''

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






"""simple docstring"""

from typing import Callable, Dict, Optional, Tuple

import torch
from torch import nn
from torch.distributions import (
    AffineTransform,
    Distribution,
    Independent,
    NegativeBinomial,
    Normal,
    StudentT,
    TransformedDistribution,
)




class SCREAMING_SNAKE_CASE__					(		__snake_case      ):



						def __init__(self						,     _lowercase						,     _lowercase=None						,     _lowercase=None						,     _lowercase=0							):





													'''simple docstring'''

													__a		:		Any									=       1.0 if scale is None else scale
													__a		:		str									=       0.0 if loc is None else loc

													super().__init__(_lowercase						,     [AffineTransform(loc=self.loc						,     scale=self.scale						,     event_dim=_lowercase							)]							)



						@property
						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													return self.base_dist.mean * self.scale + self.loc



						@property
						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													return self.base_dist.variance * self.scale**2





						@property
						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													return self.variance.sqrt()







class SCREAMING_SNAKE_CASE__					(		nn.Module      ):



						def __init__(self						,     _lowercase						,     _lowercase						,     _lowercase						,     **_lowercase							):





													'''simple docstring'''

													super().__init__(**_lowercase							)
													__a		:		str									=       args_dim
													__a		:		List[Any]									=       nn.ModuleList([nn.Linear(_lowercase						,     _lowercase							) for dim in args_dim.values()]							)
													__a		:		Dict									=       domain_map





						def     lowerCAmelCase__(self						,     _lowercase							):





													'''simple docstring'''

													__a		:		List[Any]									=       [proj(_lowercase							) for proj in self.proj]

													return self.domain_map(*_lowercase							)







class SCREAMING_SNAKE_CASE__					(		nn.Module      ):



						def __init__(self						,     _lowercase							):





													'''simple docstring'''

													super().__init__()
													__a		:		Optional[int]									=       function





						def     lowerCAmelCase__(self						,     _lowercase						,     *_lowercase							):





													'''simple docstring'''

													return self.function(_lowercase						,     *_lowercase							)







class SCREAMING_SNAKE_CASE__					:
						_lowerCAmelCase							=					42
						_lowerCAmelCase							=					42
						_lowerCAmelCase							=					42



						def __init__(self						,     _lowercase = 1							):





													'''simple docstring'''

													__a		:		Optional[int]									=       dim
													__a		:		str									=       {k: dim * self.args_dim[k] for k in self.args_dim}



						def     lowerCAmelCase__(self						,     _lowercase							):





													'''simple docstring'''

													if self.dim == 1:
																				return self.distribution_class(*_lowercase							)
													else:
																				return Independent(self.distribution_class(*_lowercase							)						,     1							)



						def     lowerCAmelCase__(self						,     _lowercase						,     _lowercase = None						,     _lowercase = None						,     ):





													'''simple docstring'''

													__a		:		Tuple									=       self._base_distribution(_lowercase							)
													if loc is None and scale is None:
																				return distr
													else:
																				return AffineTransformed(_lowercase						,     loc=_lowercase						,     scale=_lowercase						,     event_dim=self.event_dim							)



						@property
						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													return () if self.dim == 1 else (self.dim,)



						@property
						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													return len(self.event_shape							)



						@property
						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													return 0.0



						def     lowerCAmelCase__(self						,     _lowercase							):





													'''simple docstring'''

													return ParameterProjection(
													    in_features=_lowercase						,     args_dim=self.args_dim						,     domain_map=LambdaLayer(self.domain_map							)						,     )



						def     lowerCAmelCase__(self						,     *_lowercase							):





													'''simple docstring'''

													raise NotImplementedError()





						@staticmethod
						def     lowerCAmelCase__(_lowercase							):





													'''simple docstring'''

													return (x + torch.sqrt(torch.square(_lowercase							) + 4.0							)) / 2.0







class SCREAMING_SNAKE_CASE__					(		__snake_case      ):
						_lowerCAmelCase							=					{"df": 1, "loc": 1, "scale": 1}
						_lowerCAmelCase							=					StudentT



						@classmethod
						def     lowerCAmelCase__(cls						,     _lowercase						,     _lowercase						,     _lowercase							):





													'''simple docstring'''

													__a		:		int									=       cls.squareplus(_lowercase							).clamp_min(torch.finfo(scale.dtype							).eps							)
													__a		:		Optional[Any]									=       2.0 + cls.squareplus(_lowercase							)
													return df.squeeze(-1							), loc.squeeze(-1							), scale.squeeze(-1							)







class SCREAMING_SNAKE_CASE__					(		__snake_case      ):
						_lowerCAmelCase							=					{"loc": 1, "scale": 1}
						_lowerCAmelCase							=					Normal



						@classmethod
						def     lowerCAmelCase__(cls						,     _lowercase						,     _lowercase							):





													'''simple docstring'''

													__a		:		str									=       cls.squareplus(_lowercase							).clamp_min(torch.finfo(scale.dtype							).eps							)
													return loc.squeeze(-1							), scale.squeeze(-1							)







class SCREAMING_SNAKE_CASE__					(		__snake_case      ):
						_lowerCAmelCase							=					{"total_count": 1, "logits": 1}
						_lowerCAmelCase							=					NegativeBinomial



						@classmethod
						def     lowerCAmelCase__(cls						,     _lowercase						,     _lowercase							):





													'''simple docstring'''

													__a		:		Union[str, Any]									=       cls.squareplus(_lowercase							)
													return total_count.squeeze(-1							), logits.squeeze(-1							)



						def     lowerCAmelCase__(self						,     _lowercase							):





													'''simple docstring'''

													__a							,     __a		:		Optional[Any]									=       distr_args
													if self.dim == 1:
																				return self.distribution_class(total_count=_lowercase						,     logits=_lowercase							)
													else:
																				return Independent(self.distribution_class(total_count=_lowercase						,     logits=_lowercase							)						,     1							)





						def     lowerCAmelCase__(self						,     _lowercase						,     _lowercase = None						,     _lowercase = None							):





													'''simple docstring'''

													__a							,     __a		:		List[Any]									=       distr_args

													if scale is not None:
																				# See scaling property of Gamma.
																				logits += scale.log()

													return self._base_distribution((total_count, logits)							)

