

import functools
import operator

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


lowercase_             =     logging.get_logger(__name__)

lowercase_             =     {
    'microsoft/unispeech-sat-base-100h-libri-ft': (
        'https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json'
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}





class 				__lowerCAmelCase  (      SCREAMING_SNAKE_CASE							):
  _a		    =						"""unispeech-sat"""




  def __init__(       self							,     lowerCAmelCase=32							,     lowerCAmelCase=768							,     lowerCAmelCase=12							,     lowerCAmelCase=12							,     lowerCAmelCase=3_072							,     lowerCAmelCase="gelu"							,     lowerCAmelCase=0.1							,     lowerCAmelCase=0.1							,     lowerCAmelCase=0.1							,     lowerCAmelCase=0.0							,     lowerCAmelCase=0.0							,     lowerCAmelCase=0.1							,     lowerCAmelCase=0.1							,     lowerCAmelCase=0.02							,     lowerCAmelCase=1e-5							,     lowerCAmelCase="group"							,     lowerCAmelCase="gelu"							,     lowerCAmelCase=(512, 512, 512, 512, 512, 512, 512)							,     lowerCAmelCase=(5, 2, 2, 2, 2, 2, 2)							,     lowerCAmelCase=(10, 3, 3, 3, 3, 2, 2)							,     lowerCAmelCase=False							,     lowerCAmelCase=128							,     lowerCAmelCase=16							,     lowerCAmelCase=False							,     lowerCAmelCase=True							,     lowerCAmelCase=0.05							,     lowerCAmelCase=10							,     lowerCAmelCase=2							,     lowerCAmelCase=0.0							,     lowerCAmelCase=10							,     lowerCAmelCase=0							,     lowerCAmelCase=320							,     lowerCAmelCase=2							,     lowerCAmelCase=0.1							,     lowerCAmelCase=100							,     lowerCAmelCase=256							,     lowerCAmelCase=256							,     lowerCAmelCase=0.1							,     lowerCAmelCase="mean"							,     lowerCAmelCase=False							,     lowerCAmelCase=False							,     lowerCAmelCase=256							,     lowerCAmelCase=(512, 512, 512, 512, 1_500)							,     lowerCAmelCase=(5, 3, 3, 1, 1)							,     lowerCAmelCase=(1, 2, 3, 1, 1)							,     lowerCAmelCase=512							,     lowerCAmelCase=0							,     lowerCAmelCase=1							,     lowerCAmelCase=2							,     lowerCAmelCase=504							,     **lowerCAmelCase							,     )						->				Tuple:
        '''simple docstring'''






        super().__init__(**lowerCAmelCase							,     pad_token_id=lowerCAmelCase							,     bos_token_id=lowerCAmelCase							,     eos_token_id=lowerCAmelCase      )
        _lowercase			 =hidden_size
        _lowercase			 =feat_extract_norm
        _lowercase			 =feat_extract_activation
        _lowercase			 =list(lowerCAmelCase      )
        _lowercase			 =list(lowerCAmelCase      )
        _lowercase			 =list(lowerCAmelCase      )
        _lowercase			 =conv_bias
        _lowercase			 =num_conv_pos_embeddings
        _lowercase			 =num_conv_pos_embedding_groups
        _lowercase			 =len(self.conv_dim      )
        _lowercase			 =num_hidden_layers
        _lowercase			 =intermediate_size
        _lowercase			 =hidden_act
        _lowercase			 =num_attention_heads
        _lowercase			 =hidden_dropout
        _lowercase			 =attention_dropout
        _lowercase			 =activation_dropout
        _lowercase			 =feat_proj_dropout
        _lowercase			 =final_dropout
        _lowercase			 =layerdrop
        _lowercase			 =layer_norm_eps
        _lowercase			 =initializer_range
        _lowercase			 =vocab_size
        _lowercase			 =num_clusters
        _lowercase			 =do_stable_layer_norm
        _lowercase			 =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
        _lowercase			 =apply_spec_augment
        _lowercase			 =mask_time_prob
        _lowercase			 =mask_time_length
        _lowercase			 =mask_time_min_masks
        _lowercase			 =mask_feature_prob
        _lowercase			 =mask_feature_length
        _lowercase			 =mask_feature_min_masks

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

        # ctc loss
        _lowercase			 =ctc_loss_reduction
        _lowercase			 =ctc_zero_infinity

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

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




  @property
  def 						A__  (       self      )						->				Optional[int]:
        '''simple docstring'''






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





import math

import tensorflow as tf
from packaging import version
def   a   (    A__			:     Tuple  )					->   List[Any]:





      """simple docstring"""



      _lowercase			 =tf.convert_to_tensor(A__  )
      _lowercase			 =0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0  )   ,     x.dtype  )  ))

      return x * cdf
def   a   (    A__			:     Any  )					->   int:





      """simple docstring"""



      _lowercase			 =tf.convert_to_tensor(A__  )
      _lowercase			 =tf.cast(math.pi   ,     x.dtype  )
      _lowercase			 =tf.cast(0.044715   ,     x.dtype  )
      _lowercase			 =0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi  ) * (x + coeff * tf.pow(A__   ,     3  ))  ))

      return x * cdf
def   a   (    A__			:     Optional[int]  )					->   int:





      """simple docstring"""



      _lowercase			 =tf.convert_to_tensor(A__  )

      return x * tf.tanh(tf.math.softplus(A__  )  )
def   a   (    A__			:     Tuple  )					->   List[str]:





      """simple docstring"""



      _lowercase			 =tf.convert_to_tensor(A__  )
      _lowercase			 =tf.cast(0.044715   ,     x.dtype  )
      _lowercase			 =tf.cast(0.7978845608   ,     x.dtype  )

      return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)  ))
def   a   (    A__			:     int  )					->   Any:





      """simple docstring"""



      _lowercase			 =tf.convert_to_tensor(A__  )
      _lowercase			 =tf.cast(1.702   ,     x.dtype  )
      return x * tf.math.sigmoid(coeff * x  )
def   a   (    A__			:     int  )					->   Dict:





      """simple docstring"""



      return tf.clip_by_value(_gelu(A__  )   ,     -10   ,     10  )
def   a   (    A__			:     Optional[int]   ,     A__			:     int=-1  )					->   Optional[Any]:





      """simple docstring"""



      _lowercase , _lowercase			 =tf.split(A__   ,     2   ,     axis=A__  )
      return a * tf.math.sigmoid(A__  )


if version.parse(tf.version.VERSION) >= version.parse('2.4'):
  def   a   (    A__			:     Any  )					->   Dict:





        """simple docstring"""



        return tf.keras.activations.gelu(A__   ,     approximate=A__  )

  lowercase_             =     tf.keras.activations.gelu







  lowercase_             =     approximate_gelu_wrap
else:
  lowercase_             =     _gelu
  lowercase_             =     _gelu_new


lowercase_             =     {
    'gelu': gelu,
    'gelu_10': gelu_aa,
    'gelu_fast': gelu_fast,
    'gelu_new': gelu_new,
    'glu': glu,
    'mish': mish,
    'quick_gelu': quick_gelu,
    'relu': tf.keras.activations.relu,
    'sigmoid': tf.keras.activations.sigmoid,
    'silu': tf.keras.activations.swish,
    'swish': tf.keras.activations.swish,
    'tanh': tf.keras.activations.tanh,
}







def   a   (    A__			:     Optional[int]  )					->   str:





      """simple docstring"""



      if activation_string in ACTaFN:
            return ACTaFN[activation_string]
      else:
            raise KeyError(F'''function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()  )}'''  )


