





from argparse import ArgumentParser

from .add_new_model import AddNewModelCommand
from .add_new_model_like import AddNewModelLikeCommand
from .convert import ConvertCommand
from .download import DownloadCommand
from .env import EnvironmentCommand
from .lfs import LfsCommands
from .pt_to_tf import PTtoTFCommand
from .run import RunCommand
from .serving import ServeCommand
from .user import UserCommands




def     a__ (					):






   '''simple docstring'''






   UpperCAmelCase_											=ArgumentParser("Transformers CLI tool"  ,    usage="transformers-cli <command> [<args>]"  )
   UpperCAmelCase_											=parser.add_subparsers(help="transformers-cli command helpers"  )

   # Register commands
   ConvertCommand.register_subcommand(lowercase__  )
   DownloadCommand.register_subcommand(lowercase__  )
   EnvironmentCommand.register_subcommand(lowercase__  )
   RunCommand.register_subcommand(lowercase__  )
   ServeCommand.register_subcommand(lowercase__  )
   UserCommands.register_subcommand(lowercase__  )
   AddNewModelCommand.register_subcommand(lowercase__  )
   AddNewModelLikeCommand.register_subcommand(lowercase__  )
   LfsCommands.register_subcommand(lowercase__  )
   PTtoTFCommand.register_subcommand(lowercase__  )

   # Let's go
   UpperCAmelCase_											=parser.parse_args()

   if not hasattr(lowercase__  ,    "func"  ):
      parser.print_help()
      exit(1  )

   # Run
   UpperCAmelCase_											=args.func(lowercase__  )
   service.run()


if __name__ == "__main__":
     main()











import gc
import unittest

import numpy as np
import torch

from diffusers import DanceDiffusionPipeline, IPNDMScheduler, UNetaDModel
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS, UNCONDITIONAL_AUDIO_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()

class      A       (	__lowercase		,      unittest.TestCase						):
      _snake_case							     =DanceDiffusionPipeline
      _snake_case							     =UNCONDITIONAL_AUDIO_GENERATION_PARAMS
      _snake_case							     =PipelineTesterMixin.required_optional_params - {
          '''callback''',
          '''latents''',
          '''callback_steps''',
          '''output_type''',
          '''num_images_per_prompt''',
      }
      _snake_case							     =UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS
      _snake_case							     =False
      _snake_case							     =False



      def 	lowerCAmelCase__    (	self:						Tuple       )						->    Tuple:
         '''simple docstring'''

         torch.manual_seed(0       )
         UpperCAmelCase_											=UNetaDModel(
             block_out_channels=(32, 32, 64)		,  extra_in_channels=16		,  sample_size=512		,  sample_rate=1_6000		,  in_channels=2		,  out_channels=2		,  flip_sin_to_cos=_lowerCAmelCase		,  use_timestep_embedding=_lowerCAmelCase		,  time_embedding_type="fourier"		,  mid_block_type="UNetMidBlock1D"		,  down_block_types=("DownBlock1DNoSkip", "DownBlock1D", "AttnDownBlock1D")		,  up_block_types=("AttnUpBlock1D", "UpBlock1D", "UpBlock1DNoSkip")		,  )
         UpperCAmelCase_											=IPNDMScheduler()

         UpperCAmelCase_											={
             "unet": unet,
             "scheduler": scheduler,
         }
         return components



      def 	lowerCAmelCase__    (	self:						str		,  _lowerCAmelCase:						Tuple		,  _lowerCAmelCase:						List[str]=0       )						->    str:
         '''simple docstring'''

         if str(_lowerCAmelCase       ).startswith("mps"       ):
            UpperCAmelCase_											=torch.manual_seed(_lowerCAmelCase       )
         else:
            UpperCAmelCase_											=torch.Generator(device=_lowerCAmelCase       ).manual_seed(_lowerCAmelCase       )
         UpperCAmelCase_											={
             "batch_size": 1,
             "generator": generator,
             "num_inference_steps": 4,
         }
         return inputs



      def 	lowerCAmelCase__    (	self:						Dict       )						->    Tuple:
         '''simple docstring'''

         UpperCAmelCase_											="cpu"  # ensure determinism for the device-dependent torch.Generator
         UpperCAmelCase_											=self.get_dummy_components()
         UpperCAmelCase_											=DanceDiffusionPipeline(**_lowerCAmelCase       )
         UpperCAmelCase_											=pipe.to(_lowerCAmelCase       )
         pipe.set_progress_bar_config(disable=_lowerCAmelCase       )

         UpperCAmelCase_											=self.get_dummy_inputs(_lowerCAmelCase       )
         UpperCAmelCase_											=pipe(**_lowerCAmelCase       )
         UpperCAmelCase_											=output.audios

         UpperCAmelCase_											=audio[0, -3:, -3:]

         assert audio.shape == (1, 2, components["unet"].sample_size)
         UpperCAmelCase_											=np.array([-0.72_65, 1.00_00, -0.83_88, 0.11_75, 0.94_98, -1.00_00]       )
         assert np.abs(audio_slice.flatten() - expected_slice       ).max() < 1e-2



      @skip_mps
      def 	lowerCAmelCase__    (	self:						Optional[int]       )						->    Any:
         '''simple docstring'''

         return super().test_save_load_local()



      @skip_mps
      def 	lowerCAmelCase__    (	self:						Union[str, Any]       )						->    int:
         '''simple docstring'''

         return super().test_dict_tuple_outputs_equivalent(expected_max_difference=3e-3       )



      @skip_mps
      def 	lowerCAmelCase__    (	self:						List[str]       )						->    Optional[int]:
         '''simple docstring'''

         return super().test_save_load_optional_components()



      @skip_mps
      def 	lowerCAmelCase__    (	self:						Optional[Any]       )						->    Union[str, Any]:
         '''simple docstring'''

         return super().test_attention_slicing_forward_pass()






      def 	lowerCAmelCase__    (	self:						Optional[int]       )						->    Optional[Any]:
         '''simple docstring'''

         super().test_inference_batch_single_identical(expected_max_diff=3e-3       )

@slow
@require_torch_gpu
class      A       (	unittest.TestCase						):



      def 	lowerCAmelCase__    (	self:						Any       )						->    Optional[Any]:
         '''simple docstring'''

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



      def 	lowerCAmelCase__    (	self:						Union[str, Any]       )						->    Tuple:
         '''simple docstring'''

         UpperCAmelCase_											=torch_device

         UpperCAmelCase_											=DanceDiffusionPipeline.from_pretrained("harmonai/maestro-150k"       )
         UpperCAmelCase_											=pipe.to(_lowerCAmelCase       )
         pipe.set_progress_bar_config(disable=_lowerCAmelCase       )

         UpperCAmelCase_											=torch.manual_seed(0       )
         UpperCAmelCase_											=pipe(generator=_lowerCAmelCase		,  num_inference_steps=100		,  audio_length_in_s=4.0_96       )
         UpperCAmelCase_											=output.audios

         UpperCAmelCase_											=audio[0, -3:, -3:]

         assert audio.shape == (1, 2, pipe.unet.sample_size)
         UpperCAmelCase_											=np.array([-0.01_92, -0.02_31, -0.03_18, -0.00_59, 0.00_02, -0.00_20]       )

         assert np.abs(audio_slice.flatten() - expected_slice       ).max() < 1e-2






      def 	lowerCAmelCase__    (	self:						Tuple       )						->    Any:
         '''simple docstring'''

         UpperCAmelCase_											=torch_device

         UpperCAmelCase_											=DanceDiffusionPipeline.from_pretrained("harmonai/maestro-150k"		,  torch_dtype=torch.floataa       )
         UpperCAmelCase_											=pipe.to(_lowerCAmelCase       )
         pipe.set_progress_bar_config(disable=_lowerCAmelCase       )

         UpperCAmelCase_											=torch.manual_seed(0       )
         UpperCAmelCase_											=pipe(generator=_lowerCAmelCase		,  num_inference_steps=100		,  audio_length_in_s=4.0_96       )
         UpperCAmelCase_											=output.audios

         UpperCAmelCase_											=audio[0, -3:, -3:]

         assert audio.shape == (1, 2, pipe.unet.sample_size)
         UpperCAmelCase_											=np.array([-0.03_67, -0.04_88, -0.07_71, -0.05_25, -0.04_44, -0.03_41]       )

         assert np.abs(audio_slice.flatten() - expected_slice       ).max() < 1e-2




