





import gc
import unittest

import numpy as np
import torch

from diffusers import DanceDiffusionPipeline, IPNDMScheduler, UNetaDModel
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS, UNCONDITIONAL_AUDIO_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()





class 				a			(      __lowercase   ,unittest.TestCase			):
				SCREAMING_SNAKE_CASE__     :   Union[str, Any]		      =     DanceDiffusionPipeline
				SCREAMING_SNAKE_CASE__     :   Optional[int]		      =     UNCONDITIONAL_AUDIO_GENERATION_PARAMS
				SCREAMING_SNAKE_CASE__     :   List[str]		      =     PipelineTesterMixin.required_optional_params - {
				    '''callback''',
				    '''latents''',
				    '''callback_steps''',
				    '''output_type''',
				    '''num_images_per_prompt''',
				}
				SCREAMING_SNAKE_CASE__     :   List[str]		      =     UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS
				SCREAMING_SNAKE_CASE__     :   int		      =     False
				SCREAMING_SNAKE_CASE__     :   int		      =     False






				def 			snake_case_    (  self					):

										"""simple docstring"""




										torch.manual_seed(0					)
										__SCREAMING_SNAKE_CASE:				Any           =   UNetaDModel(
										    block_out_channels=(32, 32, 64)			, extra_in_channels=16			, sample_size=512			, sample_rate=16000			, in_channels=2			, out_channels=2			, flip_sin_to_cos=_lowerCAmelCase			, use_timestep_embedding=_lowerCAmelCase			, time_embedding_type='''fourier'''			, mid_block_type='''UNetMidBlock1D'''			, down_block_types=('''DownBlock1DNoSkip''', '''DownBlock1D''', '''AttnDownBlock1D''')			, up_block_types=('''AttnUpBlock1D''', '''UpBlock1D''', '''UpBlock1DNoSkip''')			, )
										__SCREAMING_SNAKE_CASE:				List[Any]           =   IPNDMScheduler()

										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   {
										    '''unet''': unet,
										    '''scheduler''': scheduler,
										}
										return components






				def 			snake_case_    (  self			, _lowerCAmelCase			, _lowerCAmelCase=0					):

										"""simple docstring"""




										if str(_lowerCAmelCase					).startswith('''mps'''					):
																__SCREAMING_SNAKE_CASE:				Any           =   torch.manual_seed(_lowerCAmelCase					)
										else:
																__SCREAMING_SNAKE_CASE:				str           =   torch.Generator(device=_lowerCAmelCase					).manual_seed(_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Tuple           =   {
										    '''batch_size''': 1,
										    '''generator''': generator,
										    '''num_inference_steps''': 4,
										}
										return inputs






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[str]           =   '''cpu'''  # ensure determinism for the device-dependent torch.Generator
										__SCREAMING_SNAKE_CASE:				Dict           =   self.get_dummy_components()
										__SCREAMING_SNAKE_CASE:				Dict           =   DanceDiffusionPipeline(**_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				int           =   pipe.to(_lowerCAmelCase					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				int           =   self.get_dummy_inputs(_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				List[str]           =   pipe(**_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   output.audios

										__SCREAMING_SNAKE_CASE:				int           =   audio[0, -3:, -3:]

										assert audio.shape == (1, 2, components["unet"].sample_size)
										__SCREAMING_SNAKE_CASE:				List[str]           =   np.array([-0.7265, 1.0000, -0.8388, 0.1175, 0.9498, -1.0000]					)
										assert np.abs(audio_slice.flatten() - expected_slice					).max() < 1e-2






				@skip_mps
				def 			snake_case_    (  self					):

										"""simple docstring"""




										return super().test_save_load_local()






				@skip_mps
				def 			snake_case_    (  self					):

										"""simple docstring"""




										return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3e-3					)






				@skip_mps
				def 			snake_case_    (  self					):

										"""simple docstring"""




										return super().test_save_load_optional_components()






				@skip_mps
				def 			snake_case_    (  self					):

										"""simple docstring"""




										return super().test_attention_slicing_forward_pass()






				def 			snake_case_    (  self					):

										"""simple docstring"""




										super().test_inference_batch_single_identical(expected_max_diff=3e-3					)





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






				def 			snake_case_    (  self					):

										"""simple docstring"""




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






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				str           =   torch_device

										__SCREAMING_SNAKE_CASE:				List[Any]           =   DanceDiffusionPipeline.from_pretrained('''harmonai/maestro-150k'''					)
										__SCREAMING_SNAKE_CASE:				Any           =   pipe.to(_lowerCAmelCase					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				List[str]           =   torch.manual_seed(0					)
										__SCREAMING_SNAKE_CASE:				Dict           =   pipe(generator=_lowerCAmelCase			, num_inference_steps=100			, audio_length_in_s=4.096					)
										__SCREAMING_SNAKE_CASE:				List[Any]           =   output.audios

										__SCREAMING_SNAKE_CASE:				Dict           =   audio[0, -3:, -3:]

										assert audio.shape == (1, 2, pipe.unet.sample_size)
										__SCREAMING_SNAKE_CASE:				Any           =   np.array([-0.0192, -0.0231, -0.0318, -0.0059, 0.0002, -0.0020]					)

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






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				str           =   torch_device

										__SCREAMING_SNAKE_CASE:				List[Any]           =   DanceDiffusionPipeline.from_pretrained('''harmonai/maestro-150k'''			, torch_dtype=torch.floataa					)
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   pipe.to(_lowerCAmelCase					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				List[str]           =   torch.manual_seed(0					)
										__SCREAMING_SNAKE_CASE:				List[str]           =   pipe(generator=_lowerCAmelCase			, num_inference_steps=100			, audio_length_in_s=4.096					)
										__SCREAMING_SNAKE_CASE:				List[Any]           =   output.audios

										__SCREAMING_SNAKE_CASE:				Dict           =   audio[0, -3:, -3:]

										assert audio.shape == (1, 2, pipe.unet.sample_size)
										__SCREAMING_SNAKE_CASE:				Any           =   np.array([-0.0367, -0.0488, -0.0771, -0.0525, -0.0444, -0.0341]					)

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










from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


lowerCAmelCase							:       List[str]					 =	{
    """configuration_gpt_bigcode""": ["""GPT_BIGCODE_PRETRAINED_CONFIG_ARCHIVE_MAP""", """GPTBigCodeConfig"""],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowerCAmelCase							:       str					 =	[
							    """GPT_BIGCODE_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """GPTBigCodeForSequenceClassification""",
							    """GPTBigCodeForTokenClassification""",
							    """GPTBigCodeForCausalLM""",
							    """GPTBigCodeModel""",
							    """GPTBigCodePreTrainedModel""",
							]

if TYPE_CHECKING:
							from .configuration_gpt_bigcode import GPT_BIGCODE_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTBigCodeConfig

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_gpt_bigcode import (
														    GPT_BIGCODE_PRETRAINED_MODEL_ARCHIVE_LIST,
														    GPTBigCodeForCausalLM,
														    GPTBigCodeForSequenceClassification,
														    GPTBigCodeForTokenClassification,
														    GPTBigCodeModel,
														    GPTBigCodePreTrainedModel,
														)


else:
							import sys

							lowerCAmelCase							:       List[str]					 =	_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



