




'''simple docstring'''

import collections
import inspect
import unittest

from transformers import NatConfig
from transformers.testing_utils import require_natten, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch
		from torch import nn

		from transformers import NatBackbone, NatForImageClassification, NatModel
		from transformers.models.nat.modeling_nat import NAT_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
		from PIL import Image

		from transformers import AutoImageProcessor





class __magic_name__:






						def __init__(   self						:						Optional[int]					,   __UpperCamelCase						:						List[Any]					,   __UpperCamelCase						:						Union[str, Any]=1_3					,   __UpperCamelCase						:						str=6_4					,   __UpperCamelCase						:						Tuple=4					,   __UpperCamelCase						:						Union[str, Any]=3					,   __UpperCamelCase						:						Optional[Any]=1_6					,   __UpperCamelCase						:						Optional[Any]=[1, 2, 1]					,   __UpperCamelCase						:						Dict=[2, 4, 8]					,   __UpperCamelCase						:						str=3					,   __UpperCamelCase						:						Optional[Any]=2.0					,   __UpperCamelCase						:						List[str]=True					,   __UpperCamelCase						:						Union[str, Any]=0.0					,   __UpperCamelCase						:						int=0.0					,   __UpperCamelCase						:						Optional[int]=0.1					,   __UpperCamelCase						:						Optional[int]="gelu"					,   __UpperCamelCase						:						Union[str, Any]=True					,   __UpperCamelCase						:						Dict=0.02					,   __UpperCamelCase						:						List[str]=1E-5					,   __UpperCamelCase						:						Optional[Any]=True					,   __UpperCamelCase						:						Any=None					,   __UpperCamelCase						:						int=True					,   __UpperCamelCase						:						Any=1_0					,   __UpperCamelCase						:						Dict=["stage1", "stage2"]					,   __UpperCamelCase						:						Tuple=[1, 2]					,   ):



									'''simple docstring'''






									snake_case__          =						parent
									snake_case__          =						batch_size
									snake_case__          =						image_size
									snake_case__          =						patch_size
									snake_case__          =						num_channels
									snake_case__          =						embed_dim
									snake_case__          =						depths
									snake_case__          =						num_heads
									snake_case__          =						kernel_size
									snake_case__          =						mlp_ratio
									snake_case__          =						qkv_bias
									snake_case__          =						hidden_dropout_prob
									snake_case__          =						attention_probs_dropout_prob
									snake_case__          =						drop_path_rate
									snake_case__          =						hidden_act
									snake_case__          =						patch_norm
									snake_case__          =						layer_norm_eps
									snake_case__          =						initializer_range
									snake_case__          =						is_training
									snake_case__          =						scope
									snake_case__          =						use_labels
									snake_case__          =						num_labels
									snake_case__          =						out_features
									snake_case__          =						out_indices






						def       __lowerCAmelCase(   self						:						Optional[int]       ):



									'''simple docstring'''






									snake_case__          =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

									snake_case__          =						None
									if self.use_labels:
												snake_case__          =						ids_tensor([self.batch_size]					,   self.num_labels       )

									snake_case__          =						self.get_config()

									return config, pixel_values, labels






						def       __lowerCAmelCase(   self						:						Dict       ):



									'''simple docstring'''






									return NatConfig(
									    num_labels=self.num_labels					,   image_size=self.image_size					,   patch_size=self.patch_size					,   num_channels=self.num_channels					,   embed_dim=self.embed_dim					,   depths=self.depths					,   num_heads=self.num_heads					,   kernel_size=self.kernel_size					,   mlp_ratio=self.mlp_ratio					,   qkv_bias=self.qkv_bias					,   hidden_dropout_prob=self.hidden_dropout_prob					,   attention_probs_dropout_prob=self.attention_probs_dropout_prob					,   drop_path_rate=self.drop_path_rate					,   hidden_act=self.hidden_act					,   patch_norm=self.patch_norm					,   layer_norm_eps=self.layer_norm_eps					,   initializer_range=self.initializer_range					,   out_features=self.out_features					,   out_indices=self.out_indices					,   )






						def       __lowerCAmelCase(   self						:						Optional[Any]					,   __UpperCamelCase						:						Any					,   __UpperCamelCase						:						Union[str, Any]					,   __UpperCamelCase						:						Any       ):



									'''simple docstring'''






									snake_case__          =						NatModel(config=__UpperCamelCase       )
									model.to(__UpperCamelCase       )
									model.eval()
									snake_case__          =						model(__UpperCamelCase       )

									snake_case__          =						snake_case__          =						(config.image_size // config.patch_size) // (2 ** (len(config.depths       ) - 1))
									snake_case__          =						int(config.embed_dim * 2 ** (len(config.depths       ) - 1)       )

									self.parent.assertEqual(
									    result.last_hidden_state.shape					,   (self.batch_size, expected_height, expected_width, expected_dim)       )






						def       __lowerCAmelCase(   self						:						Union[str, Any]					,   __UpperCamelCase						:						Optional[Any]					,   __UpperCamelCase						:						Any					,   __UpperCamelCase						:						Any       ):



									'''simple docstring'''






									snake_case__          =						NatForImageClassification(__UpperCamelCase       )
									model.to(__UpperCamelCase       )
									model.eval()
									snake_case__          =						model(__UpperCamelCase					,   labels=__UpperCamelCase       )
									self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.num_labels)       )

									# test greyscale images
									snake_case__          =						1
									snake_case__          =						NatForImageClassification(__UpperCamelCase       )
									model.to(__UpperCamelCase       )
									model.eval()

									snake_case__          =						floats_tensor([self.batch_size, 1, self.image_size, self.image_size]       )
									snake_case__          =						model(__UpperCamelCase       )
									self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.num_labels)       )






						def       __lowerCAmelCase(   self						:						Optional[Any]					,   __UpperCamelCase						:						List[str]					,   __UpperCamelCase						:						Dict					,   __UpperCamelCase						:						str       ):



									'''simple docstring'''






									snake_case__          =						NatBackbone(config=__UpperCamelCase       )
									model.to(__UpperCamelCase       )
									model.eval()
									snake_case__          =						model(__UpperCamelCase       )

									# verify hidden states
									self.parent.assertEqual(len(result.feature_maps       )					,   len(config.out_features       )       )
									self.parent.assertListEqual(list(result.feature_maps[0].shape       )					,   [self.batch_size, model.channels[0], 1_6, 1_6]       )

									# verify channels
									self.parent.assertEqual(len(model.channels       )					,   len(config.out_features       )       )

									# verify backbone works with out_features=None
									snake_case__          =						None
									snake_case__          =						NatBackbone(config=__UpperCamelCase       )
									model.to(__UpperCamelCase       )
									model.eval()
									snake_case__          =						model(__UpperCamelCase       )

									# verify feature maps
									self.parent.assertEqual(len(result.feature_maps       )					,   1       )
									self.parent.assertListEqual(list(result.feature_maps[0].shape       )					,   [self.batch_size, model.channels[-1], 4, 4]       )

									# verify channels
									self.parent.assertEqual(len(model.channels       )					,   1       )







						def       __lowerCAmelCase(   self						:						Union[str, Any]       ):



									'''simple docstring'''






									snake_case__          =						self.prepare_config_and_inputs()
									snake_case__    ,			snake_case__    ,			snake_case__          =						config_and_inputs
									snake_case__          =						{"""pixel_values""": pixel_values}
									return config, inputs_dict







@require_natten
@require_torch
class __magic_name__(						__lowerCAmelCase    ,		__lowerCAmelCase    ,		unittest.TestCase      ):
						UpperCAmelCase_		:					Optional[int]    =  (
						    (
						        NatModel,
						        NatForImageClassification,
						        NatBackbone,
						    )
						    if is_torch_available()
						    else ()
						)
						UpperCAmelCase_		:					str    =  (
						    {"""feature-extraction""": NatModel, """image-classification""": NatForImageClassification}
						    if is_torch_available()
						    else {}
						)
						UpperCAmelCase_		:					List[Any]    =  False

						UpperCAmelCase_		:					Optional[Any]    =  False
						UpperCAmelCase_		:					List[Any]    =  False
						UpperCAmelCase_		:					Optional[int]    =  False
						UpperCAmelCase_		:					int    =  False






						def       __lowerCAmelCase(   self						:						Any       ):



									'''simple docstring'''






									snake_case__          =						NatModelTester(self       )
									snake_case__          =						ConfigTester(self					,   config_class=__UpperCamelCase					,   embed_dim=3_7       )






						def       __lowerCAmelCase(   self						:						Optional[int]       ):



									'''simple docstring'''






									self.create_and_test_config_common_properties()
									self.config_tester.create_and_test_config_to_json_string()
									self.config_tester.create_and_test_config_to_json_file()
									self.config_tester.create_and_test_config_from_and_save_pretrained()
									self.config_tester.create_and_test_config_with_num_labels()
									self.config_tester.check_config_can_be_init_without_params()
									self.config_tester.check_config_arguments_init()






						def       __lowerCAmelCase(   self						:						Any       ):



									'''simple docstring'''






									return






						def       __lowerCAmelCase(   self						:						int       ):



									'''simple docstring'''






									snake_case__          =						self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*__UpperCamelCase       )






						def       __lowerCAmelCase(   self						:						List[str]       ):



									'''simple docstring'''






									snake_case__          =						self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*__UpperCamelCase       )






						def       __lowerCAmelCase(   self						:						str       ):



									'''simple docstring'''






									snake_case__          =						self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_backbone(*__UpperCamelCase       )






						@unittest.skip(reason="""Nat does not use inputs_embeds"""       )
						def       __lowerCAmelCase(   self						:						str       ):



									'''simple docstring'''






									pass






						@unittest.skip(reason="""Nat does not use feedforward chunking"""       )
						def       __lowerCAmelCase(   self						:						Dict       ):



									'''simple docstring'''






									pass






						def       __lowerCAmelCase(   self						:						Dict       ):



									'''simple docstring'''






									snake_case__    ,			snake_case__          =						self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
												snake_case__          =						model_class(__UpperCamelCase       )
												self.assertIsInstance(model.get_input_embeddings()					,   (nn.Module)       )
												snake_case__          =						model.get_output_embeddings()
												self.assertTrue(x is None or isinstance(__UpperCamelCase					,   nn.Linear       )       )






						def       __lowerCAmelCase(   self						:						Union[str, Any]       ):



									'''simple docstring'''






									snake_case__    ,			snake_case__          =						self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
												snake_case__          =						model_class(__UpperCamelCase       )
												snake_case__          =						inspect.signature(model.forward       )
												# signature.parameters is an OrderedDict => so arg_names order is deterministic
												snake_case__          =						[*signature.parameters.keys()]

												snake_case__          =						["""pixel_values"""]
												self.assertListEqual(arg_names[:1]					,   __UpperCamelCase       )






						def       __lowerCAmelCase(   self						:						Union[str, Any]       ):



									'''simple docstring'''






									self.skipTest("""Nat's attention operation is handled entirely by NATTEN."""       )






						def       __lowerCAmelCase(   self						:						str					,   __UpperCamelCase						:						List[str]					,   __UpperCamelCase						:						Union[str, Any]					,   __UpperCamelCase						:						Optional[int]					,   __UpperCamelCase						:						Optional[int]       ):



									'''simple docstring'''






									snake_case__          =						model_class(__UpperCamelCase       )
									model.to(__UpperCamelCase       )
									model.eval()

									with torch.no_grad():
												snake_case__          =						model(**self._prepare_for_class(__UpperCamelCase					,   __UpperCamelCase       )       )

									snake_case__          =						outputs.hidden_states

									snake_case__          =						getattr(
									    self.model_tester					,   """expected_num_hidden_layers"""					,   len(self.model_tester.depths       ) + 1       )
									self.assertEqual(len(__UpperCamelCase       )					,   __UpperCamelCase       )

									# Nat has a different seq_length
									snake_case__          =						(
									    config.patch_size
									    if isinstance(config.patch_size					,   collections.abc.Iterable       )
									    else (config.patch_size, config.patch_size)
									)

									snake_case__          =						image_size[0] // patch_size[0]
									snake_case__          =						image_size[1] // patch_size[1]

									self.assertListEqual(
									    list(hidden_states[0].shape[-3:]       )					,   [height, width, self.model_tester.embed_dim]					,   )

									if model_class.__name__ != "NatBackbone":
												snake_case__          =						outputs.reshaped_hidden_states
												self.assertEqual(len(__UpperCamelCase       )					,   __UpperCamelCase       )

												snake_case__    ,			snake_case__    ,			snake_case__    ,			snake_case__          =						reshaped_hidden_states[0].shape
												snake_case__          =						(
												    reshaped_hidden_states[0].view(__UpperCamelCase					,   __UpperCamelCase					,   __UpperCamelCase					,   __UpperCamelCase       ).permute(0					,   2					,   3					,   1       )
												)
												self.assertListEqual(
												    list(reshaped_hidden_states.shape[-3:]       )					,   [height, width, self.model_tester.embed_dim]					,   )






						def       __lowerCAmelCase(   self						:						Dict       ):



									'''simple docstring'''






									snake_case__    ,			snake_case__          =						self.model_tester.prepare_config_and_inputs_for_common()

									snake_case__          =						(
									    self.model_tester.image_size
									    if isinstance(self.model_tester.image_size					,   collections.abc.Iterable       )
									    else (self.model_tester.image_size, self.model_tester.image_size)
									)

									for model_class in self.all_model_classes:
												snake_case__          =						True
												self.check_hidden_states_output(__UpperCamelCase					,   __UpperCamelCase					,   __UpperCamelCase					,   __UpperCamelCase       )

												# check that output_hidden_states also work using config
												del inputs_dict["output_hidden_states"]
												snake_case__          =						True

												self.check_hidden_states_output(__UpperCamelCase					,   __UpperCamelCase					,   __UpperCamelCase					,   __UpperCamelCase       )






						@slow
						def       __lowerCAmelCase(   self						:						str       ):



									'''simple docstring'''






									for model_name in NAT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												snake_case__          =						NatModel.from_pretrained(__UpperCamelCase       )
												self.assertIsNotNone(__UpperCamelCase       )







						def       __lowerCAmelCase(   self						:						str       ):



									'''simple docstring'''






									snake_case__    ,			snake_case__          =						self.model_tester.prepare_config_and_inputs_for_common()

									snake_case__          =						_config_zero_init(__UpperCamelCase       )
									for model_class in self.all_model_classes:
												snake_case__          =						model_class(config=__UpperCamelCase       )
												for name, param in model.named_parameters():
															if "embeddings" not in name and param.requires_grad:
																		self.assertIn(
																		    ((param.data.mean() * 1E9).round() / 1E9).item()					,   [0.0, 1.0]					,   msg=f"""Parameter {name} of model {model_class} seems not properly initialized"""					,   )







@require_natten
@require_vision
@require_torch
class __magic_name__(						unittest.TestCase      ):






						@cached_property
						def       __lowerCAmelCase(   self						:						List[str]       ):



									'''simple docstring'''






									return AutoImageProcessor.from_pretrained("""shi-labs/nat-mini-in1k-224"""       ) if is_vision_available() else None







						@slow
						def       __lowerCAmelCase(   self						:						List[str]       ):



									'''simple docstring'''






									snake_case__          =						NatForImageClassification.from_pretrained("""shi-labs/nat-mini-in1k-224"""       ).to(__UpperCamelCase       )
									snake_case__          =						self.default_image_processor

									snake_case__          =						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""       )
									snake_case__          =						image_processor(images=__UpperCamelCase					,   return_tensors="""pt"""       ).to(__UpperCamelCase       )

									# forward pass
									with torch.no_grad():
												snake_case__          =						model(**__UpperCamelCase       )

									# verify the logits
									snake_case__          =						torch.Size((1, 1_0_0_0)       )
									self.assertEqual(outputs.logits.shape					,   __UpperCamelCase       )
									snake_case__          =						torch.tensor([0.38_05, -0.86_76, -0.39_12]       ).to(__UpperCamelCase       )
									self.assertTrue(torch.allclose(outputs.logits[0, :3]					,   __UpperCamelCase					,   atol=1E-4       )       )







@require_torch
@require_natten
class __magic_name__(						unittest.TestCase    ,		__lowerCAmelCase      ):
						UpperCAmelCase_		:					str    =  (NatBackbone,) if is_torch_available() else ()
						UpperCAmelCase_		:					List[Any]    =  NatConfig






						def       __lowerCAmelCase(   self						:						Optional[Any]       ):



									'''simple docstring'''






									snake_case__          =						NatModelTester(self       )





'''simple docstring'''

import gc
import unittest

import numpy as np
import torch

from diffusers import DDPMScheduler, MidiProcessor, SpectrogramDiffusionPipeline
from diffusers.pipelines.spectrogram_diffusion import SpectrogramContEncoder, SpectrogramNotesEncoder, TaFilmDecoder
from diffusers.utils import require_torch_gpu, skip_mps, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_note_seq, require_onnxruntime

from ..pipeline_params import TOKENS_TO_AUDIO_GENERATION_BATCH_PARAMS, TOKENS_TO_AUDIO_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()


a__         =     '''./tests/fixtures/elise_format0.mid'''





@unittest.skip("""The note-seq package currently throws an error on import"""      )
class __magic_name__(						__lowerCAmelCase    ,		unittest.TestCase      ):
						UpperCAmelCase_		:					Tuple    =  SpectrogramDiffusionPipeline
						UpperCAmelCase_		:					List[str]    =  PipelineTesterMixin.required_optional_params - {
						    """callback""",
						    """latents""",
						    """callback_steps""",
						    """output_type""",
						    """num_images_per_prompt""",
						}
						UpperCAmelCase_		:					Dict    =  False
						UpperCAmelCase_		:					Dict    =  False
						UpperCAmelCase_		:					List[str]    =  TOKENS_TO_AUDIO_GENERATION_PARAMS
						UpperCAmelCase_		:					Union[str, Any]    =  TOKENS_TO_AUDIO_GENERATION_BATCH_PARAMS






						def       __lowerCAmelCase(   self						:						Tuple       ):



									'''simple docstring'''






									torch.manual_seed(0       )
									snake_case__          =						SpectrogramNotesEncoder(
									    max_length=2_0_4_8					,   vocab_size=1_5_3_6					,   d_model=7_6_8					,   dropout_rate=0.1					,   num_layers=1					,   num_heads=1					,   d_kv=4					,   d_ff=2_0_4_8					,   feed_forward_proj="""gated-gelu"""					,   )

									snake_case__          =						SpectrogramContEncoder(
									    input_dims=1_2_8					,   targets_context_length=2_5_6					,   d_model=7_6_8					,   dropout_rate=0.1					,   num_layers=1					,   num_heads=1					,   d_kv=4					,   d_ff=2_0_4_8					,   feed_forward_proj="""gated-gelu"""					,   )

									snake_case__          =						TaFilmDecoder(
									    input_dims=1_2_8					,   targets_length=2_5_6					,   max_decoder_noise_time=2_00_00.0					,   d_model=7_6_8					,   num_layers=1					,   num_heads=1					,   d_kv=4					,   d_ff=2_0_4_8					,   dropout_rate=0.1					,   )

									snake_case__          =						DDPMScheduler()

									snake_case__          =						{
									    """notes_encoder""": notes_encoder.eval(),
									    """continuous_encoder""": continuous_encoder.eval(),
									    """decoder""": decoder.eval(),
									    """scheduler""": scheduler,
									    """melgan""": None,
									}
									return components






						def       __lowerCAmelCase(   self						:						Tuple					,   __UpperCamelCase						:						Any					,   __UpperCamelCase						:						str=0       ):



									'''simple docstring'''






									if str(__UpperCamelCase       ).startswith("""mps"""       ):
												snake_case__          =						torch.manual_seed(__UpperCamelCase       )
									else:
												snake_case__          =						torch.Generator(device=__UpperCamelCase       ).manual_seed(__UpperCamelCase       )
									snake_case__          =						{
									    """input_tokens""": [
									        [1_1_3_4, 9_0, 1_1_3_5, 1_1_3_3, 1_0_8_0, 1_1_2, 1_1_3_2, 1_0_8_0, 1_1_3_3, 1_0_7_9, 1_3_3, 1_1_3_2, 1_0_7_9, 1_1_3_3, 1] + [0] * 2_0_3_3
									    ],
									    """generator""": generator,
									    """num_inference_steps""": 4,
									    """output_type""": """mel""",
									}
									return inputs






						def       __lowerCAmelCase(   self						:						Optional[Any]       ):



									'''simple docstring'''






									snake_case__          =						"""cpu"""  # ensure determinism for the device-dependent torch.Generator
									snake_case__          =						self.get_dummy_components()
									snake_case__          =						SpectrogramDiffusionPipeline(**__UpperCamelCase       )
									snake_case__          =						pipe.to(__UpperCamelCase       )
									pipe.set_progress_bar_config(disable=__UpperCamelCase       )

									snake_case__          =						self.get_dummy_inputs(__UpperCamelCase       )
									snake_case__          =						pipe(**__UpperCamelCase       )
									snake_case__          =						output.audios

									snake_case__          =						mel[0, -3:, -3:]

									assert mel_slice.shape == (3, 3)
									snake_case__          =						np.array(
									    [-11.51_29_25, -4.78_82_15, -0.46_17_29_05, -2.05_17_15, -10.53_91_47, -10.97_09_63, -9.09_16_34, 4.0, 4.0]       )
									assert np.abs(mel_slice.flatten() - expected_slice       ).max() < 1E-2






						@skip_mps
						def       __lowerCAmelCase(   self						:						Tuple       ):



									'''simple docstring'''






									return super().test_save_load_local()






						@skip_mps
						def       __lowerCAmelCase(   self						:						List[Any]       ):



									'''simple docstring'''






									return super().test_dict_tuple_outputs_equivalent()






						@skip_mps
						def       __lowerCAmelCase(   self						:						Optional[int]       ):



									'''simple docstring'''






									return super().test_save_load_optional_components()






						@skip_mps
						def       __lowerCAmelCase(   self						:						Union[str, Any]       ):



									'''simple docstring'''






									return super().test_attention_slicing_forward_pass()






						def       __lowerCAmelCase(   self						:						Dict       ):



									'''simple docstring'''






									pass






						def       __lowerCAmelCase(   self						:						int       ):



									'''simple docstring'''






									pass







						@skip_mps
						def       __lowerCAmelCase(   self						:						Dict       ):



									'''simple docstring'''






									return super().test_progress_bar()







@slow
@require_torch_gpu
@require_onnxruntime
@require_note_seq
class __magic_name__(						unittest.TestCase      ):






						def       __lowerCAmelCase(   self						:						List[Any]       ):



									'''simple docstring'''






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






						def       __lowerCAmelCase(   self						:						int       ):



									'''simple docstring'''






									snake_case__          =						torch_device

									snake_case__          =						SpectrogramDiffusionPipeline.from_pretrained("""google/music-spectrogram-diffusion"""       )
									snake_case__          =						pipe.melgan
									snake_case__          =						None

									snake_case__          =						pipe.to(__UpperCamelCase       )
									pipe.set_progress_bar_config(disable=__UpperCamelCase       )

									def callback(__UpperCamelCase						:						List[str]					,   __UpperCamelCase						:						List[str]       ):
												# decode mel to audio
												snake_case__          =						melgan(input_features=mel_output.astype(np.floataa       )       )[0]
												assert len(audio[0]       ) == 8_1_9_2_0 * (step + 1)
												# simulate that audio is played
												return audio

									snake_case__          =						MidiProcessor()
									snake_case__          =						processor(__UpperCamelCase       )

									snake_case__          =						input_tokens[:3]
									snake_case__          =						torch.manual_seed(0       )
									pipe(__UpperCamelCase					,   num_inference_steps=5					,   generator=__UpperCamelCase					,   callback=__UpperCamelCase					,   output_type="""mel"""       )






						def       __lowerCAmelCase(   self						:						List[Any]       ):



									'''simple docstring'''






									snake_case__          =						torch_device

									snake_case__          =						SpectrogramDiffusionPipeline.from_pretrained("""google/music-spectrogram-diffusion"""       )
									snake_case__          =						pipe.to(__UpperCamelCase       )
									pipe.set_progress_bar_config(disable=__UpperCamelCase       )
									snake_case__          =						MidiProcessor()

									snake_case__          =						processor(__UpperCamelCase       )
									# just run two denoising loops
									snake_case__          =						input_tokens[:2]

									snake_case__          =						torch.manual_seed(0       )
									snake_case__          =						pipe(__UpperCamelCase					,   num_inference_steps=2					,   generator=__UpperCamelCase       )

									snake_case__          =						output.audios[0]

									assert abs(np.abs(__UpperCamelCase       ).sum() - 36_12.8_41       ) < 1E-1







						def       __lowerCAmelCase(   self						:						Union[str, Any]       ):



									'''simple docstring'''






									snake_case__          =						torch_device

									snake_case__          =						SpectrogramDiffusionPipeline.from_pretrained("""google/music-spectrogram-diffusion"""       )
									snake_case__          =						pipe.to(__UpperCamelCase       )
									pipe.set_progress_bar_config(disable=__UpperCamelCase       )

									snake_case__          =						MidiProcessor()

									snake_case__          =						processor(__UpperCamelCase       )

									# just run 4 denoising loops
									snake_case__          =						input_tokens[:4]

									snake_case__          =						torch.manual_seed(0       )
									snake_case__          =						pipe(__UpperCamelCase					,   num_inference_steps=1_0_0					,   generator=__UpperCamelCase       )

									snake_case__          =						output.audios[0]
									assert abs(np.abs(__UpperCamelCase       ).sum() - 93_89.11_11       ) < 5E-2