






"""simple docstring"""
import functools
import operator

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


_lowerCAmelCase         =	logging.get_logger(__name__)

_lowerCAmelCase         =	{
    "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  (				_SCREAMING_SNAKE_CASE						):





	"""simple docstring"""




	_A       :				Dict    =				"""unispeech"""





	def __init__(self     ,     lowerCAmelCase_=32     ,     lowerCAmelCase_=768     ,     lowerCAmelCase_=12     ,     lowerCAmelCase_=12     ,     lowerCAmelCase_=3072     ,     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_=80     ,     lowerCAmelCase_=0     ,     lowerCAmelCase_=1     ,     lowerCAmelCase_=2     ,     lowerCAmelCase_=0.5     ,     **lowerCAmelCase_     ,     ):
		super().__init__(**lowerCAmelCase_     ,     pad_token_id=lowerCAmelCase_     ,     bos_token_id=lowerCAmelCase_     ,     eos_token_id=lowerCAmelCase_							)
		A_		:						Union[str, Any]	    =   hidden_size
		A_		:						List[str]	    =   feat_extract_norm
		A_		:						Tuple	    =   feat_extract_activation
		A_		:						Any	    =   list(lowerCAmelCase_							)
		A_		:						Union[str, Any]	    =   list(lowerCAmelCase_							)
		A_		:						Dict	    =   list(lowerCAmelCase_							)
		A_		:						str	    =   conv_bias
		A_		:						Tuple	    =   num_conv_pos_embeddings
		A_		:						Tuple	    =   num_conv_pos_embedding_groups
		A_		:						Union[str, Any]	    =   len(self.conv_dim							)
		A_		:						int	    =   num_hidden_layers
		A_		:						Optional[int]	    =   intermediate_size
		A_		:						Union[str, Any]	    =   hidden_act
		A_		:						int	    =   num_attention_heads
		A_		:						List[str]	    =   hidden_dropout
		A_		:						Optional[Any]	    =   attention_dropout
		A_		:						Tuple	    =   activation_dropout
		A_		:						Any	    =   feat_proj_dropout
		A_		:						Optional[int]	    =   final_dropout
		A_		:						List[Any]	    =   layerdrop
		A_		:						List[str]	    =   layer_norm_eps
		A_		:						Dict	    =   initializer_range
		A_		:						Tuple	    =   num_ctc_classes
		A_		:						Union[str, Any]	    =   vocab_size
		A_		:						Tuple	    =   do_stable_layer_norm
		A_		:						Union[str, Any]	    =   use_weighted_layer_sum
		A_		:						Optional[int]	    =   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_		:						Dict	    =   mask_time_prob
		A_		:						List[Any]	    =   mask_time_length
		A_		:						Dict	    =   mask_time_min_masks
		A_		:						Any	    =   mask_feature_prob
		A_		:						Tuple	    =   mask_feature_length
		A_		:						Dict	    =   mask_feature_min_masks

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

		# ctc loss
		A_		:						Optional[int]	    =   ctc_loss_reduction
		A_		:						Tuple	    =   ctc_zero_infinity

		# pretraining loss
		A_		:						str	    =   replace_prob





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









"""simple docstring"""
import unittest

import torch
from torch import nn

from diffusers.models.activations import get_activation



class      SCREAMING_SNAKE_CASE  (				unittest.TestCase						):





	"""simple docstring"""




	def    lowerCamelCase(self							):
		A_		:						Optional[int]	    =   get_activation("""swish"""							)

		self.assertIsInstance(lowerCAmelCase_     ,     nn.SiLU							)

		self.assertEqual(act(torch.tensor(-100     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertNotEqual(act(torch.tensor(-1     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(0     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(20     ,     dtype=torch.floataa							)							).item()     ,     20							)





	def    lowerCamelCase(self							):
		A_		:						Dict	    =   get_activation("""silu"""							)

		self.assertIsInstance(lowerCAmelCase_     ,     nn.SiLU							)

		self.assertEqual(act(torch.tensor(-100     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertNotEqual(act(torch.tensor(-1     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(0     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(20     ,     dtype=torch.floataa							)							).item()     ,     20							)





	def    lowerCamelCase(self							):
		A_		:						Optional[Any]	    =   get_activation("""mish"""							)

		self.assertIsInstance(lowerCAmelCase_     ,     nn.Mish							)

		self.assertEqual(act(torch.tensor(-200     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertNotEqual(act(torch.tensor(-1     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(0     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(20     ,     dtype=torch.floataa							)							).item()     ,     20							)





	def    lowerCamelCase(self							):
		A_		:						int	    =   get_activation("""gelu"""							)

		self.assertIsInstance(lowerCAmelCase_     ,     nn.GELU							)

		self.assertEqual(act(torch.tensor(-100     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertNotEqual(act(torch.tensor(-1     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(0     ,     dtype=torch.floataa							)							).item()     ,     0							)
		self.assertEqual(act(torch.tensor(20     ,     dtype=torch.floataa							)							).item()     ,     20							)

