


import unittest

from transformers import MraConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_torch_available():
			import torch

			from transformers import (
			    MraForMaskedLM,
			    MraForMultipleChoice,
			    MraForQuestionAnswering,
			    MraForSequenceClassification,
			    MraForTokenClassification,
			    MraModel,
			)
			from transformers.models.mra.modeling_mra import MRA_PRETRAINED_MODEL_ARCHIVE_LIST




class    UpperCAmelCase					:




			def __init__(						self							:		Tuple       ,       __magic_name__							:		Union[str, Any]       ,       __magic_name__							:		Optional[Any]=2       ,       __magic_name__							:		str=8       ,       __magic_name__							:		int=True       ,       __magic_name__							:		Any=True       ,       __magic_name__							:		Optional[Any]=True       ,       __magic_name__							:		Tuple=True       ,       __magic_name__							:		Optional[int]=9_9       ,       __magic_name__							:		List[Any]=1_6       ,       __magic_name__							:		int=5       ,       __magic_name__							:		Tuple=2       ,       __magic_name__							:		Union[str, Any]=3_6       ,       __magic_name__							:		List[Any]="gelu"       ,       __magic_name__							:		List[str]=0.0       ,       __magic_name__							:		List[str]=0.0       ,       __magic_name__							:		Dict=5_1_2       ,       __magic_name__							:		List[str]=1_6       ,       __magic_name__							:		Union[str, Any]=2       ,       __magic_name__							:		Dict=0.02       ,       __magic_name__							:		Union[str, Any]=3       ,       __magic_name__							:		int=4       ,       __magic_name__							:		int=None       ,       ):







						"""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         =					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							:		Dict						):







						"""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							:		str						):







						"""simple docstring"""







						return MraConfig(
						    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       ,       is_decoder=__magic_name__       ,       initializer_range=self.initializer_range       ,       )




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_config()
						UpperCamelCase         =					3_0_0
						return config




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						(
						    (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  
						)         =					self.prepare_config_and_inputs()

						UpperCamelCase         =					True
						UpperCamelCase         =					floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
						UpperCamelCase         =					ids_tensor([self.batch_size, self.seq_length]       ,       vocab_size=2						)

						return (
						    config,
						    input_ids,
						    token_type_ids,
						    input_mask,
						    sequence_labels,
						    token_labels,
						    choice_labels,
						    encoder_hidden_states,
						    encoder_attention_mask,
						)




			def   lowerCamelCase_					(						self							:		Tuple       ,       __magic_name__							:		Any       ,       __magic_name__							:		Optional[int]       ,       __magic_name__							:		Union[str, Any]       ,       __magic_name__							:		str       ,       __magic_name__							:		Dict       ,       __magic_name__							:		List[Any]       ,       __magic_name__							:		Optional[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					MraModel(config=__magic_name__						)
						model.to(__magic_name__						)
						model.eval()
						UpperCamelCase         =					model(__magic_name__       ,       attention_mask=__magic_name__       ,       token_type_ids=__magic_name__						)
						UpperCamelCase         =					model(__magic_name__       ,       token_type_ids=__magic_name__						)
						UpperCamelCase         =					model(__magic_name__						)
						self.parent.assertEqual(result.last_hidden_state.shape       ,       (self.batch_size, self.seq_length, self.hidden_size)						)




			def   lowerCamelCase_					(						self							:		Tuple       ,       __magic_name__							:		Any       ,       __magic_name__							:		List[str]       ,       __magic_name__							:		Tuple       ,       __magic_name__							:		str       ,       __magic_name__							:		List[Any]       ,       __magic_name__							:		Any       ,       __magic_name__							:		Any       ,       __magic_name__							:		Optional[Any]       ,       __magic_name__							:		List[str]       ,       ):







						"""simple docstring"""







						UpperCamelCase         =					True
						UpperCamelCase         =					MraModel(__magic_name__						)
						model.to(__magic_name__						)
						model.eval()
						UpperCamelCase         =					model(
						    __magic_name__       ,       attention_mask=__magic_name__       ,       token_type_ids=__magic_name__       ,       encoder_hidden_states=__magic_name__       ,       encoder_attention_mask=__magic_name__       ,       )
						UpperCamelCase         =					model(
						    __magic_name__       ,       attention_mask=__magic_name__       ,       token_type_ids=__magic_name__       ,       encoder_hidden_states=__magic_name__       ,       )
						UpperCamelCase         =					model(__magic_name__       ,       attention_mask=__magic_name__       ,       token_type_ids=__magic_name__						)
						self.parent.assertEqual(result.last_hidden_state.shape       ,       (self.batch_size, self.seq_length, self.hidden_size)						)




			def   lowerCamelCase_					(						self							:		Optional[int]       ,       __magic_name__							:		Tuple       ,       __magic_name__							:		Optional[Any]       ,       __magic_name__							:		int       ,       __magic_name__							:		str       ,       __magic_name__							:		Any       ,       __magic_name__							:		Dict       ,       __magic_name__							:		List[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					MraForMaskedLM(config=__magic_name__						)
						model.to(__magic_name__						)
						model.eval()
						UpperCamelCase         =					model(__magic_name__       ,       attention_mask=__magic_name__       ,       token_type_ids=__magic_name__       ,       labels=__magic_name__						)
						self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.seq_length, self.vocab_size)						)




			def   lowerCamelCase_					(						self							:		Optional[int]       ,       __magic_name__							:		str       ,       __magic_name__							:		Optional[int]       ,       __magic_name__							:		Tuple       ,       __magic_name__							:		Optional[int]       ,       __magic_name__							:		List[Any]       ,       __magic_name__							:		int       ,       __magic_name__							:		Optional[int]						):







						"""simple docstring"""







						UpperCamelCase         =					MraForQuestionAnswering(config=__magic_name__						)
						model.to(__magic_name__						)
						model.eval()
						UpperCamelCase         =					model(
						    __magic_name__       ,       attention_mask=__magic_name__       ,       token_type_ids=__magic_name__       ,       start_positions=__magic_name__       ,       end_positions=__magic_name__       ,       )
						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							:		List[str]       ,       __magic_name__							:		Dict       ,       __magic_name__							:		int       ,       __magic_name__							:		Tuple       ,       __magic_name__							:		Optional[Any]       ,       __magic_name__							:		Tuple       ,       __magic_name__							:		Union[str, Any]       ,       __magic_name__							:		List[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					self.num_labels
						UpperCamelCase         =					MraForSequenceClassification(__magic_name__						)
						model.to(__magic_name__						)
						model.eval()
						UpperCamelCase         =					model(__magic_name__       ,       attention_mask=__magic_name__       ,       token_type_ids=__magic_name__       ,       labels=__magic_name__						)
						self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.num_labels)						)




			def   lowerCamelCase_					(						self							:		Dict       ,       __magic_name__							:		Union[str, Any]       ,       __magic_name__							:		int       ,       __magic_name__							:		Optional[int]       ,       __magic_name__							:		Optional[Any]       ,       __magic_name__							:		Dict       ,       __magic_name__							:		List[str]       ,       __magic_name__							:		Any						):







						"""simple docstring"""







						UpperCamelCase         =					self.num_labels
						UpperCamelCase         =					MraForTokenClassification(config=__magic_name__						)
						model.to(__magic_name__						)
						model.eval()
						UpperCamelCase         =					model(__magic_name__       ,       attention_mask=__magic_name__       ,       token_type_ids=__magic_name__       ,       labels=__magic_name__						)
						self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.seq_length, self.num_labels)						)




			def   lowerCamelCase_					(						self							:		str       ,       __magic_name__							:		Optional[Any]       ,       __magic_name__							:		str       ,       __magic_name__							:		Any       ,       __magic_name__							:		Optional[Any]       ,       __magic_name__							:		List[Any]       ,       __magic_name__							:		Dict       ,       __magic_name__							:		str						):







						"""simple docstring"""







						UpperCamelCase         =					self.num_choices
						UpperCamelCase         =					MraForMultipleChoice(config=__magic_name__						)
						model.to(__magic_name__						)
						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(
						    __magic_name__       ,       attention_mask=__magic_name__       ,       token_type_ids=__magic_name__       ,       labels=__magic_name__       ,       )
						self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.num_choices)						)





			def   lowerCamelCase_					(						self							:		str						):







						"""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    UpperCAmelCase					(       __snake_case      , unittest.TestCase    ):
			lowercase						= (
			    (
			        MraModel,
			        MraForMaskedLM,
			        MraForMultipleChoice,
			        MraForQuestionAnswering,
			        MraForSequenceClassification,
			        MraForTokenClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			lowercase						= False
			lowercase						= False
			lowercase						= False
			lowercase						= False

			lowercase						= ()




			def   lowerCamelCase_					(						self							:		Tuple						):







						"""simple docstring"""







						UpperCamelCase         =					MraModelTester(self						)
						UpperCamelCase         =					ConfigTester(self       ,       config_class=__magic_name__       ,       hidden_size=3_7						)




			def   lowerCamelCase_					(						self							:		List[Any]						):







						"""simple docstring"""







						self.config_tester.run_common_tests()




			def   lowerCamelCase_					(						self							:		Optional[int]						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__magic_name__						)




			def   lowerCamelCase_					(						self							:		str						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs()
						for type in ["absolute", "relative_key", "relative_key_query"]:
									UpperCamelCase         =					type
									self.model_tester.create_and_check_model(*__magic_name__						)




			def   lowerCamelCase_					(						self							:		Optional[int]						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*__magic_name__						)




			def   lowerCamelCase_					(						self							:		Optional[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*__magic_name__						)




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*__magic_name__						)




			def   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*__magic_name__						)




			def   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*__magic_name__						)




			@slow
			def   lowerCamelCase_					(						self							:		str						):







						"""simple docstring"""







						for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									UpperCamelCase         =					MraModel.from_pretrained(__magic_name__						)
									self.assertIsNotNone(__magic_name__						)





			@unittest.skip(reason="""MRA does not output attentions"""						)
			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						return




@require_torch
class    UpperCAmelCase					(       unittest.TestCase    ):




			@slow
			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					MraModel.from_pretrained("""uw-madison/mra-base-512-4"""						)
						UpperCamelCase         =					torch.arange(2_5_6						).unsqueeze(0						)

						with torch.no_grad():
									UpperCamelCase         =					model(__magic_name__						)[0]

						UpperCamelCase         =					torch.Size((1, 2_5_6, 7_6_8)						)
						self.assertEqual(output.shape       ,       __magic_name__						)

						UpperCamelCase         =					torch.tensor(
						    [[[-0.0_140, 0.0_830, -0.0_381], [0.1_546, 0.1_402, 0.0_220], [0.1_162, 0.0_851, 0.0_165]]]						)

						self.assertTrue(torch.allclose(output[:, :3, :3]       ,       __magic_name__       ,       atol=1e-4						)						)




			@slow
			def   lowerCamelCase_					(						self							:		Union[str, Any]						):







						"""simple docstring"""







						UpperCamelCase         =					MraForMaskedLM.from_pretrained("""uw-madison/mra-base-512-4"""						)
						UpperCamelCase         =					torch.arange(2_5_6						).unsqueeze(0						)

						with torch.no_grad():
									UpperCamelCase         =					model(__magic_name__						)[0]

						UpperCamelCase         =					5_0_2_6_5

						UpperCamelCase         =					torch.Size((1, 2_5_6, vocab_size)						)
						self.assertEqual(output.shape       ,       __magic_name__						)

						UpperCamelCase         =					torch.tensor(
						    [[[9.2_595, -3.6_038, 11.8_819], [9.3_869, -3.2_693, 11.0_956], [11.8_524, -3.4_938, 13.1_210]]]						)

						self.assertTrue(torch.allclose(output[:, :3, :3]       ,       __magic_name__       ,       atol=1e-4						)						)





			@slow
			def   lowerCamelCase_					(						self							:		str						):







						"""simple docstring"""







						UpperCamelCase         =					MraForMaskedLM.from_pretrained("""uw-madison/mra-base-4096-8-d3"""						)
						UpperCamelCase         =					torch.arange(4_0_9_6						).unsqueeze(0						)

						with torch.no_grad():
									UpperCamelCase         =					model(__magic_name__						)[0]

						UpperCamelCase         =					5_0_2_6_5

						UpperCamelCase         =					torch.Size((1, 4_0_9_6, vocab_size)						)
						self.assertEqual(output.shape       ,       __magic_name__						)

						UpperCamelCase         =					torch.tensor(
						    [[[5.4_789, -2.3_564, 7.5_064], [7.9_067, -1.3_369, 9.9_668], [9.0_712, -1.8_106, 7.0_380]]]						)

						self.assertTrue(torch.allclose(output[:, :3, :3]       ,       __magic_name__       ,       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    UpperCAmelCase					(       unittest.TestCase    ):




			def   lowerCamelCase_					(						self							:		Optional[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					tempfile.mkdtemp()

						# fmt: off
						UpperCamelCase         =					["""""", """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
						UpperCamelCase         =					dict(zip(__magic_name__       ,       range(len(__magic_name__						)						)						)						)
						UpperCamelCase         =					["""#version: 0.2""", """l o""", """lo w</w>""", """e r</w>""", """"""]
						UpperCamelCase         =					{"""unk_token""": """<unk>"""}

						UpperCamelCase         =					os.path.join(self.tmpdirname       ,       VOCAB_FILES_NAMES["""vocab_file"""]						)
						UpperCamelCase         =					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(__magic_name__						) + """\n"""						)
						with open(self.merges_file       ,       """w"""       ,       encoding="""utf-8"""						) as fp:
									fp.write("""\n""".join(__magic_name__						)						)

						UpperCamelCase         =					{
						    """do_resize""": True,
						    """size""": 2_0,
						    """do_center_crop""": True,
						    """crop_size""": 1_8,
						    """do_normalize""": True,
						    """image_mean""": [0.48_145_466, 0.4_578_275, 0.40_821_073],
						    """image_std""": [0.26_862_954, 0.26_130_258, 0.27_577_711],
						}
						UpperCamelCase         =					os.path.join(self.tmpdirname       ,       __magic_name__						)
						with open(self.image_processor_file       ,       """w"""       ,       encoding="""utf-8"""						) as fp:
									json.dump(__magic_name__       ,       __magic_name__						)




			def   lowerCamelCase_					(						self							:		str       ,       **__magic_name__							:		Tuple						):







						"""simple docstring"""







						return CLIPTokenizer.from_pretrained(self.tmpdirname       ,       pad_token="""!"""       ,       **__magic_name__						)




			def   lowerCamelCase_					(						self							:		Optional[int]       ,       **__magic_name__							:		str						):







						"""simple docstring"""







						return CLIPTokenizerFast.from_pretrained(self.tmpdirname       ,       pad_token="""!"""       ,       **__magic_name__						)




			def   lowerCamelCase_					(						self							:		Optional[int]       ,       **__magic_name__							:		Optional[Any]						):







						"""simple docstring"""







						return OwlViTImageProcessor.from_pretrained(self.tmpdirname       ,       **__magic_name__						)




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						shutil.rmtree(self.tmpdirname						)




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					[np.random.randint(2_5_5       ,       size=(3, 3_0, 4_0_0)       ,       dtype=np.uinta						)]

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

						return image_inputs




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_tokenizer()
						UpperCamelCase         =					self.get_rust_tokenizer()
						UpperCamelCase         =					self.get_image_processor()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)
						processor_slow.save_pretrained(self.tmpdirname						)
						UpperCamelCase         =					OwlViTProcessor.from_pretrained(self.tmpdirname       ,       use_fast=__magic_name__						)

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)
						processor_fast.save_pretrained(self.tmpdirname						)
						UpperCamelCase         =					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       ,       __magic_name__						)
						self.assertIsInstance(processor_fast.tokenizer       ,       __magic_name__						)

						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       ,       __magic_name__						)
						self.assertIsInstance(processor_fast.image_processor       ,       __magic_name__						)




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						UpperCamelCase         =					OwlViTProcessor(tokenizer=self.get_tokenizer()       ,       image_processor=self.get_image_processor()						)
						processor.save_pretrained(self.tmpdirname						)

						UpperCamelCase         =					self.get_tokenizer(bos_token="""(BOS)"""       ,       eos_token="""(EOS)"""						)
						UpperCamelCase         =					self.get_image_processor(do_normalize=__magic_name__						)

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

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

						self.assertEqual(processor.image_processor.to_json_string()       ,       image_processor_add_kwargs.to_json_string()						)
						self.assertIsInstance(processor.image_processor       ,       __magic_name__						)




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_image_processor()
						UpperCamelCase         =					self.get_tokenizer()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)

						UpperCamelCase         =					self.prepare_image_inputs()

						UpperCamelCase         =					image_processor(__magic_name__       ,       return_tensors="""np"""						)
						UpperCamelCase         =					processor(images=__magic_name__       ,       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   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_image_processor()
						UpperCamelCase         =					self.get_tokenizer()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)

						UpperCamelCase         =					"""lower newer"""

						UpperCamelCase         =					processor(text=__magic_name__       ,       return_tensors="""np"""						)

						UpperCamelCase         =					tokenizer(__magic_name__       ,       return_tensors="""np"""						)

						for key in encoded_tok.keys():
									self.assertListEqual(encoded_tok[key][0].tolist()       ,       encoded_processor[key][0].tolist()						)




			def   lowerCamelCase_					(						self							:		Optional[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_image_processor()
						UpperCamelCase         =					self.get_tokenizer()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)

						UpperCamelCase         =					"""lower newer"""
						UpperCamelCase         =					self.prepare_image_inputs()

						UpperCamelCase         =					processor(text=__magic_name__       ,       images=__magic_name__						)

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

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




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						UpperCamelCase         =					"""google/owlvit-base-patch32"""
						UpperCamelCase         =					OwlViTProcessor.from_pretrained(__magic_name__						)

						UpperCamelCase         =					["""cat""", """nasa badge"""]
						UpperCamelCase         =					processor(text=__magic_name__						)

						UpperCamelCase         =					1_6
						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(__magic_name__						):
									processor()




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					"""google/owlvit-base-patch32"""
						UpperCamelCase         =					OwlViTProcessor.from_pretrained(__magic_name__						)

						UpperCamelCase         =					[["""cat""", """nasa badge"""], ["""person"""]]
						UpperCamelCase         =					processor(text=__magic_name__						)

						UpperCamelCase         =					1_6
						UpperCamelCase         =					len(__magic_name__						)
						UpperCamelCase         =					max([len(__magic_name__						) 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(__magic_name__						):
									processor()




			def   lowerCamelCase_					(						self							:		List[str]						):







						"""simple docstring"""







						UpperCamelCase         =					"""google/owlvit-base-patch32"""
						UpperCamelCase         =					OwlViTProcessor.from_pretrained(__magic_name__						)

						UpperCamelCase         =					["""cat""", """nasa badge"""]
						UpperCamelCase         =					processor(text=__magic_name__						)

						UpperCamelCase         =					1_6
						UpperCamelCase         =					inputs["""input_ids"""]
						UpperCamelCase         =					[
						    [4_9_4_0_6, 2_3_6_8, 4_9_4_0_7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
						    [4_9_4_0_6, 6_8_4_1, 1_1_3_0_1, 4_9_4_0_7, 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   lowerCamelCase_					(						self							:		str						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_image_processor()
						UpperCamelCase         =					self.get_tokenizer()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)

						UpperCamelCase         =					self.prepare_image_inputs()
						UpperCamelCase         =					self.prepare_image_inputs()

						UpperCamelCase         =					processor(images=__magic_name__       ,       query_images=__magic_name__						)

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

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





			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_image_processor()
						UpperCamelCase         =					self.get_tokenizer()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)

						UpperCamelCase         =					[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

						UpperCamelCase         =					processor.batch_decode(__magic_name__						)
						UpperCamelCase         =					tokenizer.batch_decode(__magic_name__						)

						self.assertListEqual(__magic_name__       ,       __magic_name__						)




