





"""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 				__lowercase			(			_UpperCamelCase   ,      unittest.TestCase							):







					'''simple docstring'''




					__lowerCAmelCase  =  DanceDiffusionPipeline
					__lowerCAmelCase  =  UNCONDITIONAL_AUDIO_GENERATION_PARAMS
					__lowerCAmelCase  =  PipelineTesterMixin.required_optional_params - {
					    '''callback''',
					    '''latents''',
					    '''callback_steps''',
					    '''output_type''',
					    '''num_images_per_prompt''',
					}
					__lowerCAmelCase  =  UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS
					__lowerCAmelCase  =  False
					__lowerCAmelCase  =  False







					def  _lowerCamelCase		(						self     ):
									torch.manual_seed(0     )
									__a :						List[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=_UpperCAmelCase	,			use_timestep_embedding=_UpperCAmelCase	,			time_embedding_type='''fourier'''	,			mid_block_type='''UNetMidBlock1D'''	,			down_block_types=('''DownBlock1DNoSkip''', '''DownBlock1D''', '''AttnDownBlock1D''')	,			up_block_types=('''AttnUpBlock1D''', '''UpBlock1D''', '''UpBlock1DNoSkip''')	,			)
									__a :						int			       =  IPNDMScheduler()

									__a :						Any			       =  {
									    '''unet''': unet,
									    '''scheduler''': scheduler,
									}
									return components







					def  _lowerCamelCase		(						self	,			_UpperCAmelCase	,			_UpperCAmelCase=0     ):
									if str(_UpperCAmelCase     ).startswith('''mps'''     ):
													__a :						Dict			       =  torch.manual_seed(_UpperCAmelCase     )
									else:
													__a :						Any			       =  torch.Generator(device=_UpperCAmelCase     ).manual_seed(_UpperCAmelCase     )
									__a :						Any			       =  {
									    '''batch_size''': 1,
									    '''generator''': generator,
									    '''num_inference_steps''': 4,
									}
									return inputs







					def  _lowerCamelCase		(						self     ):
									__a :						Tuple			       =  '''cpu'''  # ensure determinism for the device-dependent torch.Generator
									__a :						Optional[Any]			       =  self.get_dummy_components()
									__a :						Union[str, Any]			       =  DanceDiffusionPipeline(**_UpperCAmelCase     )
									__a :						int			       =  pipe.to(_UpperCAmelCase     )
									pipe.set_progress_bar_config(disable=_UpperCAmelCase     )

									__a :						int			       =  self.get_dummy_inputs(_UpperCAmelCase     )
									__a :						Dict			       =  pipe(**_UpperCAmelCase     )
									__a :						List[Any]			       =  output.audios

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

									assert audio.shape == (1, 2, components["unet"].sample_size)
									__a :						Optional[Any]			       =  np.array([-0.7_2_6_5, 1.0_0_0_0, -0.8_3_8_8, 0.1_1_7_5, 0.9_4_9_8, -1.0_0_0_0]     )
									assert np.abs(audio_slice.flatten() - expected_slice     ).max() < 1e-2







					@skip_mps
					def  _lowerCamelCase		(						self     ):
									return super().test_save_load_local()







					@skip_mps
					def  _lowerCamelCase		(						self     ):
									return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3e-3     )







					@skip_mps
					def  _lowerCamelCase		(						self     ):
									return super().test_save_load_optional_components()







					@skip_mps
					def  _lowerCamelCase		(						self     ):
									return super().test_attention_slicing_forward_pass()







					def  _lowerCamelCase		(						self     ):
									super().test_inference_batch_single_identical(expected_max_diff=3e-3     )






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







					'''simple docstring'''




					def  _lowerCamelCase		(						self     ):
									# clean up the VRAM after each test
									super().tearDown()
									gc.collect()
									torch.cuda.empty_cache()







					def  _lowerCamelCase		(						self     ):
									__a :						Tuple			       =  torch_device

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

									__a :						Tuple			       =  torch.manual_seed(0     )
									__a :						Optional[int]			       =  pipe(generator=_UpperCAmelCase	,			num_inference_steps=100	,			audio_length_in_s=4.0_9_6     )
									__a :						Any			       =  output.audios

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

									assert audio.shape == (1, 2, pipe.unet.sample_size)
									__a :						Dict			       =  np.array([-0.0_1_9_2, -0.0_2_3_1, -0.0_3_1_8, -0.0_0_5_9, 0.0_0_0_2, -0.0_0_2_0]     )

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







					def  _lowerCamelCase		(						self     ):
									__a :						List[str]			       =  torch_device

									__a :						int			       =  DanceDiffusionPipeline.from_pretrained('''harmonai/maestro-150k'''	,			torch_dtype=torch.floataa     )
									__a :						Tuple			       =  pipe.to(_UpperCAmelCase     )
									pipe.set_progress_bar_config(disable=_UpperCAmelCase     )

									__a :						Optional[Any]			       =  torch.manual_seed(0     )
									__a :						Optional[Any]			       =  pipe(generator=_UpperCAmelCase	,			num_inference_steps=100	,			audio_length_in_s=4.0_9_6     )
									__a :						Any			       =  output.audios

									__a :						Optional[Any]			       =  audio[0, -3:, -3:]

									assert audio.shape == (1, 2, pipe.unet.sample_size)
									__a :						str			       =  np.array([-0.0_3_6_7, -0.0_4_8_8, -0.0_7_7_1, -0.0_5_2_5, -0.0_4_4_4, -0.0_3_4_1]     )

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






"""simple docstring"""






def     __A      (			a_						:float   ,       a_						:float)		->		float:
				return price * (1 + tax_rate)


if __name__ == "__main__":
		print(F'{price_plus_tax(100, 0.25) = }')
		print(F'{price_plus_tax(125.50, 0.05) = }')