





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


_UpperCAmelCase				:       str	   =				logging.get_logger(__name__)

_UpperCAmelCase				:       int	   =				{
    """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							(					snake_case_			):
 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  :      Optional[Any]			,     UpperCAmelCase  :      Tuple=50265			,     UpperCAmelCase  :      int=1024			,     UpperCAmelCase  :      List[Any]=12			,     UpperCAmelCase  :      List[str]=16			,     UpperCAmelCase  :      Any=4096			,     UpperCAmelCase  :      Dict="gelu"			,     UpperCAmelCase  :      Union[str, Any]=512			,     UpperCAmelCase  :      int=0.1			,     UpperCAmelCase  :      Optional[Any]=0.0			,     UpperCAmelCase  :      List[Any]=0.0			,     UpperCAmelCase  :      str=2			,     UpperCAmelCase  :      Dict=0.0_2			,     UpperCAmelCase  :      List[Any]=0.0			,     UpperCAmelCase  :      str=True			,     UpperCAmelCase  :      List[str]=False			,     UpperCAmelCase  :      Any=True			,     UpperCAmelCase  :      Optional[int]=True			,     UpperCAmelCase  :      List[Any]=1			,     UpperCAmelCase  :      Optional[Any]=0			,     UpperCAmelCase  :      Optional[int]=2			,     **UpperCAmelCase  :      List[Any]			,     )			->	str:
     lowerCamelCase__    :      str					 =		vocab_size
     lowerCamelCase__    :      Optional[int]					 =		d_model
     lowerCamelCase__    :      List[Any]					 =		decoder_layers
     lowerCamelCase__    :      Optional[int]					 =		decoder_attention_heads
     lowerCamelCase__    :      Optional[int]					 =		decoder_ffn_dim
     lowerCamelCase__    :      int					 =		activation_function
     lowerCamelCase__    :      Any					 =		max_position_embeddings
     lowerCamelCase__    :      Dict					 =		dropout
     lowerCamelCase__    :      Any					 =		attention_dropout
     lowerCamelCase__    :      Tuple					 =		activation_dropout
     lowerCamelCase__    :      Optional[int]					 =		init_std
     lowerCamelCase__    :      Union[str, Any]					 =		decoder_layerdrop
     lowerCamelCase__    :      int					 =		use_cache
     lowerCamelCase__    :      Union[str, Any]					 =		scale_embedding
     lowerCamelCase__    :      List[str]					 =		use_learned_position_embeddings
     lowerCamelCase__    :      List[Any]					 =		layernorm_embedding

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












'''simple docstring'''

import importlib.metadata
import operator
import re
import sys
from typing import Optional

from packaging import version


lowercase_					= {
    """<""": operator.lt,
    """<=""": operator.le,
    """==""": operator.eq,
    """!=""": operator.ne,
    """>=""": operator.ge,
    """>""": operator.gt,
}





def lowerCamelCase						(     __lowerCamelCase :    Tuple					,       __lowerCamelCase :    Optional[Any]					,       __lowerCamelCase :    Dict					,       __lowerCamelCase :    List[Any]					,       __lowerCamelCase :    Optional[int]					,       __lowerCamelCase :    Optional[Any]    )						->Tuple:
    if got_ver is None or want_ver is None:
        raise ValueError(
            F'Unable to compare versions for {requirement}: need={want_ver} found={got_ver}. This is unusual. Consider'
            F' reinstalling {pkg}.'    )
    if not ops[op](version.parse(__lowerCamelCase    )					,       version.parse(__lowerCamelCase    )    ):
        raise ImportError(
            F'{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}'    )





def lowerCamelCase						(     __lowerCamelCase :    str					,       __lowerCamelCase :    Optional[str] = None    )						->None:
    _SCREAMING_SNAKE_CASE									=			F'\n{hint}' if hint is not None else """"""

    # non-versioned check
    if re.match(R"""^[\w_\-\d]+$"""					,       __lowerCamelCase    ):
        _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE									=			requirement, None, None
    else:
        _SCREAMING_SNAKE_CASE									=			re.findall(R"""^([^!=<>\s]+)([\s!=<>]{1,2}.+)"""					,       __lowerCamelCase    )
        if not match:
            raise ValueError(
                """requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but"""
                F' got {requirement}'    )
        _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE									=			match[0]
        _SCREAMING_SNAKE_CASE									=			want_full.split(""","""    )  # there could be multiple requirements
        _SCREAMING_SNAKE_CASE									=			{}
        for w in want_range:
            _SCREAMING_SNAKE_CASE									=			re.findall(R"""^([\s!=<>]{1,2})(.+)"""					,       __lowerCamelCase    )
            if not match:
                raise ValueError(
                    """requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23,"""
                    F' but got {requirement}'    )
            _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE									=			match[0]
            _SCREAMING_SNAKE_CASE									=			want_ver
            if op not in ops:
                raise ValueError(F'{requirement}: need one of {list(ops.keys()    )}, but got {op}'    )

    # special case
    if pkg == "python":
        _SCREAMING_SNAKE_CASE									=			""".""".join([str(__lowerCamelCase    ) for x in sys.version_info[:3]]    )
        for op, want_ver in wanted.items():
            _compare_versions(__lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase    )
        return

    # check if any version is installed
    try:
        _SCREAMING_SNAKE_CASE									=			importlib.metadata.version(__lowerCamelCase    )
    except importlib.metadata.PackageNotFoundError:
        raise importlib.metadata.PackageNotFoundError(
            F'The \'{requirement}\' distribution was not found and is required by this application. {hint}'    )

    # check that the right version is installed if version number or a range was provided
    if want_ver is not None:
        for op, want_ver in wanted.items():
            _compare_versions(__lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase    )






def lowerCamelCase						(     __lowerCamelCase :    Union[str, Any]    )						->str:
    _SCREAMING_SNAKE_CASE									=			"""Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git main"""
    return require_version(__lowerCamelCase					,       __lowerCamelCase    )



