




'''simple docstring'''







from ..utils import DummyObject, requires_backends







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     Any          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				Tuple:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Tuple:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Dict:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     Optional[int]          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				List[Any]:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				List[str]:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				str:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     Any          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				Any:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				List[Any]:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Any:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     List[str]          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				Optional[Any]:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Dict:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				int:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     int          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				Optional[int]:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Optional[Any]:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				List[str]:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     Dict          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				Optional[Any]:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				List[Any]:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				int:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     Union[str, Any]          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				List[str]:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Optional[Any]:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				str:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     Optional[Any]          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				str:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				str:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Union[str, Any]:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     List[Any]          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				Union[str, Any]:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Any:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Optional[Any]:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     Dict          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				Dict:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				List[str]:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Optional[Any]:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     List[str]          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				Tuple:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Tuple:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Optional[int]:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     Tuple          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				List[str]:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Union[str, Any]:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				Dict:
          requires_backends(cls							,["""flax"""]							)







class 					_a (metaclass=a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     Tuple          =					["""flax"""]







     def __init__(				self							,*__a							,**__a							)      ->				Tuple:
          requires_backends(self							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				List[str]:
          requires_backends(cls							,["""flax"""]							)







     @classmethod
     def 			snake_case_      (				cls							,*__a							,**__a							)      ->				int:
          requires_backends(cls							,["""flax"""]							)









'''simple docstring'''







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 (a__,		unittest.TestCase	):





     '''simple docstring'''



     lowerCAmelCase_  :     Dict          =					DanceDiffusionPipeline
     lowerCAmelCase_  :     int          =					UNCONDITIONAL_AUDIO_GENERATION_PARAMS
     lowerCAmelCase_  :     Optional[int]          =					PipelineTesterMixin.required_optional_params - {
         """callback""",
         """latents""",
         """callback_steps""",
         """output_type""",
         """num_images_per_prompt""",
     }
     lowerCAmelCase_  :     Tuple          =					UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS
     lowerCAmelCase_  :     Dict          =					False
     lowerCAmelCase_  :     Tuple          =					False







     def 			snake_case_      (				self							)      ->				List[Any]:
          torch.manual_seed(0							)
          snake_case			:      List[str]        =			UNetaDModel(
              block_out_channels=(32, 32, 64)							,extra_in_channels=16							,sample_size=512							,sample_rate=16_000							,in_channels=2							,out_channels=2							,flip_sin_to_cos=__a							,use_timestep_embedding=__a							,time_embedding_type="""fourier"""							,mid_block_type="""UNetMidBlock1D"""							,down_block_types=("""DownBlock1DNoSkip""", """DownBlock1D""", """AttnDownBlock1D""")							,up_block_types=("""AttnUpBlock1D""", """UpBlock1D""", """UpBlock1DNoSkip""")							,)
          snake_case			:      Dict        =			IPNDMScheduler()

          snake_case			:      int        =			{
              """unet""": unet,
              """scheduler""": scheduler,
          }
          return components







     def 			snake_case_      (				self							,__a							,__a=0							)      ->				Tuple:
          if str(__a							).startswith("""mps"""							):
               snake_case			:      Optional[Any]        =			torch.manual_seed(__a							)
          else:
               snake_case			:      Union[str, Any]        =			torch.Generator(device=__a							).manual_seed(__a							)
          snake_case			:      str        =			{
              """batch_size""": 1,
              """generator""": generator,
              """num_inference_steps""": 4,
          }
          return inputs







     def 			snake_case_      (				self							)      ->				Any:
          snake_case			:      Dict        =			"""cpu"""  # ensure determinism for the device-dependent torch.Generator
          snake_case			:      str        =			self.get_dummy_components()
          snake_case			:      List[str]        =			DanceDiffusionPipeline(**__a							)
          snake_case			:      Dict        =			pipe.to(__a							)
          pipe.set_progress_bar_config(disable=__a							)

          snake_case			:      Union[str, Any]        =			self.get_dummy_inputs(__a							)
          snake_case			:      str        =			pipe(**__a							)
          snake_case			:      Union[str, Any]        =			output.audios

          snake_case			:      List[str]        =			audio[0, -3:, -3:]

          assert audio.shape == (1, 2, components["unet"].sample_size)
          snake_case			:      Optional[Any]        =			np.array([-0.7_265, 1.0_000, -0.8_388, 0.1_175, 0.9_498, -1.0_000]							)
          assert np.abs(audio_slice.flatten() - expected_slice							).max() < 1E-2







     @skip_mps
     def 			snake_case_      (				self							)      ->				List[str]:
          return super().test_save_load_local()







     @skip_mps
     def 			snake_case_      (				self							)      ->				Union[str, Any]:
          return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3E-3							)







     @skip_mps
     def 			snake_case_      (				self							)      ->				Dict:
          return super().test_save_load_optional_components()







     @skip_mps
     def 			snake_case_      (				self							)      ->				Any:
          return super().test_attention_slicing_forward_pass()







     def 			snake_case_      (				self							)      ->				str:
          super().test_inference_batch_single_identical(expected_max_diff=3E-3							)







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





     '''simple docstring'''



     def 			snake_case_      (				self							)      ->				Optional[int]:
          # clean up the VRAM after each test
          super().tearDown()
          gc.collect()
          torch.cuda.empty_cache()







     def 			snake_case_      (				self							)      ->				List[Any]:
          snake_case			:      str        =			torch_device

          snake_case			:      List[str]        =			DanceDiffusionPipeline.from_pretrained("""harmonai/maestro-150k"""							)
          snake_case			:      Any        =			pipe.to(__a							)
          pipe.set_progress_bar_config(disable=__a							)

          snake_case			:      int        =			torch.manual_seed(0							)
          snake_case			:      int        =			pipe(generator=__a							,num_inference_steps=100							,audio_length_in_s=4.096							)
          snake_case			:      Dict        =			output.audios

          snake_case			:      Union[str, Any]        =			audio[0, -3:, -3:]

          assert audio.shape == (1, 2, pipe.unet.sample_size)
          snake_case			:      Tuple        =			np.array([-0.0_192, -0.0_231, -0.0_318, -0.0_059, 0.0_002, -0.0_020]							)

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







     def 			snake_case_      (				self							)      ->				str:
          snake_case			:      str        =			torch_device

          snake_case			:      List[Any]        =			DanceDiffusionPipeline.from_pretrained("""harmonai/maestro-150k"""							,torch_dtype=torch.floataa							)
          snake_case			:      str        =			pipe.to(__a							)
          pipe.set_progress_bar_config(disable=__a							)

          snake_case			:      str        =			torch.manual_seed(0							)
          snake_case			:      List[str]        =			pipe(generator=__a							,num_inference_steps=100							,audio_length_in_s=4.096							)
          snake_case			:      Optional[int]        =			output.audios

          snake_case			:      Any        =			audio[0, -3:, -3:]

          assert audio.shape == (1, 2, pipe.unet.sample_size)
          snake_case			:      Optional[int]        =			np.array([-0.0_367, -0.0_488, -0.0_771, -0.0_525, -0.0_444, -0.0_341]							)

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



