
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     _UpperCamelCase			(   unittest.TestCase					):






			'''simple docstring'''

			@require_torch
			def  lowerCAmelCase__		(    self	:    Dict ):
							UpperCamelCase_:							Any		=  pipeline(
							    task="""zero-shot-audio-classification"""  ,		model="""hf-internal-testing/tiny-clap-htsat-unfused""" )
							UpperCamelCase_:							str		=  load_dataset("""ashraq/esc50""" )
							UpperCamelCase_:							Optional[int]		=  dataset["""train"""]["""audio"""][-1]["""array"""]
							UpperCamelCase_:							Optional[int]		=  audio_classifier(snake_case_  ,		candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""] )
							self.assertEqual(
							    nested_simplify(snake_case_ )  ,		[{"""score""": 0.501, """label""": """Sound of a dog"""}, {"""score""": 0.499, """label""": """Sound of vaccum cleaner"""}]  ,		)

			@unittest.skip("""No models are available in TF""" )
			def  lowerCAmelCase__		(    self	:    Optional[Any] ):
							pass

			@slow
			@require_torch
			def  lowerCAmelCase__		(    self	:    int ):
							UpperCamelCase_:							List[str]		=  pipeline(
							    task="""zero-shot-audio-classification"""  ,		model="""laion/clap-htsat-unfused"""  ,		)
							# This is an audio of a dog
							UpperCamelCase_:							Tuple		=  load_dataset("""ashraq/esc50""" )
							UpperCamelCase_:							Optional[int]		=  dataset["""train"""]["""audio"""][-1]["""array"""]
							UpperCamelCase_:							int		=  audio_classifier(snake_case_  ,		candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""] )

							self.assertEqual(
							    nested_simplify(snake_case_ )  ,		[
							        {"""score""": 0.999, """label""": """Sound of a dog"""},
							        {"""score""": 0.001, """label""": """Sound of vaccum cleaner"""},
							    ]  ,		)

							UpperCamelCase_:							Any		=  audio_classifier([audio] * 5  ,		candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""] )
							self.assertEqual(
							    nested_simplify(snake_case_ )  ,		[
							        [
							            {"""score""": 0.999, """label""": """Sound of a dog"""},
							            {"""score""": 0.001, """label""": """Sound of vaccum cleaner"""},
							        ],
							    ]
							    * 5  ,		)
							UpperCamelCase_:							Any		=  audio_classifier(
							    [audio] * 5  ,		candidate_labels=["""Sound of a dog""", """Sound of vaccum cleaner"""]  ,		batch_size=5 )
							self.assertEqual(
							    nested_simplify(snake_case_ )  ,		[
							        [
							            {"""score""": 0.999, """label""": """Sound of a dog"""},
							            {"""score""": 0.001, """label""": """Sound of vaccum cleaner"""},
							        ],
							    ]
							    * 5  ,		)




			@unittest.skip("""No models are available in TF""" )
			def  lowerCAmelCase__		(    self	:    Optional[Any] ):
							pass








import argparse

import torch

from transformers import GPTaConfig, GPTaModel, load_tf_weights_in_gpta
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()







def     A__   (  lowerCamelCase       ,      lowerCamelCase       ,      lowerCamelCase  )					->		Union[str, Any]:
				# Construct model
				if gpta_config_file == "":
								UpperCamelCase_:							Union[str, Any]		=  GPTaConfig()
				else:
								UpperCamelCase_:							Optional[Any]		=  GPTaConfig.from_json_file(lowerCamelCase  )
				UpperCamelCase_:							List[Any]		=  GPTaModel(lowerCamelCase  )

				# Load weights from numpy
				load_tf_weights_in_gpta(lowerCamelCase       ,      lowerCamelCase       ,      lowerCamelCase  )

				# Save pytorch-model
				UpperCamelCase_:							int		=  pytorch_dump_folder_path + """/""" + WEIGHTS_NAME
				UpperCamelCase_:							Any		=  pytorch_dump_folder_path + """/""" + CONFIG_NAME
				print(F'''Save PyTorch model to {pytorch_weights_dump_path}'''  )
				torch.save(model.state_dict()       ,      lowerCamelCase  )
				print(F'''Save configuration file to {pytorch_config_dump_path}'''  )
				with open(lowerCamelCase       ,      """w"""       ,      encoding="""utf-8"""  ) as f:
								f.write(config.to_json_string()  )


if __name__ == "__main__":
							lowerCamelCase_  :	int 				=					argparse.ArgumentParser()
							# Required parameters
							parser.add_argument(
							    """--gpt2_checkpoint_path""", default=None, type=str, required=True, help="""Path to the TensorFlow checkpoint path."""
							)
							parser.add_argument(
							    """--pytorch_dump_folder_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
							)
							parser.add_argument(
							    """--gpt2_config_file""",
							    default="""""",
							    type=str,
							    help=(
							        """An optional config json file corresponding to the pre-trained OpenAI model. \n"""
							        """This specifies the model architecture."""
							    ),
							)
							lowerCamelCase_  :	List[str] 				=					parser.parse_args()
							convert_gpta_checkpoint_to_pytorch(args.gpta_checkpoint_path, args.gpta_config_file, args.pytorch_dump_folder_path)






