from typing import List

from .keymap import KEYMAP, get_character
def 					_snake_case	(  __snake_case						):

					def decorator(__snake_case						):
										_UpperCamelCase			     =     getattr(__snake_case  ,     '''handle_key'''  ,     []						)
										handle += [key]
										setattr(__snake_case  ,     '''handle_key'''  ,     __snake_case						)
										return func

					return decorator
def 					_snake_case	(  *__snake_case						):

					def decorator(__snake_case						):
										_UpperCamelCase			     =     getattr(__snake_case  ,     '''handle_key'''  ,     []						)
										handle += keys
										setattr(__snake_case  ,     '''handle_key'''  ,     __snake_case						)
										return func

					return decorator
class     lowerCAmelCase_     (       __lowercase ):







							def __new__(   cls      :     Optional[Any] ,			_A      :     Optional[Any] ,			_A      :     Optional[int] ,			_A      :     Union[str, Any]		):
												_UpperCamelCase			     =     super().__new__(cls ,			_A ,			_A ,			_A		)
												if not hasattr(_A ,			'''key_handler'''		):
																	setattr(_A ,			'''key_handler''' ,			{}		)
												setattr(_A ,			'''handle_input''' ,			KeyHandler.handle_input		)

												for value in attrs.values():
																	_UpperCamelCase			     =     getattr(_A ,			'''handle_key''' ,			[]		)
																	for key in handled_keys:
																						_UpperCamelCase			     =     value
												return new_cls







							@staticmethod
							def  UpperCamelCase_						(   cls      :     str		):
												_UpperCamelCase			     =     get_character()
												if char != KEYMAP["undefined"]:
																	_UpperCamelCase			     =     ord(_A		)
												_UpperCamelCase			     =     cls.key_handler.get(_A		)
												if handler:
																	_UpperCamelCase			     =     char
																	return handler(cls		)
												else:
																	return None




def 					_snake_case	(  cls						):
					return KeyHandler(cls.__name__  ,     cls.__bases__  ,     cls.__dict__.copy()						)

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


_lowerCAmelCase       =		logging.get_logger(__name__)

_lowerCAmelCase       =		{
    "microsoft/trocr-base-handwritten": (
        "https://huggingface.co/microsoft/trocr-base-handwritten/resolve/main/config.json"
    ),
    # See all TrOCR models at https://huggingface.co/models?filter=trocr
}
class     lowerCAmelCase_     (       __lowercase ):
							UpperCAmelCase				   =     "trocr"
							UpperCAmelCase				   =     ["past_key_values"]
							UpperCAmelCase				   =     {
							    "num_attention_heads": "decoder_attention_heads",
							    "hidden_size": "d_model",
							    "num_hidden_layers": "decoder_layers",
							}







							def __init__(   self      :     List[str] ,			_A      :     Optional[Any]=5_0265 ,			_A      :     Optional[Any]=1024 ,			_A      :     Optional[Any]=12 ,			_A      :     Any=16 ,			_A      :     Any=4096 ,			_A      :     Optional[Any]="gelu" ,			_A      :     Union[str, Any]=512 ,			_A      :     Dict=0.1 ,			_A      :     List[str]=0.0 ,			_A      :     Optional[Any]=0.0 ,			_A      :     Union[str, Any]=2 ,			_A      :     Any=0.02 ,			_A      :     List[str]=0.0 ,			_A      :     List[str]=True ,			_A      :     str=False ,			_A      :     List[str]=True ,			_A      :     Optional[Any]=True ,			_A      :     Optional[int]=1 ,			_A      :     int=0 ,			_A      :     Any=2 ,			**_A      :     Optional[int] ,			):
												_UpperCamelCase			     =     vocab_size
												_UpperCamelCase			     =     d_model
												_UpperCamelCase			     =     decoder_layers
												_UpperCamelCase			     =     decoder_attention_heads
												_UpperCamelCase			     =     decoder_ffn_dim
												_UpperCamelCase			     =     activation_function
												_UpperCamelCase			     =     max_position_embeddings
												_UpperCamelCase			     =     dropout
												_UpperCamelCase			     =     attention_dropout
												_UpperCamelCase			     =     activation_dropout
												_UpperCamelCase			     =     init_std
												_UpperCamelCase			     =     decoder_layerdrop
												_UpperCamelCase			     =     use_cache
												_UpperCamelCase			     =     scale_embedding
												_UpperCamelCase			     =     use_learned_position_embeddings
												_UpperCamelCase			     =     layernorm_embedding

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