


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




							"""simple docstring"""


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

							def 					__snake_case      (							self :						str       )			->					str:
														torch.manual_seed(0       )
														__snake_case	:    Tuple											=     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")					,			)
														__snake_case	:    Optional[int]											=     IPNDMScheduler()

														__snake_case	:    str											=     {
														    "unet": unet,
														    "scheduler": scheduler,
														}
														return components

							def 					__snake_case      (							self :						List[str]					,			lowerCamelCase :						Dict					,			lowerCamelCase :						int=0       )			->					Optional[Any]:
														if str(lowerCamelCase       ).startswith("mps"       ):
																					__snake_case	:    str											=     torch.manual_seed(lowerCamelCase       )
														else:
																					__snake_case	:    Union[str, Any]											=     torch.Generator(device=lowerCamelCase       ).manual_seed(lowerCamelCase       )
														__snake_case	:    List[str]											=     {
														    "batch_size": 1,
														    "generator": generator,
														    "num_inference_steps": 4,
														}
														return inputs

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

														__snake_case	:    Union[str, Any]											=     self.get_dummy_inputs(lowerCamelCase       )
														__snake_case	:    str											=     pipe(**lowerCamelCase       )
														__snake_case	:    List[Any]											=     output.audios

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

														assert audio.shape == (1, 2, components["unet"].sample_size)
														__snake_case	:    Dict											=     np.array([-0.72_65, 1.00_00, -0.83_88, 0.11_75, 0.94_98, -1.00_00]       )
														assert np.abs(audio_slice.flatten() - expected_slice       ).max() < 1E-2

							@skip_mps
							def 					__snake_case      (							self :						Dict       )			->					Optional[int]:
														return super().test_save_load_local()

							@skip_mps
							def 					__snake_case      (							self :						int       )			->					Dict:
														return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3E-3       )

							@skip_mps
							def 					__snake_case      (							self :						Optional[Any]       )			->					Optional[Any]:
														return super().test_save_load_optional_components()

							@skip_mps
							def 					__snake_case      (							self :						Dict       )			->					str:
														return super().test_attention_slicing_forward_pass()






							def 					__snake_case      (							self :						Union[str, Any]       )			->					Any:
														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 :						Union[str, Any]       )			->					Any:
														# clean up the VRAM after each test
														super().tearDown()
														gc.collect()
														torch.cuda.empty_cache()

							def 					__snake_case      (							self :						Optional[int]       )			->					List[str]:
														__snake_case	:    int											=     torch_device

														__snake_case	:    Dict											=     DanceDiffusionPipeline.from_pretrained("harmonai/maestro-150k"       )
														__snake_case	:    Optional[int]											=     pipe.to(lowerCamelCase       )
														pipe.set_progress_bar_config(disable=lowerCamelCase       )

														__snake_case	:    List[str]											=     torch.manual_seed(0       )
														__snake_case	:    Tuple											=     pipe(generator=lowerCamelCase					,			num_inference_steps=100					,			audio_length_in_s=4.0_96       )
														__snake_case	:    Union[str, Any]											=     output.audios

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

														assert audio.shape == (1, 2, pipe.unet.sample_size)
														__snake_case	:    Tuple											=     np.array([-0.01_92, -0.02_31, -0.03_18, -0.00_59, 0.00_02, -0.00_20]       )

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






							def 					__snake_case      (							self :						int       )			->					str:
														__snake_case	:    int											=     torch_device

														__snake_case	:    Optional[int]											=     DanceDiffusionPipeline.from_pretrained("harmonai/maestro-150k"					,			torch_dtype=torch.floataa       )
														__snake_case	:    Tuple											=     pipe.to(lowerCamelCase       )
														pipe.set_progress_bar_config(disable=lowerCamelCase       )

														__snake_case	:    List[Any]											=     torch.manual_seed(0       )
														__snake_case	:    Optional[int]											=     pipe(generator=lowerCamelCase					,			num_inference_steps=100					,			audio_length_in_s=4.0_96       )
														__snake_case	:    Optional[int]											=     output.audios

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

														assert audio.shape == (1, 2, pipe.unet.sample_size)
														__snake_case	:    Optional[int]											=     np.array([-0.03_67, -0.04_88, -0.07_71, -0.05_25, -0.04_44, -0.03_41]       )

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





import unittest

from transformers import DonutProcessor


_snake_case  :	Dict			      =       "naver-clova-ix/donut-base"

class        a	(unittest.TestCase   ):




							"""simple docstring"""


							def 					__snake_case      (							self :						Dict       )			->					int:
														__snake_case	:    Any											=     DonutProcessor.from_pretrained(lowerCamelCase       )






							def 					__snake_case      (							self :						str       )			->					List[Any]:
														__snake_case	:    Union[str, Any]											=     {
														    "name": "John Doe",
														    "age": "99",
														    "city": "Atlanta",
														    "state": "GA",
														    "zip": "30301",
														    "phone": "123-4567",
														    "nicknames": [{"nickname": "Johnny"}, {"nickname": "JD"}],
														}

														__snake_case	:    Union[str, Any]											=     (
														    "<s_name>John Doe</s_name><s_age>99</s_age><s_city>Atlanta</s_city>"
														    "<s_state>GA</s_state><s_zip>30301</s_zip><s_phone>123-4567</s_phone>"
														    "<s_nicknames><s_nickname>Johnny</s_nickname>"
														    "<sep/><s_nickname>JD</s_nickname></s_nicknames>"
														)
														__snake_case	:    Tuple											=     self.processor.tokenajson(lowerCamelCase       )

														self.assertDictEqual(lowerCamelCase					,			lowerCamelCase       )

