


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

snake_case_						:			List[Any]													=							logging.get_logger(__name__)

snake_case_						:			Optional[int]													=							{
    '''openai/whisper-base''': '''https://huggingface.co/openai/whisper-base/resolve/main/config.json''',
}

# fmt: off
snake_case_						:			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, 3_57, 3_66, 4_38, 5_32, 6_85,
    7_05, 7_96, 9_30, 10_58, 12_20, 12_67, 12_79, 13_03, 13_43, 13_77,
    13_91, 16_35, 17_82, 18_75, 21_62, 23_61, 24_88, 34_67, 40_08, 42_11,
    46_00, 48_08, 52_99, 58_55, 63_29, 72_03, 96_09, 99_59, 1_05_63, 1_07_86,
    1_14_20, 1_17_09, 1_19_07, 1_31_63, 1_36_97, 1_37_00, 1_48_08, 1_53_06, 1_64_10, 1_67_91,
    1_79_92, 1_92_03, 1_95_10, 2_07_24, 2_23_05, 2_29_35, 2_70_07, 3_01_09, 3_04_20, 3_34_09,
    3_49_49, 4_02_83, 4_04_93, 4_05_49, 4_72_82, 4_91_46, 5_02_57, 5_03_59, 5_03_60, 5_03_61
]
snake_case_						:			Union[str, Any]													=							[
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 3_59, 5_03, 5_22, 5_42, 8_73,
    8_93, 9_02, 9_18, 9_22, 9_31, 13_50, 18_53, 19_82, 24_60, 26_27,
    32_46, 32_53, 32_68, 35_36, 38_46, 39_61, 41_83, 46_67, 65_85, 66_47,
    72_73, 90_61, 93_83, 1_04_28, 1_09_29, 1_19_38, 1_20_33, 1_23_31, 1_25_62, 1_37_93,
    1_41_57, 1_46_35, 1_52_65, 1_56_18, 1_65_53, 1_66_04, 1_83_62, 1_89_56, 2_00_75, 2_16_75,
    2_25_20, 2_61_30, 2_61_61, 2_64_35, 2_82_79, 2_94_64, 3_16_50, 3_23_02, 3_24_70, 3_68_65,
    4_28_63, 4_74_25, 4_98_70, 5_02_54, 5_02_58, 5_03_60, 5_03_61, 5_03_62
]

class 						A__							(		UpperCamelCase__  ):
						UpperCAmelCase             =						"whisper"
						UpperCAmelCase             =						["past_key_values"]
						UpperCAmelCase             =						{"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}




						def __init__(       self					:      List[str]				,    _a					:      Dict=5_1865				,    _a					:      Tuple=80				,    _a					:      Dict=6				,    _a					:      Any=4				,    _a					:      int=6				,    _a					:      Union[str, Any]=4				,    _a					:      Tuple=1536				,    _a					:      List[Any]=1536				,    _a					:      List[Any]=0.0				,    _a					:      Any=0.0				,    _a					:      Optional[int]=5_0257				,    _a					:      List[str]=True				,    _a					:      List[str]=True				,    _a					:      Any="gelu"				,    _a					:      Optional[int]=256				,    _a					:      Union[str, Any]=0.0				,    _a					:      str=0.0				,    _a					:      List[str]=0.0				,    _a					:      Optional[Any]=0.02				,    _a					:      Any=False				,    _a					:      Tuple=1500				,    _a					:      Any=448				,    _a					:      Optional[int]=5_0256				,    _a					:      int=5_0256				,    _a					:      List[str]=5_0256				,    _a					:      List[str]=None				,    _a					:      Union[str, Any]=[220, 5_0256]				,    _a					:      Tuple=False				,    _a					:      Optional[Any]=256				,    _a					:      Optional[int]=False				,    _a					:      Optional[Any]=0.05				,    _a					:      Tuple=10				,    _a					:      str=2				,    _a					:      int=0.0				,    _a					:      List[Any]=10				,    _a					:      Tuple=0				,    _a					:      int=7				,    **_a					:      Any				,    )							->     Tuple:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =vocab_size
										_SCREAMING_SNAKE_CASE			  =num_mel_bins
										_SCREAMING_SNAKE_CASE			  =d_model
										_SCREAMING_SNAKE_CASE			  =encoder_layers
										_SCREAMING_SNAKE_CASE			  =encoder_attention_heads
										_SCREAMING_SNAKE_CASE			  =decoder_layers
										_SCREAMING_SNAKE_CASE			  =decoder_attention_heads
										_SCREAMING_SNAKE_CASE			  =decoder_ffn_dim
										_SCREAMING_SNAKE_CASE			  =encoder_ffn_dim
										_SCREAMING_SNAKE_CASE			  =dropout
										_SCREAMING_SNAKE_CASE			  =attention_dropout
										_SCREAMING_SNAKE_CASE			  =activation_dropout
										_SCREAMING_SNAKE_CASE			  =activation_function
										_SCREAMING_SNAKE_CASE			  =init_std
										_SCREAMING_SNAKE_CASE			  =encoder_layerdrop
										_SCREAMING_SNAKE_CASE			  =decoder_layerdrop
										_SCREAMING_SNAKE_CASE			  =use_cache
										_SCREAMING_SNAKE_CASE			  =encoder_layers
										_SCREAMING_SNAKE_CASE			  =scale_embedding  # scale factor will be sqrt(d_model) if True
										_SCREAMING_SNAKE_CASE			  =max_source_positions
										_SCREAMING_SNAKE_CASE			  =max_target_positions

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

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

										_SCREAMING_SNAKE_CASE			  =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__							(		UpperCamelCase__  ):




						@property
						def 							__UpperCamelCase				(       self					:      Optional[Any]  )							->     Mapping[str, Mapping[int, str]]:


										"""simple docstring"""





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

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

										return common_inputs




						def 							__UpperCamelCase				(       self					:      List[str]				,    _a					:      Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]				,    _a					:      int = -1				,    _a					:      int = -1				,    _a					:      bool = False				,    _a					:      Optional["TensorType"] = None				,    _a					:      int = 2_2050				,    _a					:      float = 5.0				,    _a					:      int = 220				,    )							->     Mapping[str, Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =OrderedDict()
										_SCREAMING_SNAKE_CASE			  =OnnxConfig.generate_dummy_inputs(
										    self				,    preprocessor=preprocessor.feature_extractor				,    batch_size=_a				,    framework=_a				,    sampling_rate=_a				,    time_duration=_a				,    frequency=_a				,    )
										_SCREAMING_SNAKE_CASE			  =encoder_inputs['''input_features'''].shape[2]
										_SCREAMING_SNAKE_CASE			  =encoder_sequence_length // 2 if self.use_past else seq_length

										_SCREAMING_SNAKE_CASE			  =super().generate_dummy_inputs(
										    preprocessor.tokenizer				,    _a				,    _a				,    _a				,    _a  )

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

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

										return dummy_inputs




						@property
						def 							__UpperCamelCase				(       self					:      Union[str, Any]  )							->     float:


										"""simple docstring"""





										return 1E-3



import gc
import random
import unittest

import numpy as np
import torch

from diffusers import DDIMScheduler, KandinskyVaaPipeline, KandinskyVaaPriorPipeline, UNetaDConditionModel, VQModel
from diffusers.utils import floats_tensor, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference


enable_full_determinism()

class 						A__							(		UpperCamelCase__   ,     unittest.TestCase  ):
						UpperCAmelCase             =						KandinskyVaaPipeline
						UpperCAmelCase             =						[
						    "image_embeds",
						    "negative_image_embeds",
						]
						UpperCAmelCase             =						["image_embeds", "negative_image_embeds"]
						UpperCAmelCase             =						[
						    "generator",
						    "height",
						    "width",
						    "latents",
						    "guidance_scale",
						    "num_inference_steps",
						    "return_dict",
						    "guidance_scale",
						    "num_images_per_prompt",
						    "output_type",
						    "return_dict",
						]
						UpperCAmelCase             =						False




						@property
						def 							__UpperCamelCase				(       self					:      Tuple  )							->     str:


										"""simple docstring"""





										return 32




						@property
						def 							__UpperCamelCase				(       self					:      Any  )							->     Optional[Any]:


										"""simple docstring"""





										return 32




						@property
						def 							__UpperCamelCase				(       self					:      Optional[int]  )							->     Tuple:


										"""simple docstring"""





										return self.time_input_dim




						@property
						def 							__UpperCamelCase				(       self					:      Optional[int]  )							->     Tuple:


										"""simple docstring"""





										return self.time_input_dim * 4




						@property
						def 							__UpperCamelCase				(       self					:      List[str]  )							->     Dict:


										"""simple docstring"""





										return 100




						@property
						def 							__UpperCamelCase				(       self					:      Optional[int]  )							->     Optional[int]:


										"""simple docstring"""





										torch.manual_seed(0  )

										_SCREAMING_SNAKE_CASE			  ={
										    '''in_channels''': 4,
										    # Out channels is double in channels because predicts mean and variance
										    '''out_channels''': 8,
										    '''addition_embed_type''': '''image''',
										    '''down_block_types''': ('''ResnetDownsampleBlock2D''', '''SimpleCrossAttnDownBlock2D'''),
										    '''up_block_types''': ('''SimpleCrossAttnUpBlock2D''', '''ResnetUpsampleBlock2D'''),
										    '''mid_block_type''': '''UNetMidBlock2DSimpleCrossAttn''',
										    '''block_out_channels''': (self.block_out_channels_a, self.block_out_channels_a * 2),
										    '''layers_per_block''': 1,
										    '''encoder_hid_dim''': self.text_embedder_hidden_size,
										    '''encoder_hid_dim_type''': '''image_proj''',
										    '''cross_attention_dim''': self.cross_attention_dim,
										    '''attention_head_dim''': 4,
										    '''resnet_time_scale_shift''': '''scale_shift''',
										    '''class_embed_type''': None,
										}

										_SCREAMING_SNAKE_CASE			  =UNetaDConditionModel(**_a  )
										return model




						@property
						def 							__UpperCamelCase				(       self					:      Tuple  )							->     Tuple:


										"""simple docstring"""





										return {
										    "block_out_channels": [32, 64],
										    "down_block_types": ["DownEncoderBlock2D", "AttnDownEncoderBlock2D"],
										    "in_channels": 3,
										    "latent_channels": 4,
										    "layers_per_block": 1,
										    "norm_num_groups": 8,
										    "norm_type": "spatial",
										    "num_vq_embeddings": 12,
										    "out_channels": 3,
										    "up_block_types": [
										        "AttnUpDecoderBlock2D",
										        "UpDecoderBlock2D",
										    ],
										    "vq_embed_dim": 4,
										}




						@property
						def 							__UpperCamelCase				(       self					:      Any  )							->     Tuple:


										"""simple docstring"""





										torch.manual_seed(0  )
										_SCREAMING_SNAKE_CASE			  =VQModel(**self.dummy_movq_kwargs  )
										return model




						def 							__UpperCamelCase				(       self					:      Dict  )							->     Optional[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =self.dummy_unet
										_SCREAMING_SNAKE_CASE			  =self.dummy_movq

										_SCREAMING_SNAKE_CASE			  =DDIMScheduler(
										    num_train_timesteps=1000				,    beta_schedule='''linear'''				,    beta_start=0.0_00_85				,    beta_end=0.0_12				,    clip_sample=_a				,    set_alpha_to_one=_a				,    steps_offset=1				,    prediction_type='''epsilon'''				,    thresholding=_a				,    )

										_SCREAMING_SNAKE_CASE			  ={
										    '''unet''': unet,
										    '''scheduler''': scheduler,
										    '''movq''': movq,
										}
										return components




						def 							__UpperCamelCase				(       self					:      Optional[int]				,    _a					:      Tuple				,    _a					:      Tuple=0  )							->     Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =floats_tensor((1, self.text_embedder_hidden_size)				,    rng=random.Random(_a  )  ).to(_a  )
										_SCREAMING_SNAKE_CASE			  =floats_tensor((1, self.text_embedder_hidden_size)				,    rng=random.Random(seed + 1  )  ).to(
										    _a  )
										if str(_a  ).startswith('''mps'''  ):
														_SCREAMING_SNAKE_CASE			  =torch.manual_seed(_a  )
										else:
														_SCREAMING_SNAKE_CASE			  =torch.Generator(device=_a  ).manual_seed(_a  )
										_SCREAMING_SNAKE_CASE			  ={
										    '''image_embeds''': image_embeds,
										    '''negative_image_embeds''': negative_image_embeds,
										    '''generator''': generator,
										    '''height''': 64,
										    '''width''': 64,
										    '''guidance_scale''': 4.0,
										    '''num_inference_steps''': 2,
										    '''output_type''': '''np''',
										}
										return inputs




						def 							__UpperCamelCase				(       self					:      Optional[Any]  )							->     Union[str, Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  ='''cpu'''

										_SCREAMING_SNAKE_CASE			  =self.get_dummy_components()

										_SCREAMING_SNAKE_CASE			  =self.pipeline_class(**_a  )
										_SCREAMING_SNAKE_CASE			  =pipe.to(_a  )

										pipe.set_progress_bar_config(disable=_a  )

										_SCREAMING_SNAKE_CASE			  =pipe(**self.get_dummy_inputs(_a  )  )
										_SCREAMING_SNAKE_CASE			  =output.images

										_SCREAMING_SNAKE_CASE			  =pipe(
										    **self.get_dummy_inputs(_a  )				,    return_dict=_a				,    )[0]

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

										assert image.shape == (1, 64, 64, 3)

										_SCREAMING_SNAKE_CASE			  =np.array(
										    [0.6_23_79_76, 1.0, 0.36_44_13_32, 1.0, 0.70_63_96_34, 0.29_87_71_86, 0.85_65_21_25, 0.5_21_68_43, 0.54_45_40_46]  )

										assert (
										    np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2
										), f" expected_slice {expected_slice}, but got {image_slice.flatten()}"

										assert (
										    np.abs(image_from_tuple_slice.flatten() - expected_slice  ).max() < 1E-2
										), f" expected_slice {expected_slice}, but got {image_from_tuple_slice.flatten()}"

@slow
@require_torch_gpu
class 						A__							(		unittest.TestCase  ):




						def 							__UpperCamelCase				(       self					:      List[Any]  )							->     Dict:


										"""simple docstring"""





										super().tearDown()
										gc.collect()
										torch.cuda.empty_cache()




						def 							__UpperCamelCase				(       self					:      Union[str, Any]  )							->     str:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =load_numpy(
										    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
										    '''/kandinskyv22/kandinskyv22_text2img_cat_fp16.npy'''  )

										_SCREAMING_SNAKE_CASE			  =KandinskyVaaPriorPipeline.from_pretrained(
										    '''kandinsky-community/kandinsky-2-2-prior'''				,    torch_dtype=torch.floataa  )
										pipe_prior.to(_a  )

										_SCREAMING_SNAKE_CASE			  =KandinskyVaaPipeline.from_pretrained(
										    '''kandinsky-community/kandinsky-2-2-decoder'''				,    torch_dtype=torch.floataa  )
										_SCREAMING_SNAKE_CASE			  =pipeline.to(_a  )
										pipeline.set_progress_bar_config(disable=_a  )

										_SCREAMING_SNAKE_CASE			  ='''red cat, 4k photo'''

										_SCREAMING_SNAKE_CASE			  =torch.Generator(device='''cuda'''  ).manual_seed(0  )
										_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE			  =pipe_prior(
										    _a				,    generator=_a				,    num_inference_steps=5				,    negative_prompt=''''''				,    ).to_tuple()

										_SCREAMING_SNAKE_CASE			  =torch.Generator(device='''cuda'''  ).manual_seed(0  )
										_SCREAMING_SNAKE_CASE			  =pipeline(
										    image_embeds=_a				,    negative_image_embeds=_a				,    generator=_a				,    num_inference_steps=100				,    output_type='''np'''				,    )

										_SCREAMING_SNAKE_CASE			  =output.images[0]

										assert image.shape == (512, 512, 3)

										assert_mean_pixel_difference(_a				,    _a  )