






"""simple docstring"""


import tempfile
import unittest

import numpy as np

import transformers
from transformers import GPTaTokenizer, GPTNeoConfig, is_flax_available, is_torch_available
from transformers.testing_utils import is_pt_flax_cross_test, require_flax, slow

from ...generation.test_flax_utils import FlaxGenerationTesterMixin
from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
   import jax
   import jax.numpy as jnp

   from transformers.modeling_flax_pytorch_utils import (
       convert_pytorch_state_dict_to_flax,
       load_flax_weights_in_pytorch_model,
   )
   from transformers.models.gpt_neo.modeling_flax_gpt_neo import FlaxGPTNeoForCausalLM, FlaxGPTNeoModel

if is_torch_available():
   import torch






class 		snake_case    :





    def __init__(				self      :   Union[str, Any]							,						A      :   Union[str, Any]							,						A      :   Tuple=1_4							,						A      :   Tuple=7							,						A      :   int=True							,						A      :   Union[str, Any]=True							,						A      :   Union[str, Any]=False							,						A      :   Optional[Any]=True							,						A      :   Optional[int]=9_9							,						A      :   int=3_2							,						A      :   List[Any]=4							,						A      :   Dict=4							,						A      :   Optional[int]=[[["global", "local"], 2]]							,						A      :   Optional[int]=3_7							,						A      :   Optional[int]="gelu"							,						A      :   Optional[int]=0.1							,						A      :   Any=0.1							,						A      :   Tuple=5_1_2							,						A      :   List[Any]=7							,						A      :   Dict=0.02							,						):


      '''simple docstring'''




      a	:     List[str]							=  parent
      a	:     Optional[Any]							=  batch_size
      a	:     int							=  seq_length
      a	:     List[Any]							=  is_training
      a	:     Dict							=  use_input_mask
      a	:     Tuple							=  use_token_type_ids
      a	:     Union[str, Any]							=  use_labels
      a	:     List[Any]							=  vocab_size
      a	:     Any							=  hidden_size
      a	:     Optional[int]							=  num_hidden_layers
      a	:     Tuple							=  num_attention_heads
      a	:     Union[str, Any]							=  attention_types
      a	:     Optional[Any]							=  intermediate_size
      a	:     Optional[int]							=  hidden_act
      a	:     Dict							=  hidden_dropout_prob
      a	:     List[str]							=  attention_probs_dropout_prob
      a	:     str							=  max_position_embeddings
      a	:     Tuple							=  window_size
      a	:     Optional[Any]							=  initializer_range
      a	:     Optional[Any]							=  None
      a	:     str							=  vocab_size - 1
      a	:     str							=  vocab_size - 1
      a	:     Any							=  vocab_size - 1





    def 							lowerCamelCase__ (				self      :   List[str]     ):


      '''simple docstring'''




      a	:     List[Any]							=  ids_tensor([self.batch_size, self.seq_length]							,						self.vocab_size     )

      a	:     List[Any]							=  None
      if self.use_input_mask:
        a	:     Optional[Any]							=  random_attention_mask([self.batch_size, self.seq_length]     )

      a	:     Optional[Any]							=  GPTNeoConfig(
          vocab_size=self.vocab_size							,						hidden_size=self.hidden_size							,						num_layers=self.num_hidden_layers							,						num_heads=self.num_attention_heads							,						max_position_embeddings=self.max_position_embeddings							,						use_cache=_UpperCAmelCase							,						bos_token_id=self.bos_token_id							,						eos_token_id=self.eos_token_id							,						pad_token_id=self.pad_token_id							,						window_size=self.window_size							,						attention_types=self.attention_types							,						)

      return (config, input_ids, input_mask)





    def 							lowerCamelCase__ (				self      :   List[str]     ):


      '''simple docstring'''




      a	:     Optional[int]							=  self.prepare_config_and_inputs()
      a	:     Dict							=  config_and_inputs
      a	:     Union[str, Any]							=  {'input_ids': input_ids, 'attention_mask': attention_mask}
      return config, inputs_dict





    def 							lowerCamelCase__ (				self      :   Optional[Any]							,						A      :   str							,						A      :   Dict							,						A      :   int							,						A      :   Optional[int]     ):


      '''simple docstring'''




      a	:     Union[str, Any]							=  2_0
      a	:     Dict							=  model_class_name(_UpperCAmelCase     )

      a	:     List[Any]							=  model.init_cache(input_ids.shape[0]							,						_UpperCAmelCase     )
      a	:     Dict							=  jnp.ones((input_ids.shape[0], max_decoder_length)							,						dtype='i4'     )

      a	:     List[str]							=  jnp.broadcast_to(
          jnp.arange(input_ids.shape[-1] - 1     )[None, :]							,						(input_ids.shape[0], input_ids.shape[-1] - 1)     )
      a	:     Tuple							=  model(
          input_ids[:, :-1]							,						attention_mask=_UpperCAmelCase							,						past_key_values=_UpperCAmelCase							,						position_ids=_UpperCAmelCase							,						)

      a	:     Any							=  jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]]							,						dtype='i4'     )
      a	:     str							=  model(
          input_ids[:, -1:]							,						attention_mask=_UpperCAmelCase							,						past_key_values=outputs_cache.past_key_values							,						position_ids=_UpperCAmelCase							,						)

      a	:     Any							=  model(_UpperCAmelCase     )

      a	:     Union[str, Any]							=  np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])     )     )
      self.parent.assertTrue(diff < 1E-3							,						msg=F'''Max diff is {diff}'''     )





    def 							lowerCamelCase__ (				self      :   str							,						A      :   Optional[int]							,						A      :   Any							,						A      :   Dict							,						A      :   Tuple     ):


      '''simple docstring'''




      a	:     Tuple							=  2_0
      a	:     Union[str, Any]							=  model_class_name(_UpperCAmelCase     )

      a	:     Any							=  jnp.concatenate(
          [attention_mask, jnp.zeros((attention_mask.shape[0], max_decoder_length - attention_mask.shape[1])     )]							,						axis=-1							,						)

      a	:     str							=  model.init_cache(input_ids.shape[0]							,						_UpperCAmelCase     )
      a	:     List[Any]							=  jnp.broadcast_to(
          jnp.arange(input_ids.shape[-1] - 1     )[None, :]							,						(input_ids.shape[0], input_ids.shape[-1] - 1)     )

      a	:     int							=  model(
          input_ids[:, :-1]							,						attention_mask=_UpperCAmelCase							,						past_key_values=_UpperCAmelCase							,						position_ids=_UpperCAmelCase							,						)
      a	:     Any							=  jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]]							,						dtype='i4'     )
      a	:     List[str]							=  model(
          input_ids[:, -1:]							,						past_key_values=outputs_cache.past_key_values							,						attention_mask=_UpperCAmelCase							,						position_ids=_UpperCAmelCase							,						)

      a	:     Any							=  model(_UpperCAmelCase							,						attention_mask=_UpperCAmelCase     )

      a	:     List[str]							=  np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])     )     )
      self.parent.assertTrue(diff < 1E-3							,						msg=F'''Max diff is {diff}'''     )






@require_flax
class 		snake_case    (    _A  ,					_A  ,					unittest.TestCase			):
    __magic_name__       	=	(FlaxGPTNeoModel, FlaxGPTNeoForCausalLM) if is_flax_available() else ()
    __magic_name__       	=	(FlaxGPTNeoForCausalLM,) if is_flax_available() else ()





    def 							lowerCamelCase__ (				self      :   List[str]     ):


      '''simple docstring'''




      a	:     List[str]							=  FlaxGPTNeoModelTester(self     )





    def 							lowerCamelCase__ (				self      :   int     ):


      '''simple docstring'''




      for model_class_name in self.all_model_classes:
        a	:     Optional[Any]							=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.check_use_cache_forward(_UpperCAmelCase							,						_UpperCAmelCase							,						_UpperCAmelCase							,						_UpperCAmelCase     )





    def 							lowerCamelCase__ (				self      :   Optional[int]     ):


      '''simple docstring'''




      for model_class_name in self.all_model_classes:
        a	:     Any							=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.check_use_cache_forward_with_attn_mask(
            _UpperCAmelCase							,						_UpperCAmelCase							,						_UpperCAmelCase							,						_UpperCAmelCase     )





    @slow
    def 							lowerCamelCase__ (				self      :   Tuple     ):


      '''simple docstring'''




      a	:     Dict							=  GPTaTokenizer.from_pretrained('gpt2'							,						pad_token='<|endoftext|>'							,						padding_side='left'     )
      a	:     Tuple							=  tokenizer(['Hello this is a long string', 'Hey']							,						return_tensors='np'							,						padding=_UpperCAmelCase							,						truncation=_UpperCAmelCase     )

      a	:     Union[str, Any]							=  FlaxGPTNeoForCausalLM.from_pretrained('EleutherAI/gpt-neo-125M'     )
      a	:     Any							=  False
      a	:     Dict							=  model.config.eos_token_id

      a	:     int							=  jax.jit(model.generate     )

      a	:     List[str]							=  jit_generate(
          inputs['input_ids']							,						attention_mask=inputs['attention_mask']							,						pad_token_id=tokenizer.pad_token_id     ).sequences

      a	:     Dict							=  tokenizer.batch_decode(_UpperCAmelCase							,						skip_special_tokens=_UpperCAmelCase     )

      a	:     List[str]							=  [
          'Hello this is a long string of text.\n\nI\'m trying to get the text of the',
          'Hey, I\'m a little late to the party. I\'m going to',
      ]

      self.assertListEqual(_UpperCAmelCase							,						_UpperCAmelCase     )





    @is_pt_flax_cross_test
    def 							lowerCamelCase__ (				self      :   Union[str, Any]     ):


      '''simple docstring'''




      a	:     List[Any]							=  self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        with self.subTest(model_class.__name__     ):
          # prepare inputs
          a	:     Tuple							=  self._prepare_for_class(_UpperCAmelCase							,						_UpperCAmelCase     )
          a	:     List[str]							=  {k: torch.tensor(v.tolist()     ) for k, v in prepared_inputs_dict.items()}

          # load corresponding PyTorch class
          a	:     List[str]							=  model_class.__name__[4:]  # Skip the "Flax" at the beginning
          a	:     List[Any]							=  getattr(_UpperCAmelCase							,						_UpperCAmelCase     )

          a	:     Optional[int]							=  pt_inputs['input_ids'].shape
          a	:     List[Any]							=  np.random.randint(0							,						seq_length - 1							,						size=(batch_size,)     )
          for batch_idx, start_index in enumerate(_UpperCAmelCase     ):
            a	:     Dict							=  0
            a	:     str							=  1
            a	:     Union[str, Any]							=  0
            a	:     Union[str, Any]							=  1
          a	:     Dict							=  pt_model_class(_UpperCAmelCase     ).eval()
          a	:     str							=  model_class(_UpperCAmelCase							,						dtype=jnp.floataa     )

          a	:     int							=  convert_pytorch_state_dict_to_flax(pt_model.state_dict()							,						_UpperCAmelCase     )
          a	:     int							=  fx_state

          with torch.no_grad():
            a	:     Optional[Any]							=  pt_model(**_UpperCAmelCase     ).to_tuple()

          a	:     Tuple							=  fx_model(**_UpperCAmelCase     ).to_tuple()
          self.assertEqual(len(_UpperCAmelCase     )							,						len(_UpperCAmelCase     )							,						'Output lengths differ between Flax and PyTorch'     )
          for fx_output, pt_output in zip(_UpperCAmelCase							,						_UpperCAmelCase     ):
            self.assert_almost_equals(fx_output[:, -1]							,						pt_output[:, -1].numpy()							,						4E-2     )

          with tempfile.TemporaryDirectory() as tmpdirname:
            pt_model.save_pretrained(_UpperCAmelCase     )
            a	:     Dict							=  model_class.from_pretrained(_UpperCAmelCase							,						from_pt=_UpperCAmelCase     )

          a	:     List[Any]							=  fx_model_loaded(**_UpperCAmelCase     ).to_tuple()
          self.assertEqual(
              len(_UpperCAmelCase     )							,						len(_UpperCAmelCase     )							,						'Output lengths differ between Flax and PyTorch'     )
          for fx_output_loaded, pt_output in zip(_UpperCAmelCase							,						_UpperCAmelCase     ):
            self.assert_almost_equals(fx_output_loaded[:, -1]							,						pt_output[:, -1].numpy()							,						4E-2     )





    @is_pt_flax_cross_test
    def 							lowerCamelCase__ (				self      :   List[str]     ):


      '''simple docstring'''




      a	:     Tuple							=  self.model_tester.prepare_config_and_inputs_for_common()
      for model_class in self.all_model_classes:
        with self.subTest(model_class.__name__     ):
          # prepare inputs
          a	:     Union[str, Any]							=  self._prepare_for_class(_UpperCAmelCase							,						_UpperCAmelCase     )
          a	:     Dict							=  {k: torch.tensor(v.tolist()     ) for k, v in prepared_inputs_dict.items()}

          # load corresponding PyTorch class
          a	:     List[Any]							=  model_class.__name__[4:]  # Skip the "Flax" at the beginning
          a	:     int							=  getattr(_UpperCAmelCase							,						_UpperCAmelCase     )

          a	:     List[str]							=  pt_model_class(_UpperCAmelCase     ).eval()
          a	:     Optional[int]							=  model_class(_UpperCAmelCase							,						dtype=jnp.floataa     )

          a	:     Optional[int]							=  load_flax_weights_in_pytorch_model(_UpperCAmelCase							,						fx_model.params     )
          a	:     Union[str, Any]							=  pt_inputs['input_ids'].shape
          a	:     List[str]							=  np.random.randint(0							,						seq_length - 1							,						size=(batch_size,)     )
          for batch_idx, start_index in enumerate(_UpperCAmelCase     ):
            a	:     Optional[int]							=  0
            a	:     Dict							=  1
            a	:     Optional[Any]							=  0
            a	:     Optional[int]							=  1

          # make sure weights are tied in PyTorch
          pt_model.tie_weights()

          with torch.no_grad():
            a	:     Tuple							=  pt_model(**_UpperCAmelCase     ).to_tuple()

          a	:     Optional[int]							=  fx_model(**_UpperCAmelCase     ).to_tuple()
          self.assertEqual(len(_UpperCAmelCase     )							,						len(_UpperCAmelCase     )							,						'Output lengths differ between Flax and PyTorch'     )
          for fx_output, pt_output in zip(_UpperCAmelCase							,						_UpperCAmelCase     ):
            self.assert_almost_equals(fx_output[:, -1]							,						pt_output[:, -1].numpy()							,						4E-2     )

          with tempfile.TemporaryDirectory() as tmpdirname:
            fx_model.save_pretrained(_UpperCAmelCase     )
            a	:     Tuple							=  pt_model_class.from_pretrained(_UpperCAmelCase							,						from_flax=_UpperCAmelCase     )

          with torch.no_grad():
            a	:     str							=  pt_model_loaded(**_UpperCAmelCase     ).to_tuple()

          self.assertEqual(
              len(_UpperCAmelCase     )							,						len(_UpperCAmelCase     )							,						'Output lengths differ between Flax and PyTorch'     )
          for fx_output, pt_output in zip(_UpperCAmelCase							,						_UpperCAmelCase     ):
            self.assert_almost_equals(fx_output[:, -1]							,						pt_output[:, -1].numpy()							,						4E-2     )





    @slow
    def 							lowerCamelCase__ (				self      :   Dict     ):


      '''simple docstring'''




      for model_class_name in self.all_model_classes:
        a	:     List[str]							=  model_class_name.from_pretrained('EleutherAI/gpt-neo-125M'     )
        a	:     Any							=  model(np.ones((1, 1)     )     )
        self.assertIsNotNone(_UpperCAmelCase     )








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()


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



@unittest.skip('''The note-seq package currently throws an error on import'''	)
class      snake_case__	(   _A    ,							unittest.TestCase	):
				__lowerCAmelCase		=   SpectrogramDiffusionPipeline
				__lowerCAmelCase		=   PipelineTesterMixin.required_optional_params - {
				    '''callback''',
				    '''latents''',
				    '''callback_steps''',
				    '''output_type''',
				    '''num_images_per_prompt''',
				}
				__lowerCAmelCase		=   False
				__lowerCAmelCase		=   False
				__lowerCAmelCase		=   TOKENS_TO_AUDIO_GENERATION_PARAMS
				__lowerCAmelCase		=   TOKENS_TO_AUDIO_GENERATION_BATCH_PARAMS
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										torch.manual_seed(0   )
										__magic_name__					:				Tuple				=   SpectrogramNotesEncoder(
										    max_length=2048  ,   vocab_size=1536  ,   d_model=768  ,   dropout_rate=0.1  ,   num_layers=1  ,   num_heads=1  ,   d_kv=4  ,   d_ff=2048  ,   feed_forward_proj='gated-gelu'  ,   )

										__magic_name__					:				Union[str, Any]				=   SpectrogramContEncoder(
										    input_dims=128  ,   targets_context_length=256  ,   d_model=768  ,   dropout_rate=0.1  ,   num_layers=1  ,   num_heads=1  ,   d_kv=4  ,   d_ff=2048  ,   feed_forward_proj='gated-gelu'  ,   )

										__magic_name__					:				Optional[Any]				=   TaFilmDecoder(
										    input_dims=128  ,   targets_length=256  ,   max_decoder_noise_time=20000.0  ,   d_model=768  ,   num_layers=1  ,   num_heads=1  ,   d_kv=4  ,   d_ff=2048  ,   dropout_rate=0.1  ,   )

										__magic_name__					:				Any				=   DDPMScheduler()

										__magic_name__					:				Tuple				=   {
										    'notes_encoder': notes_encoder.eval(),
										    'continuous_encoder': continuous_encoder.eval(),
										    'decoder': decoder.eval(),
										    'scheduler': scheduler,
										    'melgan': None,
										}
										return components
				def 			UpperCamelCase_    (	self  ,   _UpperCAmelCase  ,   _UpperCAmelCase=0   ):




										"""simple docstring"""




										if str(_UpperCAmelCase   ).startswith('mps'   ):
																__magic_name__					:				str				=   torch.manual_seed(_UpperCAmelCase   )
										else:
																__magic_name__					:				Optional[int]				=   torch.Generator(device=_UpperCAmelCase   ).manual_seed(_UpperCAmelCase   )
										__magic_name__					:				List[str]				=   {
										    'input_tokens': [
										        [1134, 90, 1135, 1133, 1080, 112, 1132, 1080, 1133, 1079, 133, 1132, 1079, 1133, 1] + [0] * 2033
										    ],
										    'generator': generator,
										    'num_inference_steps': 4,
										    'output_type': 'mel',
										}
										return inputs
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Dict				=   'cpu'  # ensure determinism for the device-dependent torch.Generator
										__magic_name__					:				Optional[Any]				=   self.get_dummy_components()
										__magic_name__					:				Dict				=   SpectrogramDiffusionPipeline(**_UpperCAmelCase   )
										__magic_name__					:				Union[str, Any]				=   pipe.to(_UpperCAmelCase   )
										pipe.set_progress_bar_config(disable=_UpperCAmelCase   )

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

										__magic_name__					:				Dict				=   mel[0, -3:, -3:]

										assert mel_slice.shape == (3, 3)
										__magic_name__					:				Union[str, Any]				=   np.array(
										    [-11.512925, -4.788215, -0.46172905, -2.051715, -10.539147, -10.970963, -9.091634, 4.0, 4.0]   )
										assert np.abs(mel_slice.flatten() - expected_slice   ).max() < 1E-2
				@skip_mps
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




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




										"""simple docstring"""




										return super().test_dict_tuple_outputs_equivalent()
				@skip_mps
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




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




										"""simple docstring"""




										return super().test_attention_slicing_forward_pass()
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										pass
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										pass





				@skip_mps
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										return super().test_progress_bar()






@slow
@require_torch_gpu
@require_onnxruntime
@require_note_seq
class      snake_case__	(   unittest.TestCase	):
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										super().tearDown()
										gc.collect()
										torch.cuda.empty_cache()
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Tuple				=   torch_device

										__magic_name__					:				Optional[int]				=   SpectrogramDiffusionPipeline.from_pretrained('google/music-spectrogram-diffusion'   )
										__magic_name__					:				Dict				=   pipe.melgan
										__magic_name__					:				int				=   None

										__magic_name__					:				List[str]				=   pipe.to(_UpperCAmelCase   )
										pipe.set_progress_bar_config(disable=_UpperCAmelCase   )

										def callback(_UpperCAmelCase  ,   _UpperCAmelCase   ):
																# decode mel to audio
																__magic_name__					:				Any				=   melgan(input_features=mel_output.astype(np.floataa   )   )[0]
																assert len(audio[0]   ) == 8_1920 * (step + 1)
																# simulate that audio is played
																return audio

										__magic_name__					:				Optional[Any]				=   MidiProcessor()
										__magic_name__					:				str				=   processor(_UpperCAmelCase   )

										__magic_name__					:				Optional[int]				=   input_tokens[:3]
										__magic_name__					:				Optional[Any]				=   torch.manual_seed(0   )
										pipe(_UpperCAmelCase  ,   num_inference_steps=5  ,   generator=_UpperCAmelCase  ,   callback=_UpperCAmelCase  ,   output_type='mel'   )
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Tuple				=   torch_device

										__magic_name__					:				str				=   SpectrogramDiffusionPipeline.from_pretrained('google/music-spectrogram-diffusion'   )
										__magic_name__					:				List[str]				=   pipe.to(_UpperCAmelCase   )
										pipe.set_progress_bar_config(disable=_UpperCAmelCase   )
										__magic_name__					:				Union[str, Any]				=   MidiProcessor()

										__magic_name__					:				List[Any]				=   processor(_UpperCAmelCase   )
										# just run two denoising loops
										__magic_name__					:				List[Any]				=   input_tokens[:2]

										__magic_name__					:				int				=   torch.manual_seed(0   )
										__magic_name__					:				int				=   pipe(_UpperCAmelCase  ,   num_inference_steps=2  ,   generator=_UpperCAmelCase   )

										__magic_name__					:				List[str]				=   output.audios[0]

										assert abs(np.abs(_UpperCAmelCase   ).sum() - 3612.841   ) < 1E-1





				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Any				=   torch_device

										__magic_name__					:				List[Any]				=   SpectrogramDiffusionPipeline.from_pretrained('google/music-spectrogram-diffusion'   )
										__magic_name__					:				Any				=   pipe.to(_UpperCAmelCase   )
										pipe.set_progress_bar_config(disable=_UpperCAmelCase   )

										__magic_name__					:				List[str]				=   MidiProcessor()

										__magic_name__					:				Union[str, Any]				=   processor(_UpperCAmelCase   )

										# just run 4 denoising loops
										__magic_name__					:				List[Any]				=   input_tokens[:4]

										__magic_name__					:				Dict				=   torch.manual_seed(0   )
										__magic_name__					:				Union[str, Any]				=   pipe(_UpperCAmelCase  ,   num_inference_steps=100  ,   generator=_UpperCAmelCase   )

										__magic_name__					:				Dict				=   output.audios[0]
										assert abs(np.abs(_UpperCAmelCase   ).sum() - 9389.1111   ) < 5E-2


