





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      _lowercase				(    *_A							,					**_A		):






								'''simple docstring'''







								pass

@is_pipeline_test
@require_vision
class 	A_       (unittest.TestCase			):
	@require_torch
	def      _lowercase				(    self		):






				'''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_33, '''label''': '''a'''}, {'''score''': 0.3_33, '''label''': '''b'''}, {'''score''': 0.3_33, '''label''': '''c'''}],
				        [{'''score''': 0.3_33, '''label''': '''a'''}, {'''score''': 0.3_33, '''label''': '''c'''}, {'''score''': 0.3_33, '''label''': '''b'''}],
				    ]							,					)

				UpperCAmelCase   		=				image_classifier([image] * 5							,					candidate_labels=['''A''', '''B''', '''C''']							,					batch_size=2		)
				self.assertEqual(
				    nested_simplify(_A		)							,					[
				        [
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				        ],
				        [
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				        ],
				        [
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				        ],
				        [
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				        ],
				        [
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				        ],
				    ]							,					)
	@require_tf
	def      _lowercase				(    self		):






				'''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_33, '''label''': '''a'''}, {'''score''': 0.3_33, '''label''': '''b'''}, {'''score''': 0.3_33, '''label''': '''c'''}]							,					)

				UpperCAmelCase   		=				image_classifier([image] * 5							,					candidate_labels=['''A''', '''B''', '''C''']							,					batch_size=2		)
				self.assertEqual(
				    nested_simplify(_A		)							,					[
				        [
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				        ],
				        [
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				        ],
				        [
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				        ],
				        [
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				        ],
				        [
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				            {'''score''': 0.3_33, '''label''': ANY(_A		)},
				        ],
				    ]							,					)
	@slow
	@require_torch
	def      _lowercase				(    self		):






				'''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_11, '''label''': '''remote'''},
				        {'''score''': 0.4_85, '''label''': '''cat'''},
				        {'''score''': 0.0_04, '''label''': '''plane'''},
				    ]							,					)

				UpperCAmelCase   		=				image_classifier([image] * 5							,					candidate_labels=['''cat''', '''plane''', '''remote''']							,					batch_size=2		)
				self.assertEqual(
				    nested_simplify(_A		)							,					[
				        [
				            {'''score''': 0.5_11, '''label''': '''remote'''},
				            {'''score''': 0.4_85, '''label''': '''cat'''},
				            {'''score''': 0.0_04, '''label''': '''plane'''},
				        ],
				    ]
				    * 5							,					)







	@slow
	@require_tf
	def      _lowercase				(    self		):






				'''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_11, '''label''': '''remote'''},
				        {'''score''': 0.4_85, '''label''': '''cat'''},
				        {'''score''': 0.0_04, '''label''': '''plane'''},
				    ]							,					)

				UpperCAmelCase   		=				image_classifier([image] * 5							,					candidate_labels=['''cat''', '''plane''', '''remote''']							,					batch_size=2		)
				self.assertEqual(
				    nested_simplify(_A		)							,					[
				        [
				            {'''score''': 0.5_11, '''label''': '''remote'''},
				            {'''score''': 0.4_85, '''label''': '''cat'''},
				            {'''score''': 0.0_04, '''label''': '''plane'''},
				        ],
				    ]
				    * 5							,					)










from collections import OrderedDict
from typing import Mapping

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


__A				:    int       =   logging.get_logger(__name__)

__A				:    Tuple       =   {
    "google/bigbird-roberta-base": "https://huggingface.co/google/bigbird-roberta-base/resolve/main/config.json",
    "google/bigbird-roberta-large": "https://huggingface.co/google/bigbird-roberta-large/resolve/main/config.json",
    "google/bigbird-base-trivia-itc": "https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/config.json",
    # See all BigBird models at https://huggingface.co/models?filter=big_bird
}

class 	A_       (a_			):
	UpperCAmelCase__					=			'''big_bird'''
	def __init__(    self							,					_A=5_0_3_5_8							,					_A=7_6_8							,					_A=1_2							,					_A=1_2							,					_A=3_0_7_2							,					_A="gelu_new"							,					_A=0.1							,					_A=0.1							,					_A=4_0_9_6							,					_A=2							,					_A=0.02							,					_A=1E-12							,					_A=True							,					_A=0							,					_A=1							,					_A=2							,					_A=6_6							,					_A="block_sparse"							,					_A=True							,					_A=False							,					_A=6_4							,					_A=3							,					_A=None							,					**_A							,					):






				'''simple docstring'''







				super().__init__(
				    pad_token_id=_A							,					bos_token_id=_A							,					eos_token_id=_A							,					sep_token_id=_A							,					**_A							,					)

				UpperCAmelCase   		=				vocab_size
				UpperCAmelCase   		=				max_position_embeddings
				UpperCAmelCase   		=				hidden_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   		=				initializer_range
				UpperCAmelCase   		=				type_vocab_size
				UpperCAmelCase   		=				layer_norm_eps
				UpperCAmelCase   		=				use_cache

				UpperCAmelCase   		=				rescale_embeddings
				UpperCAmelCase   		=				attention_type
				UpperCAmelCase   		=				use_bias
				UpperCAmelCase   		=				block_size
				UpperCAmelCase   		=				num_random_blocks
				UpperCAmelCase   		=				classifier_dropout

class 	A_       (a_			):
	@property
	def      _lowercase				(    self		):






				'''simple docstring'''







				if self.task == "multiple-choice":
							UpperCAmelCase   		=				{0: '''batch''', 1: '''choice''', 2: '''sequence'''}
				else:
							UpperCAmelCase   		=				{0: '''batch''', 1: '''sequence'''}
				return OrderedDict(
				    [
				        ('''input_ids''', dynamic_axis),
				        ('''attention_mask''', dynamic_axis),
				    ]		)



