




import unittest

import numpy as np
import timeout_decorator  # noqa

from transformers import BlenderbotSmallConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...generation.test_flax_utils import FlaxGenerationTesterMixin
from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor


if is_flax_available():
						import os

						# The slow tests are often failing with OOM error on GPU
						# This makes JAX allocate exactly what is needed on demand, and deallocate memory that is no longer needed
						# but will be slower as stated here https://jax.readthedocs.io/en/latest/gpu_memory_allocation.html
						__a    :						str						      =       '''platform'''

						import jax
						import jax.numpy as jnp

						from transformers.models.blenderbot_small.modeling_flax_blenderbot_small import (
						    FlaxBlenderbotSmallForConditionalGeneration,
						    FlaxBlenderbotSmallModel,
						    shift_tokens_right,
						)
def    snake_case_	(						SCREAMING_SNAKE_CASE_							,SCREAMING_SNAKE_CASE_							,SCREAMING_SNAKE_CASE_=None							,SCREAMING_SNAKE_CASE_=None							,SCREAMING_SNAKE_CASE_=None							,SCREAMING_SNAKE_CASE_=None							,SCREAMING_SNAKE_CASE_=None							,SCREAMING_SNAKE_CASE_=None							,)     ->					Union[str, Any]:
							if attention_mask is None:
														lowercase__    :			Tuple     =				np.where(input_ids != config.pad_token_id							,1							,0							)
							if decoder_attention_mask is None:
														lowercase__    :			List[Any]     =				np.where(decoder_input_ids != config.pad_token_id							,1							,0							)
							if head_mask is None:
														lowercase__    :			List[str]     =				np.ones((config.encoder_layers, config.encoder_attention_heads)							)
							if decoder_head_mask is None:
														lowercase__    :			str     =				np.ones((config.decoder_layers, config.decoder_attention_heads)							)
							if cross_attn_head_mask is None:
														lowercase__    :			str     =				np.ones((config.decoder_layers, config.decoder_attention_heads)							)
							return {
							    "input_ids": input_ids,
							    "decoder_input_ids": decoder_input_ids,
							    "attention_mask": attention_mask,
							    "decoder_attention_mask": attention_mask,
							}







class  UpperCAmelCase:



	"""simple docstring"""






	def __init__(	self			, lowerCamelCase			, lowerCamelCase=13			, lowerCamelCase=7			, lowerCamelCase=True			, lowerCamelCase=False			, lowerCamelCase=99			, lowerCamelCase=16			, lowerCamelCase=2			, lowerCamelCase=4			, lowerCamelCase=4			, lowerCamelCase="gelu"			, lowerCamelCase=0.1			, lowerCamelCase=0.1			, lowerCamelCase=32			, lowerCamelCase=2			, lowerCamelCase=1			, lowerCamelCase=0			, lowerCamelCase=0.02			, )   ->     Optional[int]:





								"""simple docstring"""


								lowercase__    :			Union[str, Any]     =				parent
								lowercase__    :			List[str]     =				batch_size
								lowercase__    :			Any     =				seq_length
								lowercase__    :			Dict     =				is_training
								lowercase__    :			Optional[int]     =				use_labels
								lowercase__    :			List[Any]     =				vocab_size
								lowercase__    :			Tuple     =				hidden_size
								lowercase__    :			Any     =				num_hidden_layers
								lowercase__    :			int     =				num_attention_heads
								lowercase__    :			Tuple     =				intermediate_size
								lowercase__    :			Optional[int]     =				hidden_act
								lowercase__    :			Dict     =				hidden_dropout_prob
								lowercase__    :			int     =				attention_probs_dropout_prob
								lowercase__    :			Any     =				max_position_embeddings
								lowercase__    :			int     =				eos_token_id
								lowercase__    :			Union[str, Any]     =				pad_token_id
								lowercase__    :			Optional[int]     =				bos_token_id
								lowercase__    :			Dict     =				initializer_range

	def        __a      (	self							)   ->     int:





								"""simple docstring"""


								lowercase__    :			Optional[Any]     =				np.clip(ids_tensor([self.batch_size, self.seq_length - 1]			, self.vocab_size							)			, 3			, self.vocab_size							)
								lowercase__    :			str     =				np.concatenate((input_ids, 2 * np.ones((self.batch_size, 1)			, dtype=np.intaa							))			, -1							)

								lowercase__    :			Any     =				shift_tokens_right(snake_case_			, 1			, 2							)

								lowercase__    :			Union[str, Any]     =				BlenderbotSmallConfig(
								    vocab_size=self.vocab_size			, d_model=self.hidden_size			, encoder_layers=self.num_hidden_layers			, decoder_layers=self.num_hidden_layers			, encoder_attention_heads=self.num_attention_heads			, decoder_attention_heads=self.num_attention_heads			, encoder_ffn_dim=self.intermediate_size			, decoder_ffn_dim=self.intermediate_size			, dropout=self.hidden_dropout_prob			, attention_dropout=self.attention_probs_dropout_prob			, max_position_embeddings=self.max_position_embeddings			, eos_token_id=self.eos_token_id			, bos_token_id=self.bos_token_id			, pad_token_id=self.pad_token_id			, initializer_range=self.initializer_range			, use_cache=snake_case_			, )
								lowercase__    :			Optional[Any]     =				prepare_blenderbot_inputs_dict(snake_case_			, snake_case_			, snake_case_							)
								return config, inputs_dict

	def        __a      (	self							)   ->     List[str]:





								"""simple docstring"""


								lowercase__   ,  lowercase__    :			Optional[Any]     =				self.prepare_config_and_inputs()
								return config, inputs_dict

	def        __a      (	self			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase							)   ->     str:





								"""simple docstring"""


								lowercase__    :			Any     =				20
								lowercase__    :			Union[str, Any]     =				model_class_name(snake_case_							)

								lowercase__    :			List[str]     =				model.encode(inputs_dict["input_ids"]							)

								lowercase__   ,  lowercase__    :			int     =				(
								    inputs_dict["decoder_input_ids"],
								    inputs_dict["decoder_attention_mask"],
								)

								lowercase__    :			List[Any]     =				model.init_cache(decoder_input_ids.shape[0]			, snake_case_			, snake_case_							)
								lowercase__    :			str     =				jnp.ones((decoder_input_ids.shape[0], max_decoder_length)			, dtype="i4"							)

								lowercase__    :			Optional[int]     =				jnp.broadcast_to(
								    jnp.arange(decoder_input_ids.shape[-1] - 1							)[None, :]			, (decoder_input_ids.shape[0], decoder_input_ids.shape[-1] - 1)			, )
								lowercase__    :			int     =				model.decode(
								    decoder_input_ids[:, :-1]			, snake_case_			, decoder_attention_mask=snake_case_			, past_key_values=snake_case_			, decoder_position_ids=snake_case_			, )

								lowercase__    :			int     =				jnp.array(decoder_input_ids.shape[0] * [[decoder_input_ids.shape[-1] - 1]]			, dtype="i4"							)
								lowercase__    :			str     =				model.decode(
								    decoder_input_ids[:, -1:]			, snake_case_			, decoder_attention_mask=snake_case_			, past_key_values=outputs_cache.past_key_values			, decoder_position_ids=snake_case_			, )

								lowercase__    :			Dict     =				model.decode(snake_case_			, snake_case_							)

								lowercase__    :			Optional[Any]     =				np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])							)							)
								self.parent.assertTrue(diff < 1E-3			, msg=f"""Max diff is {diff}"""							)







	def        __a      (	self			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase							)   ->     List[Any]:





								"""simple docstring"""


								lowercase__    :			List[str]     =				20
								lowercase__    :			Dict     =				model_class_name(snake_case_							)

								lowercase__    :			Union[str, Any]     =				model.encode(inputs_dict["input_ids"]							)

								lowercase__   ,  lowercase__    :			List[str]     =				(
								    inputs_dict["decoder_input_ids"],
								    inputs_dict["decoder_attention_mask"],
								)

								lowercase__    :			Union[str, Any]     =				jnp.concatenate(
								    [
								        decoder_attention_mask,
								        jnp.zeros((decoder_attention_mask.shape[0], max_decoder_length - decoder_attention_mask.shape[1])							),
								    ]			, axis=-1			, )

								lowercase__    :			int     =				model.init_cache(decoder_input_ids.shape[0]			, snake_case_			, snake_case_							)
								lowercase__    :			Union[str, Any]     =				jnp.broadcast_to(
								    jnp.arange(decoder_input_ids.shape[-1] - 1							)[None, :]			, (decoder_input_ids.shape[0], decoder_input_ids.shape[-1] - 1)			, )

								lowercase__    :			int     =				model.decode(
								    decoder_input_ids[:, :-1]			, snake_case_			, decoder_attention_mask=snake_case_			, past_key_values=snake_case_			, decoder_position_ids=snake_case_			, )
								lowercase__    :			List[str]     =				jnp.array(decoder_input_ids.shape[0] * [[decoder_input_ids.shape[-1] - 1]]			, dtype="i4"							)
								lowercase__    :			List[Any]     =				model.decode(
								    decoder_input_ids[:, -1:]			, snake_case_			, past_key_values=outputs_cache.past_key_values			, decoder_attention_mask=snake_case_			, decoder_position_ids=snake_case_			, )

								lowercase__    :			str     =				model.decode(snake_case_			, snake_case_			, decoder_attention_mask=snake_case_							)

								lowercase__    :			Union[str, Any]     =				np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])							)							)
								self.parent.assertTrue(diff < 1E-3			, msg=f"""Max diff is {diff}"""							)







@require_flax
class  UpperCAmelCase(	unittest.TestCase	):



	"""simple docstring"""






	a      :   int			    =	9_9

	def        __a      (	self							)   ->     List[Any]:





								"""simple docstring"""


								lowercase__    :			Optional[Any]     =				np.array(
								    [
								        [71, 82, 18, 33, 46, 91, 2],
								        [68, 34, 26, 58, 30, 82, 2],
								        [5, 97, 17, 39, 94, 40, 2],
								        [76, 83, 94, 25, 70, 78, 2],
								        [87, 59, 41, 35, 48, 66, 2],
								        [55, 13, 16, 58, 5, 2, 1],  # note padding
								        [64, 27, 31, 51, 12, 75, 2],
								        [52, 64, 86, 17, 83, 39, 2],
								        [48, 61, 9, 24, 71, 82, 2],
								        [26, 1, 60, 48, 22, 13, 2],
								        [21, 5, 62, 28, 14, 76, 2],
								        [45, 98, 37, 86, 59, 48, 2],
								        [70, 70, 50, 9, 28, 0, 2],
								    ]			, dtype=np.intaa			, )

								lowercase__    :			Any     =				input_ids.shape[0]
								lowercase__    :			str     =				BlenderbotSmallConfig(
								    vocab_size=self.vocab_size			, d_model=24			, encoder_layers=2			, decoder_layers=2			, encoder_attention_heads=2			, decoder_attention_heads=2			, encoder_ffn_dim=32			, decoder_ffn_dim=32			, max_position_embeddings=48			, eos_token_id=2			, pad_token_id=1			, bos_token_id=0			, )
								return config, input_ids, batch_size

	def        __a      (	self							)   ->     int:





								"""simple docstring"""


								lowercase__   ,  lowercase__   ,  lowercase__    :			Optional[int]     =				self._get_config_and_data()
								lowercase__    :			Optional[int]     =				FlaxBlenderbotSmallForConditionalGeneration(snake_case_							)
								lowercase__    :			int     =				lm_model(input_ids=snake_case_							)
								lowercase__    :			Dict     =				(batch_size, input_ids.shape[1], config.vocab_size)
								self.assertEqual(outputs["logits"].shape			, snake_case_							)

	def        __a      (	self							)   ->     List[str]:





								"""simple docstring"""


								lowercase__    :			Optional[int]     =				BlenderbotSmallConfig(
								    vocab_size=self.vocab_size			, d_model=14			, encoder_layers=2			, decoder_layers=2			, encoder_attention_heads=2			, decoder_attention_heads=2			, encoder_ffn_dim=8			, decoder_ffn_dim=8			, max_position_embeddings=48			, )
								lowercase__    :			Dict     =				FlaxBlenderbotSmallForConditionalGeneration(snake_case_							)
								lowercase__    :			Optional[Any]     =				np.array([[71, 82, 18, 33, 46, 91, 2], [68, 34, 26, 58, 30, 2, 1]]			, dtype=np.intaa							)
								lowercase__    :			str     =				np.array([[82, 71, 82, 18, 2], [58, 68, 2, 1, 1]]			, dtype=np.intaa							)
								lowercase__    :			int     =				lm_model(input_ids=snake_case_			, decoder_input_ids=snake_case_							)
								lowercase__    :			List[str]     =				(*summary.shape, config.vocab_size)
								self.assertEqual(outputs["logits"].shape			, snake_case_							)







	def        __a      (	self							)   ->     Tuple:





								"""simple docstring"""


								lowercase__    :			List[Any]     =				np.array([[71, 82, 18, 33, 2, 1, 1], [68, 34, 26, 58, 30, 82, 2]]			, dtype=np.intaa							)
								lowercase__    :			int     =				shift_tokens_right(snake_case_			, 1			, 2							)
								lowercase__    :			Union[str, Any]     =				np.equal(snake_case_			, 1							).astype(np.floataa							).sum()
								lowercase__    :			Union[str, Any]     =				np.equal(snake_case_			, 1							).astype(np.floataa							).sum()
								self.assertEqual(shifted.shape			, input_ids.shape							)
								self.assertEqual(snake_case_			, n_pad_before - 1							)
								self.assertTrue(np.equal(shifted[:, 0]			, 2							).all()							)







@require_flax
class  UpperCAmelCase(	snake_case_       ,      unittest.TestCase       ,      snake_case_	):



	"""simple docstring"""






	a      :   Union[str, Any]			    =	True
	a      :   List[str]			    =	(
	    (
	        FlaxBlenderbotSmallModel,
	        FlaxBlenderbotSmallForConditionalGeneration,
	    )
	    if is_flax_available()
	    else ()
	)
	a      :   Optional[Any]			    =	(FlaxBlenderbotSmallForConditionalGeneration,) if is_flax_available() else ()

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





								"""simple docstring"""


								lowercase__    :			Dict     =				FlaxBlenderbotSmallModelTester(self							)

	def        __a      (	self							)   ->     int:





								"""simple docstring"""


								lowercase__   ,  lowercase__    :			Union[str, Any]     =				self.model_tester.prepare_config_and_inputs()
								for model_class in self.all_model_classes:
															self.model_tester.check_use_cache_forward(snake_case_			, snake_case_			, snake_case_							)

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





								"""simple docstring"""


								lowercase__   ,  lowercase__    :			Optional[int]     =				self.model_tester.prepare_config_and_inputs()
								for model_class in self.all_model_classes:
															self.model_tester.check_use_cache_forward_with_attn_mask(snake_case_			, snake_case_			, snake_case_							)

	def        __a      (	self							)   ->     str:





								"""simple docstring"""


								lowercase__   ,  lowercase__    :			Optional[Any]     =				self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
															with self.subTest(model_class.__name__							):
																						lowercase__    :			Union[str, Any]     =				self._prepare_for_class(snake_case_			, snake_case_							)
																						lowercase__    :			List[str]     =				model_class(snake_case_							)

																						@jax.jit
																						def encode_jitted(lowerCamelCase			, lowerCamelCase=None			, **lowerCamelCase							):
																													return model.encode(input_ids=snake_case_			, attention_mask=snake_case_							)

																						with self.subTest("JIT Enabled"							):
																													lowercase__    :			Any     =				encode_jitted(**snake_case_							).to_tuple()

																						with self.subTest("JIT Disabled"							):
																													with jax.disable_jit():
																																				lowercase__    :			List[Any]     =				encode_jitted(**snake_case_							).to_tuple()

																						self.assertEqual(len(snake_case_							)			, len(snake_case_							)							)
																						for jitted_output, output in zip(snake_case_			, snake_case_							):
																													self.assertEqual(jitted_output.shape			, output.shape							)

	def        __a      (	self							)   ->     List[Any]:





								"""simple docstring"""


								lowercase__   ,  lowercase__    :			Tuple     =				self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
															with self.subTest(model_class.__name__							):
																						lowercase__    :			List[Any]     =				model_class(snake_case_							)
																						lowercase__    :			Dict     =				model.encode(inputs_dict["input_ids"]			, inputs_dict["attention_mask"]							)

																						lowercase__    :			List[Any]     =				{
																						    "decoder_input_ids": inputs_dict["decoder_input_ids"],
																						    "decoder_attention_mask": inputs_dict["decoder_attention_mask"],
																						    "encoder_outputs": encoder_outputs,
																						}

																						@jax.jit
																						def decode_jitted(lowerCamelCase			, lowerCamelCase			, lowerCamelCase							):
																													return model.decode(
																													    decoder_input_ids=snake_case_			, decoder_attention_mask=snake_case_			, encoder_outputs=snake_case_			, )

																						with self.subTest("JIT Enabled"							):
																													lowercase__    :			List[Any]     =				decode_jitted(**snake_case_							).to_tuple()

																						with self.subTest("JIT Disabled"							):
																													with jax.disable_jit():
																																				lowercase__    :			List[str]     =				decode_jitted(**snake_case_							).to_tuple()

																						self.assertEqual(len(snake_case_							)			, len(snake_case_							)							)
																						for jitted_output, output in zip(snake_case_			, snake_case_							):
																													self.assertEqual(jitted_output.shape			, output.shape							)







	@slow
	def        __a      (	self							)   ->     Tuple:





								"""simple docstring"""


								for model_class_name in self.all_model_classes:
															lowercase__    :			Optional[int]     =				model_class_name.from_pretrained("facebook/blenderbot_small-90M"							)
															# FlaxBlenderbotForSequenceClassification expects eos token in input_ids
															lowercase__    :			int     =				np.ones((1, 1)							) * model.config.eos_token_id
															lowercase__    :			Union[str, Any]     =				model(snake_case_							)
															self.assertIsNotNone(snake_case_							)




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



					@staticmethod
					def 		UpperCamelCase				(    *snake_case_				:     Any					,						**snake_case_				:     str)->				int:
										pass






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



	@require_torch
	def 		UpperCamelCase				(    self				:     Dict)->				List[str]:
						__lowerCAmelCase						 =pipeline(
						    model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""					,						)
						__lowerCAmelCase						 =Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""")
						__lowerCAmelCase						 =image_classifier(snake_case_					,						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(snake_case_)					,						[
						        [{"""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"""}],
						    ]					,						)

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



	@require_tf
	def 		UpperCamelCase				(    self				:     Dict)->				Optional[Any]:
						__lowerCAmelCase						 =pipeline(
						    model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""					,						framework="""tf""")
						__lowerCAmelCase						 =Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""")
						__lowerCAmelCase						 =image_classifier(snake_case_					,						candidate_labels=["""a""", """b""", """c"""])

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

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



	@slow
	@require_torch
	def 		UpperCamelCase				(    self				:     Any)->				Dict:
						__lowerCAmelCase						 =pipeline(
						    task="""zero-shot-image-classification"""					,						model="""openai/clip-vit-base-patch32"""					,						)
						# This is an image of 2 cats with remotes and no planes
						__lowerCAmelCase						 =Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""")
						__lowerCAmelCase						 =image_classifier(snake_case_					,						candidate_labels=["""cat""", """plane""", """remote"""])

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

						__lowerCAmelCase						 =image_classifier([image] * 5					,						candidate_labels=["""cat""", """plane""", """remote"""]					,						batch_size=2)
						self.assertEqual(
						    nested_simplify(snake_case_)					,						[
						        [
						            {"""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 		UpperCamelCase				(    self				:     Optional[int])->				int:
						__lowerCAmelCase						 =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
						__lowerCAmelCase						 =Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""")
						__lowerCAmelCase						 =image_classifier(snake_case_					,						candidate_labels=["""cat""", """plane""", """remote"""])
						self.assertEqual(
						    nested_simplify(snake_case_)					,						[
						        {"""score""": 0.5_1_1, """label""": """remote"""},
						        {"""score""": 0.4_8_5, """label""": """cat"""},
						        {"""score""": 0.0_0_4, """label""": """plane"""},
						    ]					,						)

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




