





import importlib
import json
import os
from collections import OrderedDict
from typing import Dict, Optional, Union

# Build the list of all image processors
from ...configuration_utils import PretrainedConfig
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
from ...image_processing_utils import ImageProcessingMixin
from ...utils import CONFIG_NAME, IMAGE_PROCESSOR_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,
)


__A				:    Optional[Any]       =   logging.get_logger(__name__)

__A				:    Dict       =   OrderedDict(
    [
        ("align", "EfficientNetImageProcessor"),
        ("beit", "BeitImageProcessor"),
        ("bit", "BitImageProcessor"),
        ("blip", "BlipImageProcessor"),
        ("blip-2", "BlipImageProcessor"),
        ("bridgetower", "BridgeTowerImageProcessor"),
        ("chinese_clip", "ChineseCLIPImageProcessor"),
        ("clip", "CLIPImageProcessor"),
        ("clipseg", "ViTImageProcessor"),
        ("conditional_detr", "ConditionalDetrImageProcessor"),
        ("convnext", "ConvNextImageProcessor"),
        ("convnextv2", "ConvNextImageProcessor"),
        ("cvt", "ConvNextImageProcessor"),
        ("data2vec-vision", "BeitImageProcessor"),
        ("deformable_detr", "DeformableDetrImageProcessor"),
        ("deit", "DeiTImageProcessor"),
        ("deta", "DetaImageProcessor"),
        ("detr", "DetrImageProcessor"),
        ("dinat", "ViTImageProcessor"),
        ("donut-swin", "DonutImageProcessor"),
        ("dpt", "DPTImageProcessor"),
        ("efficientformer", "EfficientFormerImageProcessor"),
        ("efficientnet", "EfficientNetImageProcessor"),
        ("flava", "FlavaImageProcessor"),
        ("focalnet", "BitImageProcessor"),
        ("git", "CLIPImageProcessor"),
        ("glpn", "GLPNImageProcessor"),
        ("groupvit", "CLIPImageProcessor"),
        ("imagegpt", "ImageGPTImageProcessor"),
        ("instructblip", "BlipImageProcessor"),
        ("layoutlmv2", "LayoutLMv2ImageProcessor"),
        ("layoutlmv3", "LayoutLMv3ImageProcessor"),
        ("levit", "LevitImageProcessor"),
        ("mask2former", "Mask2FormerImageProcessor"),
        ("maskformer", "MaskFormerImageProcessor"),
        ("mgp-str", "ViTImageProcessor"),
        ("mobilenet_v1", "MobileNetV1ImageProcessor"),
        ("mobilenet_v2", "MobileNetV2ImageProcessor"),
        ("mobilevit", "MobileViTImageProcessor"),
        ("mobilevit", "MobileViTImageProcessor"),
        ("mobilevitv2", "MobileViTImageProcessor"),
        ("nat", "ViTImageProcessor"),
        ("oneformer", "OneFormerImageProcessor"),
        ("owlvit", "OwlViTImageProcessor"),
        ("perceiver", "PerceiverImageProcessor"),
        ("pix2struct", "Pix2StructImageProcessor"),
        ("poolformer", "PoolFormerImageProcessor"),
        ("regnet", "ConvNextImageProcessor"),
        ("resnet", "ConvNextImageProcessor"),
        ("sam", "SamImageProcessor"),
        ("segformer", "SegformerImageProcessor"),
        ("swiftformer", "ViTImageProcessor"),
        ("swin", "ViTImageProcessor"),
        ("swin2sr", "Swin2SRImageProcessor"),
        ("swinv2", "ViTImageProcessor"),
        ("table-transformer", "DetrImageProcessor"),
        ("timesformer", "VideoMAEImageProcessor"),
        ("tvlt", "TvltImageProcessor"),
        ("upernet", "SegformerImageProcessor"),
        ("van", "ConvNextImageProcessor"),
        ("videomae", "VideoMAEImageProcessor"),
        ("vilt", "ViltImageProcessor"),
        ("vit", "ViTImageProcessor"),
        ("vit_hybrid", "ViTHybridImageProcessor"),
        ("vit_mae", "ViTImageProcessor"),
        ("vit_msn", "ViTImageProcessor"),
        ("xclip", "CLIPImageProcessor"),
        ("yolos", "YolosImageProcessor"),
    ]
)

__A				:    Union[str, Any]       =   _LazyAutoMapping(CONFIG_MAPPING_NAMES, IMAGE_PROCESSOR_MAPPING_NAMES)





def 						__SCREAMING_SNAKE_CASE  (				UpperCamelCase__ )  ->				List[str]:







			'''simple docstring'''

			for module_name, extractors in IMAGE_PROCESSOR_MAPPING_NAMES.items():
						if class_name in extractors:
									UpperCAmelCase   		=				model_type_to_module_name(UpperCamelCase__ )

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

			for _, extractor in IMAGE_PROCESSOR_MAPPING._extra_content.items():
						if getattr(UpperCamelCase__			,			'''__name__'''			,			UpperCamelCase__ ) == class_name:
									return extractor

    # 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.
			UpperCAmelCase   		=				importlib.import_module('''transformers''' )
			if hasattr(UpperCamelCase__			,			UpperCamelCase__ ):
						return getattr(UpperCamelCase__			,			UpperCamelCase__ )

			return None





def 						__SCREAMING_SNAKE_CASE  (				UpperCamelCase__			,			UpperCamelCase__ = None			,			UpperCamelCase__ = False			,			UpperCamelCase__ = False			,			UpperCamelCase__ = None			,			UpperCamelCase__ = None			,			UpperCamelCase__ = None			,			UpperCamelCase__ = False			,			**UpperCamelCase__			,			)  ->				List[Any]:







			'''simple docstring'''

			UpperCAmelCase   		=				get_file_from_repo(
			    UpperCamelCase__			,			UpperCamelCase__			,			cache_dir=UpperCamelCase__			,			force_download=UpperCamelCase__			,			resume_download=UpperCamelCase__			,			proxies=UpperCamelCase__			,			use_auth_token=UpperCamelCase__			,			revision=UpperCamelCase__			,			local_files_only=UpperCamelCase__			,			)
			if resolved_config_file is None:
						logger.info(
						    '''Could not locate the image processor configuration file, will try to use the model config instead.''' )
						return {}

			with open(UpperCamelCase__			,			encoding='''utf-8''' ) as reader:
						return json.load(UpperCamelCase__ )






class 	A_       :
	def __init__(    self		):






				'''simple docstring'''







				raise EnvironmentError(
				    '''AutoImageProcessor is designed to be instantiated '''
				    '''using the `AutoImageProcessor.from_pretrained(pretrained_model_name_or_path)` method.'''		)
	@classmethod
	@replace_list_option_in_docstrings(_A		)
	def      _lowercase				(    cls							,					_A							,					**_A		):






				'''simple docstring'''







				UpperCAmelCase   		=				kwargs.pop('''config'''							,					_A		)
				UpperCAmelCase   		=				kwargs.pop('''trust_remote_code'''							,					_A		)
				UpperCAmelCase   		=				True

				UpperCAmelCase		,			UpperCAmelCase   		=				ImageProcessingMixin.get_image_processor_dict(_A							,					**_A		)
				UpperCAmelCase   		=				config_dict.get('''image_processor_type'''							,					_A		)
				UpperCAmelCase   		=				None
				if "AutoImageProcessor" in config_dict.get('''auto_map'''							,					{}		):
							UpperCAmelCase   		=				config_dict['''auto_map''']['''AutoImageProcessor''']

				# If we still don't have the image processor class, check if we're loading from a previous feature extractor config
				# and if so, infer the image processor class from there.
				if image_processor_class is None and image_processor_auto_map is None:
							UpperCAmelCase   		=				config_dict.pop('''feature_extractor_type'''							,					_A		)
							if feature_extractor_class is not None:
										logger.warning(
										    '''Could not find image processor class in the image processor config or the model config. Loading'''
										    ''' based on pattern matching with the model\'s feature extractor configuration.'''		)
										UpperCAmelCase   		=				feature_extractor_class.replace('''FeatureExtractor'''							,					'''ImageProcessor'''		)
							if "AutoFeatureExtractor" in config_dict.get('''auto_map'''							,					{}		):
										UpperCAmelCase   		=				config_dict['''auto_map''']['''AutoFeatureExtractor''']
										UpperCAmelCase   		=				feature_extractor_auto_map.replace('''FeatureExtractor'''							,					'''ImageProcessor'''		)
										logger.warning(
										    '''Could not find image processor auto map in the image processor config or the model config.'''
										    ''' Loading based on pattern matching with the model\'s feature extractor configuration.'''		)

        # If we don't find the image processor class in the image processor config, let's try the model config.
				if image_processor_class is None and image_processor_auto_map is None:
							if not isinstance(_A							,					_A		):
										UpperCAmelCase   		=				AutoConfig.from_pretrained(_A							,					**_A		)
							# It could be in `config.image_processor_type``
							UpperCAmelCase   		=				getattr(_A							,					'''image_processor_type'''							,					_A		)
							if hasattr(_A							,					'''auto_map'''		) and "AutoImageProcessor" in config.auto_map:
										UpperCAmelCase   		=				config.auto_map['''AutoImageProcessor''']

				if image_processor_class is not None:
							UpperCAmelCase   		=				image_processor_class_from_name(_A		)

				UpperCAmelCase   		=				image_processor_auto_map is not None
				UpperCAmelCase   		=				image_processor_class is not None or type(_A		) in IMAGE_PROCESSOR_MAPPING
				UpperCAmelCase   		=				resolve_trust_remote_code(
				    _A							,					_A							,					_A							,					_A		)

				if has_remote_code and trust_remote_code:
							UpperCAmelCase   		=				get_class_from_dynamic_module(
							    _A							,					_A							,					**_A		)
							UpperCAmelCase   		=				kwargs.pop('''code_revision'''							,					_A		)
							if os.path.isdir(_A		):
										image_processor_class.register_for_auto_class()
							return image_processor_class.from_dict(_A							,					**_A		)
				elif image_processor_class is not None:
							return image_processor_class.from_dict(_A							,					**_A		)
				# Last try: we use the IMAGE_PROCESSOR_MAPPING.
				elif type(_A		) in IMAGE_PROCESSOR_MAPPING:
							UpperCAmelCase   		=				IMAGE_PROCESSOR_MAPPING[type(_A		)]
							return image_processor_class.from_dict(_A							,					**_A		)

				raise ValueError(
				    F"""Unrecognized image processor in {pretrained_model_name_or_path}. Should have a """
				    F"""`image_processor_type` key in its {IMAGE_PROCESSOR_NAME} of {CONFIG_NAME}, or one of the following """
				    F"""`model_type` keys in its {CONFIG_NAME}: {", ".join(c for c in IMAGE_PROCESSOR_MAPPING_NAMES.keys()		)}"""		)







	@staticmethod
	def      _lowercase				(    _A							,					_A		):






				'''simple docstring'''







				IMAGE_PROCESSOR_MAPPING.register(_A							,					_A		)










from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__A				:    int       =   logging.get_logger(__name__)

__A				:    Tuple       =   {
    "google/bigbird-roberta-base": "https://huggingface.co/google/bigbird-roberta-base/resolve/main/config.json",
    "google/bigbird-roberta-large": "https://huggingface.co/google/bigbird-roberta-large/resolve/main/config.json",
    "google/bigbird-base-trivia-itc": "https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/config.json",
    # See all BigBird models at https://huggingface.co/models?filter=big_bird
}

class 	A_       (a_			):
	UpperCAmelCase__					=			'''big_bird'''
	def __init__(    self							,					_A=5_0_3_5_8							,					_A=7_6_8							,					_A=1_2							,					_A=1_2							,					_A=3_0_7_2							,					_A="gelu_new"							,					_A=0.1							,					_A=0.1							,					_A=4_0_9_6							,					_A=2							,					_A=0.02							,					_A=1E-12							,					_A=True							,					_A=0							,					_A=1							,					_A=2							,					_A=6_6							,					_A="block_sparse"							,					_A=True							,					_A=False							,					_A=6_4							,					_A=3							,					_A=None							,					**_A							,					):






				'''simple docstring'''







				super().__init__(
				    pad_token_id=_A							,					bos_token_id=_A							,					eos_token_id=_A							,					sep_token_id=_A							,					**_A							,					)

				UpperCAmelCase   		=				vocab_size
				UpperCAmelCase   		=				max_position_embeddings
				UpperCAmelCase   		=				hidden_size
				UpperCAmelCase   		=				num_hidden_layers
				UpperCAmelCase   		=				num_attention_heads
				UpperCAmelCase   		=				intermediate_size
				UpperCAmelCase   		=				hidden_act
				UpperCAmelCase   		=				hidden_dropout_prob
				UpperCAmelCase   		=				attention_probs_dropout_prob
				UpperCAmelCase   		=				initializer_range
				UpperCAmelCase   		=				type_vocab_size
				UpperCAmelCase   		=				layer_norm_eps
				UpperCAmelCase   		=				use_cache

				UpperCAmelCase   		=				rescale_embeddings
				UpperCAmelCase   		=				attention_type
				UpperCAmelCase   		=				use_bias
				UpperCAmelCase   		=				block_size
				UpperCAmelCase   		=				num_random_blocks
				UpperCAmelCase   		=				classifier_dropout

class 	A_       (a_			):
	@property
	def      _lowercase				(    self		):






				'''simple docstring'''







				if self.task == "multiple-choice":
							UpperCAmelCase   		=				{0: '''batch''', 1: '''choice''', 2: '''sequence'''}
				else:
							UpperCAmelCase   		=				{0: '''batch''', 1: '''sequence'''}
				return OrderedDict(
				    [
				        ('''input_ids''', dynamic_axis),
				        ('''attention_mask''', dynamic_axis),
				    ]		)



