


'''simple docstring'''
import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow

@is_pipeline_test
@require_torch
class     _lowerCamelCase       (     unittest.TestCase					):




 '''simple docstring'''


 @require_torch
 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		str	  =      pipeline(
      task='zero-shot-audio-classification'   ,   model='hf-internal-testing/tiny-clap-htsat-unfused'    )
  __A	:		Any	  =      load_dataset('ashraq/esc50'    )
  __A	:		Union[str, Any]	  =      dataset['train']['audio'][-1]['array']
  __A	:		List[Any]	  =      audio_classifier(__lowercase   ,   candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']    )
  self.assertEqual(
      nested_simplify(__lowercase    )   ,   [{'score': 0.5_0_1, 'label': 'Sound of a dog'}, {'score': 0.4_9_9, 'label': 'Sound of vaccum cleaner'}]   ,   )


 @unittest.skip('No models are available in TF'    )
 def 			snake_case__ (   self    ):

  """simple docstring"""







  pass


 @slow
 @require_torch
 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Optional[Any]	  =      pipeline(
      task='zero-shot-audio-classification'   ,   model='laion/clap-htsat-unfused'   ,   )
  # This is an audio of a dog
  __A	:		List[str]	  =      load_dataset('ashraq/esc50'    )
  __A	:		Any	  =      dataset['train']['audio'][-1]['array']
  __A	:		Optional[Any]	  =      audio_classifier(__lowercase   ,   candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']    )

  self.assertEqual(
      nested_simplify(__lowercase    )   ,   [
          {'score': 0.9_9_9, 'label': 'Sound of a dog'},
          {'score': 0.0_0_1, 'label': 'Sound of vaccum cleaner'},
      ]   ,   )

  __A	:		Dict	  =      audio_classifier([audio] * 5   ,   candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']    )
  self.assertEqual(
      nested_simplify(__lowercase    )   ,   [
          [
              {'score': 0.9_9_9, 'label': 'Sound of a dog'},
              {'score': 0.0_0_1, 'label': 'Sound of vaccum cleaner'},
          ],
      ]
      * 5   ,   )
  __A	:		Dict	  =      audio_classifier(
      [audio] * 5   ,   candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']   ,   batch_size=5    )
  self.assertEqual(
      nested_simplify(__lowercase    )   ,   [
          [
              {'score': 0.9_9_9, 'label': 'Sound of a dog'},
              {'score': 0.0_0_1, 'label': 'Sound of vaccum cleaner'},
          ],
      ]
      * 5   ,   )







 @unittest.skip('No models are available in TF'    )
 def 			snake_case__ (   self    ):

  """simple docstring"""







  pass










'''simple docstring'''
import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp


def       _lowercase							(					):
 __A	:		List[Any]	  =      ArgumentParser(
     description=(
         'PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes'
     )      )

 # Optional arguments for the launch helper
 parser.add_argument('--num_cores',					type=UpperCamelCase__,					default=1,					help='Number of TPU cores to use (1 or 8).'      )

 # positional
 parser.add_argument(
     'training_script',					type=UpperCamelCase__,					help=(
         'The full path to the single TPU training '
         'program/script to be launched in parallel, '
         'followed by all the arguments for the '
         'training script'
     ),					)

 # rest from the training program
 parser.add_argument('training_script_args',					nargs=UpperCamelCase__      )

 return parser.parse_args()


def       _lowercase							(					):
 __A	:		str	  =      parse_args()

 # Import training_script as a module.
 __A	:		Tuple	  =      Path(args.training_script      )
 sys.path.append(str(script_fpath.parent.resolve()      )      )
 __A	:		str	  =      script_fpath.stem
 __A	:		Dict	  =      importlib.import_module(UpperCamelCase__      )

 # Patch sys.argv
 __A	:		Optional[Any]	  =      [args.training_script] + args.training_script_args + ['--tpu_num_cores', str(args.num_cores      )]

 xmp.spawn(mod._mp_fn,					args=(),					nprocs=args.num_cores      )


if __name__ == "__main__":
 main()






