




import unittest

from transformers import 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
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    RemBertConfig,
		    RemBertForCausalLM,
		    RemBertForMaskedLM,
		    RemBertForMultipleChoice,
		    RemBertForQuestionAnswering,
		    RemBertForSequenceClassification,
		    RemBertForTokenClassification,
		    RemBertModel,
		)
		from transformers.models.rembert.modeling_rembert import REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST




class    snake_case__							:
				"""simple docstring"""



				def __init__(				self    :					List[str] ,				__lowerCamelCase    :					Optional[Any] ,				__lowerCamelCase    :					List[str]=13 ,				__lowerCamelCase    :					Optional[int]=7 ,				__lowerCamelCase    :					Dict=True ,				__lowerCamelCase    :					Optional[int]=True ,				__lowerCamelCase    :					Union[str, Any]=True ,				__lowerCamelCase    :					int=True ,				__lowerCamelCase    :					Optional[int]=99 ,				__lowerCamelCase    :					List[str]=32 ,				__lowerCamelCase    :					str=18 ,				__lowerCamelCase    :					int=43 ,				__lowerCamelCase    :					Tuple=5 ,				__lowerCamelCase    :					Optional[int]=4 ,				__lowerCamelCase    :					str=37 ,				__lowerCamelCase    :					Optional[Any]="gelu" ,				__lowerCamelCase    :					List[Any]=0.1 ,				__lowerCamelCase    :					List[str]=0.1 ,				__lowerCamelCase    :					Tuple=5_12 ,				__lowerCamelCase    :					str=16 ,				__lowerCamelCase    :					Optional[Any]=2 ,				__lowerCamelCase    :					Dict=0.02 ,				__lowerCamelCase    :					Optional[Any]=3 ,				__lowerCamelCase    :					List[Any]=4 ,				__lowerCamelCase    :					Tuple=None ,				) ->					Union[str, Any]:
							a   =      parent
							a   =      batch_size
							a   =      seq_length
							a   =      is_training
							a   =      use_input_mask
							a   =      use_token_type_ids
							a   =      use_labels
							a   =      vocab_size
							a   =      hidden_size
							a   =      input_embedding_size
							a   =      output_embedding_size
							a   =      num_hidden_layers
							a   =      num_attention_heads
							a   =      intermediate_size
							a   =      hidden_act
							a   =      hidden_dropout_prob
							a   =      attention_probs_dropout_prob
							a   =      max_position_embeddings
							a   =      type_vocab_size
							a   =      type_sequence_label_size
							a   =      initializer_range
							a   =      num_labels
							a   =      num_choices
							a   =      scope





				def 							__UpperCAmelCase							(				self    :					Optional[Any]							) ->					List[Any]:
							a   =      ids_tensor([self.batch_size, self.seq_length] ,				self.vocab_size							)

							a   =      None
							if self.use_input_mask:
										a   =      random_attention_mask([self.batch_size, self.seq_length]							)

							a   =      None
							if self.use_token_type_ids:
										a   =      ids_tensor([self.batch_size, self.seq_length] ,				self.type_vocab_size							)

							a   =      None
							a   =      None
							a   =      None
							if self.use_labels:
										a   =      ids_tensor([self.batch_size] ,				self.type_sequence_label_size							)
										a   =      ids_tensor([self.batch_size, self.seq_length] ,				self.num_labels							)
										a   =      ids_tensor([self.batch_size] ,				self.num_choices							)

							a   =      RemBertConfig(
							    vocab_size=self.vocab_size ,				hidden_size=self.hidden_size ,				input_embedding_size=self.input_embedding_size ,				output_embedding_size=self.output_embedding_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=__lowerCamelCase ,				initializer_range=self.initializer_range ,				)

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





				def 							__UpperCAmelCase							(				self    :					List[str]							) ->					Optional[int]:
							(
							    (
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		
							)   =      self.prepare_config_and_inputs()

							a   =      True
							a   =      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]							)
							a   =      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 							__UpperCAmelCase							(				self    :					Optional[Any] ,				__lowerCamelCase    :					List[Any] ,				__lowerCamelCase    :					Tuple ,				__lowerCamelCase    :					int ,				__lowerCamelCase    :					Union[str, Any] ,				__lowerCamelCase    :					Optional[int] ,				__lowerCamelCase    :					Union[str, Any] ,				__lowerCamelCase    :					str							) ->					List[Any]:
							a   =      RemBertModel(config=__lowerCamelCase							)
							model.to(__lowerCamelCase							)
							model.eval()
							a   =      model(__lowerCamelCase ,				attention_mask=__lowerCamelCase ,				token_type_ids=__lowerCamelCase							)
							a   =      model(__lowerCamelCase ,				token_type_ids=__lowerCamelCase							)
							a   =      model(__lowerCamelCase							)
							self.parent.assertEqual(result.last_hidden_state.shape ,				(self.batch_size, self.seq_length, self.hidden_size)							)





				def 							__UpperCAmelCase							(				self    :					int ,				__lowerCamelCase    :					Optional[Any] ,				__lowerCamelCase    :					List[str] ,				__lowerCamelCase    :					str ,				__lowerCamelCase    :					Union[str, Any] ,				__lowerCamelCase    :					Union[str, Any] ,				__lowerCamelCase    :					int ,				__lowerCamelCase    :					int ,				__lowerCamelCase    :					int ,				__lowerCamelCase    :					str ,				) ->					Union[str, Any]:
							a   =      True
							a   =      RemBertModel(__lowerCamelCase							)
							model.to(__lowerCamelCase							)
							model.eval()
							a   =      model(
							    __lowerCamelCase ,				attention_mask=__lowerCamelCase ,				token_type_ids=__lowerCamelCase ,				encoder_hidden_states=__lowerCamelCase ,				encoder_attention_mask=__lowerCamelCase ,				)
							a   =      model(
							    __lowerCamelCase ,				attention_mask=__lowerCamelCase ,				token_type_ids=__lowerCamelCase ,				encoder_hidden_states=__lowerCamelCase ,				)
							a   =      model(__lowerCamelCase ,				attention_mask=__lowerCamelCase ,				token_type_ids=__lowerCamelCase							)
							self.parent.assertEqual(result.last_hidden_state.shape ,				(self.batch_size, self.seq_length, self.hidden_size)							)





				def 							__UpperCAmelCase							(				self    :					List[str] ,				__lowerCamelCase    :					Union[str, Any] ,				__lowerCamelCase    :					Dict ,				__lowerCamelCase    :					Dict ,				__lowerCamelCase    :					List[str] ,				__lowerCamelCase    :					List[str] ,				__lowerCamelCase    :					Optional[int] ,				__lowerCamelCase    :					Tuple ,				__lowerCamelCase    :					Dict ,				__lowerCamelCase    :					Dict ,				) ->					Any:
							a   =      RemBertForCausalLM(config=__lowerCamelCase							)
							model.to(__lowerCamelCase							)
							model.eval()
							a   =      model(__lowerCamelCase ,				attention_mask=__lowerCamelCase ,				token_type_ids=__lowerCamelCase ,				labels=__lowerCamelCase							)
							self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.seq_length, self.vocab_size)							)





				def 							__UpperCAmelCase							(				self    :					List[str] ,				__lowerCamelCase    :					Tuple ,				__lowerCamelCase    :					Union[str, Any] ,				__lowerCamelCase    :					str ,				__lowerCamelCase    :					str ,				__lowerCamelCase    :					Any ,				__lowerCamelCase    :					Union[str, Any] ,				__lowerCamelCase    :					int							) ->					Optional[Any]:
							a   =      RemBertForMaskedLM(config=__lowerCamelCase							)
							model.to(__lowerCamelCase							)
							model.eval()
							a   =      model(__lowerCamelCase ,				attention_mask=__lowerCamelCase ,				token_type_ids=__lowerCamelCase ,				labels=__lowerCamelCase							)
							self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.seq_length, self.vocab_size)							)





				def 							__UpperCAmelCase							(				self    :					Dict ,				__lowerCamelCase    :					Tuple ,				__lowerCamelCase    :					Optional[Any] ,				__lowerCamelCase    :					int ,				__lowerCamelCase    :					str ,				__lowerCamelCase    :					str ,				__lowerCamelCase    :					List[Any] ,				__lowerCamelCase    :					Optional[int] ,				__lowerCamelCase    :					Dict ,				__lowerCamelCase    :					List[str] ,				) ->					Optional[int]:
							a   =      True
							a   =      True
							a   =      RemBertForCausalLM(config=__lowerCamelCase							)
							model.to(__lowerCamelCase							)
							model.eval()

							# first forward pass
							a   =      model(
							    __lowerCamelCase ,				attention_mask=__lowerCamelCase ,				encoder_hidden_states=__lowerCamelCase ,				encoder_attention_mask=__lowerCamelCase ,				use_cache=__lowerCamelCase ,				)
							a   =      outputs.past_key_values

							# create hypothetical multiple next token and extent to next_input_ids
							a   =      ids_tensor((self.batch_size, 3) ,				config.vocab_size							)
							a   =      ids_tensor((self.batch_size, 3) ,				vocab_size=2							)

							# append to next input_ids and
							a   =      torch.cat([input_ids, next_tokens] ,				dim=-1							)
							a   =      torch.cat([input_mask, next_mask] ,				dim=-1							)

							a   =      model(
							    __lowerCamelCase ,				attention_mask=__lowerCamelCase ,				encoder_hidden_states=__lowerCamelCase ,				encoder_attention_mask=__lowerCamelCase ,				output_hidden_states=__lowerCamelCase ,				)["hidden_states"][0]
							a   =      model(
							    __lowerCamelCase ,				attention_mask=__lowerCamelCase ,				encoder_hidden_states=__lowerCamelCase ,				encoder_attention_mask=__lowerCamelCase ,				past_key_values=__lowerCamelCase ,				output_hidden_states=__lowerCamelCase ,				)["hidden_states"][0]

							# select random slice
							a   =      ids_tensor((1,) ,				output_from_past.shape[-1]							).item()
							a   =      output_from_no_past[:, -3:, random_slice_idx].detach()
							a   =      output_from_past[:, :, random_slice_idx].detach()

							self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]							)

							# test that outputs are equal for slice
							self.parent.assertTrue(torch.allclose(__lowerCamelCase ,				__lowerCamelCase ,				atol=1e-3							)							)





				def 							__UpperCAmelCase							(				self    :					Optional[int] ,				__lowerCamelCase    :					int ,				__lowerCamelCase    :					Dict ,				__lowerCamelCase    :					int ,				__lowerCamelCase    :					str ,				__lowerCamelCase    :					str ,				__lowerCamelCase    :					List[Any] ,				__lowerCamelCase    :					Any							) ->					Optional[Any]:
							a   =      RemBertForQuestionAnswering(config=__lowerCamelCase							)
							model.to(__lowerCamelCase							)
							model.eval()
							a   =      model(
							    __lowerCamelCase ,				attention_mask=__lowerCamelCase ,				token_type_ids=__lowerCamelCase ,				start_positions=__lowerCamelCase ,				end_positions=__lowerCamelCase ,				)
							self.parent.assertEqual(result.start_logits.shape ,				(self.batch_size, self.seq_length)							)
							self.parent.assertEqual(result.end_logits.shape ,				(self.batch_size, self.seq_length)							)





				def 							__UpperCAmelCase							(				self    :					str ,				__lowerCamelCase    :					Optional[int] ,				__lowerCamelCase    :					Optional[int] ,				__lowerCamelCase    :					Optional[int] ,				__lowerCamelCase    :					Dict ,				__lowerCamelCase    :					Union[str, Any] ,				__lowerCamelCase    :					Any ,				__lowerCamelCase    :					int							) ->					Any:
							a   =      self.num_labels
							a   =      RemBertForSequenceClassification(__lowerCamelCase							)
							model.to(__lowerCamelCase							)
							model.eval()
							a   =      model(__lowerCamelCase ,				attention_mask=__lowerCamelCase ,				token_type_ids=__lowerCamelCase ,				labels=__lowerCamelCase							)
							self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.num_labels)							)





				def 							__UpperCAmelCase							(				self    :					Optional[Any] ,				__lowerCamelCase    :					Union[str, Any] ,				__lowerCamelCase    :					Tuple ,				__lowerCamelCase    :					Any ,				__lowerCamelCase    :					List[Any] ,				__lowerCamelCase    :					Union[str, Any] ,				__lowerCamelCase    :					Any ,				__lowerCamelCase    :					Any							) ->					Optional[Any]:
							a   =      self.num_labels
							a   =      RemBertForTokenClassification(config=__lowerCamelCase							)
							model.to(__lowerCamelCase							)
							model.eval()
							a   =      model(__lowerCamelCase ,				attention_mask=__lowerCamelCase ,				token_type_ids=__lowerCamelCase ,				labels=__lowerCamelCase							)
							self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.seq_length, self.num_labels)							)





				def 							__UpperCAmelCase							(				self    :					Tuple ,				__lowerCamelCase    :					str ,				__lowerCamelCase    :					List[str] ,				__lowerCamelCase    :					int ,				__lowerCamelCase    :					Dict ,				__lowerCamelCase    :					Tuple ,				__lowerCamelCase    :					str ,				__lowerCamelCase    :					Dict							) ->					int:
							a   =      self.num_choices
							a   =      RemBertForMultipleChoice(config=__lowerCamelCase							)
							model.to(__lowerCamelCase							)
							model.eval()
							a   =      input_ids.unsqueeze(1							).expand(-1 ,				self.num_choices ,				-1							).contiguous()
							a   =      token_type_ids.unsqueeze(1							).expand(-1 ,				self.num_choices ,				-1							).contiguous()
							a   =      input_mask.unsqueeze(1							).expand(-1 ,				self.num_choices ,				-1							).contiguous()
							a   =      model(
							    __lowerCamelCase ,				attention_mask=__lowerCamelCase ,				token_type_ids=__lowerCamelCase ,				labels=__lowerCamelCase ,				)
							self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.num_choices)							)





				def 							__UpperCAmelCase							(				self    :					List[Any]							) ->					Union[str, Any]:
							a   =      self.prepare_config_and_inputs()
							(
							    (
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		
							)   =      config_and_inputs
							a   =      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
							return config, inputs_dict




@require_torch
class    snake_case__							(_UpperCamelCase   ,	_UpperCamelCase   ,	unittest.TestCase       ):
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_	:							Any										= (
				    (
				        RemBertModel,
				        RemBertForMaskedLM,
				        RemBertForCausalLM,
				        RemBertForMultipleChoice,
				        RemBertForQuestionAnswering,
				        RemBertForSequenceClassification,
				        RemBertForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE_	:							List[str]										= (RemBertForCausalLM,) if is_torch_available() else ()
				SCREAMING_SNAKE_CASE_	:							Tuple										= (
				    {
				        """feature-extraction""": RemBertModel,
				        """fill-mask""": RemBertForMaskedLM,
				        """question-answering""": RemBertForQuestionAnswering,
				        """text-classification""": RemBertForSequenceClassification,
				        """text-generation""": RemBertForCausalLM,
				        """token-classification""": RemBertForTokenClassification,
				        """zero-shot""": RemBertForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)





				def 							__UpperCAmelCase							(				self    :					Optional[int]							) ->					Any:
							a   =      RemBertModelTester(self							)
							a   =      ConfigTester(self ,				config_class=__lowerCamelCase ,				hidden_size=37							)





				def 							__UpperCAmelCase							(				self    :					str							) ->					Tuple:
							self.config_tester.run_common_tests()





				def 							__UpperCAmelCase							(				self    :					List[Any]							) ->					List[Any]:
							a   =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(				self    :					List[Any]							) ->					List[Any]:
							a   =      self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
										a   =      type
										self.model_tester.create_and_check_model(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(				self    :					Optional[Any]							) ->					Dict:
							a   =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(				self    :					Union[str, Any]							) ->					str:
							a   =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(				self    :					Dict							) ->					List[Any]:
							a   =      self.model_tester.prepare_config_and_inputs_for_decoder()
							self.model_tester.create_and_check_decoder_model_past_large_inputs(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(				self    :					Optional[Any]							) ->					Optional[Any]:
							a   =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(				self    :					int							) ->					Optional[int]:
							a   =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(				self    :					Dict							) ->					List[Any]:
							a   =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(				self    :					Optional[Any]							) ->					Tuple:
							a   =      self.model_tester.prepare_config_and_inputs_for_decoder()
							self.model_tester.create_and_check_model_as_decoder(*__lowerCamelCase							)





				def 							__UpperCAmelCase							(				self    :					Optional[Any]							) ->					Tuple:
							# This regression test was failing with PyTorch < 1.3
							(
							    (
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		(
							    a
							)   ,		
							)   =      self.model_tester.prepare_config_and_inputs_for_decoder()

							a   =      None

							self.model_tester.create_and_check_model_as_decoder(
							    __lowerCamelCase ,				__lowerCamelCase ,				__lowerCamelCase ,				__lowerCamelCase ,				__lowerCamelCase ,				__lowerCamelCase ,				__lowerCamelCase ,				__lowerCamelCase ,				__lowerCamelCase ,				)





				@slow
				def 							__UpperCAmelCase							(				self    :					str							) ->					int:
							for model_name in REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										a   =      RemBertModel.from_pretrained(__lowerCamelCase							)
										self.assertIsNotNone(__lowerCamelCase							)




@require_torch
class    snake_case__							(unittest.TestCase       ):
				"""simple docstring"""



				@slow
				def 							__UpperCAmelCase							(				self    :					Dict							) ->					List[Any]:
							# Test exact values at the last hidden layer
							a   =      RemBertModel.from_pretrained("google/rembert"							)
							a   =      torch.tensor([[3_12, 5_64_98, 3_13, 21_25, 3_13]]							)
							a   =      torch.tensor([[0, 0, 0, 1, 1]]							)
							with torch.no_grad():
										a   =      model(__lowerCamelCase ,				token_type_ids=__lowerCamelCase ,				output_hidden_states=__lowerCamelCase							)

							a   =      11_52

							a   =      torch.Size((1, 5, hidden_size)							)
							self.assertEqual(output["last_hidden_state"].shape ,				__lowerCamelCase							)

							a   =      torch.tensor(
							    [
							        [
							            [0.0_754, -0.2_022, 0.1_904],
							            [-0.3_354, -0.3_692, -0.4_791],
							            [-0.2_314, -0.6_729, -0.0_749],
							            [-0.0_396, -0.3_105, -0.4_234],
							            [-0.1_571, -0.0_525, 0.5_353],
							        ]
							    ]							)

							# Running on the original tf implementation gives slightly different results here.
							# Not clear why this variations is present
							# TODO: Find reason for discrepancy
							# expected_original_implementation = [[
							#     [0.07630594074726105, -0.20146065950393677, 0.19107051193714142],
							#     [-0.3405614495277405, -0.36971670389175415, -0.4808273911476135],
							#     [-0.22587086260318756, -0.6656315922737122, -0.07844287157058716],
							#     [-0.04145475849509239, -0.3077218234539032, -0.42316967248916626],
							#     [-0.15887849032878876, -0.054529931396245956, 0.5356100797653198]
							# ]]

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












import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin




class    snake_case__							(_UpperCamelCase       ):
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_	:							List[Any]										= ["""image_processor""", """tokenizer"""]
				SCREAMING_SNAKE_CASE_	:							List[Any]										= """AutoImageProcessor"""
				SCREAMING_SNAKE_CASE_	:							Dict										= """AutoTokenizer"""





				def __init__(				self    :					int ,				__lowerCamelCase    :					Dict=None ,				__lowerCamelCase    :					int=None ,				**__lowerCamelCase    :					Optional[Any]							) ->					str:
							a   =      None
							if "feature_extractor" in kwargs:
										warnings.warn(
										    "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
										    " instead." ,				__lowerCamelCase ,				)
										a   =      kwargs.pop("feature_extractor"							)

							a   =      image_processor if image_processor is not None else feature_extractor
							if image_processor is None:
										raise ValueError("You need to specify an `image_processor`."							)
							if tokenizer is None:
										raise ValueError("You need to specify a `tokenizer`."							)

							super().__init__(__lowerCamelCase ,				__lowerCamelCase							)
							a   =      self.image_processor
							a   =      False





				def __call__(				self    :					Any ,				*__lowerCamelCase    :					int ,				**__lowerCamelCase    :					Optional[int]							) ->					int:
							# For backward compatibility
							if self._in_target_context_manager:
										return self.current_processor(*__lowerCamelCase ,				**__lowerCamelCase							)

							a   =      kwargs.pop("images" ,				__lowerCamelCase							)
							a   =      kwargs.pop("text" ,				__lowerCamelCase							)
							if len(__lowerCamelCase							) > 0:
										a   =      args[0]
										a   =      args[1:]

							if images is None and text is None:
										raise ValueError("You need to specify either an `images` or `text` input to process."							)

							if images is not None:
										a   =      self.image_processor(__lowerCamelCase ,				*__lowerCamelCase ,				**__lowerCamelCase							)
							if text is not None:
										a   =      self.tokenizer(__lowerCamelCase ,				**__lowerCamelCase							)

							if text is None:
										return inputs
							elif images is None:
										return encodings
							else:
										a   =      encodings["input_ids"]
										return inputs





				def 							__UpperCAmelCase							(				self    :					Union[str, Any] ,				*__lowerCamelCase    :					str ,				**__lowerCamelCase    :					str							) ->					Optional[Any]:
							return self.tokenizer.batch_decode(*__lowerCamelCase ,				**__lowerCamelCase							)





				def 							__UpperCAmelCase							(				self    :					Optional[Any] ,				*__lowerCamelCase    :					Union[str, Any] ,				**__lowerCamelCase    :					Any							) ->					str:
							return self.tokenizer.decode(*__lowerCamelCase ,				**__lowerCamelCase							)





				@contextmanager
				def 							__UpperCAmelCase							(				self    :					Any							) ->					Optional[int]:
							warnings.warn(
							    "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your "
							    "labels by using the argument `text` of the regular `__call__` method (either in the same call as "
							    "your images inputs, or in a separate call."							)
							a   =      True
							a   =      self.tokenizer
							yield
							a   =      self.image_processor
							a   =      False





				@property
				def 							__UpperCAmelCase							(				self    :					Dict							) ->					Optional[Any]:
							warnings.warn(
							    "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead." ,				__lowerCamelCase ,				)
							return self.image_processor_class





				@property
				def 							__UpperCAmelCase							(				self    :					int							) ->					Union[str, Any]:
							warnings.warn(
							    "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead." ,				__lowerCamelCase ,				)
							return self.image_processor






