

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


__A			:					Optional[Any]						=			logging.get_logger(__name__)

__A			:					List[str]						=			{
    'speechbrain/m-ctc-t-large': 'https://huggingface.co/speechbrain/m-ctc-t-large/resolve/main/config.json',
    # See all M-CTC-T models at https://huggingface.co/models?filter=mctct
}





class 			_SCREAMING_SNAKE_CASE (   __snake_case		):







   '''simple docstring'''




   lowerCamelCase__				=      "mctct"





   def __init__(       self					:			List[Any]     , __lowerCamelCase					:			int=8065     , __lowerCamelCase					:			List[Any]=1536     , __lowerCamelCase					:			Dict=36     , __lowerCamelCase					:			Optional[int]=6144     , __lowerCamelCase					:			Union[str, Any]=4     , __lowerCamelCase					:			Any=384     , __lowerCamelCase					:			List[str]=920     , __lowerCamelCase					:			Optional[int]=1e-5     , __lowerCamelCase					:			Tuple=0.3     , __lowerCamelCase					:			Any="relu"     , __lowerCamelCase					:			Optional[int]=0.02     , __lowerCamelCase					:			Any=0.3     , __lowerCamelCase					:			Any=0.3     , __lowerCamelCase					:			List[Any]=1     , __lowerCamelCase					:			str=0     , __lowerCamelCase					:			Dict=2     , __lowerCamelCase					:			Optional[int]=1     , __lowerCamelCase					:			Optional[Any]=0.3     , __lowerCamelCase					:			Any=1     , __lowerCamelCase					:			Dict=(7,)     , __lowerCamelCase					:			Dict=(3,)     , __lowerCamelCase					:			int=80     , __lowerCamelCase					:			Dict=1     , __lowerCamelCase					:			Any=None     , __lowerCamelCase					:			Optional[Any]="sum"     , __lowerCamelCase					:			Dict=False     , **__lowerCamelCase					:			Tuple     , ):
       super().__init__(**__lowerCamelCase     , pad_token_id=__lowerCamelCase     , bos_token_id=__lowerCamelCase     , eos_token_id=__lowerCamelCase			)
       SCREAMING_SNAKE_CASE										=   vocab_size
       SCREAMING_SNAKE_CASE										=   hidden_size
       SCREAMING_SNAKE_CASE										=   num_hidden_layers
       SCREAMING_SNAKE_CASE										=   intermediate_size
       SCREAMING_SNAKE_CASE										=   num_attention_heads
       SCREAMING_SNAKE_CASE										=   attention_head_dim
       SCREAMING_SNAKE_CASE										=   max_position_embeddings
       SCREAMING_SNAKE_CASE										=   layer_norm_eps
       SCREAMING_SNAKE_CASE										=   layerdrop
       SCREAMING_SNAKE_CASE										=   hidden_act
       SCREAMING_SNAKE_CASE										=   initializer_range
       SCREAMING_SNAKE_CASE										=   hidden_dropout_prob
       SCREAMING_SNAKE_CASE										=   attention_probs_dropout_prob
       SCREAMING_SNAKE_CASE										=   pad_token_id
       SCREAMING_SNAKE_CASE										=   bos_token_id
       SCREAMING_SNAKE_CASE										=   eos_token_id
       SCREAMING_SNAKE_CASE										=   conv_glu_dim
       SCREAMING_SNAKE_CASE										=   conv_dropout
       SCREAMING_SNAKE_CASE										=   num_conv_layers
       SCREAMING_SNAKE_CASE										=   input_feat_per_channel
       SCREAMING_SNAKE_CASE										=   input_channels
       SCREAMING_SNAKE_CASE										=   conv_channels
       SCREAMING_SNAKE_CASE										=   ctc_loss_reduction
       SCREAMING_SNAKE_CASE										=   ctc_zero_infinity

       # prevents config testing fail with exporting to json
       SCREAMING_SNAKE_CASE										=   list(__lowerCamelCase			)
       SCREAMING_SNAKE_CASE										=   list(__lowerCamelCase			)

       if len(self.conv_kernel			) != self.num_conv_layers:
           raise ValueError(
               "Configuration for convolutional module is incorrect. "
               "It is required that `len(config.conv_kernel)` == `config.num_conv_layers` "
               f"but is `len(config.conv_kernel) = {len(self.conv_kernel			)}`, "
               f"`config.num_conv_layers = {self.num_conv_layers}`."			)






import torch

from diffusers import KDPMaDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest





class UpperCAmelCase_				( _SCREAMING_SNAKE_CASE ):
  __lowerCAmelCase   :						int							=   (KDPMaDiscreteScheduler,)
  __lowerCAmelCase   :						Union[str, Any]							=   10


  def 						__UpperCAmelCase     (							self ,**__snake_case ):



       """simple docstring"""





       A_          =       {
           '''num_train_timesteps''': 1_1_0_0,
           '''beta_start''': 0.0001,
           '''beta_end''': 0.02,
           '''beta_schedule''': '''linear''',
       }

       config.update(**__snake_case )
       return config


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       for timesteps in [1_0, 5_0, 1_0_0, 1_0_0_0]:
            self.check_over_configs(num_train_timesteps=__snake_case )


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       for beta_start, beta_end in zip([0.0_0001, 0.0001, 0.001] ,[0.0002, 0.002, 0.02] ):
            self.check_over_configs(beta_start=__snake_case ,beta_end=__snake_case )


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





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


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





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


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       A_          =       self.scheduler_classes[0]
       A_          =       self.get_scheduler_config(prediction_type='''v_prediction''' )
       A_          =       scheduler_class(**__snake_case )

       scheduler.set_timesteps(self.num_inference_steps )

       A_          =       self.dummy_model()
       A_          =       self.dummy_sample_deter * scheduler.init_noise_sigma
       A_          =       sample.to(__snake_case )

       for i, t in enumerate(scheduler.timesteps ):
            A_          =       scheduler.scale_model_input(__snake_case ,__snake_case )

            A_          =       model(__snake_case ,__snake_case )

            A_          =       scheduler.step(__snake_case ,__snake_case ,__snake_case )
            A_          =       output.prev_sample

       A_          =       torch.sum(torch.abs(__snake_case ) )
       A_          =       torch.mean(torch.abs(__snake_case ) )

       if torch_device in ["cpu", "mps"]:
            assert abs(result_sum.item() - 4.69_34E-07 ) < 1E-2
            assert abs(result_mean.item() - 6.11_12E-10 ) < 1E-3
       else:
            # CUDA
            assert abs(result_sum.item() - 4.6_93_42_86_50_17_09_72E-07 ) < 1E-2
            assert abs(result_mean.item() - 0.0002 ) < 1E-3


  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       if torch_device == "mps":
            return
       A_          =       self.scheduler_classes[0]
       A_          =       self.get_scheduler_config()
       A_          =       scheduler_class(**__snake_case )

       scheduler.set_timesteps(self.num_inference_steps )

       A_          =       self.dummy_model()
       A_          =       self.dummy_sample_deter * scheduler.init_noise_sigma
       A_          =       sample.to(__snake_case )

       for i, t in enumerate(scheduler.timesteps ):
            A_          =       scheduler.scale_model_input(__snake_case ,__snake_case )

            A_          =       model(__snake_case ,__snake_case )

            A_          =       scheduler.step(__snake_case ,__snake_case ,__snake_case )
            A_          =       output.prev_sample

       A_          =       torch.sum(torch.abs(__snake_case ) )
       A_          =       torch.mean(torch.abs(__snake_case ) )

       if torch_device in ["cpu", "mps"]:
            assert abs(result_sum.item() - 20.4125 ) < 1E-2
            assert abs(result_mean.item() - 0.0266 ) < 1E-3
       else:
            # CUDA
            assert abs(result_sum.item() - 20.4125 ) < 1E-2
            assert abs(result_mean.item() - 0.0266 ) < 1E-3




  def 						__UpperCAmelCase     (							self ):



       """simple docstring"""





       if torch_device == "mps":
            return
       A_          =       self.scheduler_classes[0]
       A_          =       self.get_scheduler_config()
       A_          =       scheduler_class(**__snake_case )

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

       A_          =       self.dummy_model()
       A_          =       self.dummy_sample_deter.to(__snake_case ) * scheduler.init_noise_sigma

       for t in scheduler.timesteps:
            A_          =       scheduler.scale_model_input(__snake_case ,__snake_case )

            A_          =       model(__snake_case ,__snake_case )

            A_          =       scheduler.step(__snake_case ,__snake_case ,__snake_case )
            A_          =       output.prev_sample

       A_          =       torch.sum(torch.abs(__snake_case ) )
       A_          =       torch.mean(torch.abs(__snake_case ) )

       if str(__snake_case ).startswith('''cpu''' ):
            # The following sum varies between 148 and 156 on mps. Why?
            assert abs(result_sum.item() - 20.4125 ) < 1E-2
            assert abs(result_mean.item() - 0.0266 ) < 1E-3
       else:
            # CUDA
            assert abs(result_sum.item() - 20.4125 ) < 1E-2
            assert abs(result_mean.item() - 0.0266 ) < 1E-3



