




'''simple docstring'''
import os
import warnings
from pathlib import Path
from typing import Optional, Union

from .dynamic_module_utils import custom_object_save
from .tokenization_utils_base import PreTrainedTokenizerBase
from .utils import PushToHubMixin, copy_func, direct_transformers_import, logging


A				: int					      =			logging.get_logger(__name__)

# Dynamically import the Transformers module to grab the attribute classes of the processor form their names.
A				: Any					      =			direct_transformers_import(Path(__file__).parent)


A				: Optional[int]					      =			{
    """AutoTokenizer""": """PreTrainedTokenizerBase""",
    """AutoFeatureExtractor""": """FeatureExtractionMixin""",
    """AutoImageProcessor""": """ImageProcessingMixin""",
}






class 			SCREAMING_SNAKE_CASE(							__A	):
       snake_case_					:	int       =   ['feature_extractor', 'tokenizer']
       # Names need to be attr_class for attr in attributes
       snake_case_					:	int       =   None
       snake_case_					:	Optional[Any]       =   None
       snake_case_					:	Union[str, Any]       =   None

       def __init__(       self   ,						*lowerCamelCase__   ,						**lowerCamelCase__	)       ->   Optional[Any]:

           """simple docstring"""



           for key in kwargs:
               if key not in self.attributes:
                   raise TypeError(F'Unexpected keyword argument {key}.'	)
           for arg, attribute_name in zip(__UpperCAmelCase   ,						self.attributes	):
               if attribute_name in kwargs:
                   raise TypeError(F'Got multiple values for argument {attribute_name}.'	)
               else:
                   __lowercase     							=		arg

           if len(__UpperCAmelCase	) != len(self.attributes	):
               raise ValueError(
                   F'This processor requires {len(self.attributes	)} arguments: {", ".join(self.attributes	)}. Got '
                   F'{len(__UpperCAmelCase	)} arguments instead.'	)

           # Check each arg is of the proper class (this will also catch a user initializing in the wrong order)
           for attribute_name, arg in kwargs.items():
               __lowercase     							=		getattr(self   ,						F'{attribute_name}_class'	)
               # Nothing is ever going to be an instance of "AutoXxx", in that case we check the base class.
               __lowercase     							=		AUTO_TO_BASE_CLASS_MAPPING.get(__UpperCAmelCase   ,						__UpperCAmelCase	)
               if isinstance(__UpperCAmelCase   ,						__UpperCAmelCase	):
                   __lowercase     							=		tuple(getattr(__UpperCAmelCase   ,						__UpperCAmelCase	) for n in class_name if n is not None	)
               else:
                   __lowercase     							=		getattr(__UpperCAmelCase   ,						__UpperCAmelCase	)

               if not isinstance(__UpperCAmelCase   ,						__UpperCAmelCase	):
                   raise ValueError(
                       F'Received a {type(__UpperCAmelCase	).__name__} for argument {attribute_name}, but a {class_name} was expected.'	)

               setattr(self   ,						__UpperCAmelCase   ,						__UpperCAmelCase	)

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

           """simple docstring"""



           __lowercase     							=		[F'- {name}: {repr(getattr(self   ,						__UpperCAmelCase	)	)}' for name in self.attributes]
           __lowercase     							=		"""\n""".join(__UpperCAmelCase	)
           return F'{self.__class__.__name__}:\n{attributes_repr}'

       def        snake_case__     (       self   ,						lowerCamelCase__   ,						lowerCamelCase__ = False   ,						**lowerCamelCase__	)       ->   Optional[int]:

           """simple docstring"""



           os.makedirs(__UpperCAmelCase   ,						exist_ok=__UpperCAmelCase	)

           if push_to_hub:
               __lowercase     							=		kwargs.pop("""commit_message"""   ,						__UpperCAmelCase	)
               __lowercase     							=		kwargs.pop("""repo_id"""   ,						save_directory.split(os.path.sep	)[-1]	)
               __lowercase     							=		self._create_repo(__UpperCAmelCase   ,						**__UpperCAmelCase	)
               __lowercase     							=		self._get_files_timestamps(__UpperCAmelCase	)
           # If we have a custom config, we copy the file defining it in the folder and set the attributes so it can be
           # loaded from the Hub.
           if self._auto_class is not None:
               __lowercase     							=		[getattr(self   ,						__UpperCAmelCase	) for attribute_name in self.attributes]
               __lowercase     							=		[(a.init_kwargs if isinstance(__UpperCAmelCase   ,						__UpperCAmelCase	) else a) for a in attrs]
               custom_object_save(self   ,						__UpperCAmelCase   ,						config=__UpperCAmelCase	)

           for attribute_name in self.attributes:
               __lowercase     							=		getattr(self   ,						__UpperCAmelCase	)
               # Include the processor class in the attribute config so this processor can then be reloaded with the
               # `AutoProcessor` API.
               if hasattr(__UpperCAmelCase   ,						"""_set_processor_class"""	):
                   attribute._set_processor_class(self.__class__.__name__	)
               attribute.save_pretrained(__UpperCAmelCase	)

           if self._auto_class is not None:
               # We added an attribute to the init_kwargs of the tokenizers, which needs to be cleaned up.
               for attribute_name in self.attributes:
                   __lowercase     							=		getattr(self   ,						__UpperCAmelCase	)
                   if isinstance(__UpperCAmelCase   ,						__UpperCAmelCase	):
                       del attribute.init_kwargs["auto_map"]

           if push_to_hub:
               self._upload_modified_files(
                   __UpperCAmelCase   ,						__UpperCAmelCase   ,						__UpperCAmelCase   ,						commit_message=__UpperCAmelCase   ,						token=kwargs.get("""use_auth_token"""	)   ,						)

       @classmethod
       def        snake_case__     (       cls   ,						lowerCamelCase__   ,						lowerCamelCase__ = None   ,						lowerCamelCase__ = False   ,						lowerCamelCase__ = False   ,						lowerCamelCase__ = None   ,						lowerCamelCase__ = "main"   ,						**lowerCamelCase__   ,						)       ->   Tuple:

           """simple docstring"""



           __lowercase     							=		cache_dir
           __lowercase     							=		force_download
           __lowercase     							=		local_files_only
           __lowercase     							=		revision

           __lowercase     							=		kwargs.pop("""use_auth_token"""   ,						__UpperCAmelCase	)
           if use_auth_token is not None:
               warnings.warn(
                   """The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers."""   ,						__UpperCAmelCase	)
               if token is not None:
                   raise ValueError(
                       """`token` and `use_auth_token` are both specified. Please set only the argument `token`."""	)
               __lowercase     							=		use_auth_token

           if token is not None:
               # change to `token` in a follow-up PR
               __lowercase     							=		token

           __lowercase     							=		cls._get_arguments_from_pretrained(__UpperCAmelCase   ,						**__UpperCAmelCase	)
           return cls(*__UpperCAmelCase	)

       @classmethod
       def        snake_case__     (       cls   ,						lowerCamelCase__="AutoProcessor"	)       ->   int:

           """simple docstring"""



           if not isinstance(__UpperCAmelCase   ,						__UpperCAmelCase	):
               __lowercase     							=		auto_class.__name__

           import transformers.models.auto as auto_module

           if not hasattr(__UpperCAmelCase   ,						__UpperCAmelCase	):
               raise ValueError(F'{auto_class} is not a valid auto class.'	)

           __lowercase     							=		auto_class

       @classmethod
       def        snake_case__     (       cls   ,						lowerCamelCase__   ,						**lowerCamelCase__	)       ->   str:

           """simple docstring"""



           __lowercase     							=		[]
           for attribute_name in cls.attributes:
               __lowercase     							=		getattr(cls   ,						F'{attribute_name}_class'	)
               if isinstance(__UpperCAmelCase   ,						__UpperCAmelCase	):
                   __lowercase     							=		tuple(getattr(__UpperCAmelCase   ,						__UpperCAmelCase	) if n is not None else None for n in class_name	)
                   __lowercase     							=		kwargs.get("""use_fast"""   ,						__UpperCAmelCase	)
                   if use_fast and classes[1] is not None:
                       __lowercase     							=		classes[1]
                   else:
                       __lowercase     							=		classes[0]
               else:
                   __lowercase     							=		getattr(__UpperCAmelCase   ,						__UpperCAmelCase	)

               args.append(attribute_class.from_pretrained(__UpperCAmelCase   ,						**__UpperCAmelCase	)	)
           return args




       @property
       def        snake_case__     (       self	)       ->   Optional[int]:

           """simple docstring"""



           __lowercase     							=		getattr(self   ,						self.attributes[0]	)
           return getattr(__UpperCAmelCase   ,						"""model_input_names"""   ,						__UpperCAmelCase	)

A				: Union[str, Any]					      =			copy_func(ProcessorMixin.push_to_hub)
if ProcessorMixin.push_to_hub.__doc__ is not None:
  A				: Any					      =			ProcessorMixin.push_to_hub.__doc__.format(
      object="""processor""", object_class="""AutoProcessor""", object_files="""processor files"""
  )





"""simple docstring"""




from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCamelCase									=	logging.get_logger(__name__)

__lowerCamelCase									=	{
    "dandelin/vilt-b32-mlm": "https://huggingface.co/dandelin/vilt-b32-mlm/blob/main/config.json"
}
class      UpperCamelCase__(      __A			):
						lowerCAmelCase__	:    str    				=		'vilt'





						def __init__(							self		,__UpperCAmelCase=3_05_22		,__UpperCAmelCase=2		,__UpperCAmelCase=2		,__UpperCAmelCase=40		,__UpperCAmelCase=7_68		,__UpperCAmelCase=12		,__UpperCAmelCase=12		,__UpperCAmelCase=30_72		,__UpperCAmelCase="gelu"		,__UpperCAmelCase=0.0		,__UpperCAmelCase=0.0		,__UpperCAmelCase=0.0_2		,__UpperCAmelCase=1e-12		,__UpperCAmelCase=3_84		,__UpperCAmelCase=32		,__UpperCAmelCase=3		,__UpperCAmelCase=True		,__UpperCAmelCase=-1		,__UpperCAmelCase=False		,__UpperCAmelCase=-1		,**__UpperCAmelCase		,)       ->					Tuple:
													super().__init__(tie_word_embeddings=__UpperCAmelCase		,**__UpperCAmelCase  )

													A__						  =				vocab_size
													A__						  =				type_vocab_size
													A__						  =				modality_type_vocab_size
													A__						  =				max_position_embeddings

													A__						  =				hidden_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__						  =				initializer_range
													A__						  =				layer_norm_eps

													A__						  =				image_size
													A__						  =				patch_size
													A__						  =				num_channels
													A__						  =				qkv_bias
													A__						  =				max_image_length
													A__						  =				num_images





