import os
import unittest

from transformers import RealmTokenizerFast
from transformers.models.bert.tokenization_bert import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.realm.tokenization_realm import RealmTokenizer
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english



@require_tokenizers
class 					snake_case__       (				_UpperCamelCase					,						unittest.TestCase							):
   _SCREAMING_SNAKE_CASE	: Tuple						    =      RealmTokenizer
   _SCREAMING_SNAKE_CASE	: Any						    =      RealmTokenizerFast
   _SCREAMING_SNAKE_CASE	: Any						    =      True
   _SCREAMING_SNAKE_CASE	: Any						    =      True
   _SCREAMING_SNAKE_CASE	: Any						    =      filter_non_english



   def 					UpperCAmelCase__       (				self   :   int   )							->     Optional[int]:




         '''simple docstring'''




         super().setUp()

         snake_case_     :			Optional[int]       =       [
             "[UNK]",
             "[CLS]",
             "[SEP]",
             "[PAD]",
             "[MASK]",
             "want",
             "##want",
             "##ed",
             "wa",
             "un",
             "runn",
             "##ing",
             ",",
             "low",
             "lowest",
         ]
         snake_case_     :			Dict       =       os.path.join(self.tmpdirname			,	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]   )   )



   def 					UpperCAmelCase__       (				self   :   int			,	A__   :   Union[str, Any]   )							->     Dict:




         '''simple docstring'''




         snake_case_     :			str       =       "UNwant\u00E9d,running"
         snake_case_     :			List[Any]       =       "unwanted, running"
         return input_text, output_text



   def 					UpperCAmelCase__       (				self   :   Optional[Any]   )							->     Optional[Any]:




         '''simple docstring'''




         snake_case_     :			Any       =       self.tokenizer_class(self.vocab_file   )

         snake_case_     :			List[str]       =       tokenizer.tokenize("UNwant\u00E9d,running"   )
         self.assertListEqual(A__			,	["un", "##want", "##ed", ",", "runn", "##ing"]   )
         self.assertListEqual(tokenizer.convert_tokens_to_ids(A__   )			,	[9, 6, 7, 12, 10, 11]   )



   def 					UpperCAmelCase__       (				self   :   Tuple   )							->     Optional[Any]:




         '''simple docstring'''




         if not self.test_rust_tokenizer:
               return

         snake_case_     :			Union[str, Any]       =       self.get_tokenizer()
         snake_case_     :			Optional[int]       =       self.get_rust_tokenizer()

         snake_case_     :			Optional[Any]       =       "UNwant\u00E9d,running"

         snake_case_     :			int       =       tokenizer.tokenize(A__   )
         snake_case_     :			int       =       rust_tokenizer.tokenize(A__   )
         self.assertListEqual(A__			,	A__   )

         snake_case_     :			List[str]       =       tokenizer.encode(A__			,	add_special_tokens=A__   )
         snake_case_     :			str       =       rust_tokenizer.encode(A__			,	add_special_tokens=A__   )
         self.assertListEqual(A__			,	A__   )

         snake_case_     :			Dict       =       self.get_rust_tokenizer()
         snake_case_     :			Union[str, Any]       =       tokenizer.encode(A__   )
         snake_case_     :			Any       =       rust_tokenizer.encode(A__   )
         self.assertListEqual(A__			,	A__   )

         # With lower casing
         snake_case_     :			int       =       self.get_tokenizer(do_lower_case=A__   )
         snake_case_     :			str       =       self.get_rust_tokenizer(do_lower_case=A__   )

         snake_case_     :			List[Any]       =       "UNwant\u00E9d,running"

         snake_case_     :			Dict       =       tokenizer.tokenize(A__   )
         snake_case_     :			Tuple       =       rust_tokenizer.tokenize(A__   )
         self.assertListEqual(A__			,	A__   )

         snake_case_     :			Tuple       =       tokenizer.encode(A__			,	add_special_tokens=A__   )
         snake_case_     :			str       =       rust_tokenizer.encode(A__			,	add_special_tokens=A__   )
         self.assertListEqual(A__			,	A__   )

         snake_case_     :			Optional[Any]       =       self.get_rust_tokenizer()
         snake_case_     :			int       =       tokenizer.encode(A__   )
         snake_case_     :			Optional[int]       =       rust_tokenizer.encode(A__   )
         self.assertListEqual(A__			,	A__   )



   def 					UpperCAmelCase__       (				self   :   Optional[int]   )							->     Union[str, Any]:




         '''simple docstring'''




         snake_case_     :			Dict       =       BasicTokenizer()

         self.assertListEqual(tokenizer.tokenize("ah\u535A\u63A8zz"   )			,	["ah", "\u535A", "\u63A8", "zz"]   )



   def 					UpperCAmelCase__       (				self   :   int   )							->     Any:




         '''simple docstring'''




         snake_case_     :			List[str]       =       BasicTokenizer(do_lower_case=A__   )

         self.assertListEqual(
             tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  "   )			,	["hello", "!", "how", "are", "you", "?"]   )
         self.assertListEqual(tokenizer.tokenize("H\u00E9llo"   )			,	["hello"]   )



   def 					UpperCAmelCase__       (				self   :   Dict   )							->     int:




         '''simple docstring'''




         snake_case_     :			Optional[int]       =       BasicTokenizer(do_lower_case=A__			,	strip_accents=A__   )

         self.assertListEqual(
             tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "   )			,	["hällo", "!", "how", "are", "you", "?"]   )
         self.assertListEqual(tokenizer.tokenize("H\u00E9llo"   )			,	["h\u00E9llo"]   )



   def 					UpperCAmelCase__       (				self   :   Optional[Any]   )							->     Optional[Any]:




         '''simple docstring'''




         snake_case_     :			List[Any]       =       BasicTokenizer(do_lower_case=A__			,	strip_accents=A__   )

         self.assertListEqual(
             tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "   )			,	["hallo", "!", "how", "are", "you", "?"]   )
         self.assertListEqual(tokenizer.tokenize("H\u00E9llo"   )			,	["hello"]   )



   def 					UpperCAmelCase__       (				self   :   Optional[int]   )							->     Optional[Any]:




         '''simple docstring'''




         snake_case_     :			List[Any]       =       BasicTokenizer(do_lower_case=A__   )

         self.assertListEqual(
             tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "   )			,	["hallo", "!", "how", "are", "you", "?"]   )
         self.assertListEqual(tokenizer.tokenize("H\u00E9llo"   )			,	["hello"]   )



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




         '''simple docstring'''




         snake_case_     :			List[Any]       =       BasicTokenizer(do_lower_case=A__   )

         self.assertListEqual(
             tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  "   )			,	["HeLLo", "!", "how", "Are", "yoU", "?"]   )



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




         '''simple docstring'''




         snake_case_     :			Any       =       BasicTokenizer(do_lower_case=A__			,	strip_accents=A__   )

         self.assertListEqual(
             tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "   )			,	["HäLLo", "!", "how", "Are", "yoU", "?"]   )



   def 					UpperCAmelCase__       (				self   :   Tuple   )							->     Optional[Any]:




         '''simple docstring'''




         snake_case_     :			str       =       BasicTokenizer(do_lower_case=A__			,	strip_accents=A__   )

         self.assertListEqual(
             tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "   )			,	["HaLLo", "!", "how", "Are", "yoU", "?"]   )



   def 					UpperCAmelCase__       (				self   :   List[str]   )							->     Any:




         '''simple docstring'''




         snake_case_     :			Union[str, Any]       =       BasicTokenizer(do_lower_case=A__			,	never_split=["[UNK]"]   )

         self.assertListEqual(
             tokenizer.tokenize(" \tHeLLo!how  \n Are yoU? [UNK]"   )			,	["HeLLo", "!", "how", "Are", "yoU", "?", "[UNK]"]   )



   def 					UpperCAmelCase__       (				self   :   Optional[int]   )							->     Optional[Any]:




         '''simple docstring'''




         snake_case_     :			int       =       ["[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn", "##ing"]

         snake_case_     :			List[Any]       =       {}
         for i, token in enumerate(A__   ):
               snake_case_     :			str       =       i
         snake_case_     :			Dict       =       WordpieceTokenizer(vocab=A__			,	unk_token="[UNK]"   )

         self.assertListEqual(tokenizer.tokenize(""   )			,	[]   )

         self.assertListEqual(tokenizer.tokenize("unwanted running"   )			,	["un", "##want", "##ed", "runn", "##ing"]   )

         self.assertListEqual(tokenizer.tokenize("unwantedX running"   )			,	["[UNK]", "runn", "##ing"]   )



   def 					UpperCAmelCase__       (				self   :   List[str]   )							->     Tuple:




         '''simple docstring'''




         self.assertTrue(_is_whitespace(" "   )   )
         self.assertTrue(_is_whitespace("\t"   )   )
         self.assertTrue(_is_whitespace("\r"   )   )
         self.assertTrue(_is_whitespace("\n"   )   )
         self.assertTrue(_is_whitespace("\u00A0"   )   )

         self.assertFalse(_is_whitespace("A"   )   )
         self.assertFalse(_is_whitespace("-"   )   )



   def 					UpperCAmelCase__       (				self   :   Dict   )							->     Optional[int]:




         '''simple docstring'''




         self.assertTrue(_is_control("\u0005"   )   )

         self.assertFalse(_is_control("A"   )   )
         self.assertFalse(_is_control(" "   )   )
         self.assertFalse(_is_control("\t"   )   )
         self.assertFalse(_is_control("\r"   )   )



   def 					UpperCAmelCase__       (				self   :   Any   )							->     List[str]:




         '''simple docstring'''




         self.assertTrue(_is_punctuation("-"   )   )
         self.assertTrue(_is_punctuation("$"   )   )
         self.assertTrue(_is_punctuation("`"   )   )
         self.assertTrue(_is_punctuation("."   )   )

         self.assertFalse(_is_punctuation("A"   )   )
         self.assertFalse(_is_punctuation(" "   )   )



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




         '''simple docstring'''




         snake_case_     :			Optional[int]       =       self.get_tokenizer()

         # Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
         self.assertListEqual([tokenizer.tokenize(A__   ) for t in ["Test", "\xad", "test"]]			,	[["[UNK]"], [], ["[UNK]"]]   )

         if self.test_rust_tokenizer:
               snake_case_     :			int       =       self.get_rust_tokenizer()
               self.assertListEqual(
                   [rust_tokenizer.tokenize(A__   ) for t in ["Test", "\xad", "test"]]			,	[["[UNK]"], [], ["[UNK]"]]   )



   @slow
   def 					UpperCAmelCase__       (				self   :   Tuple   )							->     int:




         '''simple docstring'''




         snake_case_     :			Any       =       self.tokenizer_class.from_pretrained("bert-base-uncased"   )

         snake_case_     :			List[Any]       =       tokenizer.encode("sequence builders"			,	add_special_tokens=A__   )
         snake_case_     :			Optional[int]       =       tokenizer.encode("multi-sequence build"			,	add_special_tokens=A__   )

         snake_case_     :			List[str]       =       tokenizer.build_inputs_with_special_tokens(A__   )
         snake_case_     :			Optional[int]       =       tokenizer.build_inputs_with_special_tokens(A__			,	A__   )

         assert encoded_sentence == [1_01] + text + [1_02]
         assert encoded_pair == [1_01] + text + [1_02] + text_a + [1_02]



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




         '''simple docstring'''




         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
               with self.subTest(f"{tokenizer.__class__.__name__} ({pretrained_name})"   ):
                     snake_case_     :			Dict       =       self.rust_tokenizer_class.from_pretrained(A__			,	**A__   )

                     snake_case_     :			Optional[int]       =       f"A, naïve {tokenizer_r.mask_token} AllenNLP sentence."
                     snake_case_     :			Union[str, Any]       =       tokenizer_r.encode_plus(
                         A__			,	return_attention_mask=A__			,	return_token_type_ids=A__			,	return_offsets_mapping=A__			,	add_special_tokens=A__			,	)

                     snake_case_     :			int       =       tokenizer_r.do_lower_case if hasattr(A__			,	"do_lower_case"   ) else False
                     snake_case_     :			str       =       (
                         [
                             ((0, 0), tokenizer_r.cls_token),
                             ((0, 1), "A"),
                             ((1, 2), ","),
                             ((3, 5), "na"),
                             ((5, 6), "##ï"),
                             ((6, 8), "##ve"),
                             ((9, 15), tokenizer_r.mask_token),
                             ((16, 21), "Allen"),
                             ((21, 23), "##NL"),
                             ((23, 24), "##P"),
                             ((25, 33), "sentence"),
                             ((33, 34), "."),
                             ((0, 0), tokenizer_r.sep_token),
                         ]
                         if not do_lower_case
                         else [
                             ((0, 0), tokenizer_r.cls_token),
                             ((0, 1), "a"),
                             ((1, 2), ","),
                             ((3, 8), "naive"),
                             ((9, 15), tokenizer_r.mask_token),
                             ((16, 21), "allen"),
                             ((21, 23), "##nl"),
                             ((23, 24), "##p"),
                             ((25, 33), "sentence"),
                             ((33, 34), "."),
                             ((0, 0), tokenizer_r.sep_token),
                         ]
                     )

                     self.assertEqual(
                         [e[1] for e in expected_results]			,	tokenizer_r.convert_ids_to_tokens(tokens["input_ids"]   )   )
                     self.assertEqual([e[0] for e in expected_results]			,	tokens["offset_mapping"]   )



   @slow
   def 					UpperCAmelCase__       (				self   :   Union[str, Any]   )							->     List[Any]:




         '''simple docstring'''




         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
               with self.subTest(f"{tokenizer.__class__.__name__} ({pretrained_name})"   ):
                     snake_case_     :			List[str]       =       self.rust_tokenizer_class.from_pretrained(A__			,	**A__   )
                     snake_case_     :			int       =       self.tokenizer_class.from_pretrained(A__			,	**A__   )
                     snake_case_     :			Any       =       [["Hello world!", "Nice to meet you!"], ["The cute cat.", "The adorable dog."]]

                     snake_case_     :			Union[str, Any]       =       tokenizer_r.batch_encode_candidates(A__			,	max_length=10			,	return_tensors="np"   )
                     snake_case_     :			Optional[int]       =       tokenizer_p.batch_encode_candidates(A__			,	max_length=10			,	return_tensors="np"   )

                     snake_case_     :			Any       =       (2, 2, 10)

                     self.assertEqual(encoded_sentence_r["input_ids"].shape			,	A__   )
                     self.assertEqual(encoded_sentence_r["attention_mask"].shape			,	A__   )
                     self.assertEqual(encoded_sentence_r["token_type_ids"].shape			,	A__   )

                     self.assertEqual(encoded_sentence_p["input_ids"].shape			,	A__   )
                     self.assertEqual(encoded_sentence_p["attention_mask"].shape			,	A__   )
                     self.assertEqual(encoded_sentence_p["token_type_ids"].shape			,	A__   )




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


UpperCAmelCase							=       "./tests/fixtures/elise_format0.mid"



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



   def 					UpperCAmelCase__       (				self   :   Tuple   )							->     Optional[Any]:




         '''simple docstring'''




         torch.manual_seed(0   )
         snake_case_     :			List[Any]       =       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"			,	)

         snake_case_     :			int       =       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"			,	)

         snake_case_     :			Any       =       TaFilmDecoder(
             input_dims=1_28			,	targets_length=2_56			,	max_decoder_noise_time=2_0000.0			,	d_model=7_68			,	num_layers=1			,	num_heads=1			,	d_kv=4			,	d_ff=20_48			,	dropout_rate=0.1			,	)

         snake_case_     :			List[Any]       =       DDPMScheduler()

         snake_case_     :			List[Any]       =       {
             "notes_encoder": notes_encoder.eval(),
             "continuous_encoder": continuous_encoder.eval(),
             "decoder": decoder.eval(),
             "scheduler": scheduler,
             "melgan": None,
         }
         return components



   def 					UpperCAmelCase__       (				self   :   Dict			,	A__   :   int			,	A__   :   Dict=0   )							->     Tuple:




         '''simple docstring'''




         if str(A__   ).startswith("mps"   ):
               snake_case_     :			List[Any]       =       torch.manual_seed(A__   )
         else:
               snake_case_     :			List[Any]       =       torch.Generator(device=A__   ).manual_seed(A__   )
         snake_case_     :			Optional[int]       =       {
             "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 					UpperCAmelCase__       (				self   :   Union[str, Any]   )							->     str:




         '''simple docstring'''




         snake_case_     :			List[Any]       =       "cpu"  # ensure determinism for the device-dependent torch.Generator
         snake_case_     :			List[Any]       =       self.get_dummy_components()
         snake_case_     :			str       =       SpectrogramDiffusionPipeline(**A__   )
         snake_case_     :			Optional[int]       =       pipe.to(A__   )
         pipe.set_progress_bar_config(disable=A__   )

         snake_case_     :			List[Any]       =       self.get_dummy_inputs(A__   )
         snake_case_     :			Union[str, Any]       =       pipe(**A__   )
         snake_case_     :			str       =       output.audios

         snake_case_     :			List[Any]       =       mel[0, -3:, -3:]

         assert mel_slice.shape == (3, 3)
         snake_case_     :			Any       =       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 					UpperCAmelCase__       (				self   :   Any   )							->     Tuple:




         '''simple docstring'''




         return super().test_save_load_local()



   @skip_mps
   def 					UpperCAmelCase__       (				self   :   Union[str, Any]   )							->     List[Any]:




         '''simple docstring'''




         return super().test_dict_tuple_outputs_equivalent()



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




         '''simple docstring'''




         return super().test_save_load_optional_components()



   @skip_mps
   def 					UpperCAmelCase__       (				self   :   Optional[int]   )							->     List[str]:




         '''simple docstring'''




         return super().test_attention_slicing_forward_pass()



   def 					UpperCAmelCase__       (				self   :   List[str]   )							->     List[Any]:




         '''simple docstring'''




         pass



   def 					UpperCAmelCase__       (				self   :   Dict   )							->     str:




         '''simple docstring'''




         pass



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




         '''simple docstring'''




         return super().test_progress_bar()



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



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




         '''simple docstring'''




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



   def 					UpperCAmelCase__       (				self   :   int   )							->     Dict:




         '''simple docstring'''




         snake_case_     :			Optional[int]       =       torch_device

         snake_case_     :			List[str]       =       SpectrogramDiffusionPipeline.from_pretrained("google/music-spectrogram-diffusion"   )
         snake_case_     :			Dict       =       pipe.melgan
         snake_case_     :			Optional[Any]       =       None

         snake_case_     :			int       =       pipe.to(A__   )
         pipe.set_progress_bar_config(disable=A__   )

         def callback(A__   :   Dict			,	A__   :   Optional[Any]   ):
               # decode mel to audio
               snake_case_     :			str       =       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

         snake_case_     :			List[str]       =       MidiProcessor()
         snake_case_     :			Dict       =       processor(A__   )

         snake_case_     :			Optional[Any]       =       input_tokens[:3]
         snake_case_     :			Dict       =       torch.manual_seed(0   )
         pipe(A__			,	num_inference_steps=5			,	generator=A__			,	callback=A__			,	output_type="mel"   )



   def 					UpperCAmelCase__       (				self   :   Any   )							->     List[Any]:




         '''simple docstring'''




         snake_case_     :			Any       =       torch_device

         snake_case_     :			List[Any]       =       SpectrogramDiffusionPipeline.from_pretrained("google/music-spectrogram-diffusion"   )
         snake_case_     :			Any       =       pipe.to(A__   )
         pipe.set_progress_bar_config(disable=A__   )
         snake_case_     :			Any       =       MidiProcessor()

         snake_case_     :			List[Any]       =       processor(A__   )
         # just run two denoising loops
         snake_case_     :			str       =       input_tokens[:2]

         snake_case_     :			Tuple       =       torch.manual_seed(0   )
         snake_case_     :			int       =       pipe(A__			,	num_inference_steps=2			,	generator=A__   )

         snake_case_     :			int       =       output.audios[0]

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



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




         '''simple docstring'''




         snake_case_     :			Union[str, Any]       =       torch_device

         snake_case_     :			Union[str, Any]       =       SpectrogramDiffusionPipeline.from_pretrained("google/music-spectrogram-diffusion"   )
         snake_case_     :			Tuple       =       pipe.to(A__   )
         pipe.set_progress_bar_config(disable=A__   )

         snake_case_     :			int       =       MidiProcessor()

         snake_case_     :			int       =       processor(A__   )

         # just run 4 denoising loops
         snake_case_     :			Union[str, Any]       =       input_tokens[:4]

         snake_case_     :			Optional[Any]       =       torch.manual_seed(0   )
         snake_case_     :			Optional[Any]       =       pipe(A__			,	num_inference_steps=1_00			,	generator=A__   )

         snake_case_     :			List[str]       =       output.audios[0]
         assert abs(np.abs(A__   ).sum() - 9389.1111   ) < 5E-2



