"""simple docstring"""





from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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 (
				    TFFunnelBaseModel,
				    TFFunnelForMaskedLM,
				    TFFunnelForMultipleChoice,
				    TFFunnelForPreTraining,
				    TFFunnelForQuestionAnswering,
				    TFFunnelForSequenceClassification,
				    TFFunnelForTokenClassification,
				    TFFunnelModel,
				)
class  _snake_case     :






						def __init__(       self      :			Any							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Any=13							,					UpperCAmelCase      :			Optional[int]=7							,					UpperCAmelCase      :			Any=True							,					UpperCAmelCase      :			Optional[Any]=True							,					UpperCAmelCase      :			int=True							,					UpperCAmelCase      :			Tuple=True							,					UpperCAmelCase      :			Tuple=99							,					UpperCAmelCase      :			Any=[1, 1, 2]							,					UpperCAmelCase      :			Optional[int]=1							,					UpperCAmelCase      :			Optional[Any]=32							,					UpperCAmelCase      :			Optional[int]=4							,					UpperCAmelCase      :			List[Any]=8							,					UpperCAmelCase      :			List[str]=37							,					UpperCAmelCase      :			str="gelu_new"							,					UpperCAmelCase      :			List[Any]=0.1							,					UpperCAmelCase      :			List[Any]=0.1							,					UpperCAmelCase      :			List[str]=0.0							,					UpperCAmelCase      :			Union[str, Any]=512							,					UpperCAmelCase      :			Tuple=3							,					UpperCAmelCase      :			Dict=0.0_2							,					UpperCAmelCase      :			Any=3							,					UpperCAmelCase      :			Any=4							,					UpperCAmelCase      :			Any=None							,					UpperCAmelCase      :			Optional[Any]=False							,					):
													__lowerCamelCase					:		Optional[Any]		   =     parent
													__lowerCamelCase					:		Optional[int]		   =     batch_size
													__lowerCamelCase					:		List[Any]		   =     seq_length
													__lowerCamelCase					:		List[str]		   =     is_training
													__lowerCamelCase					:		Optional[Any]		   =     use_input_mask
													__lowerCamelCase					:		Dict		   =     use_token_type_ids
													__lowerCamelCase					:		str		   =     use_labels
													__lowerCamelCase					:		Optional[int]		   =     vocab_size
													__lowerCamelCase					:		List[Any]		   =     block_sizes
													__lowerCamelCase					:		Tuple		   =     num_decoder_layers
													__lowerCamelCase					:		Tuple		   =     d_model
													__lowerCamelCase					:		str		   =     n_head
													__lowerCamelCase					:		List[Any]		   =     d_head
													__lowerCamelCase					:		Optional[Any]		   =     d_inner
													__lowerCamelCase					:		Dict		   =     hidden_act
													__lowerCamelCase					:		Any		   =     hidden_dropout
													__lowerCamelCase					:		Union[str, Any]		   =     attention_dropout
													__lowerCamelCase					:		Any		   =     activation_dropout
													__lowerCamelCase					:		Union[str, Any]		   =     max_position_embeddings
													__lowerCamelCase					:		Optional[int]		   =     type_vocab_size
													__lowerCamelCase					:		Optional[Any]		   =     2
													__lowerCamelCase					:		Optional[Any]		   =     num_labels
													__lowerCamelCase					:		Optional[Any]		   =     num_choices
													__lowerCamelCase					:		str		   =     scope
													__lowerCamelCase					:		Dict		   =     initializer_std

													# Used in the tests to check the size of the first attention layer
													__lowerCamelCase					:		int		   =     n_head
													# Used in the tests to check the size of the first hidden state
													__lowerCamelCase					:		List[str]		   =     self.d_model
													# Used in the tests to check the number of output hidden states/attentions
													__lowerCamelCase					:		List[Any]		   =     sum(self.block_sizes    ) + (0 if base else self.num_decoder_layers)
													# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
													# the last hidden state of the first block (which is the first hidden state of the decoder).
													if not base:
																				__lowerCamelCase					:		Optional[int]		   =     self.num_hidden_layers + 2






						def       lowerCamelCase__     (       self      :			int    ):
													__lowerCamelCase					:		Union[str, Any]		   =     ids_tensor([self.batch_size, self.seq_length]							,					self.vocab_size    )

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

													__lowerCamelCase					:		Union[str, Any]		   =     None
													if self.use_token_type_ids:
																				__lowerCamelCase					:		Optional[int]		   =     ids_tensor([self.batch_size, self.seq_length]							,					self.type_vocab_size    )

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

													__lowerCamelCase					:		int		   =     FunnelConfig(
													    vocab_size=self.vocab_size							,					block_sizes=self.block_sizes							,					num_decoder_layers=self.num_decoder_layers							,					d_model=self.d_model							,					n_head=self.n_head							,					d_head=self.d_head							,					d_inner=self.d_inner							,					hidden_act=self.hidden_act							,					hidden_dropout=self.hidden_dropout							,					attention_dropout=self.attention_dropout							,					activation_dropout=self.activation_dropout							,					max_position_embeddings=self.max_position_embeddings							,					type_vocab_size=self.type_vocab_size							,					initializer_std=self.initializer_std							,					)

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






						def       lowerCamelCase__     (       self      :			Tuple							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Tuple							,					UpperCAmelCase      :			str							,					):
													__lowerCamelCase					:		Optional[Any]		   =     TFFunnelModel(config=UpperCAmelCase    )
													__lowerCamelCase					:		Optional[int]		   =     {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
													__lowerCamelCase					:		Optional[int]		   =     model(UpperCAmelCase    )

													__lowerCamelCase					:		int		   =     [input_ids, input_mask]
													__lowerCamelCase					:		List[Any]		   =     model(UpperCAmelCase    )

													__lowerCamelCase					:		Dict		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.d_model)    )

													__lowerCamelCase					:		int		   =     False
													__lowerCamelCase					:		Dict		   =     TFFunnelModel(config=UpperCAmelCase    )
													__lowerCamelCase					:		Optional[Any]		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.d_model)    )

													__lowerCamelCase					:		List[str]		   =     False
													__lowerCamelCase					:		Optional[int]		   =     TFFunnelModel(config=UpperCAmelCase    )
													__lowerCamelCase					:		Any		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.d_model)    )






						def       lowerCamelCase__     (       self      :			Optional[int]							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			Tuple							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Dict							,					UpperCAmelCase      :			int							,					):
													__lowerCamelCase					:		Optional[int]		   =     TFFunnelBaseModel(config=UpperCAmelCase    )
													__lowerCamelCase					:		List[str]		   =     {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
													__lowerCamelCase					:		Dict		   =     model(UpperCAmelCase    )

													__lowerCamelCase					:		List[str]		   =     [input_ids, input_mask]
													__lowerCamelCase					:		List[str]		   =     model(UpperCAmelCase    )

													__lowerCamelCase					:		Optional[Any]		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, 2, self.d_model)    )

													__lowerCamelCase					:		Optional[int]		   =     False
													__lowerCamelCase					:		str		   =     TFFunnelBaseModel(config=UpperCAmelCase    )
													__lowerCamelCase					:		Any		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, 3, self.d_model)    )

													__lowerCamelCase					:		List[Any]		   =     False
													__lowerCamelCase					:		Optional[Any]		   =     TFFunnelBaseModel(config=UpperCAmelCase    )
													__lowerCamelCase					:		str		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, 2, self.d_model)    )






						def       lowerCamelCase__     (       self      :			Any							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			Dict							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			List[Any]							,					):
													__lowerCamelCase					:		Any		   =     TFFunnelForPreTraining(config=UpperCAmelCase    )
													__lowerCamelCase					:		List[str]		   =     {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
													__lowerCamelCase					:		List[Any]		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length)    )






						def       lowerCamelCase__     (       self      :			List[Any]							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Tuple							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			int							,					UpperCAmelCase      :			Dict							,					UpperCAmelCase      :			Dict							,					):
													__lowerCamelCase					:		Optional[Any]		   =     TFFunnelForMaskedLM(config=UpperCAmelCase    )
													__lowerCamelCase					:		Any		   =     {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
													__lowerCamelCase					:		List[str]		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.vocab_size)    )






						def       lowerCamelCase__     (       self      :			Union[str, Any]							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			Dict							,					UpperCAmelCase      :			Optional[int]							,					):
													__lowerCamelCase					:		Any		   =     self.num_labels
													__lowerCamelCase					:		Union[str, Any]		   =     TFFunnelForSequenceClassification(config=UpperCAmelCase    )
													__lowerCamelCase					:		str		   =     {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
													__lowerCamelCase					:		int		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_labels)    )






						def       lowerCamelCase__     (       self      :			List[Any]							,					UpperCAmelCase      :			List[str]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			Optional[int]							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Optional[Any]							,					):
													__lowerCamelCase					:		List[str]		   =     self.num_choices
													__lowerCamelCase					:		int		   =     TFFunnelForMultipleChoice(config=UpperCAmelCase    )
													__lowerCamelCase					:		Any		   =     tf.tile(tf.expand_dims(UpperCAmelCase							,					1    )							,					(1, self.num_choices, 1)    )
													__lowerCamelCase					:		List[str]		   =     tf.tile(tf.expand_dims(UpperCAmelCase							,					1    )							,					(1, self.num_choices, 1)    )
													__lowerCamelCase					:		int		   =     tf.tile(tf.expand_dims(UpperCAmelCase							,					1    )							,					(1, self.num_choices, 1)    )
													__lowerCamelCase					:		Optional[int]		   =     {
													    "input_ids": multiple_choice_inputs_ids,
													    "attention_mask": multiple_choice_input_mask,
													    "token_type_ids": multiple_choice_token_type_ids,
													}
													__lowerCamelCase					:		str		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_choices)    )






						def       lowerCamelCase__     (       self      :			Optional[Any]							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			Tuple							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			List[Any]							,					UpperCAmelCase      :			Any							,					UpperCAmelCase      :			Optional[Any]							,					):
													__lowerCamelCase					:		Dict		   =     self.num_labels
													__lowerCamelCase					:		Dict		   =     TFFunnelForTokenClassification(config=UpperCAmelCase    )
													__lowerCamelCase					:		Dict		   =     {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
													__lowerCamelCase					:		Tuple		   =     model(UpperCAmelCase    )
													self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.num_labels)    )






						def       lowerCamelCase__     (       self      :			Dict							,					UpperCAmelCase      :			Dict							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			List[str]							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Optional[Any]							,					UpperCAmelCase      :			Optional[Any]							,					):
													__lowerCamelCase					:		Dict		   =     TFFunnelForQuestionAnswering(config=UpperCAmelCase    )
													__lowerCamelCase					:		str		   =     {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
													__lowerCamelCase					:		Tuple		   =     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       lowerCamelCase__     (       self      :			int    ):
													__lowerCamelCase					:		Dict		   =     self.prepare_config_and_inputs()
													(
													    (
													    __lowerCamelCase
													)   ,  (
													    __lowerCamelCase
													)   ,  (
													    __lowerCamelCase
													)   ,  (
													    __lowerCamelCase
													)   ,  (
													    __lowerCamelCase
													)   ,  (
													    __lowerCamelCase
													)   ,  (
													    __lowerCamelCase
													)   ,  
													)					:		List[str]		   =     config_and_inputs
													__lowerCamelCase					:		str		   =     {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
													return config, inputs_dict

@require_tf
class  _snake_case     (					a__				, a__				, unittest.TestCase		):
						snake_case__			  =			(
						    (
						        TFFunnelModel,
						        TFFunnelForMaskedLM,
						        TFFunnelForPreTraining,
						        TFFunnelForQuestionAnswering,
						        TFFunnelForTokenClassification,
						    )
						    if is_tf_available()
						    else ()
						)
						snake_case__			  =			(
						    {
						        "feature-extraction": (TFFunnelBaseModel, TFFunnelModel),
						        "fill-mask": TFFunnelForMaskedLM,
						        "question-answering": TFFunnelForQuestionAnswering,
						        "text-classification": TFFunnelForSequenceClassification,
						        "token-classification": TFFunnelForTokenClassification,
						        "zero-shot": TFFunnelForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						snake_case__			  =			False
						snake_case__			  =			False






						def       lowerCamelCase__     (       self      :			Optional[int]    ):
													__lowerCamelCase					:		List[str]		   =     TFFunnelModelTester(self    )
													__lowerCamelCase					:		List[Any]		   =     ConfigTester(self							,					config_class=UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			List[Any]    ):
													self.config_tester.run_common_tests()






						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													__lowerCamelCase					:		Dict		   =     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													__lowerCamelCase					:		Union[str, Any]		   =     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_pretraining(*UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			str    ):
													__lowerCamelCase					:		Optional[int]		   =     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			str    ):
													__lowerCamelCase					:		Optional[int]		   =     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase    )







						def       lowerCamelCase__     (       self      :			Any    ):
													__lowerCamelCase					:		Union[str, Any]		   =     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase    )

@require_tf
class  _snake_case     (					a__				, unittest.TestCase		):
						snake_case__			  =			(
						    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
						)
						snake_case__			  =			False
						snake_case__			  =			False






						def       lowerCamelCase__     (       self      :			str    ):
													__lowerCamelCase					:		Union[str, Any]		   =     TFFunnelModelTester(self							,					base=UpperCAmelCase    )
													__lowerCamelCase					:		int		   =     ConfigTester(self							,					config_class=UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			Tuple    ):
													self.config_tester.run_common_tests()






						def       lowerCamelCase__     (       self      :			str    ):
													__lowerCamelCase					:		Dict		   =     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_base_model(*UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			Dict    ):
													__lowerCamelCase					:		Any		   =     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase    )







						def       lowerCamelCase__     (       self      :			Optional[int]    ):
													__lowerCamelCase					:		List[str]		   =     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase    )
"""simple docstring"""





import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import MgpstrTokenizer
from transformers.models.mgp_str.tokenization_mgp_str import VOCAB_FILES_NAMES
from transformers.testing_utils import require_torch, require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_torch_available, is_vision_available


if is_torch_available():
				import torch


if is_vision_available():
				from PIL import Image

				from transformers import MgpstrProcessor, ViTImageProcessor
@require_torch
@require_vision
class  _snake_case     (					unittest.TestCase		):
						snake_case__			  =			ViTImageProcessor if is_vision_available() else None






						@property
						def       lowerCamelCase__     (       self      :			List[Any]    ):
													return self.image_processor_tester.prepare_image_processor_dict()






						def       lowerCamelCase__     (       self      :			Tuple    ):
													__lowerCamelCase					:		str		   =     (3, 32, 128)
													__lowerCamelCase					:		Optional[int]		   =     tempfile.mkdtemp()

													# fmt: off
													__lowerCamelCase					:		Tuple		   =     ["[GO]", "[s]", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
													# fmt: on
													__lowerCamelCase					:		Dict		   =     dict(zip(UpperCAmelCase							,					range(len(UpperCAmelCase    )    )    )    )

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

													__lowerCamelCase					:		int		   =     {
													    "do_normalize": False,
													    "do_resize": True,
													    "image_processor_type": "ViTImageProcessor",
													    "resample": 3,
													    "size": {"height": 32, "width": 128},
													}
													__lowerCamelCase					:		Dict		   =     os.path.join(self.tmpdirname							,					UpperCAmelCase    )
													with open(self.image_processor_file							,					"w"							,					encoding="utf-8"    ) as fp:
																				json.dump(UpperCAmelCase							,					UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			Tuple							,					**UpperCAmelCase      :			Optional[int]    ):
													return MgpstrTokenizer.from_pretrained(self.tmpdirname							,					**UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			List[str]							,					**UpperCAmelCase      :			List[str]    ):
													return ViTImageProcessor.from_pretrained(self.tmpdirname							,					**UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			Tuple    ):
													shutil.rmtree(self.tmpdirname    )






						def       lowerCamelCase__     (       self      :			str    ):
													__lowerCamelCase					:		Any		   =     np.random.randint(255							,					size=(3, 30, 400)							,					dtype=np.uinta    )

													__lowerCamelCase					:		Union[str, Any]		   =     Image.fromarray(np.moveaxis(UpperCAmelCase							,					0							,					-1    )    )

													return image_input






						def       lowerCamelCase__     (       self      :			List[str]    ):
													__lowerCamelCase					:		Union[str, Any]		   =     self.get_tokenizer()
													__lowerCamelCase					:		Any		   =     self.get_image_processor()

													__lowerCamelCase					:		List[Any]		   =     MgpstrProcessor(tokenizer=UpperCAmelCase							,					image_processor=UpperCAmelCase    )
													processor.save_pretrained(self.tmpdirname    )
													__lowerCamelCase					:		str		   =     MgpstrProcessor.from_pretrained(self.tmpdirname							,					use_fast=UpperCAmelCase    )

													self.assertEqual(processor.char_tokenizer.get_vocab()							,					tokenizer.get_vocab()    )
													self.assertIsInstance(processor.char_tokenizer							,					UpperCAmelCase    )

													self.assertEqual(processor.image_processor.to_json_string()							,					image_processor.to_json_string()    )
													self.assertIsInstance(processor.image_processor							,					UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			Optional[int]    ):
													__lowerCamelCase					:		Any		   =     self.get_tokenizer()
													__lowerCamelCase					:		Dict		   =     self.get_image_processor()

													__lowerCamelCase					:		Optional[int]		   =     MgpstrProcessor(tokenizer=UpperCAmelCase							,					image_processor=UpperCAmelCase    )
													processor.save_pretrained(self.tmpdirname    )

													__lowerCamelCase					:		Dict		   =     self.get_tokenizer(bos_token="(BOS)"							,					eos_token="(EOS)"    )
													__lowerCamelCase					:		Any		   =     self.get_image_processor(do_normalize=UpperCAmelCase							,					padding_value=1.0    )

													__lowerCamelCase					:		List[str]		   =     MgpstrProcessor.from_pretrained(
													    self.tmpdirname							,					bos_token="(BOS)"							,					eos_token="(EOS)"							,					do_normalize=UpperCAmelCase							,					padding_value=1.0    )

													self.assertEqual(processor.char_tokenizer.get_vocab()							,					tokenizer_add_kwargs.get_vocab()    )
													self.assertIsInstance(processor.char_tokenizer							,					UpperCAmelCase    )

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






						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													__lowerCamelCase					:		List[str]		   =     self.get_image_processor()
													__lowerCamelCase					:		Dict		   =     self.get_tokenizer()

													__lowerCamelCase					:		Optional[int]		   =     MgpstrProcessor(tokenizer=UpperCAmelCase							,					image_processor=UpperCAmelCase    )

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

													__lowerCamelCase					:		Optional[int]		   =     image_processor(UpperCAmelCase							,					return_tensors="np"    )
													__lowerCamelCase					:		Tuple		   =     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       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													__lowerCamelCase					:		int		   =     self.get_image_processor()
													__lowerCamelCase					:		Any		   =     self.get_tokenizer()

													__lowerCamelCase					:		int		   =     MgpstrProcessor(tokenizer=UpperCAmelCase							,					image_processor=UpperCAmelCase    )

													__lowerCamelCase					:		Optional[Any]		   =     "test"

													__lowerCamelCase					:		List[Any]		   =     processor(text=UpperCAmelCase    )

													__lowerCamelCase					:		Optional[int]		   =     tokenizer(UpperCAmelCase    )
													for key in encoded_tok.keys():
																				self.assertListEqual(encoded_tok[key]							,					encoded_processor[key]    )






						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													__lowerCamelCase					:		Union[str, Any]		   =     self.get_image_processor()
													__lowerCamelCase					:		Optional[Any]		   =     self.get_tokenizer()

													__lowerCamelCase					:		Optional[int]		   =     MgpstrProcessor(tokenizer=UpperCAmelCase							,					image_processor=UpperCAmelCase    )

													__lowerCamelCase					:		str		   =     "test"
													__lowerCamelCase					:		Union[str, Any]		   =     self.prepare_image_inputs()

													__lowerCamelCase					:		Optional[Any]		   =     processor(text=UpperCAmelCase							,					images=UpperCAmelCase    )

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

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






						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													__lowerCamelCase					:		Any		   =     self.get_image_processor()
													__lowerCamelCase					:		Optional[Any]		   =     self.get_tokenizer()

													__lowerCamelCase					:		Dict		   =     MgpstrProcessor(tokenizer=UpperCAmelCase							,					image_processor=UpperCAmelCase    )

													__lowerCamelCase					:		Optional[Any]		   =     [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9], [3, 4, 3, 1, 1, 8, 9]]

													__lowerCamelCase					:		List[Any]		   =     processor.char_decode(UpperCAmelCase    )
													__lowerCamelCase					:		Dict		   =     tokenizer.batch_decode(UpperCAmelCase    )
													__lowerCamelCase					:		Any		   =     [seq.replace(" "							,					""    ) for seq in decoded_tok]

													self.assertListEqual(UpperCAmelCase							,					UpperCAmelCase    )






						def       lowerCamelCase__     (       self      :			Any    ):
													__lowerCamelCase					:		str		   =     self.get_image_processor()
													__lowerCamelCase					:		str		   =     self.get_tokenizer()

													__lowerCamelCase					:		Union[str, Any]		   =     MgpstrProcessor(tokenizer=UpperCAmelCase							,					image_processor=UpperCAmelCase    )

													__lowerCamelCase					:		Tuple		   =     None
													__lowerCamelCase					:		int		   =     self.prepare_image_inputs()

													__lowerCamelCase					:		List[str]		   =     processor(text=UpperCAmelCase							,					images=UpperCAmelCase    )

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







						def       lowerCamelCase__     (       self      :			Optional[Any]    ):
													__lowerCamelCase					:		Optional[Any]		   =     self.get_image_processor()
													__lowerCamelCase					:		Tuple		   =     self.get_tokenizer()

													__lowerCamelCase					:		List[Any]		   =     MgpstrProcessor(tokenizer=UpperCAmelCase							,					image_processor=UpperCAmelCase    )

													__lowerCamelCase					:		Optional[int]		   =     torch.randn(1							,					27							,					38    )
													__lowerCamelCase					:		List[str]		   =     torch.randn(1							,					27							,					50257    )
													__lowerCamelCase					:		Union[str, Any]		   =     torch.randn(1							,					27							,					30522    )

													__lowerCamelCase					:		str		   =     processor.batch_decode([char_input, bpe_input, wp_input]    )

													self.assertListEqual(list(results.keys()    )							,					["generated_text", "scores", "char_preds", "bpe_preds", "wp_preds"]    )