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	):
      A__		     =		'trocr'
      A__		     =		['past_key_values']
      A__		     =		{
          'num_attention_heads': 'decoder_attention_heads',
          'hidden_size': 'd_model',
          'num_hidden_layers': 'decoder_layers',
      }

      def __init__(   self      ,				__UpperCAmelCase=5_0265      ,				__UpperCAmelCase=1024      ,				__UpperCAmelCase=12      ,				__UpperCAmelCase=16      ,				__UpperCAmelCase=4096      ,				__UpperCAmelCase="gelu"      ,				__UpperCAmelCase=512      ,				__UpperCAmelCase=0.1      ,				__UpperCAmelCase=0.0      ,				__UpperCAmelCase=0.0      ,				__UpperCAmelCase=2      ,				__UpperCAmelCase=0.02      ,				__UpperCAmelCase=0.0      ,				__UpperCAmelCase=True      ,				__UpperCAmelCase=False      ,				__UpperCAmelCase=True      ,				__UpperCAmelCase=True      ,				__UpperCAmelCase=1      ,				__UpperCAmelCase=0      ,				__UpperCAmelCase=2      ,				**__UpperCAmelCase      ,				):
        lowerCAmelCase__				:  Tuple		       =     vocab_size
        lowerCAmelCase__				:  Any		       =     d_model
        lowerCAmelCase__				:  Optional[Any]		       =     decoder_layers
        lowerCAmelCase__				:  Tuple		       =     decoder_attention_heads
        lowerCAmelCase__				:  List[Any]		       =     decoder_ffn_dim
        lowerCAmelCase__				:  Any		       =     activation_function
        lowerCAmelCase__				:  Optional[int]		       =     max_position_embeddings
        lowerCAmelCase__				:  Union[str, Any]		       =     dropout
        lowerCAmelCase__				:  Dict		       =     attention_dropout
        lowerCAmelCase__				:  Any		       =     activation_dropout
        lowerCAmelCase__				:  Any		       =     init_std
        lowerCAmelCase__				:  int		       =     decoder_layerdrop
        lowerCAmelCase__				:  Optional[int]		       =     use_cache
        lowerCAmelCase__				:  Optional[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      ,				)







from collections.abc import Callable






class  _lowerCAmelCase     :

      def __init__(   self      ,				__UpperCAmelCase = None		):
        # Stores actual heap items.
        lowerCAmelCase__				:  list		       =     []
        # Stores indexes of each item for supporting updates and deletion.
        lowerCAmelCase__				:  dict		       =     {}
        # Stores current size of heap.
        lowerCAmelCase__				:  Any		       =     0
        # Stores function used to evaluate the score of an item on which basis ordering
        # will be done.
        lowerCAmelCase__				:  Union[str, Any]		       =     key or (lambda __UpperCAmelCase		: x)

      def 	__magic_name__(   self      ,				__UpperCAmelCase		):
        return int((i - 1) / 2		) if i > 0 else None

      def 	__magic_name__(   self      ,				__UpperCAmelCase		):
        lowerCAmelCase__				:  Optional[Any]		       =     int(2 * i + 1		)
        return left if 0 < left < self.size else None

      def 	__magic_name__(   self      ,				__UpperCAmelCase		):
        lowerCAmelCase__				:  List[str]		       =     int(2 * i + 2		)
        return right if 0 < right < self.size else None

      def 	__magic_name__(   self      ,				__UpperCAmelCase      ,				__UpperCAmelCase		):
        lowerCAmelCase__       ,			lowerCAmelCase__				:  List[str]		       =     (
            self.pos_map[self.arr[j][0]],
            self.pos_map[self.arr[i][0]],
        )
        # Then swap the items in the list.
        lowerCAmelCase__       ,			lowerCAmelCase__				:  Any		       =     self.arr[j], self.arr[i]

      def 	__magic_name__(   self      ,				__UpperCAmelCase      ,				__UpperCAmelCase		):
        return self.arr[i][1] < self.arr[j][1]

      def 	__magic_name__(   self      ,				__UpperCAmelCase		):
        lowerCAmelCase__				:  Optional[int]		       =     self._left(__UpperCAmelCase		)
        lowerCAmelCase__				:  Any		       =     self._right(__UpperCAmelCase		)
        lowerCAmelCase__				:  str		       =     i

        if left is not None and not self._cmp(__UpperCAmelCase      ,				__UpperCAmelCase		):
          lowerCAmelCase__				:  Dict		       =     left
        if right is not None and not self._cmp(__UpperCAmelCase      ,				__UpperCAmelCase		):
          lowerCAmelCase__				:  List[str]		       =     right

        return valid_parent

      def 	__magic_name__(   self      ,				__UpperCAmelCase		):
        lowerCAmelCase__				:  Tuple		       =     self._parent(__UpperCAmelCase		)
        while parent is not None and not self._cmp(__UpperCAmelCase      ,				__UpperCAmelCase		):
          self._swap(__UpperCAmelCase      ,				__UpperCAmelCase		)
          lowerCAmelCase__       ,			lowerCAmelCase__				:  Dict		       =     parent, self._parent(__UpperCAmelCase		)

      def 	__magic_name__(   self      ,				__UpperCAmelCase		):
        lowerCAmelCase__				:  str		       =     self._get_valid_parent(__UpperCAmelCase		)
        while valid_parent != index:
          self._swap(__UpperCAmelCase      ,				__UpperCAmelCase		)
          lowerCAmelCase__       ,			lowerCAmelCase__				:  List[Any]		       =     valid_parent, self._get_valid_parent(__UpperCAmelCase		)

      def 	__magic_name__(   self      ,				__UpperCAmelCase      ,				__UpperCAmelCase		):
        if item not in self.pos_map:
          return
        lowerCAmelCase__				:  Tuple		       =     self.pos_map[item]
        lowerCAmelCase__				:  Any		       =     [item, self.key(__UpperCAmelCase		)]
        # Make sure heap is right in both up and down direction.
        # Ideally only one of them will make any change.
        self._heapify_up(__UpperCAmelCase		)
        self._heapify_down(__UpperCAmelCase		)

      def 	__magic_name__(   self      ,				__UpperCAmelCase		):
        if item not in self.pos_map:
          return
        lowerCAmelCase__				:  Tuple		       =     self.pos_map[item]
        del self.pos_map[item]
        lowerCAmelCase__				:  Tuple		       =     self.arr[self.size - 1]
        lowerCAmelCase__				:  int		       =     index
        self.size -= 1
        # Make sure heap is right in both up and down direction. Ideally only one
        # of them will make any change- so no performance loss in calling both.
        if self.size > index:
          self._heapify_up(__UpperCAmelCase		)
          self._heapify_down(__UpperCAmelCase		)

      def 	__magic_name__(   self      ,				__UpperCAmelCase      ,				__UpperCAmelCase		):
        lowerCAmelCase__				:  Optional[int]		       =     len(self.arr		)
        if arr_len == self.size:
          self.arr.append([item, self.key(__UpperCAmelCase		)]		)
        else:
          lowerCAmelCase__				:  str		       =     [item, self.key(__UpperCAmelCase		)]
        lowerCAmelCase__				:  Optional[Any]		       =     self.size
        self.size += 1
        self._heapify_up(self.size - 1		)

      def 	__magic_name__(   self		):
        return self.arr[0] if self.size else None







      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  int		       =     self.get_top()
        if top_item_tuple:
          self.delete_item(top_item_tuple[0]		)
        return top_item_tuple



def      __lowerCAmelCase			(					)     ->	None:
  pass


if __name__ == "__main__":
     import doctest

     doctest.testmod()

