






from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
		import tensorflow as tf

		from transformers import (
		    TF_MODEL_FOR_PRETRAINING_MAPPING,
		    TFMobileBertForMaskedLM,
		    TFMobileBertForMultipleChoice,
		    TFMobileBertForNextSentencePrediction,
		    TFMobileBertForPreTraining,
		    TFMobileBertForQuestionAnswering,
		    TFMobileBertForSequenceClassification,
		    TFMobileBertForTokenClassification,
		    TFMobileBertModel,
		)





@require_tf
class 	snake_case__ (							lowerCAmelCase_						,  lowerCAmelCase_						,  unittest.TestCase				):
	lowercase__						:					str											=   (
	    (
	        TFMobileBertModel,
	        TFMobileBertForMaskedLM,
	        TFMobileBertForNextSentencePrediction,
	        TFMobileBertForPreTraining,
	        TFMobileBertForQuestionAnswering,
	        TFMobileBertForSequenceClassification,
	        TFMobileBertForTokenClassification,
	        TFMobileBertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	lowercase__						:					Dict											=   (
	    {
	        'feature-extraction': TFMobileBertModel,
	        'fill-mask': TFMobileBertForMaskedLM,
	        'question-answering': TFMobileBertForQuestionAnswering,
	        'text-classification': TFMobileBertForSequenceClassification,
	        'token-classification': TFMobileBertForTokenClassification,
	        'zero-shot': TFMobileBertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	lowercase__						:					Dict											=   False
	lowercase__						:					List[str]											=   False
	def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__=False			)							->				Dict:
							__magic_name__      :       int       						= super()._prepare_for_class(__lowerCAmelCase      ,       __lowerCAmelCase      ,       return_labels=__lowerCAmelCase			)

							if return_labels:
													if model_class in get_values(__lowerCAmelCase			):
																			__magic_name__      :       Optional[Any]       						= tf.zeros(self.model_tester.batch_size      ,       dtype=tf.intaa			)

							return inputs_dict





	class 	snake_case__ (							lowerCAmelCase_				):
		def __init__(    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__=13      ,       lowerCAmelCase__=7      ,       lowerCAmelCase__=True      ,       lowerCAmelCase__=True      ,       lowerCAmelCase__=True      ,       lowerCAmelCase__=True      ,       lowerCAmelCase__=99      ,       lowerCAmelCase__=32      ,       lowerCAmelCase__=32      ,       lowerCAmelCase__=2      ,       lowerCAmelCase__=4      ,       lowerCAmelCase__=37      ,       lowerCAmelCase__="gelu"      ,       lowerCAmelCase__=0.1      ,       lowerCAmelCase__=0.1      ,       lowerCAmelCase__=5_12      ,       lowerCAmelCase__=16      ,       lowerCAmelCase__=2      ,       lowerCAmelCase__=0.0_2      ,       lowerCAmelCase__=3      ,       lowerCAmelCase__=4      ,       lowerCAmelCase__=None      ,       )							->				str:
								__magic_name__      :       Tuple       						= parent
								__magic_name__      :       Union[str, Any]       						= batch_size
								__magic_name__      :       Dict       						= seq_length
								__magic_name__      :       Dict       						= is_training
								__magic_name__      :       List[str]       						= use_input_mask
								__magic_name__      :       Union[str, Any]       						= use_token_type_ids
								__magic_name__      :       Union[str, Any]       						= use_labels
								__magic_name__      :       int       						= vocab_size
								__magic_name__      :       int       						= hidden_size
								__magic_name__      :       int       						= num_hidden_layers
								__magic_name__      :       List[Any]       						= num_attention_heads
								__magic_name__      :       List[str]       						= intermediate_size
								__magic_name__      :       str       						= hidden_act
								__magic_name__      :       Dict       						= hidden_dropout_prob
								__magic_name__      :       List[str]       						= attention_probs_dropout_prob
								__magic_name__      :       Tuple       						= max_position_embeddings
								__magic_name__      :       List[str]       						= type_vocab_size
								__magic_name__      :       Optional[int]       						= type_sequence_label_size
								__magic_name__      :       int       						= initializer_range
								__magic_name__      :       List[str]       						= num_labels
								__magic_name__      :       int       						= num_choices
								__magic_name__      :       Optional[Any]       						= scope
								__magic_name__      :       Optional[Any]       						= embedding_size
		def       __magic_name__    (    self			)							->				Union[str, Any]:
								__magic_name__      :       List[str]       						= ids_tensor([self.batch_size, self.seq_length]      ,       self.vocab_size			)

								__magic_name__      :       Tuple       						= None
								if self.use_input_mask:
														__magic_name__      :       List[str]       						= random_attention_mask([self.batch_size, self.seq_length]			)

								__magic_name__      :       List[Any]       						= None
								if self.use_token_type_ids:
														__magic_name__      :       Optional[Any]       						= ids_tensor([self.batch_size, self.seq_length]      ,       self.type_vocab_size			)

								__magic_name__      :       List[str]       						= None
								__magic_name__      :       str       						= None
								__magic_name__      :       Optional[int]       						= None
								if self.use_labels:
														__magic_name__      :       List[Any]       						= ids_tensor([self.batch_size]      ,       self.type_sequence_label_size			)
														__magic_name__      :       List[str]       						= ids_tensor([self.batch_size, self.seq_length]      ,       self.num_labels			)
														__magic_name__      :       Tuple       						= ids_tensor([self.batch_size]      ,       self.num_choices			)

								__magic_name__      :       Union[str, Any]       						= MobileBertConfig(
								    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      ,       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      ,       initializer_range=self.initializer_range      ,       embedding_size=self.embedding_size      ,       )

								return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
		def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				Tuple:
								__magic_name__      :       Optional[int]       						= TFMobileBertModel(config=__lowerCAmelCase			)
								__magic_name__      :       Union[str, Any]       						= {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								__magic_name__      :       Dict       						= model(__lowerCAmelCase			)

								__magic_name__      :       str       						= [input_ids, input_mask]
								__magic_name__      :       List[str]       						= model(__lowerCAmelCase			)

								__magic_name__      :       str       						= model(__lowerCAmelCase			)

								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       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				Any:
								__magic_name__      :       Union[str, Any]       						= TFMobileBertForMaskedLM(config=__lowerCAmelCase			)
								__magic_name__      :       int       						= {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								__magic_name__      :       Tuple       						= model(__lowerCAmelCase			)
								self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.seq_length, self.vocab_size)			)
		def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				Tuple:
								__magic_name__      :       Any       						= TFMobileBertForNextSentencePrediction(config=__lowerCAmelCase			)
								__magic_name__      :       Optional[Any]       						= {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								__magic_name__      :       Any       						= model(__lowerCAmelCase			)
								self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, 2)			)
		def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				Union[str, Any]:
								__magic_name__      :       Any       						= TFMobileBertForPreTraining(config=__lowerCAmelCase			)
								__magic_name__      :       Dict       						= {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								__magic_name__      :       str       						= model(__lowerCAmelCase			)
								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       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				int:
								__magic_name__      :       List[str]       						= self.num_labels
								__magic_name__      :       Dict       						= TFMobileBertForSequenceClassification(config=__lowerCAmelCase			)
								__magic_name__      :       int       						= {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								__magic_name__      :       List[str]       						= model(__lowerCAmelCase			)
								self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.num_labels)			)
		def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				List[Any]:
								__magic_name__      :       List[str]       						= self.num_choices
								__magic_name__      :       int       						= TFMobileBertForMultipleChoice(config=__lowerCAmelCase			)
								__magic_name__      :       Optional[int]       						= tf.tile(tf.expand_dims(__lowerCAmelCase      ,       1			)      ,       (1, self.num_choices, 1)			)
								__magic_name__      :       Optional[Any]       						= tf.tile(tf.expand_dims(__lowerCAmelCase      ,       1			)      ,       (1, self.num_choices, 1)			)
								__magic_name__      :       str       						= tf.tile(tf.expand_dims(__lowerCAmelCase      ,       1			)      ,       (1, self.num_choices, 1)			)
								__magic_name__      :       List[Any]       						= {
								    """input_ids""": multiple_choice_inputs_ids,
								    """attention_mask""": multiple_choice_input_mask,
								    """token_type_ids""": multiple_choice_token_type_ids,
								}
								__magic_name__      :       List[Any]       						= model(__lowerCAmelCase			)
								self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.num_choices)			)
		def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				Optional[int]:
								__magic_name__      :       Optional[Any]       						= self.num_labels
								__magic_name__      :       int       						= TFMobileBertForTokenClassification(config=__lowerCAmelCase			)
								__magic_name__      :       int       						= {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								__magic_name__      :       Any       						= model(__lowerCAmelCase			)
								self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.seq_length, self.num_labels)			)
		def       __magic_name__    (    self      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__      ,       lowerCAmelCase__			)							->				Optional[Any]:
								__magic_name__      :       Optional[Any]       						= TFMobileBertForQuestionAnswering(config=__lowerCAmelCase			)
								__magic_name__      :       Tuple       						= {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								__magic_name__      :       str       						= model(__lowerCAmelCase			)
								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       __magic_name__    (    self			)							->				Union[str, Any]:
								__magic_name__      :       Optional[Any]       						= self.prepare_config_and_inputs()
								(
								    (
								    __magic_name__			
								)						,(
								    __magic_name__			
								)						,(
								    __magic_name__			
								)						,(
								    __magic_name__			
								)						,(
								    __magic_name__			
								)						,(
								    __magic_name__			
								)						,(
								    __magic_name__			
								)						,			
								)      :       Optional[Any]       						= config_and_inputs
								__magic_name__      :       Tuple       						= {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
								return config, inputs_dict



	def       __magic_name__    (    self			)							->				List[str]:
							__magic_name__      :       Dict       						= TFMobileBertModelTest.TFMobileBertModelTester(self			)
							__magic_name__      :       Dict       						= ConfigTester(self      ,       config_class=__lowerCAmelCase      ,       hidden_size=37			)
	def       __magic_name__    (    self			)							->				List[str]:
							self.config_tester.run_common_tests()
	def       __magic_name__    (    self			)							->				int:
							__magic_name__      :       Union[str, Any]       						= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_model(*__lowerCAmelCase			)
	def       __magic_name__    (    self			)							->				List[str]:
							__magic_name__      :       List[str]       						= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_masked_lm(*__lowerCAmelCase			)
	def       __magic_name__    (    self			)							->				Optional[Any]:
							__magic_name__      :       Tuple       						= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_multiple_choice(*__lowerCAmelCase			)
	def       __magic_name__    (    self			)							->				str:
							__magic_name__      :       List[Any]       						= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*__lowerCAmelCase			)
	def       __magic_name__    (    self			)							->				int:
							__magic_name__      :       Tuple       						= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_pretraining(*__lowerCAmelCase			)
	def       __magic_name__    (    self			)							->				Any:
							__magic_name__      :       List[Any]       						= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_question_answering(*__lowerCAmelCase			)
	def       __magic_name__    (    self			)							->				Dict:
							__magic_name__      :       Union[str, Any]       						= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_sequence_classification(*__lowerCAmelCase			)
	def       __magic_name__    (    self			)							->				Any:
							__magic_name__      :       Dict       						= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mobilebert_for_token_classification(*__lowerCAmelCase			)







	@slow
	def       __magic_name__    (    self			)							->				str:
							# for model_name in TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							for model_name in ["google/mobilebert-uncased"]:
													__magic_name__      :       int       						= TFMobileBertModel.from_pretrained(__lowerCAmelCase			)
													self.assertIsNotNone(__lowerCAmelCase			)





@require_tf
class 	snake_case__ (							unittest.TestCase				):
	@slow
	def       __magic_name__    (    self			)							->				Optional[Any]:
							__magic_name__      :       List[Any]       						= TFMobileBertForPreTraining.from_pretrained("""google/mobilebert-uncased"""			)
							__magic_name__      :       str       						= tf.constant([[0, 1, 2, 3, 4, 5]]			)
							__magic_name__      :       Tuple       						= model(__lowerCAmelCase			)[0]

							__magic_name__      :       Dict       						= [1, 6, 3_05_22]
							self.assertEqual(output.shape      ,       __lowerCAmelCase			)

							__magic_name__      :       List[Any]       						= tf.constant(
							    [
							        [
							            [-4.5_9_1_9_5_4_7, -9.2_4_8_2_9_5, -9.6_4_5_2_5_6],
							            [-6.7_3_0_6_1_7_5, -6.4_4_0_2_8_4, -6.6_0_5_2_8_3_7],
							            [-7.2_7_4_3_5_0_6, -6.7_8_4_7_9_1_5, -6.0_2_4_6_7_3],
							        ]
							    ]			)
							tf.debugging.assert_near(output[:, :3, :3]      ,       __lowerCAmelCase      ,       atol=1e-4			)








import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
		from PIL import Image

		from transformers import OwlViTImageProcessor, OwlViTProcessor





@require_vision
class 	snake_case__ (							unittest.TestCase				):
	def       __magic_name__    (    self			)							->				int:
							__magic_name__      :       List[str]       						= tempfile.mkdtemp()

							# fmt: off
							__magic_name__      :       Union[str, Any]       						= ["""""", """l""", """o""", """w""", """e""", """r""", """s""", """t""", """i""", """d""", """n""", """lo""", """l</w>""", """w</w>""", """r</w>""", """t</w>""", """low</w>""", """er</w>""", """lowest</w>""", """newer</w>""", """wider""", """<unk>""", """<|startoftext|>""", """<|endoftext|>"""]
							# fmt: on
							__magic_name__      :       Any       						= dict(zip(lowerCAmelCase__      ,       range(len(lowerCAmelCase__			)			)			)			)
							__magic_name__      :       int       						= ["""#version: 0.2""", """l o""", """lo w</w>""", """e r</w>""", """"""]
							__magic_name__      :       Any       						= {"""unk_token""": """<unk>"""}

							__magic_name__      :       Optional[Any]       						= os.path.join(self.tmpdirname      ,       VOCAB_FILES_NAMES["""vocab_file"""]			)
							__magic_name__      :       Optional[int]       						= os.path.join(self.tmpdirname      ,       VOCAB_FILES_NAMES["""merges_file"""]			)
							with open(self.vocab_file      ,       """w"""      ,       encoding="""utf-8"""			) as fp:
													fp.write(json.dumps(lowerCAmelCase__			) + """\n"""			)
							with open(self.merges_file      ,       """w"""      ,       encoding="""utf-8"""			) as fp:
													fp.write("""\n""".join(lowerCAmelCase__			)			)

							__magic_name__      :       int       						= {
							    """do_resize""": True,
							    """size""": 20,
							    """do_center_crop""": True,
							    """crop_size""": 18,
							    """do_normalize""": True,
							    """image_mean""": [0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3],
							    """image_std""": [0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1],
							}
							__magic_name__      :       List[str]       						= os.path.join(self.tmpdirname      ,       lowerCAmelCase__			)
							with open(self.image_processor_file      ,       """w"""      ,       encoding="""utf-8"""			) as fp:
													json.dump(lowerCAmelCase__      ,       lowerCAmelCase__			)
	def       __magic_name__    (    self      ,       **lowerCAmelCase__			)							->				List[str]:
							return CLIPTokenizer.from_pretrained(self.tmpdirname      ,       pad_token="""!"""      ,       **lowerCAmelCase__			)
	def       __magic_name__    (    self      ,       **lowerCAmelCase__			)							->				Any:
							return CLIPTokenizerFast.from_pretrained(self.tmpdirname      ,       pad_token="""!"""      ,       **lowerCAmelCase__			)
	def       __magic_name__    (    self      ,       **lowerCAmelCase__			)							->				Optional[Any]:
							return OwlViTImageProcessor.from_pretrained(self.tmpdirname      ,       **lowerCAmelCase__			)
	def       __magic_name__    (    self			)							->				int:
							shutil.rmtree(self.tmpdirname			)
	def       __magic_name__    (    self			)							->				int:
							__magic_name__      :       str       						= [np.random.randint(2_55      ,       size=(3, 30, 4_00)      ,       dtype=np.uinta			)]

							__magic_name__      :       Any       						= [Image.fromarray(np.moveaxis(lowerCAmelCase__      ,       0      ,       -1			)			) for x in image_inputs]

							return image_inputs
	def       __magic_name__    (    self			)							->				Union[str, Any]:
							__magic_name__      :       Any       						= self.get_tokenizer()
							__magic_name__      :       str       						= self.get_rust_tokenizer()
							__magic_name__      :       Tuple       						= self.get_image_processor()

							__magic_name__      :       List[str]       						= OwlViTProcessor(tokenizer=lowerCAmelCase__      ,       image_processor=lowerCAmelCase__			)
							processor_slow.save_pretrained(self.tmpdirname			)
							__magic_name__      :       Optional[int]       						= OwlViTProcessor.from_pretrained(self.tmpdirname      ,       use_fast=lowerCAmelCase__			)

							__magic_name__      :       int       						= OwlViTProcessor(tokenizer=lowerCAmelCase__      ,       image_processor=lowerCAmelCase__			)
							processor_fast.save_pretrained(self.tmpdirname			)
							__magic_name__      :       List[Any]       						= OwlViTProcessor.from_pretrained(self.tmpdirname			)

							self.assertEqual(processor_slow.tokenizer.get_vocab()      ,       tokenizer_slow.get_vocab()			)
							self.assertEqual(processor_fast.tokenizer.get_vocab()      ,       tokenizer_fast.get_vocab()			)
							self.assertEqual(tokenizer_slow.get_vocab()      ,       tokenizer_fast.get_vocab()			)
							self.assertIsInstance(processor_slow.tokenizer      ,       lowerCAmelCase__			)
							self.assertIsInstance(processor_fast.tokenizer      ,       lowerCAmelCase__			)

							self.assertEqual(processor_slow.image_processor.to_json_string()      ,       image_processor.to_json_string()			)
							self.assertEqual(processor_fast.image_processor.to_json_string()      ,       image_processor.to_json_string()			)
							self.assertIsInstance(processor_slow.image_processor      ,       lowerCAmelCase__			)
							self.assertIsInstance(processor_fast.image_processor      ,       lowerCAmelCase__			)
	def       __magic_name__    (    self			)							->				Optional[int]:
							__magic_name__      :       Optional[Any]       						= OwlViTProcessor(tokenizer=self.get_tokenizer()      ,       image_processor=self.get_image_processor()			)
							processor.save_pretrained(self.tmpdirname			)

							__magic_name__      :       str       						= self.get_tokenizer(bos_token="""(BOS)"""      ,       eos_token="""(EOS)"""			)
							__magic_name__      :       Any       						= self.get_image_processor(do_normalize=lowerCAmelCase__			)

							__magic_name__      :       Tuple       						= OwlViTProcessor.from_pretrained(
							    self.tmpdirname      ,       bos_token="""(BOS)"""      ,       eos_token="""(EOS)"""      ,       do_normalize=lowerCAmelCase__			)

							self.assertEqual(processor.tokenizer.get_vocab()      ,       tokenizer_add_kwargs.get_vocab()			)
							self.assertIsInstance(processor.tokenizer      ,       lowerCAmelCase__			)

							self.assertEqual(processor.image_processor.to_json_string()      ,       image_processor_add_kwargs.to_json_string()			)
							self.assertIsInstance(processor.image_processor      ,       lowerCAmelCase__			)
	def       __magic_name__    (    self			)							->				Dict:
							__magic_name__      :       int       						= self.get_image_processor()
							__magic_name__      :       int       						= self.get_tokenizer()

							__magic_name__      :       Union[str, Any]       						= OwlViTProcessor(tokenizer=lowerCAmelCase__      ,       image_processor=lowerCAmelCase__			)

							__magic_name__      :       Dict       						= self.prepare_image_inputs()

							__magic_name__      :       Any       						= image_processor(lowerCAmelCase__      ,       return_tensors="""np"""			)
							__magic_name__      :       str       						= processor(images=lowerCAmelCase__      ,       return_tensors="""np"""			)

							for key in input_image_proc.keys():
													self.assertAlmostEqual(input_image_proc[key].sum()      ,       input_processor[key].sum()      ,       delta=1e-2			)
	def       __magic_name__    (    self			)							->				Tuple:
							__magic_name__      :       Union[str, Any]       						= self.get_image_processor()
							__magic_name__      :       int       						= self.get_tokenizer()

							__magic_name__      :       int       						= OwlViTProcessor(tokenizer=lowerCAmelCase__      ,       image_processor=lowerCAmelCase__			)

							__magic_name__      :       Optional[int]       						= """lower newer"""

							__magic_name__      :       Tuple       						= processor(text=lowerCAmelCase__      ,       return_tensors="""np"""			)

							__magic_name__      :       Optional[int]       						= tokenizer(lowerCAmelCase__      ,       return_tensors="""np"""			)

							for key in encoded_tok.keys():
													self.assertListEqual(encoded_tok[key][0].tolist()      ,       encoded_processor[key][0].tolist()			)
	def       __magic_name__    (    self			)							->				Tuple:
							__magic_name__      :       Tuple       						= self.get_image_processor()
							__magic_name__      :       Union[str, Any]       						= self.get_tokenizer()

							__magic_name__      :       List[str]       						= OwlViTProcessor(tokenizer=lowerCAmelCase__      ,       image_processor=lowerCAmelCase__			)

							__magic_name__      :       Any       						= """lower newer"""
							__magic_name__      :       Union[str, Any]       						= self.prepare_image_inputs()

							__magic_name__      :       int       						= processor(text=lowerCAmelCase__      ,       images=lowerCAmelCase__			)

							self.assertListEqual(list(inputs.keys()			)      ,       ["""input_ids""", """attention_mask""", """pixel_values"""]			)

							# test if it raises when no input is passed
							with pytest.raises(lowerCAmelCase__			):
													processor()
	def       __magic_name__    (    self			)							->				Optional[Any]:
							__magic_name__      :       Dict       						= """google/owlvit-base-patch32"""
							__magic_name__      :       int       						= OwlViTProcessor.from_pretrained(lowerCAmelCase__			)

							__magic_name__      :       List[Any]       						= ["""cat""", """nasa badge"""]
							__magic_name__      :       Any       						= processor(text=lowerCAmelCase__			)

							__magic_name__      :       Dict       						= 16
							self.assertListEqual(list(inputs.keys()			)      ,       ["""input_ids""", """attention_mask"""]			)
							self.assertEqual(inputs["""input_ids"""].shape      ,       (2, seq_length)			)

							# test if it raises when no input is passed
							with pytest.raises(lowerCAmelCase__			):
													processor()
	def       __magic_name__    (    self			)							->				List[Any]:
							__magic_name__      :       List[str]       						= """google/owlvit-base-patch32"""
							__magic_name__      :       Optional[Any]       						= OwlViTProcessor.from_pretrained(lowerCAmelCase__			)

							__magic_name__      :       Tuple       						= [["""cat""", """nasa badge"""], ["""person"""]]
							__magic_name__      :       Tuple       						= processor(text=lowerCAmelCase__			)

							__magic_name__      :       str       						= 16
							__magic_name__      :       str       						= len(lowerCAmelCase__			)
							__magic_name__      :       int       						= max([len(lowerCAmelCase__			) for texts in input_texts]			)

							self.assertListEqual(list(inputs.keys()			)      ,       ["""input_ids""", """attention_mask"""]			)
							self.assertEqual(inputs["""input_ids"""].shape      ,       (batch_size * num_max_text_queries, seq_length)			)

							# test if it raises when no input is passed
							with pytest.raises(lowerCAmelCase__			):
													processor()
	def       __magic_name__    (    self			)							->				Any:
							__magic_name__      :       Optional[int]       						= """google/owlvit-base-patch32"""
							__magic_name__      :       Any       						= OwlViTProcessor.from_pretrained(lowerCAmelCase__			)

							__magic_name__      :       str       						= ["""cat""", """nasa badge"""]
							__magic_name__      :       List[str]       						= processor(text=lowerCAmelCase__			)

							__magic_name__      :       List[Any]       						= 16
							__magic_name__      :       Any       						= inputs["""input_ids"""]
							__magic_name__      :       Optional[Any]       						= [
							    [4_94_06, 23_68, 4_94_07, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
							    [4_94_06, 68_41, 1_13_01, 4_94_07, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
							]

							self.assertListEqual(list(inputs.keys()			)      ,       ["""input_ids""", """attention_mask"""]			)
							self.assertEqual(inputs["""input_ids"""].shape      ,       (2, seq_length)			)
							self.assertListEqual(list(input_ids[0]			)      ,       predicted_ids[0]			)
							self.assertListEqual(list(input_ids[1]			)      ,       predicted_ids[1]			)
	def       __magic_name__    (    self			)							->				Tuple:
							__magic_name__      :       List[str]       						= self.get_image_processor()
							__magic_name__      :       Dict       						= self.get_tokenizer()

							__magic_name__      :       Tuple       						= OwlViTProcessor(tokenizer=lowerCAmelCase__      ,       image_processor=lowerCAmelCase__			)

							__magic_name__      :       Tuple       						= self.prepare_image_inputs()
							__magic_name__      :       List[Any]       						= self.prepare_image_inputs()

							__magic_name__      :       List[str]       						= processor(images=lowerCAmelCase__      ,       query_images=lowerCAmelCase__			)

							self.assertListEqual(list(inputs.keys()			)      ,       ["""query_pixel_values""", """pixel_values"""]			)

							# test if it raises when no input is passed
							with pytest.raises(lowerCAmelCase__			):
													processor()







	def       __magic_name__    (    self			)							->				Any:
							__magic_name__      :       Optional[Any]       						= self.get_image_processor()
							__magic_name__      :       List[Any]       						= self.get_tokenizer()

							__magic_name__      :       Tuple       						= OwlViTProcessor(tokenizer=lowerCAmelCase__      ,       image_processor=lowerCAmelCase__			)

							__magic_name__      :       Union[str, Any]       						= [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

							__magic_name__      :       Optional[Any]       						= processor.batch_decode(lowerCAmelCase__			)
							__magic_name__      :       Optional[int]       						= tokenizer.batch_decode(lowerCAmelCase__			)

							self.assertListEqual(lowerCAmelCase__      ,       lowerCAmelCase__			)
