code: 
  
  
  
  
  
  '''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      :				str											=					"""./tests/fixtures/elise_format0.mid"""
  
  
  
  
  
  @unittest.skip("""The note-seq package currently throws an error on import"""     )
  class 					_UpperCAmelCase							(		lowerCAmelCase_			,      unittest.TestCase     ):
  		a     :     Tuple     						=SpectrogramDiffusionPipeline
  		a     :     int     						=PipelineTesterMixin.required_optional_params - {
  		    """callback""",
  		    """latents""",
  		    """callback_steps""",
  		    """output_type""",
  		    """num_images_per_prompt""",
  		}
  		a     :     Any     						=False
  		a     :     str     						=False
  		a     :     Tuple     						=TOKENS_TO_AUDIO_GENERATION_PARAMS
  		a     :     int     						=TOKENS_TO_AUDIO_GENERATION_BATCH_PARAMS
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					torch.manual_seed(0    )
  					__lowerCAmelCase      		=       SpectrogramNotesEncoder(
  					    max_length=20_48,vocab_size=15_36,d_model=7_68,dropout_rate=0.1,num_layers=1,num_heads=1,d_kv=4,d_ff=20_48,feed_forward_proj="""gated-gelu""",)
  
  					__lowerCAmelCase      		=       SpectrogramContEncoder(
  					    input_dims=1_28,targets_context_length=2_56,d_model=7_68,dropout_rate=0.1,num_layers=1,num_heads=1,d_kv=4,d_ff=20_48,feed_forward_proj="""gated-gelu""",)
  
  					__lowerCAmelCase      		=       TaFilmDecoder(
  					    input_dims=1_28,targets_length=2_56,max_decoder_noise_time=2_00_00.0,d_model=7_68,num_layers=1,num_heads=1,d_kv=4,d_ff=20_48,dropout_rate=0.1,)
  
  					__lowerCAmelCase      		=       DDPMScheduler()
  
  					__lowerCAmelCase      		=       {
  					    """notes_encoder""": notes_encoder.eval(),
  					    """continuous_encoder""": continuous_encoder.eval(),
  					    """decoder""": decoder.eval(),
  					    """scheduler""": scheduler,
  					    """melgan""": None,
  					}
  					return components
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE=0    ):
  
  
  
  					'''simple docstring'''
  
  					if str(__SCREAMING_SNAKE_CASE    ).startswith("""mps"""    ):
  								__lowerCAmelCase      		=       torch.manual_seed(__SCREAMING_SNAKE_CASE    )
  					else:
  								__lowerCAmelCase      		=       torch.Generator(device=__SCREAMING_SNAKE_CASE    ).manual_seed(__SCREAMING_SNAKE_CASE    )
  					__lowerCAmelCase      		=       {
  					    """input_tokens""": [
  					        [11_34, 90, 11_35, 11_33, 10_80, 1_12, 11_32, 10_80, 11_33, 10_79, 1_33, 11_32, 10_79, 11_33, 1] + [0] * 20_33
  					    ],
  					    """generator""": generator,
  					    """num_inference_steps""": 4,
  					    """output_type""": """mel""",
  					}
  					return inputs
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       """cpu"""  # ensure determinism for the device-dependent torch.Generator
  					__lowerCAmelCase      		=       self.get_dummy_components()
  					__lowerCAmelCase      		=       SpectrogramDiffusionPipeline(**__SCREAMING_SNAKE_CASE    )
  					__lowerCAmelCase      		=       pipe.to(__SCREAMING_SNAKE_CASE    )
  					pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE    )
  
  					__lowerCAmelCase      		=       self.get_dummy_inputs(__SCREAMING_SNAKE_CASE    )
  					__lowerCAmelCase      		=       pipe(**__SCREAMING_SNAKE_CASE    )
  					__lowerCAmelCase      		=       output.audios
  
  					__lowerCAmelCase      		=       mel[0, -3:, -3:]
  
  					assert mel_slice.shape == (3, 3)
  					__lowerCAmelCase      		=       np.array(
  					    [-11.51_2925, -4.78_8215, -0.4617_2905, -2.05_1715, -10.53_9147, -10.97_0963, -9.09_1634, 4.0, 4.0]    )
  					assert np.abs(mel_slice.flatten() - expected_slice    ).max() < 1e-2
  		@skip_mps
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					return super().test_save_load_local()
  		@skip_mps
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					return super().test_dict_tuple_outputs_equivalent()
  		@skip_mps
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					return super().test_save_load_optional_components()
  		@skip_mps
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					return super().test_attention_slicing_forward_pass()
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					pass
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					pass
  
  
  
  
  
  
  
  		@skip_mps
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					return super().test_progress_bar()
  
  
  
  
  
  @slow
  @require_torch_gpu
  @require_onnxruntime
  @require_note_seq
  class 					_UpperCAmelCase							(		unittest.TestCase     ):
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					super().tearDown()
  					gc.collect()
  					torch.cuda.empty_cache()
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       torch_device
  
  					__lowerCAmelCase      		=       SpectrogramDiffusionPipeline.from_pretrained("""google/music-spectrogram-diffusion"""    )
  					__lowerCAmelCase      		=       pipe.melgan
  					__lowerCAmelCase      		=       None
  
  					__lowerCAmelCase      		=       pipe.to(__SCREAMING_SNAKE_CASE    )
  					pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE    )
  
  					def callback(__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE    ):
  								# decode mel to audio
  								__lowerCAmelCase      		=       melgan(input_features=mel_output.astype(np.floataa    )    )[0]
  								assert len(audio[0]    ) == 8_19_20 * (step + 1)
  								# simulate that audio is played
  								return audio
  
  					__lowerCAmelCase      		=       MidiProcessor()
  					__lowerCAmelCase      		=       processor(__SCREAMING_SNAKE_CASE    )
  
  					__lowerCAmelCase      		=       input_tokens[:3]
  					__lowerCAmelCase      		=       torch.manual_seed(0    )
  					pipe(__SCREAMING_SNAKE_CASE,num_inference_steps=5,generator=__SCREAMING_SNAKE_CASE,callback=__SCREAMING_SNAKE_CASE,output_type="""mel"""    )
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       torch_device
  
  					__lowerCAmelCase      		=       SpectrogramDiffusionPipeline.from_pretrained("""google/music-spectrogram-diffusion"""    )
  					__lowerCAmelCase      		=       pipe.to(__SCREAMING_SNAKE_CASE    )
  					pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE    )
  					__lowerCAmelCase      		=       MidiProcessor()
  
  					__lowerCAmelCase      		=       processor(__SCREAMING_SNAKE_CASE    )
  					# just run two denoising loops
  					__lowerCAmelCase      		=       input_tokens[:2]
  
  					__lowerCAmelCase      		=       torch.manual_seed(0    )
  					__lowerCAmelCase      		=       pipe(__SCREAMING_SNAKE_CASE,num_inference_steps=2,generator=__SCREAMING_SNAKE_CASE    )
  
  					__lowerCAmelCase      		=       output.audios[0]
  
  					assert abs(np.abs(__SCREAMING_SNAKE_CASE    ).sum() - 3612.841    ) < 1e-1
  
  
  
  
  
  
  
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       torch_device
  
  					__lowerCAmelCase      		=       SpectrogramDiffusionPipeline.from_pretrained("""google/music-spectrogram-diffusion"""    )
  					__lowerCAmelCase      		=       pipe.to(__SCREAMING_SNAKE_CASE    )
  					pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE    )
  
  					__lowerCAmelCase      		=       MidiProcessor()
  
  					__lowerCAmelCase      		=       processor(__SCREAMING_SNAKE_CASE    )
  
  					# just run 4 denoising loops
  					__lowerCAmelCase      		=       input_tokens[:4]
  
  					__lowerCAmelCase      		=       torch.manual_seed(0    )
  					__lowerCAmelCase      		=       pipe(__SCREAMING_SNAKE_CASE,num_inference_steps=1_00,generator=__SCREAMING_SNAKE_CASE    )
  
  					__lowerCAmelCase      		=       output.audios[0]
  					assert abs(np.abs(__SCREAMING_SNAKE_CASE    ).sum() - 9389.1111    ) < 5e-2
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  
  
  from __future__ import annotations
  
  from collections.abc import Iterable, Iterator
  from typing import Any, Generic, TypeVar
  
  _a      :				Dict											=					TypeVar("""T""", bound=bool)
  
  
  
  
  
  class 					_UpperCAmelCase							(		Generic[T]     ):
  		def __init__(						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       value
  					__lowerCAmelCase      		=       None
  					__lowerCAmelCase      		=       None
  		@property
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					return self._value
  
  
  
  
  
  
  
  		@staticmethod
  		def 						lowerCamelCase__    (						__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					if not roota:
  								return roota
  
  					if not roota:
  								return roota
  
  					if roota.value > roota.value:
  								__lowerCAmelCase		, __lowerCAmelCase      		=       roota, roota
  
  					__lowerCAmelCase      		=       roota
  					__lowerCAmelCase      		=       roota.right
  					__lowerCAmelCase      		=       roota.left
  					__lowerCAmelCase      		=       SkewNode.merge(__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE    )
  
  					return result
  
  
  
  
  
  class 					_UpperCAmelCase							(		Generic[T]     ):
  		def __init__(						self,__SCREAMING_SNAKE_CASE = ()    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       None
  					if data:
  								for item in data:
  											self.insert(__SCREAMING_SNAKE_CASE    )
  		def __bool__(						self    ):
  
  
  
  					'''simple docstring'''
  
  					return self._root is not None
  		def __iter__(						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       []
  					while self:
  								result.append(self.pop()    )
  
  					# Pushing items back to the heap not to clear it.
  					for item in result:
  								self.insert(__SCREAMING_SNAKE_CASE    )
  
  					return iter(__SCREAMING_SNAKE_CASE    )
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       SkewNode.merge(self._root,SkewNode(__SCREAMING_SNAKE_CASE    )    )
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       self.top()
  					__lowerCAmelCase      		=       (
  					    SkewNode.merge(self._root.left,self._root.right    ) if self._root else None
  					)
  
  					return result
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					if not self._root:
  								raise IndexError("""Can't get top element for the empty heap."""    )
  					return self._root.value
  
  
  
  
  
  
  
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       None
  
  
  if __name__ == "__main__":
  	import doctest
  
  	doctest.testmod()
  
  