


import json
import os
from typing import Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


lowerCAmelCase__			:      Tuple								=logging.get_logger(__name__)

lowerCAmelCase__			:      str								={'vocab_file': 'vocab.json'}

lowerCAmelCase__			:      Union[str, Any]								={
    'vocab_file': {
        'mgp-str': 'https://huggingface.co/alibaba-damo/mgp-str-base/blob/main/vocab.json',
    }
}

lowerCAmelCase__			:      str								={'mgp-str': 27}







class 	__lowercase    (__SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							_UpperCAmelCase      =						VOCAB_FILES_NAMES
							_UpperCAmelCase      =						PRETRAINED_VOCAB_FILES_MAP
							_UpperCAmelCase      =						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES






							def __init__(      self			,						lowerCAmelCase__			,						lowerCAmelCase__="[GO]"			,						lowerCAmelCase__="[GO]"			,						lowerCAmelCase__="[s]"			,						lowerCAmelCase__="[GO]"			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										super().__init__(
										    unk_token=lowerCAmelCase__			,						bos_token=lowerCAmelCase__			,						eos_token=lowerCAmelCase__			,						pad_token=lowerCAmelCase__			,						**lowerCAmelCase__			,						)

										with open(lowerCAmelCase__			,						encoding='utf-8'       ) as vocab_handle:
													SCREAMING_SNAKE_CASE_		:     int					=					json.load(lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					{v: k for k, v in self.vocab.items()}






							@property
							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										return len(self.vocab       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										return dict(self.vocab			,						**self.added_tokens_encoder       )






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Tuple					=					[]
										for s in text:
													char_tokens.extend(lowerCAmelCase__       )
										return char_tokens






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__       ):





										"""simple docstring"""




										return self.vocab.get(lowerCAmelCase__			,						self.vocab.get(self.unk_token       )       )






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__       ):





										"""simple docstring"""




										return self.decoder.get(lowerCAmelCase__       )






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__			,						lowerCAmelCase__ = None       ):





										"""simple docstring"""




										if not os.path.isdir(lowerCAmelCase__       ):
													logger.error('Vocabulary path ({}) should be a directory'.format(lowerCAmelCase__       )       )
													return
										SCREAMING_SNAKE_CASE_		:     List[str]					=					os.path.join(
										    lowerCAmelCase__			,						(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']       )

										with open(lowerCAmelCase__			,						'w'			,						encoding='utf-8'       ) as f:
													f.write(json.dumps(self.vocab			,						indent=2			,						sort_keys=lowerCAmelCase__			,						ensure_ascii=lowerCAmelCase__       ) + '\n'       )

										return (vocab_file,)









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





