



from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

a_			=					TypeVar("""T""")
a_			=					TypeVar("""U""")



class  __lowerCAmelCase     (	Generic[T, U]   ):




 def __init__(						self	,				__UpperCAmelCase	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    key
    __lowerCamelCase													=    val
    __lowerCamelCase													=    None
    __lowerCamelCase													=    None




 def __repr__(						self				):



    '''simple docstring'''
    return (
        F"""Node: key: {self.key}, val: {self.val}, """
        F"""has next: {bool(self.next				)}, has prev: {bool(self.prev				)}"""
    )



class  __lowerCAmelCase     (	Generic[T, U]   ):




 def __init__(						self				):



    '''simple docstring'''
    __lowerCamelCase													=    DoubleLinkedListNode(__UpperCAmelCase	,				__UpperCAmelCase				)
    __lowerCamelCase													=    DoubleLinkedListNode(__UpperCAmelCase	,				__UpperCAmelCase				)
    __lowerCamelCase							,__lowerCamelCase													=    self.rear, self.head




 def __repr__(						self				):



    '''simple docstring'''
    __lowerCamelCase													=    ['''DoubleLinkedList''']
    __lowerCamelCase													=    self.head
    while node.next is not None:
       rep.append(str(__UpperCAmelCase				)				)
       __lowerCamelCase													=    node.next
    rep.append(str(self.rear				)				)
    return ",\n    ".join(__UpperCAmelCase				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    self.rear.prev

    # All nodes other than self.head are guaranteed to have non-None previous
    assert previous is not None

    __lowerCamelCase													=    node
    __lowerCamelCase													=    previous
    __lowerCamelCase													=    node
    __lowerCamelCase													=    self.rear




 def        lowerCamelCase      (						self	,				__UpperCAmelCase				):



    '''simple docstring'''

    if node.prev is None or node.next is None:
       return None

    __lowerCamelCase													=    node.next
    __lowerCamelCase													=    node.prev
    __lowerCamelCase													=    None
    __lowerCamelCase													=    None
    return node



class  __lowerCAmelCase     (	Generic[T, U]   ):
 lowerCAmelCase__       					=  {}




 def __init__(						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    DoubleLinkedList()
    __lowerCamelCase													=    capacity
    __lowerCamelCase													=    0
    __lowerCamelCase													=    0
    __lowerCamelCase													=    0
    __lowerCamelCase													=    {}




 def __repr__(						self				):



    '''simple docstring'''
    return (
        F"""CacheInfo(hits={self.hits}, misses={self.miss}, """
        F"""capacity={self.capacity}, current size={self.num_keys})"""
    )




 def __contains__(						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    return key in self.cache




 def        lowerCamelCase      (						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    # Note: pythonic interface would throw KeyError rather than return None

    if key in self.cache:
       self.hits += 1
       __lowerCamelCase													=    self.cache[key]
       __lowerCamelCase													=    self.list.remove(self.cache[key]				)
       assert node == value_node

       # node is guaranteed not None because it is in self.cache
       assert node is not None
       self.list.add(__UpperCAmelCase				)
       return node.val
    self.miss += 1
    return None




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase				):



    '''simple docstring'''

    if key not in self.cache:
       if self.num_keys >= self.capacity:
          # delete first node (oldest) when over capacity
          __lowerCamelCase													=    self.list.head.next

          # guaranteed to have a non-None first node when num_keys > 0
          # explain to type checker via assertions
          assert first_node is not None
          assert first_node.key is not None
          assert (
              self.list.remove(__UpperCAmelCase				) is not None
          )  # node guaranteed to be in list assert node.key is not None

          del self.cache[first_node.key]
          self.num_keys -= 1
       __lowerCamelCase													=    DoubleLinkedListNode(__UpperCAmelCase	,				__UpperCAmelCase				)
       self.list.add(self.cache[key]				)
       self.num_keys += 1

    else:
       # bump node to the end of the list, update value
       __lowerCamelCase													=    self.list.remove(self.cache[key]				)
       assert node is not None  # node guaranteed to be in list
       __lowerCamelCase													=    value
       self.list.add(__UpperCAmelCase				)




 @classmethod
 def        lowerCamelCase      (						cls	,				__UpperCAmelCase = 128				):



    '''simple docstring'''

    def cache_decorator_inner(__UpperCAmelCase				) -> Callable[..., U]:
       def cache_decorator_wrapper(*__UpperCAmelCase				) -> U:
          if func not in cls.decorator_function_to_instance_map:
             __lowerCamelCase													=    LRUCache(__UpperCAmelCase				)

          __lowerCamelCase													=    cls.decorator_function_to_instance_map[func].get(args[0]				)
          if result is None:
             __lowerCamelCase													=    func(*__UpperCAmelCase				)
             cls.decorator_function_to_instance_map[func].put(args[0]	,				__UpperCAmelCase				)
          return result

       def cache_info() -> LRUCache[T, U]:
          return cls.decorator_function_to_instance_map[func]

       setattr(__UpperCAmelCase	,				'''cache_info'''	,				__UpperCAmelCase				)  # noqa: B010

       return cache_decorator_wrapper

    return cache_decorator_inner


if __name__ == "__main__":
  import doctest

  doctest.testmod()











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


a_			=					logging.get_logger(__name__)

a_			=					{
    """unc-nlp/lxmert-base-uncased""": """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/config.json""",
}



class  __lowerCAmelCase     (	lowerCAmelCase__   ):
 lowerCAmelCase__       					=  """lxmert"""
 lowerCAmelCase__       					=  {}




 def __init__(						self	,				__UpperCAmelCase=30522	,				__UpperCAmelCase=768	,				__UpperCAmelCase=12	,				__UpperCAmelCase=9500	,				__UpperCAmelCase=1600	,				__UpperCAmelCase=400	,				__UpperCAmelCase=3072	,				__UpperCAmelCase="gelu"	,				__UpperCAmelCase=0.1	,				__UpperCAmelCase=0.1	,				__UpperCAmelCase=512	,				__UpperCAmelCase=2	,				__UpperCAmelCase=0.02	,				__UpperCAmelCase=1E-1_2	,				__UpperCAmelCase=9	,				__UpperCAmelCase=5	,				__UpperCAmelCase=5	,				__UpperCAmelCase=2048	,				__UpperCAmelCase=4	,				__UpperCAmelCase=6.67	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				**__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    vocab_size
    __lowerCamelCase													=    hidden_size
    __lowerCamelCase													=    num_attention_heads
    __lowerCamelCase													=    hidden_act
    __lowerCamelCase													=    intermediate_size
    __lowerCamelCase													=    hidden_dropout_prob
    __lowerCamelCase													=    attention_probs_dropout_prob
    __lowerCamelCase													=    max_position_embeddings
    __lowerCamelCase													=    type_vocab_size
    __lowerCamelCase													=    initializer_range
    __lowerCamelCase													=    layer_norm_eps
    __lowerCamelCase													=    num_qa_labels
    __lowerCamelCase													=    num_object_labels
    __lowerCamelCase													=    num_attr_labels
    __lowerCamelCase													=    l_layers
    __lowerCamelCase													=    x_layers
    __lowerCamelCase													=    r_layers
    __lowerCamelCase													=    visual_feat_dim
    __lowerCamelCase													=    visual_pos_dim
    __lowerCamelCase													=    visual_loss_normalizer
    __lowerCamelCase													=    task_matched
    __lowerCamelCase													=    task_mask_lm
    __lowerCamelCase													=    task_obj_predict
    __lowerCamelCase													=    task_qa
    __lowerCamelCase													=    visual_obj_loss
    __lowerCamelCase													=    visual_attr_loss
    __lowerCamelCase													=    visual_feat_loss
    __lowerCamelCase													=    {'''vision''': r_layers, '''cross_encoder''': x_layers, '''language''': l_layers}
    super().__init__(**__UpperCAmelCase				)






