
"""simple docstring"""




import gc
import unittest

import numpy as np
import torch
import torch.nn.functional as F
from transformers import (
    ClapTextConfig,
    ClapTextModelWithProjection,
    RobertaTokenizer,
    SpeechTaHifiGan,
    SpeechTaHifiGanConfig,
)

from diffusers import (
    AudioLDMPipeline,
    AutoencoderKL,
    DDIMScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    UNetaDConditionModel,
)
from diffusers.utils import is_xformers_available, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from ..pipeline_params import TEXT_TO_AUDIO_BATCH_PARAMS, TEXT_TO_AUDIO_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()



class 			lowerCAmelCase_		(a__				,      unittest.TestCase						):


				"""simple docstring"""



				__UpperCamelCase   :		Union[str, Any]       =     AudioLDMPipeline
				__UpperCamelCase   :		List[str]       =     TEXT_TO_AUDIO_PARAMS
				__UpperCamelCase   :		List[Any]       =     TEXT_TO_AUDIO_BATCH_PARAMS
				__UpperCamelCase   :		str       =     frozenset(
				    [
				        '''num_inference_steps''',
				        '''num_waveforms_per_prompt''',
				        '''generator''',
				        '''latents''',
				        '''output_type''',
				        '''return_dict''',
				        '''callback''',
				        '''callback_steps''',
				    ]						)



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



											"""simple docstring"""




											torch.manual_seed(0					)
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     UNetaDConditionModel(
											    block_out_channels=(32, 64)     , layers_per_block=2     , sample_size=32     , in_channels=4     , out_channels=4     , down_block_types=("""DownBlock2D""", """CrossAttnDownBlock2D""")     , up_block_types=("""CrossAttnUpBlock2D""", """UpBlock2D""")     , cross_attention_dim=(32, 64)     , class_embed_type="""simple_projection"""     , projection_class_embeddings_input_dim=32     , class_embeddings_concat=SCREAMING_SNAKE_CASE__     , )
											SCREAMING_SNAKE_CASE__		: Any     =     DDIMScheduler(
											    beta_start=0.00085     , beta_end=0.012     , beta_schedule="""scaled_linear"""     , clip_sample=SCREAMING_SNAKE_CASE__     , set_alpha_to_one=SCREAMING_SNAKE_CASE__     , )
											torch.manual_seed(0					)
											SCREAMING_SNAKE_CASE__		: int     =     AutoencoderKL(
											    block_out_channels=[32, 64]     , in_channels=1     , out_channels=1     , down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]     , up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]     , latent_channels=4     , )
											torch.manual_seed(0					)
											SCREAMING_SNAKE_CASE__		: str     =     ClapTextConfig(
											    bos_token_id=0     , eos_token_id=2     , hidden_size=32     , intermediate_size=37     , layer_norm_eps=1E-05     , num_attention_heads=4     , num_hidden_layers=5     , pad_token_id=1     , vocab_size=10_00     , projection_dim=32     , )
											SCREAMING_SNAKE_CASE__		: Dict     =     ClapTextModelWithProjection(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     RobertaTokenizer.from_pretrained("""hf-internal-testing/tiny-random-roberta"""     , model_max_length=77					)

											SCREAMING_SNAKE_CASE__		: Optional[int]     =     SpeechTaHifiGanConfig(
											    model_in_dim=8     , sampling_rate=1_60_00     , upsample_initial_channel=16     , upsample_rates=[2, 2]     , upsample_kernel_sizes=[4, 4]     , resblock_kernel_sizes=[3, 7]     , resblock_dilation_sizes=[[1, 3, 5], [1, 3, 5]]     , normalize_before=SCREAMING_SNAKE_CASE__     , )

											SCREAMING_SNAKE_CASE__		: int     =     SpeechTaHifiGan(SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Dict     =     {
											    """unet""": unet,
											    """scheduler""": scheduler,
											    """vae""": vae,
											    """text_encoder""": text_encoder,
											    """tokenizer""": tokenizer,
											    """vocoder""": vocoder,
											}
											return components



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__=0					)      ->	Dict:



											"""simple docstring"""




											if str(SCREAMING_SNAKE_CASE__					).startswith("""mps"""					):
																		SCREAMING_SNAKE_CASE__		: Any     =     torch.manual_seed(SCREAMING_SNAKE_CASE__					)
											else:
																		SCREAMING_SNAKE_CASE__		: List[Any]     =     torch.Generator(device=SCREAMING_SNAKE_CASE__					).manual_seed(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Any     =     {
											    """prompt""": """A hammer hitting a wooden surface""",
											    """generator""": generator,
											    """num_inference_steps""": 2,
											    """guidance_scale""": 6.0,
											}
											return inputs



				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: List[Any]     =     """cpu"""  # ensure determinism for the device-dependent torch.Generator

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     self.get_dummy_components()
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     AudioLDMPipeline(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: List[Any]     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											audioldm_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     self.get_dummy_inputs(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: List[str]     =     audioldm_pipe(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: List[str]     =     output.audios[0]

											assert audio.ndim == 1
											assert len(SCREAMING_SNAKE_CASE__					) == 2_56

											SCREAMING_SNAKE_CASE__		: int     =     audio[:10]
											SCREAMING_SNAKE_CASE__		: str     =     np.array(
											    [-0.0050, 0.0050, -0.0060, 0.0033, -0.0026, 0.0033, -0.0027, 0.0033, -0.0028, 0.0033]					)

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



				def 			__magic_name__					(self					)      ->	str:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: int     =     self.get_dummy_components()
											SCREAMING_SNAKE_CASE__		: Tuple     =     AudioLDMPipeline(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Any     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: List[Any]     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											audioldm_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: List[str]     =     self.get_dummy_inputs(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Dict     =     3 * [inputs["""prompt"""]]

											# forward
											SCREAMING_SNAKE_CASE__		: Tuple     =     audioldm_pipe(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: List[Any]     =     output.audios[0]

											SCREAMING_SNAKE_CASE__		: Optional[int]     =     self.get_dummy_inputs(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Dict     =     3 * [inputs.pop("""prompt"""					)]

											SCREAMING_SNAKE_CASE__		: str     =     audioldm_pipe.tokenizer(
											    SCREAMING_SNAKE_CASE__     , padding="""max_length"""     , max_length=audioldm_pipe.tokenizer.model_max_length     , truncation=SCREAMING_SNAKE_CASE__     , return_tensors="""pt"""     , )
											SCREAMING_SNAKE_CASE__		: Tuple     =     text_inputs["""input_ids"""].to(SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Dict     =     audioldm_pipe.text_encoder(
											    SCREAMING_SNAKE_CASE__     , )
											SCREAMING_SNAKE_CASE__		: int     =     prompt_embeds.text_embeds
											# additional L_2 normalization over each hidden-state
											SCREAMING_SNAKE_CASE__		: Tuple     =     F.normalize(SCREAMING_SNAKE_CASE__     , dim=-1					)

											SCREAMING_SNAKE_CASE__		: int     =     prompt_embeds

											# forward
											SCREAMING_SNAKE_CASE__		: List[str]     =     audioldm_pipe(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     output.audios[0]

											assert np.abs(audio_a - audio_a					).max() < 1E-2



				def 			__magic_name__					(self					)      ->	Dict:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Dict     =     self.get_dummy_components()
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     AudioLDMPipeline(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: List[str]     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											audioldm_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: str     =     self.get_dummy_inputs(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     3 * ["""this is a negative prompt"""]
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     negative_prompt
											SCREAMING_SNAKE_CASE__		: Tuple     =     3 * [inputs["""prompt"""]]

											# forward
											SCREAMING_SNAKE_CASE__		: Any     =     audioldm_pipe(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: List[str]     =     output.audios[0]

											SCREAMING_SNAKE_CASE__		: Any     =     self.get_dummy_inputs(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     3 * [inputs.pop("""prompt"""					)]

											SCREAMING_SNAKE_CASE__		: Dict     =     []
											for p in [prompt, negative_prompt]:
																		SCREAMING_SNAKE_CASE__		: Dict     =     audioldm_pipe.tokenizer(
																		    SCREAMING_SNAKE_CASE__     , padding="""max_length"""     , max_length=audioldm_pipe.tokenizer.model_max_length     , truncation=SCREAMING_SNAKE_CASE__     , return_tensors="""pt"""     , )
																		SCREAMING_SNAKE_CASE__		: Any     =     text_inputs["""input_ids"""].to(SCREAMING_SNAKE_CASE__					)

																		SCREAMING_SNAKE_CASE__		: Any     =     audioldm_pipe.text_encoder(
																		    SCREAMING_SNAKE_CASE__     , )
																		SCREAMING_SNAKE_CASE__		: List[str]     =     text_embeds.text_embeds
																		# additional L_2 normalization over each hidden-state
																		SCREAMING_SNAKE_CASE__		: int     =     F.normalize(SCREAMING_SNAKE_CASE__     , dim=-1					)

																		embeds.append(SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: Tuple     =     embeds

											# forward
											SCREAMING_SNAKE_CASE__		: Any     =     audioldm_pipe(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Dict     =     output.audios[0]

											assert np.abs(audio_a - audio_a					).max() < 1E-2



				def 			__magic_name__					(self					)      ->	Optional[Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Tuple     =     """cpu"""  # ensure determinism for the device-dependent torch.Generator
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     self.get_dummy_components()
											SCREAMING_SNAKE_CASE__		: Any     =     PNDMScheduler(skip_prk_steps=SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: int     =     AudioLDMPipeline(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Dict     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											audioldm_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: int     =     self.get_dummy_inputs(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: int     =     """egg cracking"""
											SCREAMING_SNAKE_CASE__		: Tuple     =     audioldm_pipe(**SCREAMING_SNAKE_CASE__     , negative_prompt=SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Any     =     output.audios[0]

											assert audio.ndim == 1
											assert len(SCREAMING_SNAKE_CASE__					) == 2_56

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     audio[:10]
											SCREAMING_SNAKE_CASE__		: str     =     np.array(
											    [-0.0051, 0.0050, -0.0060, 0.0034, -0.0026, 0.0033, -0.0027, 0.0033, -0.0028, 0.0032]					)

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



				def 			__magic_name__					(self					)      ->	Tuple:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: int     =     """cpu"""  # ensure determinism for the device-dependent torch.Generator
											SCREAMING_SNAKE_CASE__		: Dict     =     self.get_dummy_components()
											SCREAMING_SNAKE_CASE__		: str     =     PNDMScheduler(skip_prk_steps=SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Dict     =     AudioLDMPipeline(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Any     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											audioldm_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     """A hammer hitting a wooden surface"""

											# test num_waveforms_per_prompt=1 (default)
											SCREAMING_SNAKE_CASE__		: List[Any]     =     audioldm_pipe(SCREAMING_SNAKE_CASE__     , num_inference_steps=2					).audios

											assert audios.shape == (1, 2_56)

											# test num_waveforms_per_prompt=1 (default) for batch of prompts
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     2
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     audioldm_pipe([prompt] * batch_size     , num_inference_steps=2					).audios

											assert audios.shape == (batch_size, 2_56)

											# test num_waveforms_per_prompt for single prompt
											SCREAMING_SNAKE_CASE__		: Any     =     2
											SCREAMING_SNAKE_CASE__		: Any     =     audioldm_pipe(SCREAMING_SNAKE_CASE__     , num_inference_steps=2     , num_waveforms_per_prompt=SCREAMING_SNAKE_CASE__					).audios

											assert audios.shape == (num_waveforms_per_prompt, 2_56)

											# test num_waveforms_per_prompt for batch of prompts
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     2
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     audioldm_pipe(
											    [prompt] * batch_size     , num_inference_steps=2     , num_waveforms_per_prompt=SCREAMING_SNAKE_CASE__					).audios

											assert audios.shape == (batch_size * num_waveforms_per_prompt, 2_56)



				def 			__magic_name__					(self					)      ->	Any:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Optional[int]     =     """cpu"""  # ensure determinism for the device-dependent torch.Generator
											SCREAMING_SNAKE_CASE__		: Tuple     =     self.get_dummy_components()
											SCREAMING_SNAKE_CASE__		: Dict     =     AudioLDMPipeline(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											audioldm_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: int     =     audioldm_pipe.vocoder.config.sampling_rate

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     self.get_dummy_inputs(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     audioldm_pipe(audio_length_in_s=0.016     , **SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Tuple     =     output.audios[0]

											assert audio.ndim == 1
											assert len(SCREAMING_SNAKE_CASE__					) / vocoder_sampling_rate == 0.016

											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     audioldm_pipe(audio_length_in_s=0.032     , **SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     output.audios[0]

											assert audio.ndim == 1
											assert len(SCREAMING_SNAKE_CASE__					) / vocoder_sampling_rate == 0.032



				def 			__magic_name__					(self					)      ->	Any:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Optional[int]     =     self.get_dummy_components()
											SCREAMING_SNAKE_CASE__		: Dict     =     AudioLDMPipeline(**SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Any     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											audioldm_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Dict     =     ["""hey"""]

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     audioldm_pipe(SCREAMING_SNAKE_CASE__     , num_inference_steps=1					)
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     output.audios.shape
											assert audio_shape == (1, 2_56)

											SCREAMING_SNAKE_CASE__		: str     =     audioldm_pipe.vocoder.config
											config.model_in_dim *= 2
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     SpeechTaHifiGan(SCREAMING_SNAKE_CASE__					).to(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: int     =     audioldm_pipe(SCREAMING_SNAKE_CASE__     , num_inference_steps=1					)
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     output.audios.shape
											# waveform shape is unchanged, we just have 2x the number of mel channels in the spectrogram
											assert audio_shape == (1, 2_56)



				def 			__magic_name__					(self					)      ->	Any:



											"""simple docstring"""




											self._test_attention_slicing_forward_pass(test_mean_pixel_difference=SCREAMING_SNAKE_CASE__					)



				def 			__magic_name__					(self					)      ->	Tuple:



											"""simple docstring"""




											self._test_inference_batch_single_identical(test_mean_pixel_difference=SCREAMING_SNAKE_CASE__					)



				@unittest.skipIf(
				    torch_device != """cuda""" or not is_xformers_available()     , reason="""XFormers attention is only available with CUDA and `xformers` installed"""     , )
				def 			__magic_name__					(self					)      ->	Optional[int]:



											"""simple docstring"""




											self._test_xformers_attention_forwardGenerator_pass(test_mean_pixel_difference=SCREAMING_SNAKE_CASE__					)






@slow
class 			lowerCAmelCase_		(unittest.TestCase						):


				"""simple docstring"""



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



											"""simple docstring"""




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



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__="cpu"     , SCREAMING_SNAKE_CASE__=torch.floataa     , SCREAMING_SNAKE_CASE__=0					)      ->	Optional[int]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: str     =     torch.Generator(device=SCREAMING_SNAKE_CASE__					).manual_seed(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     np.random.RandomState(SCREAMING_SNAKE_CASE__					).standard_normal((1, 8, 1_28, 16)					)
											SCREAMING_SNAKE_CASE__		: Tuple     =     torch.from_numpy(SCREAMING_SNAKE_CASE__					).to(device=SCREAMING_SNAKE_CASE__     , dtype=SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: int     =     {
											    """prompt""": """A hammer hitting a wooden surface""",
											    """latents""": latents,
											    """generator""": generator,
											    """num_inference_steps""": 3,
											    """guidance_scale""": 2.5,
											}
											return inputs



				def 			__magic_name__					(self					)      ->	Tuple:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: List[Any]     =     AudioLDMPipeline.from_pretrained("""cvssp/audioldm"""					)
											SCREAMING_SNAKE_CASE__		: int     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											audioldm_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     self.get_inputs(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: str     =     25
											SCREAMING_SNAKE_CASE__		: List[str]     =     audioldm_pipe(**SCREAMING_SNAKE_CASE__					).audios[0]

											assert audio.ndim == 1
											assert len(SCREAMING_SNAKE_CASE__					) == 8_19_20

											SCREAMING_SNAKE_CASE__		: List[Any]     =     audio[7_72_30:7_72_40]
											SCREAMING_SNAKE_CASE__		: int     =     np.array(
											    [-0.4884, -0.4607, 0.0023, 0.5007, 0.5896, 0.5151, 0.3813, -0.0208, -0.3687, -0.4315]					)
											SCREAMING_SNAKE_CASE__		: int     =     np.abs(expected_slice - audio_slice					).max()
											assert max_diff < 1E-2



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



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: str     =     AudioLDMPipeline.from_pretrained("""cvssp/audioldm"""					)
											SCREAMING_SNAKE_CASE__		: List[Any]     =     LMSDiscreteScheduler.from_config(audioldm_pipe.scheduler.config					)
											SCREAMING_SNAKE_CASE__		: int     =     audioldm_pipe.to(SCREAMING_SNAKE_CASE__					)
											audioldm_pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: List[Any]     =     self.get_inputs(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Tuple     =     audioldm_pipe(**SCREAMING_SNAKE_CASE__					).audios[0]

											assert audio.ndim == 1
											assert len(SCREAMING_SNAKE_CASE__					) == 8_19_20

											SCREAMING_SNAKE_CASE__		: Any     =     audio[2_77_80:2_77_90]
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     np.array([-0.2131, -0.0873, -0.0124, -0.0189, 0.0569, 0.1373, 0.1883, 0.2886, 0.3297, 0.2212]					)
											SCREAMING_SNAKE_CASE__		: str     =     np.abs(expected_slice - audio_slice					).max()
											assert max_diff < 3E-2






"""simple docstring"""




import copy
from collections import OrderedDict
from typing import Dict, Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


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

UpperCAmelCase__   :					str												=				{
    'facebook/detr-resnet-50': 'https://huggingface.co/facebook/detr-resnet-50/resolve/main/config.json',
    # See all DETR models at https://huggingface.co/models?filter=detr
}



class 			lowerCAmelCase_		(a__						):


				"""simple docstring"""



				__UpperCamelCase   :		List[Any]       =     '''detr'''
				__UpperCamelCase   :		List[Any]       =     ['''past_key_values''']
				__UpperCamelCase   :		List[Any]       =     {
				    '''hidden_size''': '''d_model''',
				    '''num_attention_heads''': '''encoder_attention_heads''',
				}



				def __init__(self     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=None     , SCREAMING_SNAKE_CASE__=3     , SCREAMING_SNAKE_CASE__=1_00     , SCREAMING_SNAKE_CASE__=6     , SCREAMING_SNAKE_CASE__=20_48     , SCREAMING_SNAKE_CASE__=8     , SCREAMING_SNAKE_CASE__=6     , SCREAMING_SNAKE_CASE__=20_48     , SCREAMING_SNAKE_CASE__=8     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__="relu"     , SCREAMING_SNAKE_CASE__=2_56     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=0.02     , SCREAMING_SNAKE_CASE__=1.0     , SCREAMING_SNAKE_CASE__=False     , SCREAMING_SNAKE_CASE__="sine"     , SCREAMING_SNAKE_CASE__="resnet50"     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=False     , SCREAMING_SNAKE_CASE__=1     , SCREAMING_SNAKE_CASE__=5     , SCREAMING_SNAKE_CASE__=2     , SCREAMING_SNAKE_CASE__=1     , SCREAMING_SNAKE_CASE__=1     , SCREAMING_SNAKE_CASE__=5     , SCREAMING_SNAKE_CASE__=2     , SCREAMING_SNAKE_CASE__=0.1     , **SCREAMING_SNAKE_CASE__     , )      ->	Optional[Any]:



											"""simple docstring"""




											if backbone_config is not None and use_timm_backbone:
																		raise ValueError("""You can't specify both `backbone_config` and `use_timm_backbone`."""					)

											if not use_timm_backbone:
																		if backbone_config is None:
																									logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""					)
																									SCREAMING_SNAKE_CASE__		: Any     =     CONFIG_MAPPING["""resnet"""](out_features=["""stage4"""]					)
																		elif isinstance(SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					):
																									SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     backbone_config.get("""model_type"""					)
																									SCREAMING_SNAKE_CASE__		: int     =     CONFIG_MAPPING[backbone_model_type]
																									SCREAMING_SNAKE_CASE__		: str     =     config_class.from_dict(SCREAMING_SNAKE_CASE__					)
																		# set timm attributes to None
																		SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: List[str]     =     None, None, None

											SCREAMING_SNAKE_CASE__		: Optional[int]     =     use_timm_backbone
											SCREAMING_SNAKE_CASE__		: Tuple     =     backbone_config
											SCREAMING_SNAKE_CASE__		: List[Any]     =     num_channels
											SCREAMING_SNAKE_CASE__		: Tuple     =     num_queries
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     d_model
											SCREAMING_SNAKE_CASE__		: str     =     encoder_ffn_dim
											SCREAMING_SNAKE_CASE__		: str     =     encoder_layers
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     encoder_attention_heads
											SCREAMING_SNAKE_CASE__		: Any     =     decoder_ffn_dim
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     decoder_layers
											SCREAMING_SNAKE_CASE__		: Dict     =     decoder_attention_heads
											SCREAMING_SNAKE_CASE__		: List[str]     =     dropout
											SCREAMING_SNAKE_CASE__		: Tuple     =     attention_dropout
											SCREAMING_SNAKE_CASE__		: Tuple     =     activation_dropout
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     activation_function
											SCREAMING_SNAKE_CASE__		: Any     =     init_std
											SCREAMING_SNAKE_CASE__		: Dict     =     init_xavier_std
											SCREAMING_SNAKE_CASE__		: Any     =     encoder_layerdrop
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     decoder_layerdrop
											SCREAMING_SNAKE_CASE__		: Dict     =     encoder_layers
											SCREAMING_SNAKE_CASE__		: List[str]     =     auxiliary_loss
											SCREAMING_SNAKE_CASE__		: List[Any]     =     position_embedding_type
											SCREAMING_SNAKE_CASE__		: List[str]     =     backbone
											SCREAMING_SNAKE_CASE__		: Dict     =     use_pretrained_backbone
											SCREAMING_SNAKE_CASE__		: Any     =     dilation
											# Hungarian matcher
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     class_cost
											SCREAMING_SNAKE_CASE__		: Tuple     =     bbox_cost
											SCREAMING_SNAKE_CASE__		: List[Any]     =     giou_cost
											# Loss coefficients
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     mask_loss_coefficient
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     dice_loss_coefficient
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     bbox_loss_coefficient
											SCREAMING_SNAKE_CASE__		: Any     =     giou_loss_coefficient
											SCREAMING_SNAKE_CASE__		: List[str]     =     eos_coefficient
											super().__init__(is_encoder_decoder=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)



				@property
				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											return self.encoder_attention_heads



				@property
				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											return self.d_model



				@classmethod
				def 			__magic_name__					(cls     , SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)      ->	Tuple:



											"""simple docstring"""




											return cls(backbone_config=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)



				def 			__magic_name__					(self					)      ->	Dict[str, any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Dict     =     copy.deepcopy(self.__dict__					)
											if output["backbone_config"] is not None:
																		SCREAMING_SNAKE_CASE__		: Any     =     self.backbone_config.to_dict()
											SCREAMING_SNAKE_CASE__		: Dict     =     self.__class__.model_type
											return output






class 			lowerCAmelCase_		(a__						):


				"""simple docstring"""



				__UpperCamelCase   :		Any       =     version.parse('''1.11'''						)



				@property
				def 			__magic_name__					(self					)      ->	Mapping[str, Mapping[int, str]]:



											"""simple docstring"""




											return OrderedDict(
											    [
											        ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
											        ("""pixel_mask""", {0: """batch"""}),
											    ]					)



				@property
				def 			__magic_name__					(self					)      ->	float:



											"""simple docstring"""




											return 1E-5



				@property
				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											return 12




