





"""simple docstring"""






import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


A 			=  False
try:
		A 			=  _is_package_available('''google.colab''')
except ModuleNotFoundError:
		pass




@input.register
class 				__lowercase			:







					'''simple docstring'''




					def __init__(						self	,			_UpperCAmelCase = None	,			_UpperCAmelCase = []     ):
									__a :						str			       =  0
									__a :						Union[str, Any]			       =  choices
									__a :						Optional[int]			       =  prompt
									if sys.platform == "win32":
													__a :						List[Any]			       =  '''*'''
									else:
													__a :						Tuple			       =  '''➔ '''







					def  _lowerCamelCase		(						self	,			_UpperCAmelCase	,			_UpperCAmelCase = ""     ):
									if sys.platform != "win32":
													writeColor(self.choices[index]	,			32	,			_UpperCAmelCase     )
									else:
													forceWrite(self.choices[index]	,			_UpperCAmelCase     )







					def  _lowerCamelCase		(						self	,			_UpperCAmelCase     ):
									if index == self.position:
													forceWrite(f""" {self.arrow_char} """     )
													self.write_choice(_UpperCAmelCase     )
									else:
													forceWrite(f"""    {self.choices[index]}"""     )
									reset_cursor()







					def  _lowerCamelCase		(						self	,			_UpperCAmelCase	,			_UpperCAmelCase = 1     ):
									__a :						List[str]			       =  self.position
									if direction == Direction.DOWN:
													if self.position + 1 >= len(self.choices     ):
																	return
													self.position += num_spaces
									else:
													if self.position - 1 < 0:
																	return
													self.position -= num_spaces
									clear_line()
									self.print_choice(_UpperCAmelCase     )
									move_cursor(_UpperCAmelCase	,			direction.name     )
									self.print_choice(self.position     )







					@input.mark(KEYMAP['''up''']     )
					def  _lowerCamelCase		(						self     ):
									self.move_direction(Direction.UP     )







					@input.mark(KEYMAP['''down''']     )
					def  _lowerCamelCase		(						self     ):
									self.move_direction(Direction.DOWN     )







					@input.mark(KEYMAP['''newline''']     )
					def  _lowerCamelCase		(						self     ):
									move_cursor(len(self.choices     ) - self.position	,			'''DOWN'''     )
									return self.position







					@input.mark(KEYMAP['''interrupt''']     )
					def  _lowerCamelCase		(						self     ):
									move_cursor(len(self.choices     ) - self.position	,			'''DOWN'''     )
									raise KeyboardInterrupt







					@input.mark_multiple(*[KEYMAP[str(_UpperCAmelCase     )] for number in range(10     )]     )
					def  _lowerCamelCase		(						self     ):
									__a :						Tuple			       =  int(chr(self.current_selection     )     )
									__a :						Optional[Any]			       =  index - self.position
									if index == self.position:
													return
									if index < len(self.choices     ):
													if self.position > index:
																	self.move_direction(Direction.UP	,			-movement     )
													elif self.position < index:
																	self.move_direction(Direction.DOWN	,			_UpperCAmelCase     )
													else:
																	return
									else:
													return







					def  _lowerCamelCase		(						self	,			_UpperCAmelCase = 0     ):
									if self.prompt:
													linebreak()
													forceWrite(self.prompt	,			'''\n'''     )
													if in_colab:
																	forceWrite('''Please input a choice index (starting from 0), and press enter'''	,			'''\n'''     )
													else:
																	forceWrite('''Please select a choice using the arrow or number keys, and selecting with enter'''	,			'''\n'''     )
									__a :						List[Any]			       =  default_choice
									for i in range(len(self.choices     )     ):
													self.print_choice(_UpperCAmelCase     )
													forceWrite('''\n'''     )
									move_cursor(len(self.choices     ) - self.position	,			'''UP'''     )
									with cursor.hide():
													while True:
																	if in_colab:
																					try:
																									__a :						Optional[Any]			       =  int(builtins.input()     )
																					except ValueError:
																									__a :						Any			       =  default_choice
																	else:
																					__a :						Optional[Any]			       =  self.handle_input()
																	if choice is not None:
																					reset_cursor()
																					for _ in range(len(self.choices     ) + 1     ):
																									move_cursor(1	,			'''UP'''     )
																									clear_line()
																					self.write_choice(_UpperCAmelCase	,			'''\n'''     )
																					return choice






"""simple docstring"""






import copy
import os
from typing import Union

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


A 			=  logging.get_logger(__name__)

A 			=  {
    '''microsoft/git-base''': '''https://huggingface.co/microsoft/git-base/resolve/main/config.json''',
}




class 				__lowercase			(			_UpperCamelCase							):







					'''simple docstring'''




					__lowerCAmelCase  =  '''git_vision_model'''







					def __init__(						self	,			_UpperCAmelCase=768	,			_UpperCAmelCase=3072	,			_UpperCAmelCase=12	,			_UpperCAmelCase=12	,			_UpperCAmelCase=3	,			_UpperCAmelCase=224	,			_UpperCAmelCase=16	,			_UpperCAmelCase="quick_gelu"	,			_UpperCAmelCase=1e-5	,			_UpperCAmelCase=0.0	,			_UpperCAmelCase=0.0_2	,			**_UpperCAmelCase	,			):
									super().__init__(**_UpperCAmelCase     )

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







					@classmethod
					def  _lowerCamelCase		(						cls	,			_UpperCAmelCase	,			**_UpperCAmelCase     ):
									cls._set_token_in_kwargs(_UpperCAmelCase     )

									__a       ,						__a :						Dict			       =  cls.get_config_dict(_UpperCAmelCase	,			**_UpperCAmelCase     )

									# get the vision config dict if we are loading from GITConfig
									if config_dict.get('''model_type'''     ) == "git":
													__a :						int			       =  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(_UpperCAmelCase	,			**_UpperCAmelCase     )






class 				__lowercase			(			_UpperCamelCase							):







					'''simple docstring'''




					__lowerCAmelCase  =  '''git'''







					def __init__(						self	,			_UpperCAmelCase=None	,			_UpperCAmelCase=30522	,			_UpperCAmelCase=768	,			_UpperCAmelCase=6	,			_UpperCAmelCase=12	,			_UpperCAmelCase=3072	,			_UpperCAmelCase="gelu"	,			_UpperCAmelCase=0.1	,			_UpperCAmelCase=0.1	,			_UpperCAmelCase=1024	,			_UpperCAmelCase=0.0_2	,			_UpperCAmelCase=1e-1_2	,			_UpperCAmelCase=0	,			_UpperCAmelCase="absolute"	,			_UpperCAmelCase=True	,			_UpperCAmelCase=False	,			_UpperCAmelCase=101	,			_UpperCAmelCase=102	,			_UpperCAmelCase=None	,			**_UpperCAmelCase	,			):
									super().__init__(bos_token_id=_UpperCAmelCase	,			eos_token_id=_UpperCAmelCase	,			pad_token_id=_UpperCAmelCase	,			**_UpperCAmelCase     )

									if vision_config is None:
													__a :						Union[str, Any]			       =  {}
													logger.info('''vision_config is None. initializing the GitVisionConfig with default values.'''     )

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

									__a :						str			       =  bos_token_id
									__a :						Dict			       =  eos_token_id







					def  _lowerCamelCase		(						self     ):
									__a :						Optional[int]			       =  copy.deepcopy(self.__dict__     )
									__a :						int			       =  self.vision_config.to_dict()
									__a :						Tuple			       =  self.__class__.model_type
									return output