


import tempfile
import unittest

from make_student import create_student_by_copying_alternating_layers

from transformers import AutoConfig
from transformers.file_utils import cached_property
from transformers.testing_utils import require_torch


lowerCAmelCase							=						"""sshleifer/bart-tiny-random"""
lowerCAmelCase							=						"""patrickvonplaten/t5-tiny-random"""




@require_torch
class        lowerCamelCase      (     unittest.TestCase   ):


	@cached_property
	def    A(						self):
							return AutoConfig.from_pretrained(lowercase__)


	def    A(						self):
							__UpperCAmelCase						,			*__UpperCAmelCase :       Dict  						=  create_student_by_copying_alternating_layers(lowercase__							,    tempfile.mkdtemp()							,    e=1							,    d=1)
							self.assertEqual(student.config.num_hidden_layers							,    1)


	def    A(						self):
							__UpperCAmelCase						,			*__UpperCAmelCase :       Union[str, Any]  						=  create_student_by_copying_alternating_layers(lowercase__							,    tempfile.mkdtemp()							,    e=1							,    d=lowercase__)


	def    A(						self):
							__UpperCAmelCase						,			*__UpperCAmelCase :       Tuple  						=  create_student_by_copying_alternating_layers(lowercase__							,    tempfile.mkdtemp()							,    e=1							,    d=lowercase__)
							self.assertEqual(student.config.encoder_layers							,    1)
							self.assertEqual(student.config.decoder_layers							,    self.teacher_config.encoder_layers)


	def    A(						self):
							__UpperCAmelCase						,			*__UpperCAmelCase :       Dict  						=  create_student_by_copying_alternating_layers(lowercase__							,    tempfile.mkdtemp()							,    e=1							,    d=1)
							self.assertEqual(student.config.encoder_layers							,    1)
							self.assertEqual(student.config.decoder_layers							,    1)


	def    A(						self):
							with self.assertRaises(lowercase__):
													create_student_by_copying_alternating_layers(lowercase__							,    tempfile.mkdtemp()							,    e=lowercase__							,    d=lowercase__)





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


	@require_torch
	def    A(						self):
							__UpperCAmelCase :       str  						=  pipeline(
							    task='''zero-shot-audio-classification'''							,    model='''hf-internal-testing/tiny-clap-htsat-unfused''')
							__UpperCAmelCase :       Optional[int]  						=  load_dataset('''ashraq/esc50''')
							__UpperCAmelCase :       Dict  						=  dataset['''train''']['''audio'''][-1]['''array''']
							__UpperCAmelCase :       Union[str, 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    A(						self):
							pass


	@slow
	@require_torch
	def    A(						self):
							__UpperCAmelCase :       int  						=  pipeline(
							    task='''zero-shot-audio-classification'''							,    model='''laion/clap-htsat-unfused'''							,    )
							# This is an audio of a dog
							__UpperCAmelCase :       Optional[Any]  						=  load_dataset('''ashraq/esc50''')
							__UpperCAmelCase :       Union[str, Any]  						=  dataset['''train''']['''audio'''][-1]['''array''']
							__UpperCAmelCase :       Union[str, 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'''},
							    ]							,    )

							__UpperCAmelCase :       Optional[Any]  						=  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							,    )
							__UpperCAmelCase :       Optional[Any]  						=  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    A(						self):
							pass

