




import unittest

from transformers import YosoConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import (
        YosoForMaskedLM,
        YosoForMultipleChoice,
        YosoForQuestionAnswering,
        YosoForSequenceClassification,
        YosoForTokenClassification,
        YosoModel,
    )
    from transformers.models.yoso.modeling_yoso import YOSO_PRETRAINED_MODEL_ARCHIVE_LIST





class 		A__    :






 def __init__(     self    ,					lowerCamelCase    ,					lowerCamelCase=13    ,					lowerCamelCase=7    ,					lowerCamelCase=True    ,					lowerCamelCase=True    ,					lowerCamelCase=True    ,					lowerCamelCase=True    ,					lowerCamelCase=99    ,					lowerCamelCase=32    ,					lowerCamelCase=5    ,					lowerCamelCase=4    ,					lowerCamelCase=37    ,					lowerCamelCase="gelu"    ,					lowerCamelCase=0.1    ,					lowerCamelCase=0.1    ,					lowerCamelCase=512    ,					lowerCamelCase=16    ,					lowerCamelCase=2    ,					lowerCamelCase=0.0_2    ,					lowerCamelCase=3    ,					lowerCamelCase=4    ,					lowerCamelCase=None    ,					)				->       Optional[int]:




      """simple docstring"""






      __magic_name__ :							List[Any]		       =							parent
      __magic_name__ :							str		       =							batch_size
      __magic_name__ :							int		       =							seq_length
      __magic_name__ :							List[str]		       =							is_training
      __magic_name__ :							Dict		       =							use_input_mask
      __magic_name__ :							Optional[Any]		       =							use_token_type_ids
      __magic_name__ :							Optional[Any]		       =							use_labels
      __magic_name__ :							Optional[Any]		       =							vocab_size
      __magic_name__ :							Tuple		       =							hidden_size
      __magic_name__ :							List[str]		       =							num_hidden_layers
      __magic_name__ :							List[str]		       =							num_attention_heads
      __magic_name__ :							Optional[Any]		       =							intermediate_size
      __magic_name__ :							Tuple		       =							hidden_act
      __magic_name__ :							Tuple		       =							hidden_dropout_prob
      __magic_name__ :							int		       =							attention_probs_dropout_prob
      __magic_name__ :							Union[str, Any]		       =							max_position_embeddings
      __magic_name__ :							Optional[Any]		       =							type_vocab_size
      __magic_name__ :							Optional[int]		       =							type_sequence_label_size
      __magic_name__ :							Tuple		       =							initializer_range
      __magic_name__ :							Any		       =							num_labels
      __magic_name__ :							Union[str, Any]		       =							num_choices
      __magic_name__ :							List[Any]		       =							scope






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




      """simple docstring"""






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

      __magic_name__ :							List[str]		       =							None
      if self.use_input_mask:
           __magic_name__ :							Tuple		       =							random_attention_mask([self.batch_size, self.seq_length]						)

      __magic_name__ :							Tuple		       =							None
      if self.use_token_type_ids:
           __magic_name__ :							List[Any]		       =							ids_tensor([self.batch_size, self.seq_length]    ,					self.type_vocab_size						)

      __magic_name__ :							str		       =							None
      __magic_name__ :							Dict		       =							None
      __magic_name__ :							List[str]		       =							None
      if self.use_labels:
           __magic_name__ :							List[Any]		       =							ids_tensor([self.batch_size]    ,					self.type_sequence_label_size						)
           __magic_name__ :							Optional[int]		       =							ids_tensor([self.batch_size, self.seq_length]    ,					self.num_labels						)
           __magic_name__ :							Optional[Any]		       =							ids_tensor([self.batch_size]    ,					self.num_choices						)

      __magic_name__ :							List[Any]		       =							self.get_config()

      return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






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




      """simple docstring"""






      return YosoConfig(
          vocab_size=self.vocab_size    ,					hidden_size=self.hidden_size    ,					num_hidden_layers=self.num_hidden_layers    ,					num_attention_heads=self.num_attention_heads    ,					intermediate_size=self.intermediate_size    ,					hidden_act=self.hidden_act    ,					hidden_dropout_prob=self.hidden_dropout_prob    ,					attention_probs_dropout_prob=self.attention_probs_dropout_prob    ,					max_position_embeddings=self.max_position_embeddings    ,					type_vocab_size=self.type_vocab_size    ,					is_decoder=lowerCamelCase    ,					initializer_range=self.initializer_range    ,					)






 def 			lowercase				(     self						)				->       Dict:




      """simple docstring"""






      __magic_name__ :							Dict		       =							self.get_config()
      __magic_name__ :							Optional[Any]		       =							300
      return config






 def 			lowercase				(     self						)				->       Tuple:




      """simple docstring"""






      (
          __magic_name__			
      ) :							Optional[Any]		       =							self.prepare_config_and_inputs()

      __magic_name__ :							Union[str, Any]		       =							True
      __magic_name__ :							str		       =							floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
      __magic_name__ :							Dict		       =							ids_tensor([self.batch_size, self.seq_length]    ,					vocab_size=2						)

      return (
          config,
          input_ids,
          token_type_ids,
          input_mask,
          sequence_labels,
          token_labels,
          choice_labels,
          encoder_hidden_states,
          encoder_attention_mask,
      )






 def 			lowercase				(     self    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase						)				->       str:




      """simple docstring"""






      __magic_name__ :							List[str]		       =							YosoModel(config=lowerCamelCase						)
      model.to(lowerCamelCase						)
      model.eval()
      __magic_name__ :							Dict		       =							model(lowerCamelCase    ,					attention_mask=lowerCamelCase    ,					token_type_ids=lowerCamelCase						)
      __magic_name__ :							List[str]		       =							model(lowerCamelCase    ,					token_type_ids=lowerCamelCase						)
      __magic_name__ :							Optional[Any]		       =							model(lowerCamelCase						)
      self.parent.assertEqual(result.last_hidden_state.shape    ,					(self.batch_size, self.seq_length, self.hidden_size)						)






 def 			lowercase				(     self    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					)				->       int:




      """simple docstring"""






      __magic_name__ :							Any		       =							True
      __magic_name__ :							Tuple		       =							YosoModel(lowerCamelCase						)
      model.to(lowerCamelCase						)
      model.eval()
      __magic_name__ :							str		       =							model(
          lowerCamelCase    ,					attention_mask=lowerCamelCase    ,					token_type_ids=lowerCamelCase    ,					encoder_hidden_states=lowerCamelCase    ,					encoder_attention_mask=lowerCamelCase    ,					)
      __magic_name__ :							Optional[Any]		       =							model(
          lowerCamelCase    ,					attention_mask=lowerCamelCase    ,					token_type_ids=lowerCamelCase    ,					encoder_hidden_states=lowerCamelCase    ,					)
      __magic_name__ :							List[str]		       =							model(lowerCamelCase    ,					attention_mask=lowerCamelCase    ,					token_type_ids=lowerCamelCase						)
      self.parent.assertEqual(result.last_hidden_state.shape    ,					(self.batch_size, self.seq_length, self.hidden_size)						)






 def 			lowercase				(     self    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase						)				->       Tuple:




      """simple docstring"""






      __magic_name__ :							Tuple		       =							YosoForMaskedLM(config=lowerCamelCase						)
      model.to(lowerCamelCase						)
      model.eval()
      __magic_name__ :							List[str]		       =							model(lowerCamelCase    ,					attention_mask=lowerCamelCase    ,					token_type_ids=lowerCamelCase    ,					labels=lowerCamelCase						)
      self.parent.assertEqual(result.logits.shape    ,					(self.batch_size, self.seq_length, self.vocab_size)						)






 def 			lowercase				(     self    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase						)				->       Optional[int]:




      """simple docstring"""






      __magic_name__ :							Union[str, Any]		       =							YosoForQuestionAnswering(config=lowerCamelCase						)
      model.to(lowerCamelCase						)
      model.eval()
      __magic_name__ :							Union[str, Any]		       =							model(
          lowerCamelCase    ,					attention_mask=lowerCamelCase    ,					token_type_ids=lowerCamelCase    ,					start_positions=lowerCamelCase    ,					end_positions=lowerCamelCase    ,					)
      self.parent.assertEqual(result.start_logits.shape    ,					(self.batch_size, self.seq_length)						)
      self.parent.assertEqual(result.end_logits.shape    ,					(self.batch_size, self.seq_length)						)






 def 			lowercase				(     self    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase						)				->       str:




      """simple docstring"""






      __magic_name__ :							Optional[int]		       =							self.num_labels
      __magic_name__ :							Optional[int]		       =							YosoForSequenceClassification(lowerCamelCase						)
      model.to(lowerCamelCase						)
      model.eval()
      __magic_name__ :							int		       =							model(lowerCamelCase    ,					attention_mask=lowerCamelCase    ,					token_type_ids=lowerCamelCase    ,					labels=lowerCamelCase						)
      self.parent.assertEqual(result.logits.shape    ,					(self.batch_size, self.num_labels)						)






 def 			lowercase				(     self    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase						)				->       Optional[int]:




      """simple docstring"""






      __magic_name__ :							List[Any]		       =							self.num_labels
      __magic_name__ :							str		       =							YosoForTokenClassification(config=lowerCamelCase						)
      model.to(lowerCamelCase						)
      model.eval()
      __magic_name__ :							Optional[int]		       =							model(lowerCamelCase    ,					attention_mask=lowerCamelCase    ,					token_type_ids=lowerCamelCase    ,					labels=lowerCamelCase						)
      self.parent.assertEqual(result.logits.shape    ,					(self.batch_size, self.seq_length, self.num_labels)						)






 def 			lowercase				(     self    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase    ,					lowerCamelCase						)				->       str:




      """simple docstring"""






      __magic_name__ :							str		       =							self.num_choices
      __magic_name__ :							List[str]		       =							YosoForMultipleChoice(config=lowerCamelCase						)
      model.to(lowerCamelCase						)
      model.eval()
      __magic_name__ :							int		       =							input_ids.unsqueeze(1						).expand(-1    ,					self.num_choices    ,					-1						).contiguous()
      __magic_name__ :							Union[str, Any]		       =							token_type_ids.unsqueeze(1						).expand(-1    ,					self.num_choices    ,					-1						).contiguous()
      __magic_name__ :							List[Any]		       =							input_mask.unsqueeze(1						).expand(-1    ,					self.num_choices    ,					-1						).contiguous()
      __magic_name__ :							Optional[Any]		       =							model(
          lowerCamelCase    ,					attention_mask=lowerCamelCase    ,					token_type_ids=lowerCamelCase    ,					labels=lowerCamelCase    ,					)
      self.parent.assertEqual(result.logits.shape    ,					(self.batch_size, self.num_choices)						)






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




      """simple docstring"""






      __magic_name__ :							Union[str, Any]		       =							self.prepare_config_and_inputs()
      (
          __magic_name__			
      ) :							int		       =							config_and_inputs
      __magic_name__ :							str		       =							{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
      return config, inputs_dict





@require_torch
class 		A__    (       __SCREAMING_SNAKE_CASE		,					__SCREAMING_SNAKE_CASE		,					unittest.TestCase			):
 lowerCamelCase__		:			List[str]       =(
     (
         YosoModel,
         YosoForMaskedLM,
         YosoForMultipleChoice,
         YosoForQuestionAnswering,
         YosoForSequenceClassification,
         YosoForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 lowerCamelCase__		:			Dict       =False
 lowerCamelCase__		:			Any       =False
 lowerCamelCase__		:			Dict       =False

 lowerCamelCase__		:			Optional[int]       =()
 lowerCamelCase__		:			int       =(
     {
         "feature-extraction": YosoModel,
         "fill-mask": YosoForMaskedLM,
         "question-answering": YosoForQuestionAnswering,
         "text-classification": YosoForSequenceClassification,
         "token-classification": YosoForTokenClassification,
         "zero-shot": YosoForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )






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




      """simple docstring"""






      __magic_name__ :							Union[str, Any]		       =							YosoModelTester(self						)
      __magic_name__ :							Dict		       =							ConfigTester(self    ,					config_class=lowerCamelCase    ,					hidden_size=37						)






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




      """simple docstring"""






      self.config_tester.run_common_tests()






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




      """simple docstring"""






      __magic_name__ :							List[str]		       =							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*lowerCamelCase						)






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




      """simple docstring"""






      __magic_name__ :							Union[str, Any]		       =							self.model_tester.prepare_config_and_inputs()
      for type in ["absolute", "relative_key", "relative_key_query"]:
           __magic_name__ :							Optional[int]		       =							type
           self.model_tester.create_and_check_model(*lowerCamelCase						)






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




      """simple docstring"""






      __magic_name__ :							Optional[Any]		       =							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase						)






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




      """simple docstring"""






      __magic_name__ :							Optional[Any]		       =							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase						)






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




      """simple docstring"""






      __magic_name__ :							Union[str, Any]		       =							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*lowerCamelCase						)






 def 			lowercase				(     self						)				->       Tuple:




      """simple docstring"""






      __magic_name__ :							str		       =							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase						)






 def 			lowercase				(     self						)				->       int:




      """simple docstring"""






      __magic_name__ :							List[Any]		       =							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*lowerCamelCase						)






 @slow
 def 			lowercase				(     self						)				->       List[Any]:




      """simple docstring"""






      for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           __magic_name__ :							Optional[int]		       =							YosoModel.from_pretrained(lowerCamelCase						)
           self.assertIsNotNone(lowerCamelCase						)






 def 			lowercase				(     self						)				->       Dict:




      """simple docstring"""






      return





@require_torch
class 		A__    (       unittest.TestCase			):






 @slow
 def 			lowercase				(     self						)				->       Any:




      """simple docstring"""






      __magic_name__ :							List[str]		       =							YosoModel.from_pretrained('''uw-madison/yoso-4096'''						)
      __magic_name__ :							Dict		       =							torch.tensor([[0, 1, 2, 3, 4, 5]]						)

      with torch.no_grad():
           __magic_name__ :							int		       =							model(lowerCamelCase						)[0]

      __magic_name__ :							List[str]		       =							torch.Size((1, 6, 768)						)
      self.assertEqual(output.shape    ,					lowerCamelCase						)

      __magic_name__ :							Any		       =							torch.tensor(
          [[[-0.0_6_1_1, 0.1_2_4_2, 0.0_8_4_0], [0.0_2_8_0, -0.0_0_4_8, 0.1_1_2_5], [0.0_1_0_6, 0.0_2_2_6, 0.0_7_5_1]]]						)

      self.assertTrue(torch.allclose(output[:, :3, :3]    ,					lowerCamelCase    ,					atol=1e-4						)						)






 @slow
 def 			lowercase				(     self						)				->       Dict:




      """simple docstring"""






      __magic_name__ :							Any		       =							YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''						)
      __magic_name__ :							Optional[int]		       =							torch.tensor([[0, 1, 2, 3, 4, 5]]						)

      with torch.no_grad():
           __magic_name__ :							List[str]		       =							model(lowerCamelCase						)[0]

      __magic_name__ :							int		       =							50265

      __magic_name__ :							List[str]		       =							torch.Size((1, 6, vocab_size)						)
      self.assertEqual(output.shape    ,					lowerCamelCase						)

      __magic_name__ :							List[str]		       =							torch.tensor(
          [[[-2.1_3_1_3, -3.7_2_8_5, -2.2_4_0_7], [-2.7_0_4_7, -3.3_3_1_4, -2.6_4_0_8], [0.0_6_2_9, -2.5_1_6_6, -0.3_3_5_6]]]						)

      self.assertTrue(torch.allclose(output[:, :3, :3]    ,					lowerCamelCase    ,					atol=1e-4						)						)






 @slow
 def 			lowercase				(     self						)				->       Tuple:




      """simple docstring"""






      __magic_name__ :							Union[str, Any]		       =							YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''						)
      __magic_name__ :							Optional[int]		       =							torch.arange(4096						).unsqueeze(0						)

      with torch.no_grad():
           __magic_name__ :							Tuple		       =							model(lowerCamelCase						)[0]

      __magic_name__ :							List[str]		       =							50265

      __magic_name__ :							List[Any]		       =							torch.Size((1, 4096, vocab_size)						)
      self.assertEqual(output.shape    ,					lowerCamelCase						)

      __magic_name__ :							Optional[Any]		       =							torch.tensor(
          [[[-2.3_9_1_4, -4.3_7_4_2, -5.0_9_5_6], [-4.0_9_8_8, -4.2_3_8_4, -7.0_4_0_6], [-3.1_4_2_7, -3.7_1_9_2, -6.6_8_0_0]]]						)

      self.assertTrue(torch.allclose(output[:, :3, :3]    ,					lowerCamelCase    ,					atol=1e-4						)						)









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_		=							'''./tests/fixtures/elise_format0.mid'''





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






	def 			lowercase				(     self						)				->       Any:




						"""simple docstring"""






						torch.manual_seed(0						)
						__magic_name__ :							Optional[Any]		       =							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__ :							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__ :							List[Any]		       =							TaFilmDecoder(
						    input_dims=128    ,					targets_length=256    ,					max_decoder_noise_time=2_0_0_0_0.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__ :							Dict		       =							{
						    '''notes_encoder''': notes_encoder.eval(),
						    '''continuous_encoder''': continuous_encoder.eval(),
						    '''decoder''': decoder.eval(),
						    '''scheduler''': scheduler,
						    '''melgan''': None,
						}
						return components






	def 			lowercase				(     self    ,					lowerCamelCase    ,					lowerCamelCase=0						)				->       Dict:




						"""simple docstring"""






						if str(lowerCamelCase						).startswith('''mps'''						):
											__magic_name__ :							List[str]		       =							torch.manual_seed(lowerCamelCase						)
						else:
											__magic_name__ :							Any		       =							torch.Generator(device=lowerCamelCase						).manual_seed(lowerCamelCase						)
						__magic_name__ :							Any		       =							{
						    '''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 			lowercase				(     self						)				->       Optional[int]:




						"""simple docstring"""






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

						__magic_name__ :							Tuple		       =							self.get_dummy_inputs(lowerCamelCase						)
						__magic_name__ :							List[str]		       =							pipe(**lowerCamelCase						)
						__magic_name__ :							Any		       =							output.audios

						__magic_name__ :							Union[str, Any]		       =							mel[0, -3:, -3:]

						assert mel_slice.shape == (3, 3)
						__magic_name__ :							Dict		       =							np.array(
						    [-1_1.5_1_2_9_2_5, -4.7_8_8_2_1_5, -0.4_6_1_7_2_9_0_5, -2.0_5_1_7_1_5, -1_0.5_3_9_1_4_7, -1_0.9_7_0_9_6_3, -9.0_9_1_6_3_4, 4.0, 4.0]						)
						assert np.abs(mel_slice.flatten() - expected_slice						).max() < 1e-2






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




						"""simple docstring"""






						return super().test_save_load_local()






	@skip_mps
	def 			lowercase				(     self						)				->       str:




						"""simple docstring"""






						return super().test_dict_tuple_outputs_equivalent()






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




						"""simple docstring"""






						return super().test_save_load_optional_components()






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




						"""simple docstring"""






						return super().test_attention_slicing_forward_pass()






	def 			lowercase				(     self						)				->       Tuple:




						"""simple docstring"""






						pass






	def 			lowercase				(     self						)				->       int:




						"""simple docstring"""






						pass






	@skip_mps
	def 			lowercase				(     self						)				->       Optional[Any]:




						"""simple docstring"""






						return super().test_progress_bar()





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






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




						"""simple docstring"""






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






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




						"""simple docstring"""






						__magic_name__ :							List[Any]		       =							torch_device

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

						__magic_name__ :							Tuple		       =							pipe.to(lowerCamelCase						)
						pipe.set_progress_bar_config(disable=lowerCamelCase						)

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

						__magic_name__ :							int		       =							MidiProcessor()
						__magic_name__ :							List[str]		       =							processor(lowerCamelCase						)

						__magic_name__ :							Dict		       =							input_tokens[:3]
						__magic_name__ :							Any		       =							torch.manual_seed(0						)
						pipe(lowerCamelCase    ,					num_inference_steps=5    ,					generator=lowerCamelCase    ,					callback=lowerCamelCase    ,					output_type='''mel'''						)






	def 			lowercase				(     self						)				->       int:




						"""simple docstring"""






						__magic_name__ :							Optional[int]		       =							torch_device

						__magic_name__ :							int		       =							SpectrogramDiffusionPipeline.from_pretrained('''google/music-spectrogram-diffusion'''						)
						__magic_name__ :							str		       =							pipe.to(lowerCamelCase						)
						pipe.set_progress_bar_config(disable=lowerCamelCase						)
						__magic_name__ :							Any		       =							MidiProcessor()

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

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

						__magic_name__ :							Union[str, Any]		       =							output.audios[0]

						assert abs(np.abs(lowerCamelCase						).sum() - 3_6_1_2.8_4_1						) < 1e-1






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




						"""simple docstring"""






						__magic_name__ :							Optional[int]		       =							torch_device

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

						__magic_name__ :							Optional[int]		       =							MidiProcessor()

						__magic_name__ :							str		       =							processor(lowerCamelCase						)

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

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

						__magic_name__ :							Optional[int]		       =							output.audios[0]
						assert abs(np.abs(lowerCamelCase						).sum() - 9_3_8_9.1_1_1_1						) < 5e-2



