
"""simple docstring"""


import functools
import operator

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


SCREAMING_SNAKE_CASE      =     logging.get_logger(__name__)

SCREAMING_SNAKE_CASE      =     {
    """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   __a  (      _lowerCAmelCase	):
       UpperCamelCase_		:					Optional[Any]   =			'''unispeech'''






       def __init__(  self :							Tuple       ,      UpperCAmelCase_ :							List[Any]=32       ,      UpperCAmelCase_ :							str=768       ,      UpperCAmelCase_ :							Dict=12       ,      UpperCAmelCase_ :							int=12       ,      UpperCAmelCase_ :							Optional[Any]=3_072       ,      UpperCAmelCase_ :							List[Any]="gelu"       ,      UpperCAmelCase_ :							str=0.1       ,      UpperCAmelCase_ :							Any=0.1       ,      UpperCAmelCase_ :							List[Any]=0.1       ,      UpperCAmelCase_ :							List[Any]=0.0       ,      UpperCAmelCase_ :							List[str]=0.0       ,      UpperCAmelCase_ :							Tuple=0.1       ,      UpperCAmelCase_ :							str=0.1       ,      UpperCAmelCase_ :							Dict=0.02       ,      UpperCAmelCase_ :							Dict=1e-5       ,      UpperCAmelCase_ :							Optional[Any]="group"       ,      UpperCAmelCase_ :							Union[str, Any]="gelu"       ,      UpperCAmelCase_ :							List[str]=(512, 512, 512, 512, 512, 512, 512)       ,      UpperCAmelCase_ :							Any=(5, 2, 2, 2, 2, 2, 2)       ,      UpperCAmelCase_ :							Optional[int]=(10, 3, 3, 3, 3, 2, 2)       ,      UpperCAmelCase_ :							Dict=False       ,      UpperCAmelCase_ :							List[str]=128       ,      UpperCAmelCase_ :							Optional[int]=16       ,      UpperCAmelCase_ :							Tuple=False       ,      UpperCAmelCase_ :							int=True       ,      UpperCAmelCase_ :							Any=0.05       ,      UpperCAmelCase_ :							List[str]=10       ,      UpperCAmelCase_ :							Optional[Any]=2       ,      UpperCAmelCase_ :							List[Any]=0.0       ,      UpperCAmelCase_ :							Optional[int]=10       ,      UpperCAmelCase_ :							Union[str, Any]=0       ,      UpperCAmelCase_ :							int=320       ,      UpperCAmelCase_ :							Union[str, Any]=2       ,      UpperCAmelCase_ :							Optional[Any]=0.1       ,      UpperCAmelCase_ :							Optional[Any]=100       ,      UpperCAmelCase_ :							str=256       ,      UpperCAmelCase_ :							Tuple=256       ,      UpperCAmelCase_ :							List[Any]=0.1       ,      UpperCAmelCase_ :							Tuple="mean"       ,      UpperCAmelCase_ :							Tuple=False       ,      UpperCAmelCase_ :							Union[str, Any]=False       ,      UpperCAmelCase_ :							Optional[Any]=256       ,      UpperCAmelCase_ :							Dict=80       ,      UpperCAmelCase_ :							Union[str, Any]=0       ,      UpperCAmelCase_ :							Optional[int]=1       ,      UpperCAmelCase_ :							Union[str, Any]=2       ,      UpperCAmelCase_ :							Optional[int]=0.5       ,      **UpperCAmelCase_ :							Optional[Any]       ,      )->  List[str]:







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

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

              # ctc loss
              UpperCamelCase					 =		ctc_loss_reduction
              UpperCamelCase					 =		ctc_zero_infinity

              # pretraining loss
              UpperCamelCase					 =		replace_prob






       @property
       def 	_SCREAMING_SNAKE_CASE       (  self :							Any			)->  str:







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







"""simple docstring"""


import torch

from diffusers import EulerDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest



class   __a  (      _lowerCAmelCase	):
       UpperCamelCase_		:					Any   =			(EulerDiscreteScheduler,)
       UpperCamelCase_		:					Dict   =			10






       def 	_SCREAMING_SNAKE_CASE       (  self :							Any       ,      **UpperCAmelCase_ :							str			)->  Union[str, Any]:







              """simple docstring"""
              UpperCamelCase					 =		{
                  "num_train_timesteps": 1_100,
                  "beta_start": 0.0001,
                  "beta_end": 0.02,
                  "beta_schedule": "linear",
              }

              config.update(**UpperCAmelCase_			)
              return config






       def 	_SCREAMING_SNAKE_CASE       (  self :							List[Any]			)->  Any:







              """simple docstring"""
              for timesteps in [10, 50, 100, 1_000]:
                     self.check_over_configs(num_train_timesteps=UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							int			)->  Any:







              """simple docstring"""
              for beta_start, beta_end in zip([0.00001, 0.0001, 0.001]       ,      [0.0002, 0.002, 0.02]			):
                     self.check_over_configs(beta_start=UpperCAmelCase_       ,      beta_end=UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							str			)->  Dict:







              """simple docstring"""
              for schedule in ["linear", "scaled_linear"]:
                     self.check_over_configs(beta_schedule=UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							List[Any]			)->  int:







              """simple docstring"""
              for prediction_type in ["epsilon", "v_prediction"]:
                     self.check_over_configs(prediction_type=UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							str			)->  Any:







              """simple docstring"""
              UpperCamelCase					 =		self.scheduler_classes[0]
              UpperCamelCase					 =		self.get_scheduler_config()
              UpperCamelCase					 =		scheduler_class(**UpperCAmelCase_			)

              scheduler.set_timesteps(self.num_inference_steps			)

              UpperCamelCase					 =		torch.manual_seed(0			)

              UpperCamelCase					 =		self.dummy_model()
              UpperCamelCase					 =		self.dummy_sample_deter * scheduler.init_noise_sigma
              UpperCamelCase					 =		sample.to(UpperCAmelCase_			)

              for i, t in enumerate(scheduler.timesteps			):
                     UpperCamelCase					 =		scheduler.scale_model_input(UpperCAmelCase_       ,      UpperCAmelCase_			)

                     UpperCamelCase					 =		model(UpperCAmelCase_       ,      UpperCAmelCase_			)

                     UpperCamelCase					 =		scheduler.step(UpperCAmelCase_       ,      UpperCAmelCase_       ,      UpperCAmelCase_       ,      generator=UpperCAmelCase_			)
                     UpperCamelCase					 =		output.prev_sample

              UpperCamelCase					 =		torch.sum(torch.abs(UpperCAmelCase_			)			)
              UpperCamelCase					 =		torch.mean(torch.abs(UpperCAmelCase_			)			)

              assert abs(result_sum.item() - 10.0807			) < 1e-2
              assert abs(result_mean.item() - 0.0131			) < 1e-3






       def 	_SCREAMING_SNAKE_CASE       (  self :							List[str]			)->  str:







              """simple docstring"""
              UpperCamelCase					 =		self.scheduler_classes[0]
              UpperCamelCase					 =		self.get_scheduler_config(prediction_type="v_prediction"			)
              UpperCamelCase					 =		scheduler_class(**UpperCAmelCase_			)

              scheduler.set_timesteps(self.num_inference_steps			)

              UpperCamelCase					 =		torch.manual_seed(0			)

              UpperCamelCase					 =		self.dummy_model()
              UpperCamelCase					 =		self.dummy_sample_deter * scheduler.init_noise_sigma
              UpperCamelCase					 =		sample.to(UpperCAmelCase_			)

              for i, t in enumerate(scheduler.timesteps			):
                     UpperCamelCase					 =		scheduler.scale_model_input(UpperCAmelCase_       ,      UpperCAmelCase_			)

                     UpperCamelCase					 =		model(UpperCAmelCase_       ,      UpperCAmelCase_			)

                     UpperCamelCase					 =		scheduler.step(UpperCAmelCase_       ,      UpperCAmelCase_       ,      UpperCAmelCase_       ,      generator=UpperCAmelCase_			)
                     UpperCamelCase					 =		output.prev_sample

              UpperCamelCase					 =		torch.sum(torch.abs(UpperCAmelCase_			)			)
              UpperCamelCase					 =		torch.mean(torch.abs(UpperCAmelCase_			)			)

              assert abs(result_sum.item() - 0.0002			) < 1e-2
              assert abs(result_mean.item() - 2.2_676e-06			) < 1e-3






       def 	_SCREAMING_SNAKE_CASE       (  self :							List[str]			)->  Tuple:







              """simple docstring"""
              UpperCamelCase					 =		self.scheduler_classes[0]
              UpperCamelCase					 =		self.get_scheduler_config()
              UpperCamelCase					 =		scheduler_class(**UpperCAmelCase_			)

              scheduler.set_timesteps(self.num_inference_steps       ,      device=UpperCAmelCase_			)

              UpperCamelCase					 =		torch.manual_seed(0			)

              UpperCamelCase					 =		self.dummy_model()
              UpperCamelCase					 =		self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
              UpperCamelCase					 =		sample.to(UpperCAmelCase_			)

              for t in scheduler.timesteps:
                     UpperCamelCase					 =		scheduler.scale_model_input(UpperCAmelCase_       ,      UpperCAmelCase_			)

                     UpperCamelCase					 =		model(UpperCAmelCase_       ,      UpperCAmelCase_			)

                     UpperCamelCase					 =		scheduler.step(UpperCAmelCase_       ,      UpperCAmelCase_       ,      UpperCAmelCase_       ,      generator=UpperCAmelCase_			)
                     UpperCamelCase					 =		output.prev_sample

              UpperCamelCase					 =		torch.sum(torch.abs(UpperCAmelCase_			)			)
              UpperCamelCase					 =		torch.mean(torch.abs(UpperCAmelCase_			)			)

              assert abs(result_sum.item() - 10.0807			) < 1e-2
              assert abs(result_mean.item() - 0.0131			) < 1e-3






       def 	_SCREAMING_SNAKE_CASE       (  self :							Optional[int]			)->  Any:







              """simple docstring"""
              UpperCamelCase					 =		self.scheduler_classes[0]
              UpperCamelCase					 =		self.get_scheduler_config()
              UpperCamelCase					 =		scheduler_class(**UpperCAmelCase_       ,      use_karras_sigmas=UpperCAmelCase_			)

              scheduler.set_timesteps(self.num_inference_steps       ,      device=UpperCAmelCase_			)

              UpperCamelCase					 =		torch.manual_seed(0			)

              UpperCamelCase					 =		self.dummy_model()
              UpperCamelCase					 =		self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
              UpperCamelCase					 =		sample.to(UpperCAmelCase_			)

              for t in scheduler.timesteps:
                     UpperCamelCase					 =		scheduler.scale_model_input(UpperCAmelCase_       ,      UpperCAmelCase_			)

                     UpperCamelCase					 =		model(UpperCAmelCase_       ,      UpperCAmelCase_			)

                     UpperCamelCase					 =		scheduler.step(UpperCAmelCase_       ,      UpperCAmelCase_       ,      UpperCAmelCase_       ,      generator=UpperCAmelCase_			)
                     UpperCamelCase					 =		output.prev_sample

              UpperCamelCase					 =		torch.sum(torch.abs(UpperCAmelCase_			)			)
              UpperCamelCase					 =		torch.mean(torch.abs(UpperCAmelCase_			)			)

              assert abs(result_sum.item() - 124.52299499511719			) < 1e-2
              assert abs(result_mean.item() - 0.16213932633399963			) < 1e-3





