






from __future__ import annotations

import unittest

from transformers import RoFormerConfig, is_tf_available
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 (
				    TFRoFormerForCausalLM,
				    TFRoFormerForMaskedLM,
				    TFRoFormerForMultipleChoice,
				    TFRoFormerForQuestionAnswering,
				    TFRoFormerForSequenceClassification,
				    TFRoFormerForTokenClassification,
				    TFRoFormerModel,
				)
				from transformers.models.roformer.modeling_tf_roformer import (
				    TFRoFormerSelfAttention,
				    TFRoFormerSinusoidalPositionalEmbedding,
				)


class 							__a							:





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__ ,    UpperCamelCase__=13 ,    UpperCamelCase__=7 ,    UpperCamelCase__=True ,    UpperCamelCase__=True ,    UpperCamelCase__=True ,    UpperCamelCase__=True ,    UpperCamelCase__=99 ,    UpperCamelCase__=32 ,    UpperCamelCase__=2 ,    UpperCamelCase__=4 ,    UpperCamelCase__=37 ,    UpperCamelCase__="gelu" ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=0.1 ,    UpperCamelCase__=512 ,    UpperCamelCase__=16 ,    UpperCamelCase__=2 ,    UpperCamelCase__=0.02 ,    UpperCamelCase__=3 ,    UpperCamelCase__=4 ,    UpperCamelCase__=None ,    ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   parent
						SCREAMING_SNAKE_CASE_   :	int													=   13
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   7
						SCREAMING_SNAKE_CASE_   :	Dict													=   True
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   True
						SCREAMING_SNAKE_CASE_   :	Dict													=   True
						SCREAMING_SNAKE_CASE_   :	Dict													=   True
						SCREAMING_SNAKE_CASE_   :	str													=   99
						SCREAMING_SNAKE_CASE_   :	Any													=   32
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   2
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   4
						SCREAMING_SNAKE_CASE_   :	Dict													=   37
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   'gelu'
						SCREAMING_SNAKE_CASE_   :	Dict													=   0.1
						SCREAMING_SNAKE_CASE_   :	Tuple													=   0.1
						SCREAMING_SNAKE_CASE_   :	Any													=   512
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   16
						SCREAMING_SNAKE_CASE_   :	Dict													=   2
						SCREAMING_SNAKE_CASE_   :	str													=   0.02
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   3
						SCREAMING_SNAKE_CASE_   :	int													=   4
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   None


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   ids_tensor([self.batch_size, self.seq_length] ,    self.vocab_size       )

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   None
						if self.use_input_mask:
										SCREAMING_SNAKE_CASE_   :	Dict													=   random_attention_mask([self.batch_size, self.seq_length]       )

						SCREAMING_SNAKE_CASE_   :	Dict													=   None
						if self.use_token_type_ids:
										SCREAMING_SNAKE_CASE_   :	Optional[int]													=   ids_tensor([self.batch_size, self.seq_length] ,    self.type_vocab_size       )

						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   None
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   None
						SCREAMING_SNAKE_CASE_   :	List[str]													=   None
						if self.use_labels:
										SCREAMING_SNAKE_CASE_   :	str													=   ids_tensor([self.batch_size] ,    self.type_sequence_label_size       )
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   ids_tensor([self.batch_size, self.seq_length] ,    self.num_labels       )
										SCREAMING_SNAKE_CASE_   :	Dict													=   ids_tensor([self.batch_size] ,    self.num_choices       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   RoFormerConfig(
						    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 ,    return_dict=UpperCamelCase__ ,    )

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	str													=   TFRoFormerModel(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   [input_ids, input_mask]
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   model(UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   model(UpperCamelCase__       )

						self.parent.assertEqual(result.last_hidden_state.shape ,    (self.batch_size, self.seq_length, self.hidden_size)       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   True
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   TFRoFormerForCausalLM(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   {
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						    'token_type_ids': token_type_ids,
						}
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   model(UpperCamelCase__       )['logits']
						self.parent.assertListEqual(
						    list(prediction_scores.numpy().shape       ) ,    [self.batch_size, self.seq_length, self.vocab_size]       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   TFRoFormerForMaskedLM(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   {
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						    'token_type_ids': token_type_ids,
						}
						SCREAMING_SNAKE_CASE_   :	Any													=   model(UpperCamelCase__       )
						self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.seq_length, self.vocab_size)       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   self.num_labels
						SCREAMING_SNAKE_CASE_   :	Dict													=   TFRoFormerForSequenceClassification(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	str													=   {
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						    'token_type_ids': token_type_ids,
						}

						SCREAMING_SNAKE_CASE_   :	Any													=   model(UpperCamelCase__       )
						self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.num_labels)       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   self.num_choices
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   TFRoFormerForMultipleChoice(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	str													=   tf.tile(tf.expand_dims(UpperCamelCase__ ,    1       ) ,    (1, self.num_choices, 1)       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   tf.tile(tf.expand_dims(UpperCamelCase__ ,    1       ) ,    (1, self.num_choices, 1)       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   tf.tile(tf.expand_dims(UpperCamelCase__ ,    1       ) ,    (1, self.num_choices, 1)       )
						SCREAMING_SNAKE_CASE_   :	int													=   {
						    'input_ids': multiple_choice_inputs_ids,
						    'attention_mask': multiple_choice_input_mask,
						    'token_type_ids': multiple_choice_token_type_ids,
						}
						SCREAMING_SNAKE_CASE_   :	Any													=   model(UpperCamelCase__       )
						self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.num_choices)       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	int													=   self.num_labels
						SCREAMING_SNAKE_CASE_   :	Dict													=   TFRoFormerForTokenClassification(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   {
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						    'token_type_ids': token_type_ids,
						}
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   model(UpperCamelCase__       )
						self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.seq_length, self.num_labels)       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   TFRoFormerForQuestionAnswering(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	int													=   {
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						    'token_type_ids': token_type_ids,
						}

						SCREAMING_SNAKE_CASE_   :	str													=   model(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   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.prepare_config_and_inputs()
						(
						    (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       
						)   :	Any													=   config_and_inputs
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
						return config, inputs_dict






@require_tf
class 							__a							(  __A ,	__A ,	unittest.TestCase						):





		'''simple docstring'''



		UpperCAmelCase__      :				List[Any]				    =						(
		    (
		        TFRoFormerModel,
		        TFRoFormerForCausalLM,
		        TFRoFormerForMaskedLM,
		        TFRoFormerForQuestionAnswering,
		        TFRoFormerForSequenceClassification,
		        TFRoFormerForTokenClassification,
		        TFRoFormerForMultipleChoice,
		    )
		    if is_tf_available()
		    else ()
		)
		UpperCAmelCase__      :				Dict				    =						(
		    {
		        """feature-extraction""": TFRoFormerModel,
		        """fill-mask""": TFRoFormerForMaskedLM,
		        """question-answering""": TFRoFormerForQuestionAnswering,
		        """text-classification""": TFRoFormerForSequenceClassification,
		        """text-generation""": TFRoFormerForCausalLM,
		        """token-classification""": TFRoFormerForTokenClassification,
		        """zero-shot""": TFRoFormerForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)

		UpperCAmelCase__      :				int				    =						False
		UpperCAmelCase__      :				Union[str, Any]				    =						False


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						if pipeline_test_casse_name == "TextGenerationPipelineTests":
										return True

						return False


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   TFRoFormerModelTester(self       )
						SCREAMING_SNAKE_CASE_   :	str													=   ConfigTester(self ,    config_class=UpperCamelCase__ ,    hidden_size=37       )


		def   __snake_case			(						self       ):
						self.config_tester.run_common_tests()


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	int													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_lm_head(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	int													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__       )






		@slow
		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   TFRoFormerModel.from_pretrained('junnyu/roformer_chinese_base'       )
						self.assertIsNotNone(UpperCamelCase__       )






@require_tf
class 							__a							(  unittest.TestCase						):





		'''simple docstring'''



		@slow
		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   TFRoFormerForMaskedLM.from_pretrained('junnyu/roformer_chinese_base'       )
						SCREAMING_SNAKE_CASE_   :	Tuple													=   tf.constant([[0, 1, 2, 3, 4, 5]]       )
						SCREAMING_SNAKE_CASE_   :	Any													=   model(UpperCamelCase__       )[0]

						# TODO Replace vocab size
						SCREAMING_SNAKE_CASE_   :	Tuple													=   50000

						SCREAMING_SNAKE_CASE_   :	str													=   [1, 6, vocab_size]
						self.assertEqual(output.shape ,    UpperCamelCase__       )

						print(output[:, :3, :3]       )

						# TODO Replace values below with what was printed above.
						SCREAMING_SNAKE_CASE_   :	str													=   tf.constant(
						    [
						        [
						            [-0.12_05_33_41, -1.0_26_49_01, 0.29_22_19_46],
						            [-1.5_13_37_83, 0.19_74_33, 0.15_19_06_07],
						            [-5.0_13_54_03, -3.90_02_56, -0.84_03_87_64],
						        ]
						    ]       )
						tf.debugging.assert_near(output[:, :3, :3] ,    UpperCamelCase__ ,    atol=1E-4       )






@require_tf
class 							__a							(  unittest.TestCase						):





		'''simple docstring'''



		UpperCAmelCase__      :				Union[str, Any]				    =						1e-4


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   tf.constant([[4, 10]]       )
						SCREAMING_SNAKE_CASE_   :	int													=   TFRoFormerSinusoidalPositionalEmbedding(num_positions=6 ,    embedding_dim=6       )

						SCREAMING_SNAKE_CASE_   :	Any													=   emba(input_ids.shape       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   tf.constant(
						    [[0.00_00, 0.00_00, 0.00_00, 1.00_00, 1.00_00, 1.00_00], [0.84_15, 0.04_64, 0.00_22, 0.54_03, 0.99_89, 1.00_00]]       )

						tf.debugging.assert_near(UpperCamelCase__ ,    UpperCamelCase__ ,    atol=self.tolerance       )






		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   tf.constant(
						    [
						        [0.00_00, 0.00_00, 0.00_00, 0.00_00, 0.00_00],
						        [0.84_15, 0.82_19, 0.80_20, 0.78_19, 0.76_17],
						        [0.90_93, 0.93_64, 0.95_81, 0.97_49, 0.98_70],
						    ]       )
						SCREAMING_SNAKE_CASE_   :	str													=   TFRoFormerSinusoidalPositionalEmbedding(num_positions=512 ,    embedding_dim=512       )
						emba([2, 16, 512]       )
						SCREAMING_SNAKE_CASE_   :	Tuple													=   emba.weight[:3, :5]

						tf.debugging.assert_near(UpperCamelCase__ ,    UpperCamelCase__ ,    atol=self.tolerance       )






@require_tf
class 							__a							(  unittest.TestCase						):





		'''simple docstring'''



		UpperCAmelCase__      :				List[Any]				    =						1e-4


		def   __snake_case			(						self       ):
						# 2,12,16,64
						SCREAMING_SNAKE_CASE_   :	Dict													=   tf.reshape(tf.range(2 * 12 * 16 * 64 ,    dtype=tf.floataa       ) ,    shape=(2, 12, 16, 64)       ) / 100

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   -tf.reshape(tf.range(2 * 12 * 16 * 64 ,    dtype=tf.floataa       ) ,    shape=(2, 12, 16, 64)       ) / 100

						SCREAMING_SNAKE_CASE_   :	int													=   TFRoFormerSinusoidalPositionalEmbedding(num_positions=32 ,    embedding_dim=64       )
						SCREAMING_SNAKE_CASE_   :	int													=   embed_positions([2, 16, 768]       )[None, None, :, :]

						SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	Any													=   TFRoFormerSelfAttention.apply_rotary_position_embeddings(
						    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   tf.constant(
						    [
						        [0.00_00, 0.01_00, 0.02_00, 0.03_00, 0.04_00, 0.05_00, 0.06_00, 0.07_00],
						        [-0.20_12, 0.88_97, 0.02_63, 0.94_01, 0.20_74, 0.94_63, 0.34_81, 0.93_43],
						        [-1.70_57, 0.62_71, -1.21_45, 1.38_97, -0.63_03, 1.76_47, -0.11_73, 1.89_85],
						        [-2.17_31, -1.63_97, -2.73_58, 0.28_54, -2.18_40, 1.71_83, -1.30_18, 2.48_71],
						        [0.27_17, -3.61_73, -2.92_06, -2.19_88, -3.66_38, 0.38_58, -2.91_55, 2.29_80],
						        [3.98_59, -2.15_80, -0.79_84, -4.49_04, -4.11_81, -2.02_52, -4.47_82, 1.12_53],
						    ]       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   tf.constant(
						    [
						        [0.00_00, -0.01_00, -0.02_00, -0.03_00, -0.04_00, -0.05_00, -0.06_00, -0.07_00],
						        [0.20_12, -0.88_97, -0.02_63, -0.94_01, -0.20_74, -0.94_63, -0.34_81, -0.93_43],
						        [1.70_57, -0.62_71, 1.21_45, -1.38_97, 0.63_03, -1.76_47, 0.11_73, -1.89_85],
						        [2.17_31, 1.63_97, 2.73_58, -0.28_54, 2.18_40, -1.71_83, 1.30_18, -2.48_71],
						        [-0.27_17, 3.61_73, 2.92_06, 2.19_88, 3.66_38, -0.38_58, 2.91_55, -2.29_80],
						        [-3.98_59, 2.15_80, 0.79_84, 4.49_04, 4.11_81, 2.02_52, 4.47_82, -1.12_53],
						    ]       )

						tf.debugging.assert_near(query_layer[0, 0, :6, :8] ,    UpperCamelCase__ ,    atol=self.tolerance       )
						tf.debugging.assert_near(key_layer[0, 0, :6, :8] ,    UpperCamelCase__ ,    atol=self.tolerance       )







import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import BertTokenizer, BertTokenizerFast
from transformers.models.bert.tokenization_bert 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 AlignProcessor, EfficientNetImageProcessor


@require_vision
class 							__a							(  unittest.TestCase						):





		'''simple docstring'''



		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   tempfile.mkdtemp()

						SCREAMING_SNAKE_CASE_   :	List[str]													=   [
						    '[UNK]',
						    '[CLS]',
						    '[SEP]',
						    '[PAD]',
						    '[MASK]',
						    'want',
						    '##want',
						    '##ed',
						    'wa',
						    'un',
						    'runn',
						    '##ing',
						    ',',
						    'low',
						    'lowest',
						]
						SCREAMING_SNAKE_CASE_   :	Dict													=   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]       )       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   {
						    'do_resize': True,
						    'size': 20,
						    'do_center_crop': True,
						    'crop_size': 18,
						    'do_normalize': True,
						    'image_mean': [0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73],
						    'image_std': [0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11],
						}
						SCREAMING_SNAKE_CASE_   :	str													=   os.path.join(self.tmpdirname ,    UpperCamelCase__       )
						with open(self.image_processor_file ,    'w' ,    encoding='utf-8'       ) as fp:
										json.dump(UpperCamelCase__ ,    UpperCamelCase__       )


		def   __snake_case			(						self ,    **UpperCamelCase__       ):
						return BertTokenizer.from_pretrained(self.tmpdirname ,    **UpperCamelCase__       )


		def   __snake_case			(						self ,    **UpperCamelCase__       ):
						return BertTokenizerFast.from_pretrained(self.tmpdirname ,    **UpperCamelCase__       )


		def   __snake_case			(						self ,    **UpperCamelCase__       ):
						return EfficientNetImageProcessor.from_pretrained(self.tmpdirname ,    **UpperCamelCase__       )


		def   __snake_case			(						self       ):
						shutil.rmtree(self.tmpdirname       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   [np.random.randint(255 ,    size=(3, 30, 400) ,    dtype=np.uinta       )]
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   [Image.fromarray(np.moveaxis(UpperCamelCase__ ,    0 ,    -1       )       ) for x in image_inputs]
						return image_inputs


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.get_tokenizer()
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.get_rust_tokenizer()
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.get_image_processor()

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )
						processor_slow.save_pretrained(self.tmpdirname       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   AlignProcessor.from_pretrained(self.tmpdirname ,    use_fast=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )
						processor_fast.save_pretrained(self.tmpdirname       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   AlignProcessor.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 ,    UpperCamelCase__       )
						self.assertIsInstance(processor_fast.tokenizer ,    UpperCamelCase__       )

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


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   AlignProcessor(tokenizer=self.get_tokenizer() ,    image_processor=self.get_image_processor()       )
						processor.save_pretrained(self.tmpdirname       )

						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.get_tokenizer(bos_token='(BOS)' ,    eos_token='(EOS)'       )
						SCREAMING_SNAKE_CASE_   :	int													=   self.get_image_processor(do_normalize=UpperCamelCase__ ,    padding_value=1.0       )

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   AlignProcessor.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 ,    UpperCamelCase__       )

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


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	int													=   self.get_image_processor()
						SCREAMING_SNAKE_CASE_   :	str													=   self.get_tokenizer()

						SCREAMING_SNAKE_CASE_   :	str													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   self.prepare_image_inputs()

						SCREAMING_SNAKE_CASE_   :	int													=   image_processor(UpperCamelCase__ ,    return_tensors='np'       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   processor(images=UpperCamelCase__ ,    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   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.get_image_processor()
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.get_tokenizer()

						SCREAMING_SNAKE_CASE_   :	List[str]													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   'lower newer'

						SCREAMING_SNAKE_CASE_   :	Tuple													=   processor(text=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	int													=   tokenizer(UpperCamelCase__ ,    padding='max_length' ,    max_length=64       )

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


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.get_image_processor()
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   self.get_tokenizer()

						SCREAMING_SNAKE_CASE_   :	str													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	str													=   'lower newer'
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   self.prepare_image_inputs()

						SCREAMING_SNAKE_CASE_   :	Optional[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 pytest.raises(UpperCamelCase__       ):
										processor()


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.get_image_processor()
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.get_tokenizer()

						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

						SCREAMING_SNAKE_CASE_   :	List[str]													=   processor.batch_decode(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Any													=   tokenizer.batch_decode(UpperCamelCase__       )

						self.assertListEqual(UpperCamelCase__ ,    UpperCamelCase__       )






		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.get_image_processor()
						SCREAMING_SNAKE_CASE_   :	int													=   self.get_tokenizer()

						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	str													=   'lower newer'
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.prepare_image_inputs()

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   processor(text=UpperCamelCase__ ,    images=UpperCamelCase__       )

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