





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

__A							:			Any         =			logging.get_logger(__name__)

__A							:			Any         =			{
    "openai/whisper-base": "https://huggingface.co/openai/whisper-base/resolve/main/config.json",
}

# fmt: off
__A							:			int         =			[
    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
]
__A							:			Dict         =			[
    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      lowerCamelCase(						__snake_case	):
     '''simple docstring'''


     __magic_name__   =			'whisper'
     __magic_name__   =			['past_key_values']
     __magic_name__   =			{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}




     def __init__(    self				,     snake_case_=5_1865				,     snake_case_=80				,     snake_case_=6				,     snake_case_=4				,     snake_case_=6				,     snake_case_=4				,     snake_case_=1536				,     snake_case_=1536				,     snake_case_=0.0				,     snake_case_=0.0				,     snake_case_=5_0257				,     snake_case_=True				,     snake_case_=True				,     snake_case_="gelu"				,     snake_case_=256				,     snake_case_=0.0				,     snake_case_=0.0				,     snake_case_=0.0				,     snake_case_=0.02				,     snake_case_=False				,     snake_case_=1500				,     snake_case_=448				,     snake_case_=5_0256				,     snake_case_=5_0256				,     snake_case_=5_0256				,     snake_case_=None				,     snake_case_=[220, 5_0256]				,     snake_case_=False				,     snake_case_=256				,     snake_case_=False				,     snake_case_=0.05				,     snake_case_=10				,     snake_case_=2				,     snake_case_=0.0				,     snake_case_=10				,     snake_case_=0				,     snake_case_=7				,     **snake_case_				,     ):
         _A     =							vocab_size
         _A     =							num_mel_bins
         _A     =							d_model
         _A     =							encoder_layers
         _A     =							encoder_attention_heads
         _A     =							decoder_layers
         _A     =							decoder_attention_heads
         _A     =							decoder_ffn_dim
         _A     =							encoder_ffn_dim
         _A     =							dropout
         _A     =							attention_dropout
         _A     =							activation_dropout
         _A     =							activation_function
         _A     =							init_std
         _A     =							encoder_layerdrop
         _A     =							decoder_layerdrop
         _A     =							use_cache
         _A     =							encoder_layers
         _A     =							scale_embedding  # scale factor will be sqrt(d_model) if True
         _A     =							max_source_positions
         _A     =							max_target_positions

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

         # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
         _A     =							apply_spec_augment
         _A     =							mask_time_prob
         _A     =							mask_time_length
         _A     =							mask_time_min_masks
         _A     =							mask_feature_prob
         _A     =							mask_feature_length
         _A     =							mask_feature_min_masks

         _A     =							median_filter_width

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







class      lowerCamelCase(						__snake_case	):
     '''simple docstring'''


     @property
     def        lowerCAmelCase__		(    self							):
         _A     =							OrderedDict(
             [
                 ('input_features', {0: 'batch', 1: 'feature_size', 2: 'encoder_sequence'}),
             ]							)
         if self.use_past:
             _A     =							{0: 'batch'}
         else:
             _A     =							{0: 'batch', 1: 'decoder_sequence'}

         if self.use_past:
             self.fill_with_past_key_values_(snake_case_				,     direction='inputs'							)

         return common_inputs




     def        lowerCAmelCase__		(    self				,     snake_case_				,     snake_case_ = -1				,     snake_case_ = -1				,     snake_case_ = False				,     snake_case_ = None				,     snake_case_ = 2_2050				,     snake_case_ = 5.0				,     snake_case_ = 220				,     ):
         _A     =							OrderedDict()
         _A     =							OnnxConfig.generate_dummy_inputs(
             self				,     preprocessor=preprocessor.feature_extractor				,     batch_size=snake_case_				,     framework=snake_case_				,     sampling_rate=snake_case_				,     time_duration=snake_case_				,     frequency=snake_case_				,     )
         _A     =							encoder_inputs['input_features'].shape[2]
         _A     =							encoder_sequence_length // 2 if self.use_past else seq_length

         _A     =							super().generate_dummy_inputs(
             preprocessor.tokenizer				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_							)

         _A     =							encoder_inputs.pop('input_features'							)
         _A     =							decoder_inputs.pop('decoder_input_ids'							)

         if "past_key_values" in decoder_inputs:
             _A     =							decoder_inputs.pop('past_key_values'							)

         return dummy_inputs




     @property
     def        lowerCAmelCase__		(    self							):
         return 1E-3












import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()







class      lowerCamelCase(						unittest.TestCase	):
     '''simple docstring'''


     @property
     def        lowerCAmelCase__		(    self							):
         torch.manual_seed(0							)
         _A     =							UNetaDModel(
             block_out_channels=(32, 64)				,     layers_per_block=2				,     sample_size=32				,     in_channels=3				,     out_channels=3				,     down_block_types=('DownBlock2D', 'AttnDownBlock2D')				,     up_block_types=('AttnUpBlock2D', 'UpBlock2D')				,     )
         return model




     def        lowerCAmelCase__		(    self							):
         _A     =							self.dummy_uncond_unet
         _A     =							KarrasVeScheduler()

         _A     =							KarrasVePipeline(unet=snake_case_				,     scheduler=snake_case_							)
         pipe.to(snake_case_							)
         pipe.set_progress_bar_config(disable=snake_case_							)

         _A     =							torch.manual_seed(0							)
         _A     =							pipe(num_inference_steps=2				,     generator=snake_case_				,     output_type='numpy'							).images

         _A     =							torch.manual_seed(0							)
         _A     =							pipe(num_inference_steps=2				,     generator=snake_case_				,     output_type='numpy'				,     return_dict=snake_case_							)[0]

         _A     =							image[0, -3:, -3:, -1]
         _A     =							image_from_tuple[0, -3:, -3:, -1]

         assert image.shape == (1, 32, 32, 3)
         _A     =							np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]							)

         assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2
         assert np.abs(image_from_tuple_slice.flatten() - expected_slice							).max() < 1E-2







@slow
@require_torch
class      lowerCamelCase(						unittest.TestCase	):
     '''simple docstring'''


     def        lowerCAmelCase__		(    self							):
         _A     =							'google/ncsnpp-celebahq-256'
         _A     =							UNetaDModel.from_pretrained(snake_case_							)
         _A     =							KarrasVeScheduler()

         _A     =							KarrasVePipeline(unet=snake_case_				,     scheduler=snake_case_							)
         pipe.to(snake_case_							)
         pipe.set_progress_bar_config(disable=snake_case_							)

         _A     =							torch.manual_seed(0							)
         _A     =							pipe(num_inference_steps=20				,     generator=snake_case_				,     output_type='numpy'							).images

         _A     =							image[0, -3:, -3:, -1]
         assert image.shape == (1, 256, 256, 3)
         _A     =							np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]							)

         assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2





