





import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import (
        MODEL_FOR_PRETRAINING_MAPPING,
        AlbertForMaskedLM,
        AlbertForMultipleChoice,
        AlbertForPreTraining,
        AlbertForQuestionAnswering,
        AlbertForSequenceClassification,
        AlbertForTokenClassification,
        AlbertModel,
    )
    from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST

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

     lowerCamelCase__       : Tuple   					=						None
     if self.use_input_mask:
         lowerCamelCase__       : Any   					=						random_attention_mask([self.batch_size, self.seq_length]      )

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

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

     lowerCamelCase__       : int   					=						self.get_config()

     return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
 def 	A_      ( self    : Optional[Any]      )     ->      Optional[int]:
     return AlbertConfig(
         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     ,	num_hidden_groups=self.num_hidden_groups     ,	)
 def 	A_      ( self    : Tuple     ,	UpperCAmelCase    : List[str]     ,	UpperCAmelCase    : List[Any]     ,	UpperCAmelCase    : Tuple     ,	UpperCAmelCase    : Optional[Any]     ,	UpperCAmelCase    : Dict     ,	UpperCAmelCase    : str     ,	UpperCAmelCase    : str      )     ->      Any:
     lowerCamelCase__       : List[Any]   					=						AlbertModel(config=UpperCAmelCase      )
     model.to(UpperCAmelCase      )
     model.eval()
     lowerCamelCase__       : Dict   					=						model(UpperCAmelCase     ,	attention_mask=UpperCAmelCase     ,	token_type_ids=UpperCAmelCase      )
     lowerCamelCase__       : Any   					=						model(UpperCAmelCase     ,	token_type_ids=UpperCAmelCase      )
     lowerCamelCase__       : int   					=						model(UpperCAmelCase      )
     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 	A_      ( self    : List[str]     ,	UpperCAmelCase    : Tuple     ,	UpperCAmelCase    : List[Any]     ,	UpperCAmelCase    : Any     ,	UpperCAmelCase    : Any     ,	UpperCAmelCase    : str     ,	UpperCAmelCase    : Tuple     ,	UpperCAmelCase    : Tuple      )     ->      Union[str, Any]:
     lowerCamelCase__       : Dict   					=						AlbertForPreTraining(config=UpperCAmelCase      )
     model.to(UpperCAmelCase      )
     model.eval()
     lowerCamelCase__       : Any   					=						model(
         UpperCAmelCase     ,	attention_mask=UpperCAmelCase     ,	token_type_ids=UpperCAmelCase     ,	labels=UpperCAmelCase     ,	sentence_order_label=UpperCAmelCase     ,	)
     self.parent.assertEqual(result.prediction_logits.shape     ,	(self.batch_size, self.seq_length, self.vocab_size)      )
     self.parent.assertEqual(result.sop_logits.shape     ,	(self.batch_size, config.num_labels)      )
 def 	A_      ( self    : Dict     ,	UpperCAmelCase    : List[Any]     ,	UpperCAmelCase    : Optional[Any]     ,	UpperCAmelCase    : Dict     ,	UpperCAmelCase    : int     ,	UpperCAmelCase    : Any     ,	UpperCAmelCase    : List[Any]     ,	UpperCAmelCase    : Any      )     ->      List[str]:
     lowerCamelCase__       : Dict   					=						AlbertForMaskedLM(config=UpperCAmelCase      )
     model.to(UpperCAmelCase      )
     model.eval()
     lowerCamelCase__       : Union[str, Any]   					=						model(UpperCAmelCase     ,	attention_mask=UpperCAmelCase     ,	token_type_ids=UpperCAmelCase     ,	labels=UpperCAmelCase      )
     self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.seq_length, self.vocab_size)      )
 def 	A_      ( self    : int     ,	UpperCAmelCase    : Optional[int]     ,	UpperCAmelCase    : int     ,	UpperCAmelCase    : List[str]     ,	UpperCAmelCase    : Dict     ,	UpperCAmelCase    : List[str]     ,	UpperCAmelCase    : str     ,	UpperCAmelCase    : Any      )     ->      Union[str, Any]:
     lowerCamelCase__       : Optional[int]   					=						AlbertForQuestionAnswering(config=UpperCAmelCase      )
     model.to(UpperCAmelCase      )
     model.eval()
     lowerCamelCase__       : Optional[Any]   					=						model(
         UpperCAmelCase     ,	attention_mask=UpperCAmelCase     ,	token_type_ids=UpperCAmelCase     ,	start_positions=UpperCAmelCase     ,	end_positions=UpperCAmelCase     ,	)
     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 	A_      ( self    : Optional[int]     ,	UpperCAmelCase    : Any     ,	UpperCAmelCase    : List[Any]     ,	UpperCAmelCase    : Dict     ,	UpperCAmelCase    : Dict     ,	UpperCAmelCase    : List[str]     ,	UpperCAmelCase    : Tuple     ,	UpperCAmelCase    : int      )     ->      Tuple:
     lowerCamelCase__       : Tuple   					=						self.num_labels
     lowerCamelCase__       : List[Any]   					=						AlbertForSequenceClassification(UpperCAmelCase      )
     model.to(UpperCAmelCase      )
     model.eval()
     lowerCamelCase__       : Union[str, Any]   					=						model(UpperCAmelCase     ,	attention_mask=UpperCAmelCase     ,	token_type_ids=UpperCAmelCase     ,	labels=UpperCAmelCase      )
     self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.num_labels)      )
 def 	A_      ( self    : List[str]     ,	UpperCAmelCase    : Any     ,	UpperCAmelCase    : Optional[Any]     ,	UpperCAmelCase    : List[str]     ,	UpperCAmelCase    : List[str]     ,	UpperCAmelCase    : Dict     ,	UpperCAmelCase    : Optional[int]     ,	UpperCAmelCase    : Tuple      )     ->      Optional[Any]:
     lowerCamelCase__       : Any   					=						self.num_labels
     lowerCamelCase__       : Tuple   					=						AlbertForTokenClassification(config=UpperCAmelCase      )
     model.to(UpperCAmelCase      )
     model.eval()
     lowerCamelCase__       : List[Any]   					=						model(UpperCAmelCase     ,	attention_mask=UpperCAmelCase     ,	token_type_ids=UpperCAmelCase     ,	labels=UpperCAmelCase      )
     self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.seq_length, self.num_labels)      )
 def 	A_      ( self    : Any     ,	UpperCAmelCase    : List[Any]     ,	UpperCAmelCase    : str     ,	UpperCAmelCase    : List[Any]     ,	UpperCAmelCase    : Tuple     ,	UpperCAmelCase    : Union[str, Any]     ,	UpperCAmelCase    : Optional[Any]     ,	UpperCAmelCase    : str      )     ->      List[Any]:
     lowerCamelCase__       : List[str]   					=						self.num_choices
     lowerCamelCase__       : str   					=						AlbertForMultipleChoice(config=UpperCAmelCase      )
     model.to(UpperCAmelCase      )
     model.eval()
     lowerCamelCase__       : List[Any]   					=						input_ids.unsqueeze(1      ).expand(-1     ,	self.num_choices     ,	-1      ).contiguous()
     lowerCamelCase__       : Optional[Any]   					=						token_type_ids.unsqueeze(1      ).expand(-1     ,	self.num_choices     ,	-1      ).contiguous()
     lowerCamelCase__       : Tuple   					=						input_mask.unsqueeze(1      ).expand(-1     ,	self.num_choices     ,	-1      ).contiguous()
     lowerCamelCase__       : Dict   					=						model(
         UpperCAmelCase     ,	attention_mask=UpperCAmelCase     ,	token_type_ids=UpperCAmelCase     ,	labels=UpperCAmelCase     ,	)
     self.parent.assertEqual(result.logits.shape     ,	(self.batch_size, self.num_choices)      )







 def 	A_      ( self    : List[str]      )     ->      List[Any]:
     lowerCamelCase__       : Optional[Any]   					=						self.prepare_config_and_inputs()
     (
         (
         lowerCamelCase__
     )					,				(
         lowerCamelCase__
     )					,				(
         lowerCamelCase__
     )					,				(
         lowerCamelCase__
     )					,				(
         lowerCamelCase__
     )					,				(
         lowerCamelCase__
     )					,				(
         lowerCamelCase__
     )					,				
     )       : Optional[Any]   					=						config_and_inputs
     lowerCamelCase__       : Any   					=						{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
     return config, inputs_dict


@require_torch
class   lowerCAmelCase				(   __UpperCamelCase,    __UpperCamelCase,    unittest.TestCase     ):
 UpperCAmelCase__						=						(
     (
         AlbertModel,
         AlbertForPreTraining,
         AlbertForMaskedLM,
         AlbertForMultipleChoice,
         AlbertForSequenceClassification,
         AlbertForTokenClassification,
         AlbertForQuestionAnswering,
     )
     if is_torch_available()
     else ()
 )
 UpperCAmelCase__						=						(
     {
         """feature-extraction""": AlbertModel,
         """fill-mask""": AlbertForMaskedLM,
         """question-answering""": AlbertForQuestionAnswering,
         """text-classification""": AlbertForSequenceClassification,
         """token-classification""": AlbertForTokenClassification,
         """zero-shot""": AlbertForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 UpperCAmelCase__						=						True
 def 	A_      ( self    : str     ,	UpperCAmelCase    : Optional[Any]     ,	UpperCAmelCase    : int     ,	UpperCAmelCase    : Dict=False      )     ->      Optional[Any]:
     lowerCamelCase__       : Dict   					=						super()._prepare_for_class(UpperCAmelCase     ,	UpperCAmelCase     ,	return_labels=UpperCAmelCase      )

     if return_labels:
         if model_class in get_values(UpperCAmelCase      ):
             lowerCamelCase__       : Union[str, Any]   					=						torch.zeros(
                 (self.model_tester.batch_size, self.model_tester.seq_length)     ,	dtype=torch.long     ,	device=UpperCAmelCase      )
             lowerCamelCase__       : Tuple   					=						torch.zeros(
                 self.model_tester.batch_size     ,	dtype=torch.long     ,	device=UpperCAmelCase      )
     return inputs_dict
 def 	A_      ( self    : Optional[Any]      )     ->      int:
     lowerCamelCase__       : List[str]   					=						AlbertModelTester(self      )
     lowerCamelCase__       : Any   					=						ConfigTester(self     ,	config_class=UpperCAmelCase     ,	hidden_size=37      )
 def 	A_      ( self    : Tuple      )     ->      Optional[int]:
     self.config_tester.run_common_tests()
 def 	A_      ( self    : Tuple      )     ->      Optional[Any]:
     lowerCamelCase__       : Optional[int]   					=						self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*UpperCAmelCase      )
 def 	A_      ( self    : Optional[Any]      )     ->      Optional[Any]:
     lowerCamelCase__       : List[str]   					=						self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_pretraining(*UpperCAmelCase      )
 def 	A_      ( self    : Tuple      )     ->      Dict:
     lowerCamelCase__       : Any   					=						self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase      )
 def 	A_      ( self    : Union[str, Any]      )     ->      List[str]:
     lowerCamelCase__       : Dict   					=						self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase      )
 def 	A_      ( self    : Tuple      )     ->      int:
     lowerCamelCase__       : str   					=						self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase      )
 def 	A_      ( self    : List[Any]      )     ->      Dict:
     lowerCamelCase__       : int   					=						self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase      )
 def 	A_      ( self    : Optional[Any]      )     ->      Dict:
     lowerCamelCase__       : Any   					=						self.model_tester.prepare_config_and_inputs()
     for type in ["absolute", "relative_key", "relative_key_query"]:
         lowerCamelCase__       : Union[str, Any]   					=						type
         self.model_tester.create_and_check_model(*UpperCAmelCase      )







 @slow
 def 	A_      ( self    : Dict      )     ->      Optional[int]:
     for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         lowerCamelCase__       : int   					=						AlbertModel.from_pretrained(UpperCAmelCase      )
         self.assertIsNotNone(UpperCAmelCase      )


@require_torch
class   lowerCAmelCase				(   unittest.TestCase     ):
 @slow
 def 	A_      ( self    : List[Any]      )     ->      Optional[int]:
     lowerCamelCase__       : Tuple   					=						AlbertModel.from_pretrained('albert-base-v2'      )
     lowerCamelCase__       : Optional[int]   					=						torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]      )
     lowerCamelCase__       : Optional[int]   					=						torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
     with torch.no_grad():
         lowerCamelCase__       : Optional[int]   					=						model(UpperCAmelCase     ,	attention_mask=UpperCAmelCase      )[0]
     lowerCamelCase__       : int   					=						torch.Size((1, 11, 768)      )
     self.assertEqual(output.shape     ,	UpperCAmelCase      )
     lowerCamelCase__       : List[Any]   					=						torch.tensor(
         [[[-0.6_5_1_3, 1.5_0_3_5, -0.2_7_6_6], [-0.6_5_1_5, 1.5_0_4_6, -0.2_7_8_0], [-0.6_5_1_2, 1.5_0_4_9, -0.2_7_8_4]]]      )

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












import json
import os
import shutil
import tempfile
import unittest

import numpy as np

from transformers import BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES, BertTokenizer
from transformers.testing_utils import require_tokenizers, require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
    from PIL import Image

    from transformers import VisionTextDualEncoderProcessor, ViTImageProcessor

@require_tokenizers
@require_vision
class   lowerCAmelCase				(   unittest.TestCase     ):
 def 	A_      ( self    : str      )     ->      Dict:
     lowerCamelCase__       : Optional[Any]   					=						tempfile.mkdtemp()

     # fmt: off
     lowerCamelCase__       : Tuple   					=						['[UNK]', '[CLS]', '[SEP]', '[PAD]', '[MASK]', 'want', '##want', '##ed', 'wa', 'un', 'runn', '##ing', ',', 'low', 'lowest']
     # fmt: on
     lowerCamelCase__       : int   					=						os.path.join(self.tmpdirname     ,	VOCAB_FILES_NAMES['vocab_file']      )
     with open(self.vocab_file     ,	'w'     ,	encoding='utf-8'      ) as vocab_writer:
         vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]      )      )

     lowerCamelCase__       : Any   					=						{
         'do_resize': True,
         'size': {'height': 18, 'width': 18},
         'do_normalize': True,
         'image_mean': [0.5, 0.5, 0.5],
         'image_std': [0.5, 0.5, 0.5],
     }
     lowerCamelCase__       : int   					=						os.path.join(self.tmpdirname     ,	UpperCAmelCase      )
     with open(self.image_processor_file     ,	'w'     ,	encoding='utf-8'      ) as fp:
         json.dump(UpperCAmelCase     ,	UpperCAmelCase      )
 def 	A_      ( self    : List[str]     ,	**UpperCAmelCase    : str      )     ->      int:
     return BertTokenizer.from_pretrained(self.tmpdirname     ,	**UpperCAmelCase      )
 def 	A_      ( self    : Optional[int]     ,	**UpperCAmelCase    : List[str]      )     ->      List[str]:
     return ViTImageProcessor.from_pretrained(self.tmpdirname     ,	**UpperCAmelCase      )
 def 	A_      ( self    : int      )     ->      Any:
     shutil.rmtree(self.tmpdirname      )
 def 	A_      ( self    : str      )     ->      str:
     lowerCamelCase__       : List[Any]   					=						[np.random.randint(255     ,	size=(3, 30, 400)     ,	dtype=np.uinta      )]

     lowerCamelCase__       : Union[str, Any]   					=						[Image.fromarray(np.moveaxis(UpperCAmelCase     ,	0     ,	-1      )      ) for x in image_inputs]

     return image_inputs
 def 	A_      ( self    : Dict      )     ->      Dict:
     lowerCamelCase__       : List[Any]   					=						self.get_tokenizer()
     lowerCamelCase__       : Tuple   					=						self.get_image_processor()

     lowerCamelCase__       : Union[str, Any]   					=						VisionTextDualEncoderProcessor(tokenizer=UpperCAmelCase     ,	image_processor=UpperCAmelCase      )

     processor.save_pretrained(self.tmpdirname      )
     lowerCamelCase__       : List[str]   					=						VisionTextDualEncoderProcessor.from_pretrained(self.tmpdirname      )

     self.assertEqual(processor.tokenizer.get_vocab()     ,	tokenizer.get_vocab()      )
     self.assertIsInstance(processor.tokenizer     ,	(BertTokenizer, BertTokenizerFast)      )

     self.assertEqual(processor.image_processor.to_json_string()     ,	image_processor.to_json_string()      )
     self.assertIsInstance(processor.image_processor     ,	UpperCAmelCase      )
 def 	A_      ( self    : List[str]      )     ->      Tuple:
     lowerCamelCase__       : List[Any]   					=						VisionTextDualEncoderProcessor(
         tokenizer=self.get_tokenizer()     ,	image_processor=self.get_image_processor()      )
     processor.save_pretrained(self.tmpdirname      )

     lowerCamelCase__       : Tuple   					=						self.get_tokenizer(bos_token='(BOS)'     ,	eos_token='(EOS)'      )
     lowerCamelCase__       : int   					=						self.get_image_processor(do_normalize=UpperCAmelCase     ,	padding_value=1.0      )

     lowerCamelCase__       : Union[str, Any]   					=						VisionTextDualEncoderProcessor.from_pretrained(
         self.tmpdirname     ,	bos_token='(BOS)'     ,	eos_token='(EOS)'     ,	do_normalize=UpperCAmelCase     ,	padding_value=1.0      )

     self.assertEqual(processor.tokenizer.get_vocab()     ,	tokenizer_add_kwargs.get_vocab()      )
     self.assertIsInstance(processor.tokenizer     ,	(BertTokenizer, BertTokenizerFast)      )

     self.assertEqual(processor.image_processor.to_json_string()     ,	image_processor_add_kwargs.to_json_string()      )
     self.assertIsInstance(processor.image_processor     ,	UpperCAmelCase      )
 def 	A_      ( self    : Any      )     ->      Tuple:
     lowerCamelCase__       : List[Any]   					=						self.get_image_processor()
     lowerCamelCase__       : Any   					=						self.get_tokenizer()

     lowerCamelCase__       : Optional[int]   					=						VisionTextDualEncoderProcessor(tokenizer=UpperCAmelCase     ,	image_processor=UpperCAmelCase      )

     lowerCamelCase__       : Optional[int]   					=						self.prepare_image_inputs()

     lowerCamelCase__       : int   					=						image_processor(UpperCAmelCase     ,	return_tensors='np'      )
     lowerCamelCase__       : List[str]   					=						processor(images=UpperCAmelCase     ,	return_tensors='np'      )

     for key in input_feat_extract.keys():
         self.assertAlmostEqual(input_feat_extract[key].sum()     ,	input_processor[key].sum()     ,	delta=1e-2      )
 def 	A_      ( self    : Tuple      )     ->      List[Any]:
     lowerCamelCase__       : Dict   					=						self.get_image_processor()
     lowerCamelCase__       : List[str]   					=						self.get_tokenizer()

     lowerCamelCase__       : str   					=						VisionTextDualEncoderProcessor(tokenizer=UpperCAmelCase     ,	image_processor=UpperCAmelCase      )

     lowerCamelCase__       : Tuple   					=						'lower newer'

     lowerCamelCase__       : Tuple   					=						processor(text=UpperCAmelCase      )

     lowerCamelCase__       : Any   					=						tokenizer(UpperCAmelCase      )

     for key in encoded_tok.keys():
         self.assertListEqual(encoded_tok[key]     ,	encoded_processor[key]      )
 def 	A_      ( self    : Optional[int]      )     ->      Any:
     lowerCamelCase__       : Optional[int]   					=						self.get_image_processor()
     lowerCamelCase__       : Tuple   					=						self.get_tokenizer()

     lowerCamelCase__       : Tuple   					=						VisionTextDualEncoderProcessor(tokenizer=UpperCAmelCase     ,	image_processor=UpperCAmelCase      )

     lowerCamelCase__       : str   					=						'lower newer'
     lowerCamelCase__       : Dict   					=						self.prepare_image_inputs()

     lowerCamelCase__       : int   					=						processor(text=UpperCAmelCase     ,	images=UpperCAmelCase      )

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

     # test if it raises when no input is passed
     with self.assertRaises(UpperCAmelCase      ):
         processor()
 def 	A_      ( self    : Optional[Any]      )     ->      List[str]:
     lowerCamelCase__       : Dict   					=						self.get_image_processor()
     lowerCamelCase__       : Union[str, Any]   					=						self.get_tokenizer()

     lowerCamelCase__       : List[str]   					=						VisionTextDualEncoderProcessor(tokenizer=UpperCAmelCase     ,	image_processor=UpperCAmelCase      )

     lowerCamelCase__       : List[str]   					=						[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

     lowerCamelCase__       : Dict   					=						processor.batch_decode(UpperCAmelCase      )
     lowerCamelCase__       : List[str]   					=						tokenizer.batch_decode(UpperCAmelCase      )

     self.assertListEqual(UpperCAmelCase     ,	UpperCAmelCase      )







 def 	A_      ( self    : Optional[int]      )     ->      List[str]:
     lowerCamelCase__       : Tuple   					=						self.get_image_processor()
     lowerCamelCase__       : List[str]   					=						self.get_tokenizer()

     lowerCamelCase__       : Union[str, Any]   					=						VisionTextDualEncoderProcessor(tokenizer=UpperCAmelCase     ,	image_processor=UpperCAmelCase      )

     lowerCamelCase__       : Dict   					=						'lower newer'
     lowerCamelCase__       : List[Any]   					=						self.prepare_image_inputs()

     lowerCamelCase__       : Union[str, Any]   					=						processor(text=UpperCAmelCase     ,	images=UpperCAmelCase      )

     self.assertListEqual(list(inputs.keys()      )     ,	processor.model_input_names      )





