



import math
import os
import unittest

from transformers import MegatronBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    MODEL_FOR_PRETRAINING_MAPPING,
							    MegatronBertForCausalLM,
							    MegatronBertForMaskedLM,
							    MegatronBertForMultipleChoice,
							    MegatronBertForNextSentencePrediction,
							    MegatronBertForPreTraining,
							    MegatronBertForQuestionAnswering,
							    MegatronBertForSequenceClassification,
							    MegatronBertForTokenClassification,
							    MegatronBertModel,
							)







class     __lowerCAmelCase					:



			def __init__(		self     :						Tuple				,	A     :						Optional[int]				,	A     :						Optional[int]=13				,	A     :						List[Any]=7				,	A     :						int=True				,	A     :						str=True				,	A     :						Optional[Any]=True				,	A     :						Optional[int]=True				,	A     :						List[Any]=99				,	A     :						Tuple=64				,	A     :						Tuple=32				,	A     :						Optional[int]=5				,	A     :						List[str]=4				,	A     :						List[Any]=37				,	A     :						Optional[int]="gelu"				,	A     :						Any=0.1				,	A     :						Optional[int]=0.1				,	A     :						Optional[int]=5_12				,	A     :						Tuple=16				,	A     :						Any=2				,	A     :						Dict=0.0_2				,	A     :						Tuple=3				,	A     :						List[Any]=4				,	A     :						int=None				,	)     ->					Optional[Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     parent
						_UpperCAmelCase	 =     batch_size
						_UpperCAmelCase	 =     seq_length
						_UpperCAmelCase	 =     is_training
						_UpperCAmelCase	 =     use_input_mask
						_UpperCAmelCase	 =     use_token_type_ids
						_UpperCAmelCase	 =     use_labels
						_UpperCAmelCase	 =     vocab_size
						_UpperCAmelCase	 =     hidden_size
						_UpperCAmelCase	 =     embedding_size
						_UpperCAmelCase	 =     num_hidden_layers
						_UpperCAmelCase	 =     num_attention_heads
						_UpperCAmelCase	 =     intermediate_size
						_UpperCAmelCase	 =     hidden_act
						_UpperCAmelCase	 =     hidden_dropout_prob
						_UpperCAmelCase	 =     attention_probs_dropout_prob
						_UpperCAmelCase	 =     max_position_embeddings
						_UpperCAmelCase	 =     type_vocab_size
						_UpperCAmelCase	 =     type_sequence_label_size
						_UpperCAmelCase	 =     initializer_range
						_UpperCAmelCase	 =     num_labels
						_UpperCAmelCase	 =     num_choices
						_UpperCAmelCase	 =     scope



			def 					_lowerCamelCase (		self     :						List[str])     ->					int:



						"""simple docstring"""






						_UpperCAmelCase	 =     ids_tensor([self.batch_size, self.seq_length]				,	self.vocab_size)

						_UpperCAmelCase	 =     None
						if self.use_input_mask:
									_UpperCAmelCase	 =     random_attention_mask([self.batch_size, self.seq_length])

						_UpperCAmelCase	 =     None
						if self.use_token_type_ids:
									_UpperCAmelCase	 =     ids_tensor([self.batch_size, self.seq_length]				,	self.type_vocab_size)

						_UpperCAmelCase	 =     None
						_UpperCAmelCase	 =     None
						_UpperCAmelCase	 =     None
						if self.use_labels:
									_UpperCAmelCase	 =     ids_tensor([self.batch_size]				,	self.type_sequence_label_size)
									_UpperCAmelCase	 =     ids_tensor([self.batch_size, self.seq_length]				,	self.num_labels)
									_UpperCAmelCase	 =     ids_tensor([self.batch_size]				,	self.num_choices)

						_UpperCAmelCase	 =     self.get_config()

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



			def 					_lowerCamelCase (		self     :						int)     ->					str:



						"""simple docstring"""






						return MegatronBertConfig(
						    vocab_size=self.vocab_size				,	hidden_size=self.hidden_size				,	num_hidden_layers=self.num_hidden_layers				,	num_attention_heads=self.num_attention_heads				,	intermediate_size=self.intermediate_size				,	embedding_size=self.embedding_size				,	hidden_act=self.hidden_act				,	hidden_dropout_prob=self.hidden_dropout_prob				,	attention_probs_dropout_prob=self.attention_probs_dropout_prob				,	max_position_embeddings=self.max_position_embeddings				,	type_vocab_size=self.type_vocab_size				,	is_decoder=A				,	initializer_range=self.initializer_range				,	)



			def 					_lowerCamelCase (		self     :						Dict				,	A     :						Union[str, Any]				,	A     :						Optional[Any]				,	A     :						List[str]				,	A     :						Tuple				,	A     :						List[Any]				,	A     :						Any				,	A     :						int)     ->					Dict:



						"""simple docstring"""






						_UpperCAmelCase	 =     MegatronBertModel(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     model(A				,	attention_mask=A				,	token_type_ids=A)
						_UpperCAmelCase	 =     model(A				,	token_type_ids=A)
						_UpperCAmelCase	 =     model(A)

						self.parent.assertEqual(result.last_hidden_state.shape				,	(self.batch_size, self.seq_length, self.hidden_size))
						self.parent.assertEqual(result.pooler_output.shape				,	(self.batch_size, self.hidden_size))



			def 					_lowerCamelCase (		self     :						Optional[Any]				,	A     :						List[str]				,	A     :						Any				,	A     :						Union[str, Any]				,	A     :						List[Any]				,	A     :						Union[str, Any]				,	A     :						Optional[int]				,	A     :						Union[str, Any])     ->					Union[str, Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     MegatronBertForMaskedLM(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     model(A				,	attention_mask=A				,	token_type_ids=A				,	labels=A)
						self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.seq_length, self.vocab_size))



			def 					_lowerCamelCase (		self     :						Optional[Any]				,	A     :						Any				,	A     :						Optional[Any]				,	A     :						Any				,	A     :						List[Any]				,	A     :						str				,	A     :						Union[str, Any]				,	A     :						int)     ->					List[Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     MegatronBertForCausalLM(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     model(A				,	attention_mask=A				,	token_type_ids=A				,	labels=A)
						self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.seq_length, self.vocab_size))



			def 					_lowerCamelCase (		self     :						str				,	A     :						List[Any]				,	A     :						List[str]				,	A     :						str				,	A     :						Dict				,	A     :						Any				,	A     :						List[str]				,	A     :						List[str])     ->					Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase	 =     MegatronBertForNextSentencePrediction(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     model(
						    A				,	attention_mask=A				,	token_type_ids=A				,	labels=A				,	)
						self.parent.assertEqual(result.logits.shape				,	(self.batch_size, 2))



			def 					_lowerCamelCase (		self     :						List[str]				,	A     :						Union[str, Any]				,	A     :						str				,	A     :						Any				,	A     :						Tuple				,	A     :						Optional[int]				,	A     :						Dict				,	A     :						Optional[int])     ->					Union[str, Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     MegatronBertForPreTraining(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     model(
						    A				,	attention_mask=A				,	token_type_ids=A				,	labels=A				,	next_sentence_label=A				,	)
						self.parent.assertEqual(result.prediction_logits.shape				,	(self.batch_size, self.seq_length, self.vocab_size))
						self.parent.assertEqual(result.seq_relationship_logits.shape				,	(self.batch_size, 2))



			def 					_lowerCamelCase (		self     :						Dict				,	A     :						str				,	A     :						List[str]				,	A     :						List[Any]				,	A     :						Any				,	A     :						Tuple				,	A     :						Optional[Any]				,	A     :						Dict)     ->					List[Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     MegatronBertForQuestionAnswering(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     model(
						    A				,	attention_mask=A				,	token_type_ids=A				,	start_positions=A				,	end_positions=A				,	)
						self.parent.assertEqual(result.start_logits.shape				,	(self.batch_size, self.seq_length))
						self.parent.assertEqual(result.end_logits.shape				,	(self.batch_size, self.seq_length))



			def 					_lowerCamelCase (		self     :						Tuple				,	A     :						Union[str, Any]				,	A     :						Tuple				,	A     :						Tuple				,	A     :						Optional[Any]				,	A     :						List[str]				,	A     :						Optional[Any]				,	A     :						Union[str, Any])     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.num_labels
						_UpperCAmelCase	 =     MegatronBertForSequenceClassification(A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     model(A				,	attention_mask=A				,	token_type_ids=A				,	labels=A)
						self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.num_labels))



			def 					_lowerCamelCase (		self     :						Optional[int]				,	A     :						Optional[Any]				,	A     :						Dict				,	A     :						Union[str, Any]				,	A     :						List[Any]				,	A     :						int				,	A     :						Dict				,	A     :						Optional[int])     ->					int:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.num_labels
						_UpperCAmelCase	 =     MegatronBertForTokenClassification(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     model(A				,	attention_mask=A				,	token_type_ids=A				,	labels=A)
						self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.seq_length, self.num_labels))



			def 					_lowerCamelCase (		self     :						Any				,	A     :						List[Any]				,	A     :						List[Any]				,	A     :						Any				,	A     :						str				,	A     :						Dict				,	A     :						Union[str, Any]				,	A     :						Tuple)     ->					List[str]:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.num_choices
						_UpperCAmelCase	 =     MegatronBertForMultipleChoice(config=A)
						model.to(A)
						model.eval()
						_UpperCAmelCase	 =     input_ids.unsqueeze(1).expand(-1				,	self.num_choices				,	-1).contiguous()
						_UpperCAmelCase	 =     token_type_ids.unsqueeze(1).expand(-1				,	self.num_choices				,	-1).contiguous()
						_UpperCAmelCase	 =     input_mask.unsqueeze(1).expand(-1				,	self.num_choices				,	-1).contiguous()
						_UpperCAmelCase	 =     model(
						    A				,	attention_mask=A				,	token_type_ids=A				,	labels=A				,	)
						self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.num_choices))



			def 					_lowerCamelCase (		self     :						int)     ->					Any:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.prepare_config_and_inputs()
						(
						    (
						    _UpperCAmelCase
						) ,  (
						    _UpperCAmelCase
						) ,  (
						    _UpperCAmelCase
						) ,  (
						    _UpperCAmelCase
						) ,  (
						    _UpperCAmelCase
						) ,  (
						    _UpperCAmelCase
						) ,  (
						    _UpperCAmelCase
						) ,  
						)	 =     config_and_inputs
						_UpperCAmelCase	 =     {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
						return config, inputs_dict







@require_torch
class     __lowerCAmelCase					(    A       ,		A       ,		unittest.TestCase		):
			UpperCamelCase           =  (
			    (
			        MegatronBertModel,
			        MegatronBertForMaskedLM,
			        MegatronBertForCausalLM,
			        MegatronBertForMultipleChoice,
			        MegatronBertForNextSentencePrediction,
			        MegatronBertForPreTraining,
			        MegatronBertForQuestionAnswering,
			        MegatronBertForSequenceClassification,
			        MegatronBertForTokenClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			UpperCamelCase           =  (
			    {
			        '''feature-extraction''': MegatronBertModel,
			        '''fill-mask''': MegatronBertForMaskedLM,
			        '''question-answering''': MegatronBertForQuestionAnswering,
			        '''text-classification''': MegatronBertForSequenceClassification,
			        '''text-generation''': MegatronBertForCausalLM,
			        '''token-classification''': MegatronBertForTokenClassification,
			        '''zero-shot''': MegatronBertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			UpperCamelCase           =  True
			# test_resize_embeddings = False
			UpperCamelCase           =  False



			def 					_lowerCamelCase (		self     :						str				,	A     :						Tuple				,	A     :						str				,	A     :						int=False)     ->					Dict:



						"""simple docstring"""






						_UpperCAmelCase	 =     super()._prepare_for_class(A				,	A				,	return_labels=A)

						if return_labels:
									if model_class in get_values(A):
												_UpperCAmelCase	 =     torch.zeros(
												    (self.model_tester.batch_size, self.model_tester.seq_length)				,	dtype=torch.long				,	device=A)
												_UpperCAmelCase	 =     torch.zeros(
												    self.model_tester.batch_size				,	dtype=torch.long				,	device=A)
						return inputs_dict



			def 					_lowerCamelCase (		self     :						Union[str, Any])     ->					Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase	 =     MegatronBertModelTester(self)
						_UpperCAmelCase	 =     ConfigTester(self				,	config_class=A				,	hidden_size=37)



			def 					_lowerCamelCase (		self     :						Tuple)     ->					Optional[int]:



						"""simple docstring"""






						self.config_tester.run_common_tests()



			def 					_lowerCamelCase (		self     :						Tuple)     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_megatron_bert_model(*A)



			def 					_lowerCamelCase (		self     :						Optional[Any])     ->					Optional[Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_megatron_bert_for_masked_lm(*A)



			def 					_lowerCamelCase (		self     :						Tuple)     ->					Dict:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_megatron_bert_for_multiple_choice(*A)



			def 					_lowerCamelCase (		self     :						str)     ->					Dict:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_megatron_bert_for_next_sequence_prediction(*A)



			def 					_lowerCamelCase (		self     :						str)     ->					Union[str, Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_megatron_bert_for_pretraining(*A)



			def 					_lowerCamelCase (		self     :						List[Any])     ->					int:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_megatron_bert_for_question_answering(*A)



			def 					_lowerCamelCase (		self     :						Optional[int])     ->					Optional[Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_megatron_bert_for_sequence_classification(*A)



			def 					_lowerCamelCase (		self     :						List[Any])     ->					Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase	 =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_megatron_bert_for_token_classification(*A)





def 							A			(  _UpperCAmelCase       :     Tuple					)       ->				Tuple:







			'''simple docstring'''
			return torch.tensor(
			    _UpperCAmelCase							,     dtype=torch.long							,     device=_UpperCAmelCase							,     )


UpperCAmelCase__     = 1E-4







@require_torch
@require_sentencepiece
@require_tokenizers
class     __lowerCAmelCase					(    unittest.TestCase		):



			@slow
			@unittest.skip('Model is not available.')
			def 					_lowerCamelCase (		self     :						Union[str, Any])     ->					List[str]:



						"""simple docstring"""






						_UpperCAmelCase	 =     'nvidia/megatron-bert-uncased-345m'
						if "MYDIR" in os.environ:
									_UpperCAmelCase	 =     os.path.join(os.environ['MYDIR']				,	A)
						_UpperCAmelCase	 =     MegatronBertModel.from_pretrained(A)
						model.to(A)
						model.half()
						_UpperCAmelCase	 =     _long_tensor([[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]])
						with torch.no_grad():
									_UpperCAmelCase	 =     model(A)[0]
						_UpperCAmelCase	 =     torch.Size((1, 9, 10_24))
						self.assertEqual(output.shape				,	A)

						_UpperCAmelCase	 =     [-0.6_0_4_0, -0.2_5_1_7, -0.1_0_2_5, 0.3_4_2_0, -0.6_7_5_8, -0.0_0_1_7, -0.1_0_8_9, -0.1_9_9_0, 0.5_7_2_8]
						for ii in range(3):
									for jj in range(3):
												_UpperCAmelCase	 =     output[0, ii, jj]
												_UpperCAmelCase	 =     expected[3 * ii + jj]
												_UpperCAmelCase	 =     'ii={} jj={} a={} b={}'.format(A				,	A				,	A				,	A)
												self.assertTrue(math.isclose(A				,	A				,	rel_tol=A				,	abs_tol=A)				,	msg=A)





import unittest

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
							from PIL import Image
else:







							class     __lowerCAmelCase					:



										@staticmethod
										def 					_lowerCamelCase (		*A     :						Union[str, Any]				,	**A     :						List[Any])     ->					Union[str, Any]:



													"""simple docstring"""






													pass







@is_pipeline_test
@require_vision
class     __lowerCAmelCase					(    unittest.TestCase		):



			@require_torch
			def 					_lowerCamelCase (		self     :						List[str])     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     pipeline(
						    model='hf-internal-testing/tiny-random-clip-zero-shot-image-classification'				,	)
						_UpperCAmelCase	 =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
						_UpperCAmelCase	 =     image_classifier(A				,	candidate_labels=['a', 'b', 'c'])

						# The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
						# python and torch versions.
						self.assertIn(
						    nested_simplify(A)				,	[
						        [{'score': 0.3_3_3, 'label': 'a'}, {'score': 0.3_3_3, 'label': 'b'}, {'score': 0.3_3_3, 'label': 'c'}],
						        [{'score': 0.3_3_3, 'label': 'a'}, {'score': 0.3_3_3, 'label': 'c'}, {'score': 0.3_3_3, 'label': 'b'}],
						    ]				,	)

						_UpperCAmelCase	 =     image_classifier([image] * 5				,	candidate_labels=['A', 'B', 'C']				,	batch_size=2)
						self.assertEqual(
						    nested_simplify(A)				,	[
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						    ]				,	)



			@require_tf
			def 					_lowerCamelCase (		self     :						str)     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     pipeline(
						    model='hf-internal-testing/tiny-random-clip-zero-shot-image-classification'				,	framework='tf')
						_UpperCAmelCase	 =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
						_UpperCAmelCase	 =     image_classifier(A				,	candidate_labels=['a', 'b', 'c'])

						self.assertEqual(
						    nested_simplify(A)				,	[{'score': 0.3_3_3, 'label': 'a'}, {'score': 0.3_3_3, 'label': 'b'}, {'score': 0.3_3_3, 'label': 'c'}]				,	)

						_UpperCAmelCase	 =     image_classifier([image] * 5				,	candidate_labels=['A', 'B', 'C']				,	batch_size=2)
						self.assertEqual(
						    nested_simplify(A)				,	[
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						        [
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						            {'score': 0.3_3_3, 'label': ANY(A)},
						        ],
						    ]				,	)



			@slow
			@require_torch
			def 					_lowerCamelCase (		self     :						Tuple)     ->					Optional[Any]:



						"""simple docstring"""






						_UpperCAmelCase	 =     pipeline(
						    task='zero-shot-image-classification'				,	model='openai/clip-vit-base-patch32'				,	)
						# This is an image of 2 cats with remotes and no planes
						_UpperCAmelCase	 =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
						_UpperCAmelCase	 =     image_classifier(A				,	candidate_labels=['cat', 'plane', 'remote'])

						self.assertEqual(
						    nested_simplify(A)				,	[
						        {'score': 0.5_1_1, 'label': 'remote'},
						        {'score': 0.4_8_5, 'label': 'cat'},
						        {'score': 0.0_0_4, 'label': 'plane'},
						    ]				,	)

						_UpperCAmelCase	 =     image_classifier([image] * 5				,	candidate_labels=['cat', 'plane', 'remote']				,	batch_size=2)
						self.assertEqual(
						    nested_simplify(A)				,	[
						        [
						            {'score': 0.5_1_1, 'label': 'remote'},
						            {'score': 0.4_8_5, 'label': 'cat'},
						            {'score': 0.0_0_4, 'label': 'plane'},
						        ],
						    ]
						    * 5				,	)



			@slow
			@require_tf
			def 					_lowerCamelCase (		self     :						List[str])     ->					Any:



						"""simple docstring"""






						_UpperCAmelCase	 =     pipeline(
						    task='zero-shot-image-classification'				,	model='openai/clip-vit-base-patch32'				,	framework='tf')
						# This is an image of 2 cats with remotes and no planes
						_UpperCAmelCase	 =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
						_UpperCAmelCase	 =     image_classifier(A				,	candidate_labels=['cat', 'plane', 'remote'])
						self.assertEqual(
						    nested_simplify(A)				,	[
						        {'score': 0.5_1_1, 'label': 'remote'},
						        {'score': 0.4_8_5, 'label': 'cat'},
						        {'score': 0.0_0_4, 'label': 'plane'},
						    ]				,	)

						_UpperCAmelCase	 =     image_classifier([image] * 5				,	candidate_labels=['cat', 'plane', 'remote']				,	batch_size=2)
						self.assertEqual(
						    nested_simplify(A)				,	[
						        [
						            {'score': 0.5_1_1, 'label': 'remote'},
						            {'score': 0.4_8_5, 'label': 'cat'},
						            {'score': 0.0_0_4, 'label': 'plane'},
						        ],
						    ]
						    * 5				,	)
