import unittest

from transformers import YosoConfig, 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 (
         YosoForMaskedLM,
         YosoForMultipleChoice,
         YosoForQuestionAnswering,
         YosoForSequenceClassification,
         YosoForTokenClassification,
         YosoModel,
     )
     from transformers.models.yoso.modeling_yoso import YOSO_PRETRAINED_MODEL_ARCHIVE_LIST



class 			UpperCamelCase					:

     '''simple docstring'''

     def __init__(       self					,					A_					,					A_=13					,					A_=7					,					A_=True					,					A_=True					,					A_=True					,					A_=True					,					A_=99					,					A_=32					,					A_=5					,					A_=4					,					A_=37					,					A_="gelu"					,					A_=0.1					,					A_=0.1					,					A_=5_12					,					A_=16					,					A_=2					,					A_=0.02					,					A_=3					,					A_=4					,					A_=None					,					)			->					str:






           """simple docstring"""
           _lowerCamelCase           =					parent
           _lowerCamelCase           =					batch_size
           _lowerCamelCase           =					seq_length
           _lowerCamelCase           =					is_training
           _lowerCamelCase           =					use_input_mask
           _lowerCamelCase           =					use_token_type_ids
           _lowerCamelCase           =					use_labels
           _lowerCamelCase           =					vocab_size
           _lowerCamelCase           =					hidden_size
           _lowerCamelCase           =					num_hidden_layers
           _lowerCamelCase           =					num_attention_heads
           _lowerCamelCase           =					intermediate_size
           _lowerCamelCase           =					hidden_act
           _lowerCamelCase           =					hidden_dropout_prob
           _lowerCamelCase           =					attention_probs_dropout_prob
           _lowerCamelCase           =					max_position_embeddings
           _lowerCamelCase           =					type_vocab_size
           _lowerCamelCase           =					type_sequence_label_size
           _lowerCamelCase           =					initializer_range
           _lowerCamelCase           =					num_labels
           _lowerCamelCase           =					num_choices
           _lowerCamelCase           =					scope



     def 		UpperCamelCase_    (       self    )			->					List[Any]:






           """simple docstring"""
           _lowerCamelCase           =					ids_tensor([self.batch_size, self.seq_length]					,					self.vocab_size    )

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

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

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

           _lowerCamelCase           =					self.get_config()

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



     def 		UpperCamelCase_    (       self    )			->					int:






           """simple docstring"""
           return YosoConfig(
               vocab_size=self.vocab_size					,					hidden_size=self.hidden_size					,					num_hidden_layers=self.num_hidden_layers					,					num_attention_heads=self.num_attention_heads					,					intermediate_size=self.intermediate_size					,					hidden_act=self.hidden_act					,					hidden_dropout_prob=self.hidden_dropout_prob					,					attention_probs_dropout_prob=self.attention_probs_dropout_prob					,					max_position_embeddings=self.max_position_embeddings					,					type_vocab_size=self.type_vocab_size					,					is_decoder=A_					,					initializer_range=self.initializer_range					,					)



     def 		UpperCamelCase_    (       self    )			->					str:






           """simple docstring"""
           _lowerCamelCase           =					self.get_config()
           _lowerCamelCase           =					3_00
           return config



     def 		UpperCamelCase_    (       self    )			->					List[str]:






           """simple docstring"""
           (
               (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       
           )           =					self.prepare_config_and_inputs()

           _lowerCamelCase           =					True
           _lowerCamelCase           =					floats_tensor([self.batch_size, self.seq_length, self.hidden_size]    )
           _lowerCamelCase           =					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					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_    )			->					List[str]:






           """simple docstring"""
           _lowerCamelCase           =					YosoModel(config=A_    )
           model.to(A_    )
           model.eval()
           _lowerCamelCase           =					model(A_					,					attention_mask=A_					,					token_type_ids=A_    )
           _lowerCamelCase           =					model(A_					,					token_type_ids=A_    )
           _lowerCamelCase           =					model(A_    )
           self.parent.assertEqual(result.last_hidden_state.shape					,					(self.batch_size, self.seq_length, self.hidden_size)    )



     def 		UpperCamelCase_    (       self					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_					,					)			->					List[Any]:






           """simple docstring"""
           _lowerCamelCase           =					True
           _lowerCamelCase           =					YosoModel(A_    )
           model.to(A_    )
           model.eval()
           _lowerCamelCase           =					model(
               A_					,					attention_mask=A_					,					token_type_ids=A_					,					encoder_hidden_states=A_					,					encoder_attention_mask=A_					,					)
           _lowerCamelCase           =					model(
               A_					,					attention_mask=A_					,					token_type_ids=A_					,					encoder_hidden_states=A_					,					)
           _lowerCamelCase           =					model(A_					,					attention_mask=A_					,					token_type_ids=A_    )
           self.parent.assertEqual(result.last_hidden_state.shape					,					(self.batch_size, self.seq_length, self.hidden_size)    )



     def 		UpperCamelCase_    (       self					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_    )			->					Any:






           """simple docstring"""
           _lowerCamelCase           =					YosoForMaskedLM(config=A_    )
           model.to(A_    )
           model.eval()
           _lowerCamelCase           =					model(A_					,					attention_mask=A_					,					token_type_ids=A_					,					labels=A_    )
           self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.seq_length, self.vocab_size)    )



     def 		UpperCamelCase_    (       self					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_    )			->					List[str]:






           """simple docstring"""
           _lowerCamelCase           =					YosoForQuestionAnswering(config=A_    )
           model.to(A_    )
           model.eval()
           _lowerCamelCase           =					model(
               A_					,					attention_mask=A_					,					token_type_ids=A_					,					start_positions=A_					,					end_positions=A_					,					)
           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					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_    )			->					Optional[int]:






           """simple docstring"""
           _lowerCamelCase           =					self.num_labels
           _lowerCamelCase           =					YosoForSequenceClassification(A_    )
           model.to(A_    )
           model.eval()
           _lowerCamelCase           =					model(A_					,					attention_mask=A_					,					token_type_ids=A_					,					labels=A_    )
           self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.num_labels)    )



     def 		UpperCamelCase_    (       self					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_    )			->					Dict:






           """simple docstring"""
           _lowerCamelCase           =					self.num_labels
           _lowerCamelCase           =					YosoForTokenClassification(config=A_    )
           model.to(A_    )
           model.eval()
           _lowerCamelCase           =					model(A_					,					attention_mask=A_					,					token_type_ids=A_					,					labels=A_    )
           self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.seq_length, self.num_labels)    )



     def 		UpperCamelCase_    (       self					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_					,					A_    )			->					List[Any]:






           """simple docstring"""
           _lowerCamelCase           =					self.num_choices
           _lowerCamelCase           =					YosoForMultipleChoice(config=A_    )
           model.to(A_    )
           model.eval()
           _lowerCamelCase           =					input_ids.unsqueeze(1    ).expand(-1					,					self.num_choices					,					-1    ).contiguous()
           _lowerCamelCase           =					token_type_ids.unsqueeze(1    ).expand(-1					,					self.num_choices					,					-1    ).contiguous()
           _lowerCamelCase           =					input_mask.unsqueeze(1    ).expand(-1					,					self.num_choices					,					-1    ).contiguous()
           _lowerCamelCase           =					model(
               A_					,					attention_mask=A_					,					token_type_ids=A_					,					labels=A_					,					)
           self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.num_choices)    )





     def 		UpperCamelCase_    (       self    )			->					Tuple:






           """simple docstring"""
           _lowerCamelCase           =					self.prepare_config_and_inputs()
           (
               (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       (
               _lowerCamelCase
           )     ,       
           )           =					config_and_inputs
           _lowerCamelCase           =					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
           return config, inputs_dict





@require_torch
class 			UpperCamelCase					(			__lowercase ,	__lowercase ,	unittest.TestCase			):

     '''simple docstring'''

     A_					    =	(
         (
             YosoModel,
             YosoForMaskedLM,
             YosoForMultipleChoice,
             YosoForQuestionAnswering,
             YosoForSequenceClassification,
             YosoForTokenClassification,
         )
         if is_torch_available()
         else ()
     )
     A_					    =	False
     A_					    =	False
     A_					    =	False

     A_					    =	()
     A_					    =	(
         {
             'feature-extraction': YosoModel,
             'fill-mask': YosoForMaskedLM,
             'question-answering': YosoForQuestionAnswering,
             'text-classification': YosoForSequenceClassification,
             'token-classification': YosoForTokenClassification,
             'zero-shot': YosoForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )



     def 		UpperCamelCase_    (       self    )			->					Dict:






           """simple docstring"""
           _lowerCamelCase           =					YosoModelTester(self    )
           _lowerCamelCase           =					ConfigTester(self					,					config_class=A_					,					hidden_size=37    )



     def 		UpperCamelCase_    (       self    )			->					Tuple:






           """simple docstring"""
           self.config_tester.run_common_tests()



     def 		UpperCamelCase_    (       self    )			->					List[str]:






           """simple docstring"""
           _lowerCamelCase           =					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*A_    )



     def 		UpperCamelCase_    (       self    )			->					Dict:






           """simple docstring"""
           _lowerCamelCase           =					self.model_tester.prepare_config_and_inputs()
           for type in ["absolute", "relative_key", "relative_key_query"]:
                 _lowerCamelCase           =					type
                 self.model_tester.create_and_check_model(*A_    )



     def 		UpperCamelCase_    (       self    )			->					Optional[Any]:






           """simple docstring"""
           _lowerCamelCase           =					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*A_    )



     def 		UpperCamelCase_    (       self    )			->					List[Any]:






           """simple docstring"""
           _lowerCamelCase           =					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*A_    )



     def 		UpperCamelCase_    (       self    )			->					int:






           """simple docstring"""
           _lowerCamelCase           =					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*A_    )



     def 		UpperCamelCase_    (       self    )			->					List[str]:






           """simple docstring"""
           _lowerCamelCase           =					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*A_    )



     def 		UpperCamelCase_    (       self    )			->					List[Any]:






           """simple docstring"""
           _lowerCamelCase           =					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*A_    )



     @slow
     def 		UpperCamelCase_    (       self    )			->					Any:






           """simple docstring"""
           for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 _lowerCamelCase           =					YosoModel.from_pretrained(A_    )
                 self.assertIsNotNone(A_    )





     def 		UpperCamelCase_    (       self    )			->					Any:






           """simple docstring"""
           return





@require_torch
class 			UpperCamelCase					(			unittest.TestCase			):

     '''simple docstring'''

     @slow
     def 		UpperCamelCase_    (       self    )			->					Optional[int]:






           """simple docstring"""
           _lowerCamelCase           =					YosoModel.from_pretrained('''uw-madison/yoso-4096'''    )
           _lowerCamelCase           =					torch.tensor([[0, 1, 2, 3, 4, 5]]    )

           with torch.no_grad():
                 _lowerCamelCase           =					model(A_    )[0]

           _lowerCamelCase           =					torch.Size((1, 6, 7_68)    )
           self.assertEqual(output.shape					,					A_    )

           _lowerCamelCase           =					torch.tensor(
               [[[-0.0611, 0.1242, 0.0840], [0.0280, -0.0048, 0.1125], [0.0106, 0.0226, 0.0751]]]    )

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



     @slow
     def 		UpperCamelCase_    (       self    )			->					Optional[int]:






           """simple docstring"""
           _lowerCamelCase           =					YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''    )
           _lowerCamelCase           =					torch.tensor([[0, 1, 2, 3, 4, 5]]    )

           with torch.no_grad():
                 _lowerCamelCase           =					model(A_    )[0]

           _lowerCamelCase           =					5_02_65

           _lowerCamelCase           =					torch.Size((1, 6, vocab_size)    )
           self.assertEqual(output.shape					,					A_    )

           _lowerCamelCase           =					torch.tensor(
               [[[-2.1313, -3.7285, -2.2407], [-2.7047, -3.3314, -2.6408], [0.0629, -2.5166, -0.3356]]]    )

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





     @slow
     def 		UpperCamelCase_    (       self    )			->					int:






           """simple docstring"""
           _lowerCamelCase           =					YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''    )
           _lowerCamelCase           =					torch.arange(40_96    ).unsqueeze(0    )

           with torch.no_grad():
                 _lowerCamelCase           =					model(A_    )[0]

           _lowerCamelCase           =					5_02_65

           _lowerCamelCase           =					torch.Size((1, 40_96, vocab_size)    )
           self.assertEqual(output.shape					,					A_    )

           _lowerCamelCase           =					torch.tensor(
               [[[-2.3914, -4.3742, -5.0956], [-4.0988, -4.2384, -7.0406], [-3.1427, -3.7192, -6.6800]]]    )

           self.assertTrue(torch.allclose(output[:, :3, :3]					,					A_					,					atol=1E-4    )    )
import importlib
import inspect
import json
import os
from collections import OrderedDict

# Build the list of all feature extractors
from ...configuration_utils import PretrainedConfig
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
from ...feature_extraction_utils import FeatureExtractionMixin
from ...image_processing_utils import ImageProcessingMixin
from ...tokenization_utils import TOKENIZER_CONFIG_FILE
from ...utils import FEATURE_EXTRACTOR_NAME, get_file_from_repo, logging
from .auto_factory import _LazyAutoMapping
from .configuration_auto import (
    CONFIG_MAPPING_NAMES,
    AutoConfig,
    model_type_to_module_name,
    replace_list_option_in_docstrings,
)
from .feature_extraction_auto import AutoFeatureExtractor
from .image_processing_auto import AutoImageProcessor
from .tokenization_auto import AutoTokenizer


snake_case__						      =			logging.get_logger(__name__)

snake_case__						      =			OrderedDict(
    [
        ('align', 'AlignProcessor'),
        ('altclip', 'AltCLIPProcessor'),
        ('bark', 'BarkProcessor'),
        ('blip', 'BlipProcessor'),
        ('blip-2', 'Blip2Processor'),
        ('bridgetower', 'BridgeTowerProcessor'),
        ('chinese_clip', 'ChineseCLIPProcessor'),
        ('clap', 'ClapProcessor'),
        ('clip', 'CLIPProcessor'),
        ('clipseg', 'CLIPSegProcessor'),
        ('flava', 'FlavaProcessor'),
        ('git', 'GitProcessor'),
        ('groupvit', 'CLIPProcessor'),
        ('hubert', 'Wav2Vec2Processor'),
        ('instructblip', 'InstructBlipProcessor'),
        ('layoutlmv2', 'LayoutLMv2Processor'),
        ('layoutlmv3', 'LayoutLMv3Processor'),
        ('markuplm', 'MarkupLMProcessor'),
        ('mctct', 'MCTCTProcessor'),
        ('mgp-str', 'MgpstrProcessor'),
        ('oneformer', 'OneFormerProcessor'),
        ('owlvit', 'OwlViTProcessor'),
        ('pix2struct', 'Pix2StructProcessor'),
        ('sam', 'SamProcessor'),
        ('sew', 'Wav2Vec2Processor'),
        ('sew-d', 'Wav2Vec2Processor'),
        ('speech_to_text', 'Speech2TextProcessor'),
        ('speech_to_text_2', 'Speech2Text2Processor'),
        ('speecht5', 'SpeechT5Processor'),
        ('trocr', 'TrOCRProcessor'),
        ('tvlt', 'TvltProcessor'),
        ('unispeech', 'Wav2Vec2Processor'),
        ('unispeech-sat', 'Wav2Vec2Processor'),
        ('vilt', 'ViltProcessor'),
        ('vision-text-dual-encoder', 'VisionTextDualEncoderProcessor'),
        ('wav2vec2', 'Wav2Vec2Processor'),
        ('wav2vec2-conformer', 'Wav2Vec2Processor'),
        ('wavlm', 'Wav2Vec2Processor'),
        ('whisper', 'WhisperProcessor'),
        ('xclip', 'XCLIPProcessor'),
    ]
)

snake_case__						      =			_LazyAutoMapping(CONFIG_MAPPING_NAMES, PROCESSOR_MAPPING_NAMES)
def    __magic_name__(	__UpperCAmelCase		)    ->     List[str]:



      '''simple docstring'''

      for module_name, processors in PROCESSOR_MAPPING_NAMES.items():
            if class_name in processors:
                  _lowerCamelCase           =					model_type_to_module_name(__UpperCAmelCase		)

                  _lowerCamelCase           =					importlib.import_module(F'.{module_name}'			,    '''transformers.models'''		)
                  try:
                        return getattr(__UpperCAmelCase			,    __UpperCAmelCase		)
                  except AttributeError:
                        continue

      for processor in PROCESSOR_MAPPING._extra_content.values():
            if getattr(__UpperCAmelCase			,    '''__name__'''			,    __UpperCAmelCase		) == class_name:
                  return processor

    # We did not fine the class, but maybe it's because a dep is missing. In that case, the class will be in the main
    # init and we return the proper dummy to get an appropriate error message.
      _lowerCamelCase           =					importlib.import_module('''transformers'''		)
      if hasattr(__UpperCAmelCase			,    __UpperCAmelCase		):
            return getattr(__UpperCAmelCase			,    __UpperCAmelCase		)

      return None




class 			UpperCamelCase					:

     '''simple docstring'''

     def __init__(       self    )			->					List[str]:






           """simple docstring"""
           raise EnvironmentError(
               '''AutoProcessor is designed to be instantiated '''
               '''using the `AutoProcessor.from_pretrained(pretrained_model_name_or_path)` method.'''    )



     @classmethod
     @replace_list_option_in_docstrings(A_    )
     def 		UpperCamelCase_    (       cls					,					A_					,					**A_    )			->					List[Any]:






           """simple docstring"""
           _lowerCamelCase           =					kwargs.pop('''config'''					,					A_    )
           _lowerCamelCase           =					kwargs.pop('''trust_remote_code'''					,					A_    )
           _lowerCamelCase           =					True

           _lowerCamelCase           =					None
           _lowerCamelCase           =					None

           # First, let's see if we have a preprocessor config.
           # Filter the kwargs for `get_file_from_repo`.
           _lowerCamelCase           =					{
               key: kwargs[key] for key in inspect.signature(A_    ).parameters.keys() if key in kwargs
           }
           # Let's start by checking whether the processor class is saved in an image processor
           _lowerCamelCase           =					get_file_from_repo(
               A_					,					A_					,					**A_    )
           if preprocessor_config_file is not None:
                 _lowerCamelCase     ,       _lowerCamelCase           =					ImageProcessingMixin.get_image_processor_dict(A_					,					**A_    )
                 _lowerCamelCase           =					config_dict.get('''processor_class'''					,					A_    )
                 if "AutoProcessor" in config_dict.get('''auto_map'''					,					{}    ):
                       _lowerCamelCase           =					config_dict['''auto_map''']['''AutoProcessor''']

        # If not found, let's check whether the processor class is saved in a feature extractor config
           if preprocessor_config_file is not None and processor_class is None:
                 _lowerCamelCase     ,       _lowerCamelCase           =					FeatureExtractionMixin.get_feature_extractor_dict(A_					,					**A_    )
                 _lowerCamelCase           =					config_dict.get('''processor_class'''					,					A_    )
                 if "AutoProcessor" in config_dict.get('''auto_map'''					,					{}    ):
                       _lowerCamelCase           =					config_dict['''auto_map''']['''AutoProcessor''']

           if processor_class is None:
                 # Next, let's check whether the processor class is saved in a tokenizer
                 _lowerCamelCase           =					get_file_from_repo(
                     A_					,					A_					,					**A_    )
                 if tokenizer_config_file is not None:
                       with open(A_					,					encoding='''utf-8'''    ) as reader:
                             _lowerCamelCase           =					json.load(A_    )

                       _lowerCamelCase           =					config_dict.get('''processor_class'''					,					A_    )
                       if "AutoProcessor" in config_dict.get('''auto_map'''					,					{}    ):
                             _lowerCamelCase           =					config_dict['''auto_map''']['''AutoProcessor''']

           if processor_class is None:
                 # Otherwise, load config, if it can be loaded.
                 if not isinstance(A_					,					A_    ):
                       _lowerCamelCase           =					AutoConfig.from_pretrained(
                           A_					,					trust_remote_code=A_					,					**A_    )

                 # And check if the config contains the processor class.
                 _lowerCamelCase           =					getattr(A_					,					'''processor_class'''					,					A_    )
                 if hasattr(A_					,					'''auto_map'''    ) and "AutoProcessor" in config.auto_map:
                       _lowerCamelCase           =					config.auto_map['''AutoProcessor''']

           if processor_class is not None:
                 _lowerCamelCase           =					processor_class_from_name(A_    )

           _lowerCamelCase           =					processor_auto_map is not None
           _lowerCamelCase           =					processor_class is not None or type(A_    ) in PROCESSOR_MAPPING
           _lowerCamelCase           =					resolve_trust_remote_code(
               A_					,					A_					,					A_					,					A_    )

           if has_remote_code and trust_remote_code:
                 _lowerCamelCase           =					get_class_from_dynamic_module(
                     A_					,					A_					,					**A_    )
                 _lowerCamelCase           =					kwargs.pop('''code_revision'''					,					A_    )
                 if os.path.isdir(A_    ):
                       processor_class.register_for_auto_class()
                 return processor_class.from_pretrained(
                     A_					,					trust_remote_code=A_					,					**A_    )
           elif processor_class is not None:
                 return processor_class.from_pretrained(
                     A_					,					trust_remote_code=A_					,					**A_    )
           # Last try: we use the PROCESSOR_MAPPING.
           elif type(A_    ) in PROCESSOR_MAPPING:
                 return PROCESSOR_MAPPING[type(A_    )].from_pretrained(A_					,					**A_    )

           # At this stage, there doesn't seem to be a `Processor` class available for this model, so let's try a
           # tokenizer.
           try:
                 return AutoTokenizer.from_pretrained(
                     A_					,					trust_remote_code=A_					,					**A_    )
           except Exception:
                 try:
                       return AutoImageProcessor.from_pretrained(
                           A_					,					trust_remote_code=A_					,					**A_    )
                 except Exception:
                       pass

                 try:
                       return AutoFeatureExtractor.from_pretrained(
                           A_					,					trust_remote_code=A_					,					**A_    )
                 except Exception:
                       pass

           raise ValueError(
               F'Unrecognized processing class in {pretrained_model_name_or_path}. Can\'t instantiate a processor, a '
               '''tokenizer, an image processor or a feature extractor for this model. Make sure the repository contains'''
               '''the files of at least one of those processing classes.'''    )





     @staticmethod
     def 		UpperCamelCase_    (       A_					,					A_    )			->					List[Any]:






           """simple docstring"""
           PROCESSOR_MAPPING.register(A_					,					A_    )