


import warnings
from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType







class 	__lowercase    (__SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							_UpperCAmelCase      =						["""image_processor""", """tokenizer"""]
							_UpperCAmelCase      =						"""FlavaImageProcessor"""
							_UpperCAmelCase      =						("""BertTokenizer""", """BertTokenizerFast""")






							def __init__(      self			,						lowerCAmelCase__=None			,						lowerCAmelCase__=None			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Any					=					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__			,						)
													SCREAMING_SNAKE_CASE_		:     Any					=					kwargs.pop('feature_extractor'       )

										SCREAMING_SNAKE_CASE_		:     Any					=					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__       )
										SCREAMING_SNAKE_CASE_		:     Dict					=					self.image_processor






							def __call__(      self			,						lowerCAmelCase__ = None			,						lowerCAmelCase__ = None			,						lowerCAmelCase__ = True			,						lowerCAmelCase__ = False			,						lowerCAmelCase__ = False			,						lowerCAmelCase__ = None			,						lowerCAmelCase__ = 0			,						lowerCAmelCase__ = None			,						lowerCAmelCase__ = None			,						lowerCAmelCase__ = None			,						lowerCAmelCase__ = None			,						lowerCAmelCase__ = None			,						lowerCAmelCase__ = False			,						lowerCAmelCase__ = False			,						lowerCAmelCase__ = False			,						lowerCAmelCase__ = False			,						lowerCAmelCase__ = True			,						lowerCAmelCase__ = None			,						**lowerCAmelCase__			,						):





										"""simple docstring"""




										if text is None and images is None:
													raise ValueError('You have to specify either text or images. Both cannot be none.'       )

										if text is not None:
													SCREAMING_SNAKE_CASE_		:     Optional[int]					=					self.tokenizer(
													    text=lowerCAmelCase__			,						add_special_tokens=lowerCAmelCase__			,						padding=lowerCAmelCase__			,						truncation=lowerCAmelCase__			,						max_length=lowerCAmelCase__			,						stride=lowerCAmelCase__			,						pad_to_multiple_of=lowerCAmelCase__			,						return_token_type_ids=lowerCAmelCase__			,						return_attention_mask=lowerCAmelCase__			,						return_overflowing_tokens=lowerCAmelCase__			,						return_special_tokens_mask=lowerCAmelCase__			,						return_offsets_mapping=lowerCAmelCase__			,						return_length=lowerCAmelCase__			,						verbose=lowerCAmelCase__			,						return_tensors=lowerCAmelCase__			,						**lowerCAmelCase__			,						)
										if images is not None:
													SCREAMING_SNAKE_CASE_		:     int					=					self.image_processor(
													    lowerCAmelCase__			,						return_image_mask=lowerCAmelCase__			,						return_codebook_pixels=lowerCAmelCase__			,						return_tensors=lowerCAmelCase__			,						**lowerCAmelCase__			,						)

										if text is not None and images is not None:
													encoding.update(lowerCAmelCase__       )
													return encoding
										elif text is not None:
													return encoding
										else:
													return BatchEncoding(data=dict(**lowerCAmelCase__       )			,						tensor_type=lowerCAmelCase__       )






							def 					UpperCamelCase__     (      self			,						*lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										return self.tokenizer.batch_decode(*lowerCAmelCase__			,						**lowerCAmelCase__       )






							def 					UpperCamelCase__     (      self			,						*lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										return self.tokenizer.decode(*lowerCAmelCase__			,						**lowerCAmelCase__       )






							@property
							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     List[Any]					=					self.tokenizer.model_input_names
										SCREAMING_SNAKE_CASE_		:     Tuple					=					self.image_processor.model_input_names
										return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names       )       )






							@property
							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										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       ):





										"""simple docstring"""




										warnings.warn(
										    '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'			,						lowerCAmelCase__			,						)
										return self.image_processor









import copy
import os
from typing import Union

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


lowerCAmelCase__			:      Tuple								=logging.get_logger(__name__)

lowerCAmelCase__			:      Optional[int]								={
    'microsoft/git-base': 'https://huggingface.co/microsoft/git-base/resolve/main/config.json',
}







class 	__lowercase    (__SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							_UpperCAmelCase      =						"""git_vision_model"""






							def __init__(      self			,						lowerCAmelCase__=7_6_8			,						lowerCAmelCase__=3_0_7_2			,						lowerCAmelCase__=1_2			,						lowerCAmelCase__=1_2			,						lowerCAmelCase__=3			,						lowerCAmelCase__=2_2_4			,						lowerCAmelCase__=1_6			,						lowerCAmelCase__="quick_gelu"			,						lowerCAmelCase__=1E-5			,						lowerCAmelCase__=0.0			,						lowerCAmelCase__=0.02			,						**lowerCAmelCase__			,						):





										"""simple docstring"""




										super().__init__(**lowerCAmelCase__       )

										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					hidden_size
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					intermediate_size
										SCREAMING_SNAKE_CASE_		:     Any					=					num_hidden_layers
										SCREAMING_SNAKE_CASE_		:     Dict					=					num_attention_heads
										SCREAMING_SNAKE_CASE_		:     Tuple					=					num_channels
										SCREAMING_SNAKE_CASE_		:     Tuple					=					patch_size
										SCREAMING_SNAKE_CASE_		:     Any					=					image_size
										SCREAMING_SNAKE_CASE_		:     Dict					=					initializer_range
										SCREAMING_SNAKE_CASE_		:     List[str]					=					attention_dropout
										SCREAMING_SNAKE_CASE_		:     Any					=					layer_norm_eps
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					hidden_act






							@classmethod
							def 					UpperCamelCase__     (      cls			,						lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										cls._set_token_in_kwargs(lowerCAmelCase__       )

										SCREAMING_SNAKE_CASE_		,      SCREAMING_SNAKE_CASE_		:     List[str]					=					cls.get_config_dict(lowerCAmelCase__			,						**lowerCAmelCase__       )

										# get the vision config dict if we are loading from GITConfig
										if config_dict.get('model_type'       ) == "git":
													SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					config_dict['vision_config']

										if "model_type" in config_dict and hasattr(cls			,						'model_type'       ) and config_dict["model_type"] != cls.model_type:
													logger.warning(
													    F'''You are using a model of type {config_dict['model_type']} to instantiate a model of type '''
													    F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''       )

										return cls.from_dict(lowerCAmelCase__			,						**lowerCAmelCase__       )







class 	__lowercase    (__SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							_UpperCAmelCase      =						"""git"""






							def __init__(      self			,						lowerCAmelCase__=None			,						lowerCAmelCase__=3_0_5_2_2			,						lowerCAmelCase__=7_6_8			,						lowerCAmelCase__=6			,						lowerCAmelCase__=1_2			,						lowerCAmelCase__=3_0_7_2			,						lowerCAmelCase__="gelu"			,						lowerCAmelCase__=0.1			,						lowerCAmelCase__=0.1			,						lowerCAmelCase__=1_0_2_4			,						lowerCAmelCase__=0.02			,						lowerCAmelCase__=1E-12			,						lowerCAmelCase__=0			,						lowerCAmelCase__="absolute"			,						lowerCAmelCase__=True			,						lowerCAmelCase__=False			,						lowerCAmelCase__=1_0_1			,						lowerCAmelCase__=1_0_2			,						lowerCAmelCase__=None			,						**lowerCAmelCase__			,						):





										"""simple docstring"""




										super().__init__(bos_token_id=lowerCAmelCase__			,						eos_token_id=lowerCAmelCase__			,						pad_token_id=lowerCAmelCase__			,						**lowerCAmelCase__       )

										if vision_config is None:
													SCREAMING_SNAKE_CASE_		:     Dict					=					{}
													logger.info('vision_config is None. initializing the GitVisionConfig with default values.'       )

										SCREAMING_SNAKE_CASE_		:     str					=					GitVisionConfig(**lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Dict					=					vocab_size
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					hidden_size
										SCREAMING_SNAKE_CASE_		:     Tuple					=					num_hidden_layers
										SCREAMING_SNAKE_CASE_		:     Any					=					num_attention_heads
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					hidden_act
										SCREAMING_SNAKE_CASE_		:     Any					=					intermediate_size
										SCREAMING_SNAKE_CASE_		:     Tuple					=					hidden_dropout_prob
										SCREAMING_SNAKE_CASE_		:     str					=					attention_probs_dropout_prob
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					max_position_embeddings
										SCREAMING_SNAKE_CASE_		:     int					=					initializer_range
										SCREAMING_SNAKE_CASE_		:     int					=					layer_norm_eps
										SCREAMING_SNAKE_CASE_		:     List[str]					=					position_embedding_type
										SCREAMING_SNAKE_CASE_		:     List[str]					=					use_cache
										SCREAMING_SNAKE_CASE_		:     Any					=					tie_word_embeddings
										SCREAMING_SNAKE_CASE_		:     Dict					=					num_image_with_embedding

										SCREAMING_SNAKE_CASE_		:     List[str]					=					bos_token_id
										SCREAMING_SNAKE_CASE_		:     str					=					eos_token_id






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					copy.deepcopy(self.__dict__       )
										SCREAMING_SNAKE_CASE_		:     str					=					self.vision_config.to_dict()
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					self.__class__.model_type
										return output





