



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



	@require_torch
	def 			__A							(       self		):
							A__							=       pipeline(
							    task="zero-shot-audio-classification"			,	model="hf-internal-testing/tiny-clap-htsat-unfused"		)
							A__							=       load_dataset("ashraq/esc50"		)
							A__							=       dataset["train"]["audio"][-1]["array"]
							A__							=       audio_classifier(UpperCAmelCase__			,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]		)
							self.assertEqual(
							    nested_simplify(UpperCAmelCase__		)			,	[{"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 			__A							(       self		):
							pass



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

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

							A__							=       audio_classifier([audio] * 5			,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]		)
							self.assertEqual(
							    nested_simplify(UpperCAmelCase__		)			,	[
							        [
							            {"score": 0.999, "label": "Sound of a dog"},
							            {"score": 0.001, "label": "Sound of vaccum cleaner"},
							        ],
							    ]
							    * 5			,	)
							A__							=       audio_classifier(
							    [audio] * 5			,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]			,	batch_size=5		)
							self.assertEqual(
							    nested_simplify(UpperCAmelCase__		)			,	[
							        [
							            {"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 			__A							(       self		):
							pass










import argparse

import torch
from huggingface_hub import hf_hub_download

from transformers import AutoTokenizer, RobertaPreLayerNormConfig, RobertaPreLayerNormForMaskedLM
from transformers.utils import logging


logging.set_verbosity_info()
UpperCAmelCase_							:      Union[str, Any]      =  logging.get_logger(__name__)
def  UpperCamelCase						(       _A			:				str			,							_A			:				str    )->       Any:





						"""simple docstring"""





						A__							=       RobertaPreLayerNormConfig.from_pretrained(
						    _A			,							architectures=["RobertaPreLayerNormForMaskedLM"]    )

						# convert state_dict
						A__							=       torch.load(hf_hub_download(repo_id=_A			,							filename="pytorch_model.bin"    )    )
						A__							=       {}
						for tensor_key, tensor_value in original_state_dict.items():
												# The transformer implementation gives the model a unique name, rather than overwiriting 'roberta'
												if tensor_key.startswith("roberta."    ):
																		A__							=       "roberta_prelayernorm." + tensor_key[len("roberta."    ) :]

												# The original implementation contains weights which are not used, remove them from the state_dict
												if tensor_key.endswith(".self.LayerNorm.weight"    ) or tensor_key.endswith(".self.LayerNorm.bias"    ):
																		continue

												A__							=       tensor_value

						A__							=       RobertaPreLayerNormForMaskedLM.from_pretrained(
						    pretrained_model_name_or_path=_A			,							config=_A			,							state_dict=_A    )
						model.save_pretrained(_A    )

						# convert tokenizer
						A__							=       AutoTokenizer.from_pretrained(_A    )
						tokenizer.save_pretrained(_A    )


if __name__ == "__main__":
						UpperCAmelCase_							:      str      =  argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    "--checkpoint-repo",
						    default=None,
						    type=str,
						    required=True,
						    help="Path the official PyTorch dump, e.g. 'andreasmadsen/efficient_mlm_m0.40'.",
						)
						parser.add_argument(
						    "--pytorch_dump_folder_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
						)
						UpperCAmelCase_							:      List[Any]      =  parser.parse_args()
						convert_roberta_prelayernorm_checkpoint_to_pytorch(args.checkpoint_repo, args.pytorch_dump_folder_path)





