


"""simple docstring"""


from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxSeqaSeqConfigWithPast
from ...utils import logging


if TYPE_CHECKING:
    from ...feature_extraction_utils import FeatureExtractionMixin
    from ...tokenization_utils_base import PreTrainedTokenizerBase
    from ...utils import TensorType

__lowerCamelCase      :Any	    =		logging.get_logger(__name__)

__lowerCamelCase      :List[str]	    =		{
    'openai/whisper-base': 'https://huggingface.co/openai/whisper-base/resolve/main/config.json',
}

# fmt: off
__lowerCamelCase      :Optional[Any]	    =		[
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 357, 366, 438, 532, 685,
    705, 796, 930, 1_058, 1_220, 1_267, 1_279, 1_303, 1_343, 1_377,
    1_391, 1_635, 1_782, 1_875, 2_162, 2_361, 2_488, 3_467, 4_008, 4_211,
    4_600, 4_808, 5_299, 5_855, 6_329, 7_203, 9_609, 9_959, 10_563, 10_786,
    11_420, 11_709, 11_907, 13_163, 13_697, 13_700, 14_808, 15_306, 16_410, 16_791,
    17_992, 19_203, 19_510, 20_724, 22_305, 22_935, 27_007, 30_109, 30_420, 33_409,
    34_949, 40_283, 40_493, 40_549, 47_282, 49_146, 50_257, 50_359, 50_360, 50_361
]
__lowerCamelCase      :List[Any]	    =		[
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 359, 503, 522, 542, 873,
    893, 902, 918, 922, 931, 1_350, 1_853, 1_982, 2_460, 2_627,
    3_246, 3_253, 3_268, 3_536, 3_846, 3_961, 4_183, 4_667, 6_585, 6_647,
    7_273, 9_061, 9_383, 10_428, 10_929, 11_938, 12_033, 12_331, 12_562, 13_793,
    14_157, 14_635, 15_265, 15_618, 16_553, 16_604, 18_362, 18_956, 20_075, 21_675,
    22_520, 26_130, 26_161, 26_435, 28_279, 29_464, 31_650, 32_302, 32_470, 36_865,
    42_863, 47_425, 49_870, 50_254, 50_258, 50_360, 50_361, 50_362
]


class 			A__	(						__lowercase):


     """simple docstring"""
     snake_case__	:					Optional[Any]													='''whisper'''
     snake_case__	:					Optional[Any]													=['''past_key_values''']
     snake_case__	:					Union[str, Any]													={'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}

     def __init__(	self:						Optional[int]     ,		__a:						int=51_865     ,		__a:						str=80     ,		__a:						int=6     ,		__a:						Union[str, Any]=4     ,		__a:						Union[str, Any]=6     ,		__a:						Union[str, Any]=4     ,		__a:						str=1_536     ,		__a:						Any=1_536     ,		__a:						int=0.0     ,		__a:						Optional[Any]=0.0     ,		__a:						Dict=50_257     ,		__a:						str=True     ,		__a:						Optional[Any]=True     ,		__a:						List[Any]="gelu"     ,		__a:						Optional[int]=256     ,		__a:						Tuple=0.0     ,		__a:						Union[str, Any]=0.0     ,		__a:						Union[str, Any]=0.0     ,		__a:						str=0.02     ,		__a:						Tuple=False     ,		__a:						Optional[Any]=1_500     ,		__a:						Optional[Any]=448     ,		__a:						List[str]=50_256     ,		__a:						int=50_256     ,		__a:						Tuple=50_256     ,		__a:						str=None     ,		__a:						Union[str, Any]=[220, 50_256]     ,		__a:						Optional[int]=False     ,		__a:						str=256     ,		__a:						str=False     ,		__a:						Tuple=0.05     ,		__a:						Union[str, Any]=10     ,		__a:						Tuple=2     ,		__a:						Optional[int]=0.0     ,		__a:						List[Any]=10     ,		__a:						Any=0     ,		__a:						Optional[int]=7     ,		**__a:						Tuple     ,		)->    str:
           lowerCamelCase					:					Optional[int]        =	vocab_size
           lowerCamelCase					:					List[str]        =	num_mel_bins
           lowerCamelCase					:					Dict        =	d_model
           lowerCamelCase					:					int        =	encoder_layers
           lowerCamelCase					:					Union[str, Any]        =	encoder_attention_heads
           lowerCamelCase					:					Any        =	decoder_layers
           lowerCamelCase					:					Optional[Any]        =	decoder_attention_heads
           lowerCamelCase					:					Dict        =	decoder_ffn_dim
           lowerCamelCase					:					List[Any]        =	encoder_ffn_dim
           lowerCamelCase					:					str        =	dropout
           lowerCamelCase					:					Tuple        =	attention_dropout
           lowerCamelCase					:					Tuple        =	activation_dropout
           lowerCamelCase					:					List[Any]        =	activation_function
           lowerCamelCase					:					List[str]        =	init_std
           lowerCamelCase					:					Union[str, Any]        =	encoder_layerdrop
           lowerCamelCase					:					List[Any]        =	decoder_layerdrop
           lowerCamelCase					:					List[str]        =	use_cache
           lowerCamelCase					:					int        =	encoder_layers
           lowerCamelCase					:					Any        =	scale_embedding  # scale factor will be sqrt(d_model) if True
           lowerCamelCase					:					Dict        =	max_source_positions
           lowerCamelCase					:					Any        =	max_target_positions

           # Audio Classification-specific parameters. Feel free to ignore for other classes.
           lowerCamelCase					:					int        =	classifier_proj_size
           lowerCamelCase					:					int        =	use_weighted_layer_sum

           # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
           lowerCamelCase					:					Any        =	apply_spec_augment
           lowerCamelCase					:					int        =	mask_time_prob
           lowerCamelCase					:					Optional[Any]        =	mask_time_length
           lowerCamelCase					:					Dict        =	mask_time_min_masks
           lowerCamelCase					:					Any        =	mask_feature_prob
           lowerCamelCase					:					Dict        =	mask_feature_length
           lowerCamelCase					:					List[str]        =	mask_feature_min_masks

           lowerCamelCase					:					int        =	median_filter_width

           super().__init__(
               pad_token_id=__a     ,		bos_token_id=__a     ,		eos_token_id=__a     ,		is_encoder_decoder=__a     ,		decoder_start_token_id=__a     ,		suppress_tokens=__a     ,		begin_suppress_tokens=__a     ,		**__a     ,		)


class 			A__	(						__lowercase):


     """simple docstring"""

     @property
     def 		a__						(	self:						Tuple	)->    Mapping[str, Mapping[int, str]]:
           lowerCamelCase					:					Tuple        =	OrderedDict(
               [
                   ("""input_features""", {0: """batch""", 1: """feature_size""", 2: """encoder_sequence"""}),
               ]	)
           if self.use_past:
                 lowerCamelCase					:					List[str]        =	{0: """batch"""}
           else:
                 lowerCamelCase					:					Tuple        =	{0: """batch""", 1: """decoder_sequence"""}

           if self.use_past:
                 self.fill_with_past_key_values_(__a     ,		direction="""inputs"""	)

           return common_inputs

     def 		a__						(	self:						int     ,		__a:						Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]     ,		__a:						int = -1     ,		__a:						int = -1     ,		__a:						bool = False     ,		__a:						Optional["TensorType"] = None     ,		__a:						int = 22_050     ,		__a:						float = 5.0     ,		__a:						int = 220     ,		)->    Mapping[str, Any]:
           lowerCamelCase					:					Dict        =	OrderedDict()
           lowerCamelCase					:					List[str]        =	OnnxConfig.generate_dummy_inputs(
               self     ,		preprocessor=preprocessor.feature_extractor     ,		batch_size=__a     ,		framework=__a     ,		sampling_rate=__a     ,		time_duration=__a     ,		frequency=__a     ,		)
           lowerCamelCase					:					Any        =	encoder_inputs["""input_features"""].shape[2]
           lowerCamelCase					:					str        =	encoder_sequence_length // 2 if self.use_past else seq_length

           lowerCamelCase					:					List[str]        =	super().generate_dummy_inputs(
               preprocessor.tokenizer     ,		__a     ,		__a     ,		__a     ,		__a	)

           lowerCamelCase					:					Union[str, Any]        =	encoder_inputs.pop("""input_features"""	)
           lowerCamelCase					:					List[Any]        =	decoder_inputs.pop("""decoder_input_ids"""	)

           if "past_key_values" in decoder_inputs:
                 lowerCamelCase					:					List[Any]        =	decoder_inputs.pop("""past_key_values"""	)

           return dummy_inputs







     @property
     def 		a__						(	self:						List[str]	)->    float:
           return 1e-3








"""simple docstring"""


import torch

from diffusers import KDPMaDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest


class 			A__	(						__lowercase):


     """simple docstring"""
     snake_case__	:					Tuple													=(KDPMaDiscreteScheduler,)
     snake_case__	:					Tuple													=10

     def 		a__						(	self:						List[Any]     ,		**__a:						Optional[int]	)->    Union[str, Any]:
           lowerCamelCase					:					int        =	{
               """num_train_timesteps""": 1_100,
               """beta_start""": 0.00_01,
               """beta_end""": 0.02,
               """beta_schedule""": """linear""",
           }

           config.update(**__a	)
           return config

     def 		a__						(	self:						Union[str, Any]	)->    Any:
           for timesteps in [10, 50, 100, 1_000]:
                 self.check_over_configs(num_train_timesteps=__a	)

     def 		a__						(	self:						str	)->    int:
           for beta_start, beta_end in zip([0.0_00_01, 0.00_01, 0.0_01]     ,		[0.00_02, 0.0_02, 0.02]	):
                 self.check_over_configs(beta_start=__a     ,		beta_end=__a	)

     def 		a__						(	self:						int	)->    Union[str, Any]:
           for schedule in ["linear", "scaled_linear"]:
                 self.check_over_configs(beta_schedule=__a	)

     def 		a__						(	self:						List[Any]	)->    List[Any]:
           for prediction_type in ["epsilon", "v_prediction"]:
                 self.check_over_configs(prediction_type=__a	)

     def 		a__						(	self:						Union[str, Any]	)->    int:
           lowerCamelCase					:					List[str]        =	self.scheduler_classes[0]
           lowerCamelCase					:					Union[str, Any]        =	self.get_scheduler_config(prediction_type="""v_prediction"""	)
           lowerCamelCase					:					List[str]        =	scheduler_class(**__a	)

           scheduler.set_timesteps(self.num_inference_steps	)

           lowerCamelCase					:					Dict        =	self.dummy_model()
           lowerCamelCase					:					List[Any]        =	self.dummy_sample_deter * scheduler.init_noise_sigma
           lowerCamelCase					:					List[Any]        =	sample.to(__a	)

           for i, t in enumerate(scheduler.timesteps	):
                 lowerCamelCase					:					Optional[Any]        =	scheduler.scale_model_input(__a     ,		__a	)

                 lowerCamelCase					:					Optional[int]        =	model(__a     ,		__a	)

                 lowerCamelCase					:					Tuple        =	scheduler.step(__a     ,		__a     ,		__a	)
                 lowerCamelCase					:					Optional[Any]        =	output.prev_sample

           lowerCamelCase					:					List[str]        =	torch.sum(torch.abs(__a	)	)
           lowerCamelCase					:					Tuple        =	torch.mean(torch.abs(__a	)	)

           if torch_device in ["cpu", "mps"]:
                 assert abs(result_sum.item() - 4.6_9_3_4e-0_7	) < 1e-2
                 assert abs(result_mean.item() - 6.1_1_1_2e-1_0	) < 1e-3
           else:
                 # CUDA
                 assert abs(result_sum.item() - 4.6_9_3_4_2_8_6_5_0_1_7_0_9_7_2e-0_7	) < 1e-2
                 assert abs(result_mean.item() - 0.00_02	) < 1e-3

     def 		a__						(	self:						Any	)->    Any:
           if torch_device == "mps":
                 return
           lowerCamelCase					:					Dict        =	self.scheduler_classes[0]
           lowerCamelCase					:					Dict        =	self.get_scheduler_config()
           lowerCamelCase					:					int        =	scheduler_class(**__a	)

           scheduler.set_timesteps(self.num_inference_steps	)

           lowerCamelCase					:					List[Any]        =	self.dummy_model()
           lowerCamelCase					:					Optional[Any]        =	self.dummy_sample_deter * scheduler.init_noise_sigma
           lowerCamelCase					:					Optional[int]        =	sample.to(__a	)

           for i, t in enumerate(scheduler.timesteps	):
                 lowerCamelCase					:					Dict        =	scheduler.scale_model_input(__a     ,		__a	)

                 lowerCamelCase					:					Optional[Any]        =	model(__a     ,		__a	)

                 lowerCamelCase					:					Tuple        =	scheduler.step(__a     ,		__a     ,		__a	)
                 lowerCamelCase					:					str        =	output.prev_sample

           lowerCamelCase					:					Tuple        =	torch.sum(torch.abs(__a	)	)
           lowerCamelCase					:					Tuple        =	torch.mean(torch.abs(__a	)	)

           if torch_device in ["cpu", "mps"]:
                 assert abs(result_sum.item() - 20.41_25	) < 1e-2
                 assert abs(result_mean.item() - 0.02_66	) < 1e-3
           else:
                 # CUDA
                 assert abs(result_sum.item() - 20.41_25	) < 1e-2
                 assert abs(result_mean.item() - 0.02_66	) < 1e-3







     def 		a__						(	self:						Optional[Any]	)->    List[Any]:
           if torch_device == "mps":
                 return
           lowerCamelCase					:					Any        =	self.scheduler_classes[0]
           lowerCamelCase					:					Union[str, Any]        =	self.get_scheduler_config()
           lowerCamelCase					:					Optional[Any]        =	scheduler_class(**__a	)

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

           lowerCamelCase					:					Union[str, Any]        =	self.dummy_model()
           lowerCamelCase					:					List[str]        =	self.dummy_sample_deter.to(__a	) * scheduler.init_noise_sigma

           for t in scheduler.timesteps:
                 lowerCamelCase					:					Union[str, Any]        =	scheduler.scale_model_input(__a     ,		__a	)

                 lowerCamelCase					:					Optional[int]        =	model(__a     ,		__a	)

                 lowerCamelCase					:					int        =	scheduler.step(__a     ,		__a     ,		__a	)
                 lowerCamelCase					:					int        =	output.prev_sample

           lowerCamelCase					:					Union[str, Any]        =	torch.sum(torch.abs(__a	)	)
           lowerCamelCase					:					int        =	torch.mean(torch.abs(__a	)	)

           if str(__a	).startswith("""cpu"""	):
                 # The following sum varies between 148 and 156 on mps. Why?
                 assert abs(result_sum.item() - 20.41_25	) < 1e-2
                 assert abs(result_mean.item() - 0.02_66	) < 1e-3
           else:
                 # CUDA
                 assert abs(result_sum.item() - 20.41_25	) < 1e-2
                 assert abs(result_mean.item() - 0.02_66	) < 1e-3




