
"""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    _UpperCAmelCase(   lowerCamelCase				,					unittest.TestCase     ):
		lowercase__      =				DanceDiffusionPipeline
		lowercase__      =				UNCONDITIONAL_AUDIO_GENERATION_PARAMS
		lowercase__      =				PipelineTesterMixin.required_optional_params - {
		    'callback',
		    'latents',
		    'callback_steps',
		    'output_type',
		    'num_images_per_prompt',
		}
		lowercase__      =				UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS
		lowercase__      =				False
		lowercase__      =				False



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






							'''simple docstring'''
							torch.manual_seed(0)
							_UpperCamelCase										=  UNetaDModel(
							    block_out_channels=(32, 32, 64)    ,		extra_in_channels=16    ,		sample_size=5_12    ,		sample_rate=1_60_00    ,		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''')    ,		)
							_UpperCamelCase										=  IPNDMScheduler()

							_UpperCamelCase										=  {
							    '''unet''': unet,
							    '''scheduler''': scheduler,
							}
							return components



		def 						UpperCAmelCase							( self    ,		__a    ,		__a=0)	->	Dict:






							'''simple docstring'''
							if str(__a).startswith('''mps'''):
												_UpperCamelCase										=  torch.manual_seed(__a)
							else:
												_UpperCamelCase										=  torch.Generator(device=__a).manual_seed(__a)
							_UpperCamelCase										=  {
							    '''batch_size''': 1,
							    '''generator''': generator,
							    '''num_inference_steps''': 4,
							}
							return inputs



		def 						UpperCAmelCase							( self)	->	Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase										=  '''cpu'''  # ensure determinism for the device-dependent torch.Generator
							_UpperCamelCase										=  self.get_dummy_components()
							_UpperCamelCase										=  DanceDiffusionPipeline(**__a)
							_UpperCamelCase										=  pipe.to(__a)
							pipe.set_progress_bar_config(disable=__a)

							_UpperCamelCase										=  self.get_dummy_inputs(__a)
							_UpperCamelCase										=  pipe(**__a)
							_UpperCamelCase										=  output.audios

							_UpperCamelCase										=  audio[0, -3:, -3:]

							assert audio.shape == (1, 2, components["unet"].sample_size)
							_UpperCamelCase										=  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 						UpperCAmelCase							( self)	->	List[str]:






							'''simple docstring'''
							return super().test_save_load_local()



		@skip_mps
		def 						UpperCAmelCase							( self)	->	List[Any]:






							'''simple docstring'''
							return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3e-3)



		@skip_mps
		def 						UpperCAmelCase							( self)	->	Any:






							'''simple docstring'''
							return super().test_save_load_optional_components()



		@skip_mps
		def 						UpperCAmelCase							( self)	->	List[str]:






							'''simple docstring'''
							return super().test_attention_slicing_forward_pass()




		def 						UpperCAmelCase							( self)	->	Any:






							'''simple docstring'''
							super().test_inference_batch_single_identical(expected_max_diff=3e-3)






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



		def 						UpperCAmelCase							( self)	->	Tuple:






							'''simple docstring'''
							# clean up the VRAM after each test
							super().tearDown()
							gc.collect()
							torch.cuda.empty_cache()



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






							'''simple docstring'''
							_UpperCamelCase										=  torch_device

							_UpperCamelCase										=  DanceDiffusionPipeline.from_pretrained('''harmonai/maestro-150k''')
							_UpperCamelCase										=  pipe.to(__a)
							pipe.set_progress_bar_config(disable=__a)

							_UpperCamelCase										=  torch.manual_seed(0)
							_UpperCamelCase										=  pipe(generator=__a    ,		num_inference_steps=1_00    ,		audio_length_in_s=4.096)
							_UpperCamelCase										=  output.audios

							_UpperCamelCase										=  audio[0, -3:, -3:]

							assert audio.shape == (1, 2, pipe.unet.sample_size)
							_UpperCamelCase										=  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 						UpperCAmelCase							( self)	->	List[Any]:






							'''simple docstring'''
							_UpperCamelCase										=  torch_device

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

							_UpperCamelCase										=  torch.manual_seed(0)
							_UpperCamelCase										=  pipe(generator=__a    ,		num_inference_steps=1_00    ,		audio_length_in_s=4.096)
							_UpperCamelCase										=  output.audios

							_UpperCamelCase										=  audio[0, -3:, -3:]

							assert audio.shape == (1, 2, pipe.unet.sample_size)
							_UpperCamelCase										=  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








"""simple docstring"""





from collections import OrderedDict
from typing import Mapping

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


_a														=		logging.get_logger(__name__)

_a														=		{
    """bert-base-uncased""": """https://huggingface.co/bert-base-uncased/resolve/main/config.json""",
    """bert-large-uncased""": """https://huggingface.co/bert-large-uncased/resolve/main/config.json""",
    """bert-base-cased""": """https://huggingface.co/bert-base-cased/resolve/main/config.json""",
    """bert-large-cased""": """https://huggingface.co/bert-large-cased/resolve/main/config.json""",
    """bert-base-multilingual-uncased""": """https://huggingface.co/bert-base-multilingual-uncased/resolve/main/config.json""",
    """bert-base-multilingual-cased""": """https://huggingface.co/bert-base-multilingual-cased/resolve/main/config.json""",
    """bert-base-chinese""": """https://huggingface.co/bert-base-chinese/resolve/main/config.json""",
    """bert-base-german-cased""": """https://huggingface.co/bert-base-german-cased/resolve/main/config.json""",
    """bert-large-uncased-whole-word-masking""": (
        """https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/config.json"""
    ),
    """bert-large-cased-whole-word-masking""": (
        """https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/config.json"""
    ),
    """bert-large-uncased-whole-word-masking-finetuned-squad""": (
        """https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/config.json"""
    ),
    """bert-large-cased-whole-word-masking-finetuned-squad""": (
        """https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/config.json"""
    ),
    """bert-base-cased-finetuned-mrpc""": """https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/config.json""",
    """bert-base-german-dbmdz-cased""": """https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/config.json""",
    """bert-base-german-dbmdz-uncased""": """https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/config.json""",
    """cl-tohoku/bert-base-japanese""": """https://huggingface.co/cl-tohoku/bert-base-japanese/resolve/main/config.json""",
    """cl-tohoku/bert-base-japanese-whole-word-masking""": (
        """https://huggingface.co/cl-tohoku/bert-base-japanese-whole-word-masking/resolve/main/config.json"""
    ),
    """cl-tohoku/bert-base-japanese-char""": (
        """https://huggingface.co/cl-tohoku/bert-base-japanese-char/resolve/main/config.json"""
    ),
    """cl-tohoku/bert-base-japanese-char-whole-word-masking""": (
        """https://huggingface.co/cl-tohoku/bert-base-japanese-char-whole-word-masking/resolve/main/config.json"""
    ),
    """TurkuNLP/bert-base-finnish-cased-v1""": (
        """https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/config.json"""
    ),
    """TurkuNLP/bert-base-finnish-uncased-v1""": (
        """https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/config.json"""
    ),
    """wietsedv/bert-base-dutch-cased""": """https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/config.json""",
    # See all BERT models at https://huggingface.co/models?filter=bert
}






class    _UpperCAmelCase(   lowerCamelCase     ):
		lowercase__      =				'bert'



		def __init__( self    ,		__a=3_05_22    ,		__a=7_68    ,		__a=12    ,		__a=12    ,		__a=30_72    ,		__a="gelu"    ,		__a=0.1    ,		__a=0.1    ,		__a=5_12    ,		__a=2    ,		__a=0.02    ,		__a=1e-12    ,		__a=0    ,		__a="absolute"    ,		__a=True    ,		__a=None    ,		**__a    ,		)	->	Optional[Any]:






							'''simple docstring'''
							super().__init__(pad_token_id=__a    ,		**__a)

							_UpperCamelCase										=  vocab_size
							_UpperCamelCase										=  hidden_size
							_UpperCamelCase										=  num_hidden_layers
							_UpperCamelCase										=  num_attention_heads
							_UpperCamelCase										=  hidden_act
							_UpperCamelCase										=  intermediate_size
							_UpperCamelCase										=  hidden_dropout_prob
							_UpperCamelCase										=  attention_probs_dropout_prob
							_UpperCamelCase										=  max_position_embeddings
							_UpperCamelCase										=  type_vocab_size
							_UpperCamelCase										=  initializer_range
							_UpperCamelCase										=  layer_norm_eps
							_UpperCamelCase										=  position_embedding_type
							_UpperCamelCase										=  use_cache
							_UpperCamelCase										=  classifier_dropout






class    _UpperCAmelCase(   lowerCamelCase     ):



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






							'''simple docstring'''
							if self.task == "multiple-choice":
												_UpperCamelCase										=  {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
							else:
												_UpperCamelCase										=  {0: '''batch''', 1: '''sequence'''}
							return OrderedDict(
							    [
							        ('''input_ids''', dynamic_axis),
							        ('''attention_mask''', dynamic_axis),
							        ('''token_type_ids''', dynamic_axis),
							    ])






