'''simple docstring'''

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







									"""simple docstring"""






									@staticmethod
									def 		UpperCamelCase__       (   *__A		,						**__A				) ->     Union[str, Any]:
															pass
@is_pipeline_test
@require_vision
class   SCREAMING_SNAKE_CASE			(						unittest.TestCase):







		"""simple docstring"""






		@require_torch
		def 		UpperCamelCase__       (   self				) ->     int:
								_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(__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.333, 'label': 'a'}, {'score': 0.333, 'label': 'b'}, {'score': 0.333, 'label': 'c'}],
								        [{'score': 0.333, 'label': 'a'}, {'score': 0.333, 'label': 'c'}, {'score': 0.333, 'label': 'b'}],
								    ]		,						)

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






		@require_tf
		def 		UpperCamelCase__       (   self				) ->     str:
								_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(__A		,						candidate_labels=['a', 'b', 'c']				)

								self.assertEqual(
								    nested_simplify(__A				)		,						[{'score': 0.333, 'label': 'a'}, {'score': 0.333, 'label': 'b'}, {'score': 0.333, 'label': 'c'}]		,						)

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






		@slow
		@require_torch
		def 		UpperCamelCase__       (   self				) ->     Tuple:
								_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(__A		,						candidate_labels=['cat', 'plane', 'remote']				)

								self.assertEqual(
								    nested_simplify(__A				)		,						[
								        {'score': 0.511, 'label': 'remote'},
								        {'score': 0.485, 'label': 'cat'},
								        {'score': 0.004, 'label': 'plane'},
								    ]		,						)

								_lowerCAmelCase										=image_classifier([image] * 5		,						candidate_labels=['cat', 'plane', 'remote']		,						batch_size=2				)
								self.assertEqual(
								    nested_simplify(__A				)		,						[
								        [
								            {'score': 0.511, 'label': 'remote'},
								            {'score': 0.485, 'label': 'cat'},
								            {'score': 0.004, 'label': 'plane'},
								        ],
								    ]
								    * 5		,						)






		@slow
		@require_tf
		def 		UpperCamelCase__       (   self				) ->     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(__A		,						candidate_labels=['cat', 'plane', 'remote']				)
								self.assertEqual(
								    nested_simplify(__A				)		,						[
								        {'score': 0.511, 'label': 'remote'},
								        {'score': 0.485, 'label': 'cat'},
								        {'score': 0.004, 'label': 'plane'},
								    ]		,						)

								_lowerCAmelCase										=image_classifier([image] * 5		,						candidate_labels=['cat', 'plane', 'remote']		,						batch_size=2				)
								self.assertEqual(
								    nested_simplify(__A				)		,						[
								        [
								            {'score': 0.511, 'label': 'remote'},
								            {'score': 0.485, 'label': 'cat'},
								            {'score': 0.004, 'label': 'plane'},
								        ],
								    ]
								    * 5		,						)






'''simple docstring'''

from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowercase_     		= logging.get_logger(__name__)

lowercase_     		= {
    '''facebook/data2vec-text-base''': '''https://huggingface.co/data2vec/resolve/main/config.json''',
}
class   SCREAMING_SNAKE_CASE			(						__lowercase):







		"""simple docstring"""
		lowercase   :      List[str]       =							'data2vec-text'






		def __init__(   self		,						__A=3_0522		,						__A=768		,						__A=12		,						__A=12		,						__A=3072		,						__A="gelu"		,						__A=0.1		,						__A=0.1		,						__A=512		,						__A=2		,						__A=0.02		,						__A=1E-12		,						__A=1		,						__A=0		,						__A=2		,						__A="absolute"		,						__A=True		,						__A=None		,						**__A		,						) ->     List[Any]:
								super().__init__(pad_token_id=__A		,						bos_token_id=__A		,						eos_token_id=__A		,						**__A				)

								_lowerCAmelCase										=vocab_size
								_lowerCAmelCase										=hidden_size
								_lowerCAmelCase										=num_hidden_layers
								_lowerCAmelCase										=num_attention_heads
								_lowerCAmelCase										=hidden_act
								_lowerCAmelCase										=intermediate_size
								_lowerCAmelCase										=hidden_dropout_prob
								_lowerCAmelCase										=attention_probs_dropout_prob
								_lowerCAmelCase										=max_position_embeddings
								_lowerCAmelCase										=type_vocab_size
								_lowerCAmelCase										=initializer_range
								_lowerCAmelCase										=layer_norm_eps
								_lowerCAmelCase										=position_embedding_type
								_lowerCAmelCase										=use_cache
								_lowerCAmelCase										=classifier_dropout

class   SCREAMING_SNAKE_CASE			(						__lowercase):







		"""simple docstring"""






		@property
		def 		UpperCamelCase__       (   self				) ->     Mapping[str, Mapping[int, str]]:
								if self.task == "multiple-choice":
														_lowerCAmelCase										={0: 'batch', 1: 'choice', 2: 'sequence'}
								else:
														_lowerCAmelCase										={0: 'batch', 1: 'sequence'}
								return OrderedDict(
								    [
								        ('input_ids', dynamic_axis),
								        ('attention_mask', dynamic_axis),
								    ]				)





