code: 
  
  
  
  
  
  import json
  import os
  import shutil
  import sys
  import tempfile
  import unittest
  from unittest import TestCase
  from unittest.mock import patch
  
  import faiss
  import numpy as np
  from datasets import Dataset
  
  from transformers import BartConfig, BartTokenizer, DPRConfig, DPRQuestionEncoderTokenizer, RagConfig
  from transformers.file_utils import is_datasets_available, is_faiss_available, is_psutil_available, is_torch_available
  from transformers.integrations import is_ray_available
  from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES as DPR_VOCAB_FILES_NAMES
  from transformers.models.rag.retrieval_rag import CustomHFIndex, RagRetriever
  from transformers.models.roberta.tokenization_roberta import VOCAB_FILES_NAMES as BART_VOCAB_FILES_NAMES
  from transformers.testing_utils import require_ray
  
  
  sys.path.append(os.path.join(os.getcwd()))  # noqa: E402 # noqa: E402 # isort:skip
  
  if is_torch_available():
  		from distributed_pytorch_retriever import RagPyTorchDistributedRetriever  # noqa: E402 # isort:skip
  else:
  		_lowercase		:     int 					=None
  
  if is_ray_available():
  		import ray  # noqa: E402 # isort:skip
  		from distributed_ray_retriever import RagRayDistributedRetriever, RayRetriever  # noqa: E402 # isort:skip
  else:
  		_lowercase		:     Any 					=None
  		_lowercase		:     Tuple 					=None
  		_lowercase		:     List[Any] 					=None
  
  
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__	):
  		if not (is_datasets_available() and is_faiss_available() and is_psutil_available()):
  				lowerCamelCase_  :    List[Any]   	=			unittest.skip('test requires Datasets, Faiss, psutil'	)(lowerCAmelCase__	)
  		return test_case
  
  
  
  
  
  
  @require_distributed_retrieval
  class 	UpperCamelCase_     (     snake_case__       ):
  
  
  
  					def      __a    (		self    :    Dict	):
  							lowerCamelCase_  :    Optional[Any]   	=			tempfile.mkdtemp()
  							lowerCamelCase_  :    Tuple   	=			8
  
  							# DPR tok
  							lowerCamelCase_  :    Any   	=			[
  							    '[UNK]',
  							    '[CLS]',
  							    '[SEP]',
  							    '[PAD]',
  							    '[MASK]',
  							    'want',
  							    '##want',
  							    '##ed',
  							    'wa',
  							    'un',
  							    'runn',
  							    '##ing',
  							    ',',
  							    'low',
  							    'lowest',
  							]
  							lowerCamelCase_  :    List[str]   	=			os.path.join(self.tmpdirname					,			'dpr_tokenizer'	)
  							os.makedirs(lowerCamelCase					,			exist_ok=lowerCamelCase	)
  							lowerCamelCase_  :    int   	=			os.path.join(lowerCamelCase					,			DPR_VOCAB_FILES_NAMES['vocab_file']	)
  							with open(self.vocab_file					,			'w'					,			encoding='utf-8'	) as vocab_writer:
  									vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]	)	)
  
  							# BART tok
  							lowerCamelCase_  :    Optional[Any]   	=			[
  							    'l',
  							    'o',
  							    'w',
  							    'e',
  							    'r',
  							    's',
  							    't',
  							    'i',
  							    'd',
  							    'n',
  							    '\u0120',
  							    '\u0120l',
  							    '\u0120n',
  							    '\u0120lo',
  							    '\u0120low',
  							    'er',
  							    '\u0120lowest',
  							    '\u0120newer',
  							    '\u0120wider',
  							    '<unk>',
  							]
  							lowerCamelCase_  :    Any   	=			dict(zip(lowerCamelCase					,			range(len(lowerCamelCase	)	)	)	)
  							lowerCamelCase_  :    str   	=			['#version: 0.2', '\u0120 l', '\u0120l o', '\u0120lo w', 'e r', '']
  							lowerCamelCase_  :    Union[str, Any]   	=			{'unk_token': '<unk>'}
  
  							lowerCamelCase_  :    int   	=			os.path.join(self.tmpdirname					,			'bart_tokenizer'	)
  							os.makedirs(lowerCamelCase					,			exist_ok=lowerCamelCase	)
  							lowerCamelCase_  :    List[Any]   	=			os.path.join(lowerCamelCase					,			BART_VOCAB_FILES_NAMES['vocab_file']	)
  							lowerCamelCase_  :    Tuple   	=			os.path.join(lowerCamelCase					,			BART_VOCAB_FILES_NAMES['merges_file']	)
  							with open(self.vocab_file					,			'w'					,			encoding='utf-8'	) as fp:
  									fp.write(json.dumps(lowerCamelCase	) + '\n'	)
  							with open(self.merges_file					,			'w'					,			encoding='utf-8'	) as fp:
  									fp.write('\n'.join(lowerCamelCase	)	)
  
  
  
  					def      __a    (		self    :    List[Any]	):
  							return DPRQuestionEncoderTokenizer.from_pretrained(os.path.join(self.tmpdirname					,			'dpr_tokenizer'	)	)
  
  
  
  					def      __a    (		self    :    Union[str, Any]	):
  							return BartTokenizer.from_pretrained(os.path.join(self.tmpdirname					,			'bart_tokenizer'	)	)
  
  
  
  					def      __a    (		self    :    str	):
  							shutil.rmtree(self.tmpdirname	)
  
  
  
  					def      __a    (		self    :    Union[str, Any]	):
  							lowerCamelCase_  :    Optional[int]   	=			Dataset.from_dict(
  							    {
  							        'id': ['0', '1'],
  							        'text': ['foo', 'bar'],
  							        'title': ['Foo', 'Bar'],
  							        'embeddings': [np.ones(self.retrieval_vector_size	), 2 * np.ones(self.retrieval_vector_size	)],
  							    }	)
  							dataset.add_faiss_index('embeddings'					,			string_factory='Flat'					,			metric_type=faiss.METRIC_INNER_PRODUCT	)
  							return dataset
  
  
  
  					def      __a    (		self    :    Any					,			lowerCamelCase    :    bool					,			lowerCamelCase    :    Optional[Any]=1_23_45	):
  							lowerCamelCase_  :    Optional[Any]   	=			self.get_dummy_dataset()
  							lowerCamelCase_  :    Optional[int]   	=			RagConfig(
  							    retrieval_vector_size=self.retrieval_vector_size					,			question_encoder=DPRConfig().to_dict()					,			generator=BartConfig().to_dict()					,			)
  							with patch('transformers.models.rag.retrieval_rag.load_dataset'	) as mock_load_dataset:
  									lowerCamelCase_  :    Optional[Any]   	=			dataset
  									lowerCamelCase_  :    List[str]   	=			RagPyTorchDistributedRetriever(
  									    lowerCamelCase					,			question_encoder_tokenizer=self.get_dpr_tokenizer()					,			generator_tokenizer=self.get_bart_tokenizer()					,			)
  									if init_retrieval:
  											retriever.init_retrieval(lowerCamelCase	)
  							return retriever
  
  
  
  					def      __a    (		self    :    Dict					,			lowerCamelCase    :    bool	):
  							# Have to run in local mode because sys.path modifications at top of
  							# file are not propogated to remote workers.
  							# https://stackoverflow.com/questions/54338013/parallel-import-a-python-file-from-sibling-folder
  							ray.init(local_mode=lowerCamelCase	)
  							lowerCamelCase_  :    Optional[int]   	=			RagConfig(
  							    retrieval_vector_size=self.retrieval_vector_size					,			question_encoder=DPRConfig().to_dict()					,			generator=BartConfig().to_dict()					,			)
  							lowerCamelCase_  :    Any   	=			ray.remote(lowerCamelCase	)
  							lowerCamelCase_  :    int   	=			[remote_cls.remote() for _ in range(1	)]
  							with patch('transformers.models.rag.retrieval_rag.load_dataset'	) as mock_load_dataset:
  									lowerCamelCase_  :    int   	=			self.get_dummy_dataset()
  									lowerCamelCase_  :    Tuple   	=			RagRayDistributedRetriever(
  									    lowerCamelCase					,			question_encoder_tokenizer=self.get_dpr_tokenizer()					,			generator_tokenizer=self.get_bart_tokenizer()					,			retrieval_workers=lowerCamelCase					,			)
  									if init_retrieval:
  											retriever.init_retrieval()
  							return retriever
  
  
  
  					def      __a    (		self    :    List[str]					,			lowerCamelCase    :    bool					,			lowerCamelCase    :    bool					,			lowerCamelCase    :    List[Any]=1_23_45	):
  							lowerCamelCase_  :    int   	=			self.get_dummy_dataset()
  							lowerCamelCase_  :    Any   	=			RagConfig(
  							    retrieval_vector_size=self.retrieval_vector_size					,			question_encoder=DPRConfig().to_dict()					,			generator=BartConfig().to_dict()					,			index_name='custom'					,			)
  							if from_disk:
  									lowerCamelCase_  :    Any   	=			os.path.join(self.tmpdirname					,			'dataset'	)
  									lowerCamelCase_  :    str   	=			os.path.join(self.tmpdirname					,			'index.faiss'	)
  									dataset.get_index('embeddings'	).save(os.path.join(self.tmpdirname					,			'index.faiss'	)	)
  									dataset.drop_index('embeddings'	)
  									dataset.save_to_disk(os.path.join(self.tmpdirname					,			'dataset'	)	)
  									del dataset
  									lowerCamelCase_  :    str   	=			RagPyTorchDistributedRetriever(
  									    lowerCamelCase					,			question_encoder_tokenizer=self.get_dpr_tokenizer()					,			generator_tokenizer=self.get_bart_tokenizer()					,			)
  							else:
  									lowerCamelCase_  :    List[Any]   	=			RagPyTorchDistributedRetriever(
  									    lowerCamelCase					,			question_encoder_tokenizer=self.get_dpr_tokenizer()					,			generator_tokenizer=self.get_bart_tokenizer()					,			index=CustomHFIndex(config.retrieval_vector_size					,			lowerCamelCase	)					,			)
  							if init_retrieval:
  									retriever.init_retrieval(lowerCamelCase	)
  							return retriever
  
  
  
  					def      __a    (		self    :    Dict					,			lowerCamelCase    :    bool					,			lowerCamelCase    :    bool	):
  							# Have to run in local mode because sys.path modifications at top of
  							# file are not propogated to remote workers.
  							# https://stackoverflow.com/questions/54338013/parallel-import-a-python-file-from-sibling-folder
  							ray.init(local_mode=lowerCamelCase	)
  							lowerCamelCase_  :    Dict   	=			self.get_dummy_dataset()
  							lowerCamelCase_  :    Dict   	=			RagConfig(
  							    retrieval_vector_size=self.retrieval_vector_size					,			question_encoder=DPRConfig().to_dict()					,			generator=BartConfig().to_dict()					,			index_name='custom'					,			)
  							lowerCamelCase_  :    Any   	=			ray.remote(lowerCamelCase	)
  							lowerCamelCase_  :    List[str]   	=			[remote_cls.remote() for _ in range(1	)]
  							if from_disk:
  									lowerCamelCase_  :    int   	=			os.path.join(self.tmpdirname					,			'dataset'	)
  									lowerCamelCase_  :    Optional[int]   	=			os.path.join(self.tmpdirname					,			'index.faiss'	)
  									dataset.get_index('embeddings'	).save(os.path.join(self.tmpdirname					,			'index.faiss'	)	)
  									dataset.drop_index('embeddings'	)
  									dataset.save_to_disk(os.path.join(self.tmpdirname					,			'dataset'	)	)
  									del dataset
  									lowerCamelCase_  :    List[Any]   	=			RagRayDistributedRetriever(
  									    lowerCamelCase					,			question_encoder_tokenizer=self.get_dpr_tokenizer()					,			generator_tokenizer=self.get_bart_tokenizer()					,			retrieval_workers=lowerCamelCase					,			index=CustomHFIndex.load_from_disk(
  									        vector_size=config.retrieval_vector_size					,			dataset_path=config.passages_path					,			index_path=config.index_path					,			)					,			)
  							else:
  									lowerCamelCase_  :    List[str]   	=			RagRayDistributedRetriever(
  									    lowerCamelCase					,			question_encoder_tokenizer=self.get_dpr_tokenizer()					,			generator_tokenizer=self.get_bart_tokenizer()					,			retrieval_workers=lowerCamelCase					,			index=CustomHFIndex(config.retrieval_vector_size					,			lowerCamelCase	)					,			)
  							if init_retrieval:
  									retriever.init_retrieval()
  							return retriever
  
  
  
  					def      __a    (		self    :    Any					,			lowerCamelCase    :    RagRetriever					,			lowerCamelCase    :    np.array					,			lowerCamelCase    :    int	):
  							lowerCamelCase_	,			lowerCamelCase_	,			lowerCamelCase_  :    List[Any]   	=			retriever.retrieve(lowerCamelCase					,			n_docs=lowerCamelCase	)
  							self.assertEqual(retrieved_doc_embeds.shape					,			(2, n_docs, self.retrieval_vector_size)	)
  							self.assertEqual(len(lowerCamelCase	)					,			2	)
  							self.assertEqual(sorted(doc_dicts[0]	)					,			['embeddings', 'id', 'text', 'title']	)
  							self.assertEqual(len(doc_dicts[0]['id']	)					,			lowerCamelCase	)
  							self.assertEqual(doc_dicts[0]['id'][0]					,			'1'	)  # max inner product is reached with second doc
  							self.assertEqual(doc_dicts[1]['id'][0]					,			'0'	)  # max inner product is reached with first doc
  							self.assertListEqual(doc_ids.tolist()					,			[[1], [0]]	)
  
  
  
  					def      __a    (		self    :    int	):
  							lowerCamelCase_  :    List[Any]   	=			1
  							lowerCamelCase_  :    Union[str, Any]   	=			np.array(
  							    [np.ones(self.retrieval_vector_size	), -np.ones(self.retrieval_vector_size	)]					,			dtype=np.floataa	)
  
  							self.distributed_retriever_check(
  							    self.get_dummy_pytorch_distributed_retriever(init_retrieval=lowerCamelCase	)					,			lowerCamelCase					,			lowerCamelCase	)
  
  
  
  					def      __a    (		self    :    Optional[int]	):
  							lowerCamelCase_  :    Optional[Any]   	=			1
  							lowerCamelCase_  :    int   	=			np.array(
  							    [np.ones(self.retrieval_vector_size	), -np.ones(self.retrieval_vector_size	)]					,			dtype=np.floataa	)
  
  							self.distributed_retriever_check(
  							    self.get_dummy_custom_hf_index_pytorch_retriever(init_retrieval=lowerCamelCase					,			from_disk=lowerCamelCase	)					,			lowerCamelCase					,			lowerCamelCase					,			)
  
  
  
  					def      __a    (		self    :    List[Any]	):
  							lowerCamelCase_  :    List[str]   	=			1
  							lowerCamelCase_  :    Union[str, Any]   	=			np.array(
  							    [np.ones(self.retrieval_vector_size	), -np.ones(self.retrieval_vector_size	)]					,			dtype=np.floataa	)
  
  							self.distributed_retriever_check(
  							    self.get_dummy_custom_hf_index_pytorch_retriever(init_retrieval=lowerCamelCase					,			from_disk=lowerCamelCase	)					,			lowerCamelCase					,			lowerCamelCase					,			)
  
  
  
  					@require_ray
  					def      __a    (		self    :    Optional[Any]	):
  							lowerCamelCase_  :    Optional[int]   	=			1
  							lowerCamelCase_  :    Tuple   	=			np.array(
  							    [np.ones(self.retrieval_vector_size	), -np.ones(self.retrieval_vector_size	)]					,			dtype=np.floataa	)
  
  							self.distributed_retriever_check(
  							    self.get_dummy_ray_distributed_retriever(init_retrieval=lowerCamelCase	)					,			lowerCamelCase					,			lowerCamelCase	)
  							ray.shutdown()
  
  
  
  					@require_ray
  					def      __a    (		self    :    List[str]	):
  							lowerCamelCase_  :    str   	=			1
  							lowerCamelCase_  :    Optional[int]   	=			np.array(
  							    [np.ones(self.retrieval_vector_size	), -np.ones(self.retrieval_vector_size	)]					,			dtype=np.floataa	)
  							with self.assertRaises(lowerCamelCase	):
  									self.distributed_retriever_check(
  									    self.get_dummy_custom_hf_index_ray_retriever(init_retrieval=lowerCamelCase					,			from_disk=lowerCamelCase	)					,			lowerCamelCase					,			lowerCamelCase					,			)
  							ray.shutdown()
  
  
  
  
  
  					@require_ray
  					def      __a    (		self    :    List[Any]	):
  							lowerCamelCase_  :    int   	=			1
  							lowerCamelCase_  :    int   	=			np.array(
  							    [np.ones(self.retrieval_vector_size	), -np.ones(self.retrieval_vector_size	)]					,			dtype=np.floataa	)
  
  							self.distributed_retriever_check(
  							    self.get_dummy_custom_hf_index_ray_retriever(init_retrieval=lowerCamelCase					,			from_disk=lowerCamelCase	)					,			lowerCamelCase					,			lowerCamelCase	)
  							ray.shutdown()
  
style_context: 
  
  
  
  
  
  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()
  
  
  _lowercase		:     Optional[Any] 					="""./tests/fixtures/elise_format0.mid"""
  
  
  
  
  
  
  @unittest.skip('The note-seq package currently throws an error on import'       )
  class 	UpperCamelCase_     (     snake_case__     ,    unittest.TestCase       ):
  					_a			:	int							=				SpectrogramDiffusionPipeline
  					_a			:	Dict							=				PipelineTesterMixin.required_optional_params - {
  					    'callback',
  					    'latents',
  					    'callback_steps',
  					    'output_type',
  					    'num_images_per_prompt',
  					}
  					_a			:	str							=				False
  					_a			:	Union[str, Any]							=				False
  					_a			:	Optional[int]							=				TOKENS_TO_AUDIO_GENERATION_PARAMS
  					_a			:	Optional[Any]							=				TOKENS_TO_AUDIO_GENERATION_BATCH_PARAMS
  
  
  
  					def      __a    (		self    :    Dict	):
  							torch.manual_seed(0	)
  							lowerCamelCase_  :    List[str]   	=			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_  :    Union[str, Any]   	=			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_  :    Union[str, Any]   	=			TaFilmDecoder(
  							    input_dims=1_28					,			targets_length=2_56					,			max_decoder_noise_time=20_000.0					,			d_model=7_68					,			num_layers=1					,			num_heads=1					,			d_kv=4					,			d_ff=20_48					,			dropout_rate=0.1					,			)
  
  							lowerCamelCase_  :    Any   	=			DDPMScheduler()
  
  							lowerCamelCase_  :    str   	=			{
  							    'notes_encoder': notes_encoder.eval(),
  							    'continuous_encoder': continuous_encoder.eval(),
  							    'decoder': decoder.eval(),
  							    'scheduler': scheduler,
  							    'melgan': None,
  							}
  							return components
  
  
  
  					def      __a    (		self    :    Any					,			lowerCamelCase    :    Any					,			lowerCamelCase    :    int=0	):
  							if str(lowerCamelCase	).startswith('mps'	):
  									lowerCamelCase_  :    Optional[int]   	=			torch.manual_seed(lowerCamelCase	)
  							else:
  									lowerCamelCase_  :    Dict   	=			torch.Generator(device=lowerCamelCase	).manual_seed(lowerCamelCase	)
  							lowerCamelCase_  :    str   	=			{
  							    '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      __a    (		self    :    Dict	):
  							lowerCamelCase_  :    str   	=			'cpu'  # ensure determinism for the device-dependent torch.Generator
  							lowerCamelCase_  :    Dict   	=			self.get_dummy_components()
  							lowerCamelCase_  :    Tuple   	=			SpectrogramDiffusionPipeline(**lowerCamelCase	)
  							lowerCamelCase_  :    List[str]   	=			pipe.to(lowerCamelCase	)
  							pipe.set_progress_bar_config(disable=lowerCamelCase	)
  
  							lowerCamelCase_  :    Optional[Any]   	=			self.get_dummy_inputs(lowerCamelCase	)
  							lowerCamelCase_  :    str   	=			pipe(**lowerCamelCase	)
  							lowerCamelCase_  :    Tuple   	=			output.audios
  
  							lowerCamelCase_  :    Tuple   	=			mel[0, -3:, -3:]
  
  							assert mel_slice.shape == (3, 3)
  							lowerCamelCase_  :    List[str]   	=			np.array(
  							    [-11.512_925, -4.788_215, -0.46_172_905, -2.051_715, -10.539_147, -10.970_963, -9.091_634, 4.0, 4.0]	)
  							assert np.abs(mel_slice.flatten() - expected_slice	).max() < 1E-2
  
  
  
  					@skip_mps
  					def      __a    (		self    :    Any	):
  							return super().test_save_load_local()
  
  
  
  					@skip_mps
  					def      __a    (		self    :    Tuple	):
  							return super().test_dict_tuple_outputs_equivalent()
  
  
  
  					@skip_mps
  					def      __a    (		self    :    Dict	):
  							return super().test_save_load_optional_components()
  
  
  
  					@skip_mps
  					def      __a    (		self    :    str	):
  							return super().test_attention_slicing_forward_pass()
  
  
  
  					def      __a    (		self    :    Any	):
  							pass
  
  
  
  					def      __a    (		self    :    Optional[int]	):
  							pass
  
  
  
  
  
  					@skip_mps
  					def      __a    (		self    :    Optional[Any]	):
  							return super().test_progress_bar()
  
  
  
  
  
  
  @slow
  @require_torch_gpu
  @require_onnxruntime
  @require_note_seq
  class 	UpperCamelCase_     (     unittest.TestCase       ):
  
  
  
  					def      __a    (		self    :    Optional[int]	):
  							# clean up the VRAM after each test
  							super().tearDown()
  							gc.collect()
  							torch.cuda.empty_cache()
  
  
  
  					def      __a    (		self    :    str	):
  							# TODO - test that pipeline can decode tokens in a callback
  							# so that music can be played live
  							lowerCamelCase_  :    Optional[Any]   	=			torch_device
  
  							lowerCamelCase_  :    Union[str, Any]   	=			SpectrogramDiffusionPipeline.from_pretrained('google/music-spectrogram-diffusion'	)
  							lowerCamelCase_  :    str   	=			pipe.melgan
  							lowerCamelCase_  :    Optional[int]   	=			None
  
  							lowerCamelCase_  :    str   	=			pipe.to(lowerCamelCase	)
  							pipe.set_progress_bar_config(disable=lowerCamelCase	)
  
  							def callback(lowerCamelCase    :    int					,			lowerCamelCase    :    int	):
  									# decode mel to audio
  									lowerCamelCase_  :    Union[str, Any]   	=			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_  :    Any   	=			MidiProcessor()
  							lowerCamelCase_  :    str   	=			processor(lowerCamelCase	)
  
  							lowerCamelCase_  :    str   	=			input_tokens[:3]
  							lowerCamelCase_  :    Dict   	=			torch.manual_seed(0	)
  							pipe(lowerCamelCase					,			num_inference_steps=5					,			generator=lowerCamelCase					,			callback=lowerCamelCase					,			output_type='mel'	)
  
  
  
  					def      __a    (		self    :    str	):
  							lowerCamelCase_  :    List[str]   	=			torch_device
  
  							lowerCamelCase_  :    List[str]   	=			SpectrogramDiffusionPipeline.from_pretrained('google/music-spectrogram-diffusion'	)
  							lowerCamelCase_  :    Union[str, Any]   	=			pipe.to(lowerCamelCase	)
  							pipe.set_progress_bar_config(disable=lowerCamelCase	)
  							lowerCamelCase_  :    int   	=			MidiProcessor()
  
  							lowerCamelCase_  :    Dict   	=			processor(lowerCamelCase	)
  							# just run two denoising loops
  							lowerCamelCase_  :    Optional[Any]   	=			input_tokens[:2]
  
  							lowerCamelCase_  :    List[Any]   	=			torch.manual_seed(0	)
  							lowerCamelCase_  :    str   	=			pipe(lowerCamelCase					,			num_inference_steps=2					,			generator=lowerCamelCase	)
  
  							lowerCamelCase_  :    Dict   	=			output.audios[0]
  
  							assert abs(np.abs(lowerCamelCase	).sum() - 3_612.841	) < 1E-1
  
  
  
  
  
  					def      __a    (		self    :    List[Any]	):
  							lowerCamelCase_  :    int   	=			torch_device
  
  							lowerCamelCase_  :    str   	=			SpectrogramDiffusionPipeline.from_pretrained('google/music-spectrogram-diffusion'	)
  							lowerCamelCase_  :    Optional[int]   	=			pipe.to(lowerCamelCase	)
  							pipe.set_progress_bar_config(disable=lowerCamelCase	)
  
  							lowerCamelCase_  :    Tuple   	=			MidiProcessor()
  
  							lowerCamelCase_  :    int   	=			processor(lowerCamelCase	)
  
  							# just run 4 denoising loops
  							lowerCamelCase_  :    Optional[Any]   	=			input_tokens[:4]
  
  							lowerCamelCase_  :    List[Any]   	=			torch.manual_seed(0	)
  							lowerCamelCase_  :    int   	=			pipe(lowerCamelCase					,			num_inference_steps=1_00					,			generator=lowerCamelCase	)
  
  							lowerCamelCase_  :    List[Any]   	=			output.audios[0]
  							assert abs(np.abs(lowerCamelCase	).sum() - 9_389.1_111	) < 5E-2
  