ó
    >:j™  ã                  óN   • S SK Jr  S SKrS SKJr  S SKrS SKJr   " S S\5      rg)é    )ÚannotationsN)ÚOrderedDict)ÚModulec                  óˆ   ^ • \ rS rSrSrSSU 4S jjjrS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rSrU =r$ )Ú
BufferDicté   a  
Holds buffers in a dictionary.

BufferDict can be indexed like a regular Python dictionary, but buffers it contains are properly registered, and
will be visible by all Module methods. `torch.nn.BufferDict` is an **ordered** dictionary that respects

* the order of insertion, and
* in `torch.nn.BufferDict.update`, the order of the merged `OrderedDict` or another `torch.nn.BufferDict` (the
  argument to `torch.nn.BufferDict.update`).

Note that `torch.nn.BufferDict.update` with other unordered mapping types (e.g., Python's plain `dict`) does not
preserve the order of the merged mapping.

Args:
    buffers (iterable, optional):
        a mapping (dictionary) of (string : `torch.Tensor`) or an iterable of key-value pairs of type (string,
        `torch.Tensor`)

```python
class MyModule(nn.Module):
    def __init__(self):
        super().__init__()
        self.buffers = nn.BufferDict({"left": torch.randn(5, 10), "right": torch.randn(5, 10)})

    def forward(self, x, choice):
        x = self.buffers[choice].mm(x)
        return x
```
c                óX   >• [         TU ]  5         X l        Ub  U R                  U5        gg)z§
Args:
    buffers (`dict`):
        A mapping (dictionary) from string to `torch.Tensor`, or an iterable of key-value pairs of type
        (string, `torch.Tensor`).
N)ÚsuperÚ__init__Ú
persistentÚupdate)ÚselfÚbuffersr   Ú	__class__s      €ÚU/home/mande/repo/quber/.venv/lib/python3.13/site-packages/peft/tuners/_buffer_dict.pyr   ÚBufferDict.__init__2   s,   ø€ ô 	‰ÑÔØ$ŒàÑØ�K‰K˜Õ ð ó    c                ó    • U R                   U   $ ©N©Ú_buffers©r   Úkeys     r   Ú__getitem__ÚBufferDict.__getitem__?   s   € Ø�}‰}˜SÑ!Ð!r   c                ó8   • U R                  XU R                  S9  g )N©r   )Úregister_bufferr   )r   r   Úbuffers      r   Ú__setitem__ÚBufferDict.__setitem__B   s   € Ø×Ñ˜S°T·_±_ÐÒEr   c                ó   • U R                   U	 g r   r   r   s     r   Ú__delitem__ÚBufferDict.__delitem__E   s   € Ø�M‰M˜#Ñr   c                ó,   • [        U R                  5      $ r   )Úlenr   ©r   s    r   Ú__len__ÚBufferDict.__len__H   s   € Ü�4—=‘=Ó!Ð!r   c                óH   • [        U R                  R                  5       5      $ r   )Úiterr   Úkeysr'   s    r   Ú__iter__ÚBufferDict.__iter__K   s   € Ü�D—M‘M×&Ñ&Ó(Ó)Ð)r   c                ó   • XR                   ;   $ r   r   r   s     r   Ú__contains__ÚBufferDict.__contains__N   s   € Ø—m‘mÑ#Ð#r   c                ó8   • U R                   R                  5         g)z%Remove all items from the BufferDict.N)r   Úclearr'   s    r   r3   ÚBufferDict.clearQ   s   € à�‰×ÑÕr   c                ó   • X   nX	 U$ )zuRemove key from the BufferDict and return its buffer.

Args:
    key (`str`):
        Key to pop from the BufferDict
© )r   r   Úvs      r   ÚpopÚBufferDict.popU   s   € ð ‰IˆØˆIØˆr   c                ó6   • U R                   R                  5       $ )z*Return an iterable of the BufferDict keys.)r   r,   r'   s    r   r,   ÚBufferDict.keys`   s   € à�}‰}×!Ñ!Ó#Ð#r   c                ó6   • U R                   R                  5       $ )z5Return an iterable of the BufferDict key/value pairs.)r   Úitemsr'   s    r   r=   ÚBufferDict.itemsd   s   € à�}‰}×"Ñ"Ó$Ð$r   c                ó6   • U R                   R                  5       $ )z,Return an iterable of the BufferDict values.)r   Úvaluesr'   s    r   r@   ÚBufferDict.valuesh   s   € à�}‰}×#Ñ#Ó%Ð%r   c           	     ó  • [        U[        R                  R                  5      (       d!  [	        S[        U5      R                  -   5      e[        U[        [        45      (       a  UR                  5        H	  u  p#X0U'   M     g	[        U[        R                  R                  5      (       a'  [        UR                  5       5       H	  u  p#X0U'   M     g	[        U5       H©  u  pE[        U[        R                  R                  5      (       d0  [	        S[        U5      -   S-   [        U5      R                  -   5      e[        U5      S:X  d2  [        S[        U5      -   S-   [        [        U5      5      -   S-   5      eUS   XS   '   M«     g	)
a¹  
Update the `torch.nn.BufferDict` with the key-value pairs from a mapping or an iterable, overwriting existing
keys.

Note:
    If `buffers` is an `OrderedDict`, a `torch.nn.BufferDict`, or an iterable of key-value pairs, the order of
    new elements in it is preserved.

Args:
    buffers (iterable):
        a mapping (dictionary) from string to `torch.Tensor`, or an iterable of key-value pairs of type
        (string, `torch.Tensor`).
zQBuffersDict.update should be called with an iterable of key/value pairs, but got z$BufferDict update sequence element #z should be Iterable; isé   z has length z; 2 is requiredé   r   N)Ú
isinstanceÚcollectionsÚabcÚIterableÚ	TypeErrorÚtypeÚ__name__r   r   r=   ÚMappingÚsortedÚ	enumerateÚstrr&   Ú
ValueError)r   r   r   r   ÚjÚps         r   r   ÚBufferDict.updatel   s[  € ô ˜'¤;§?¡?×#;Ñ#;×<Ñ<Üð8Ü:>¸w»-×:PÑ:PñQóð ô
 �g¤¬ZÐ8×9Ñ9Ø&Ÿ}™}ž‘�Ø"�S“	ò  /ä˜¤§¡×!8Ñ!8×9Ñ9Ü% g§m¡m£oÖ6‘�Ø"�S“	ò  7ô " 'Ö*‘�Ü! !¤[§_¡_×%=Ñ%=×>Ñ>Ü#Ø>ÄÀQÃÑGÐJcÑcÔfjÐklÓfm×fvÑfvÑvóð ô ˜1“v “{Ü$ðÜ! !›fñ%Ø'5ñ6Ü8;¼CÀ»F»ñDØFWñXóð ð ˜q™T��q‘T“
ò +r   c                ó¶  • / nU R                   R                  5        H§  u  p#SR                  S UR                  5        5       5      nUR                  R
                  nUS:X  a  SO$SUR                  5        SUR                  5        S3nS[        R                  " U5       S	U U S
3nUR                  SU-   S-   U-   5        M©     SR                  U5      nU$ )NÚxc              3  ó8   #   • U  H  n[        U5      v •  M     g 7fr   )rO   )Ú.0Úsizes     r   Ú	<genexpr>Ú(BufferDict.extra_repr.<locals>.<genexpr>–   s   é € Ð?²h¨d¤ D§	 	²hùs   ‚ÚcpuÚ z (Ú Ú)zBuffer containing: [z	 of size Ú]z  (z): Ú
)r   r=   ÚjoinrX   ÚdevicerJ   ÚupperÚ
get_deviceÚtorchÚtypenameÚappend)	r   Úchild_linesÚkrR   Úsize_strÚdevice_typeÚ
device_strÚparastrÚtmpstrs	            r   Ú
extra_reprÚBufferDict.extra_repr“   sÑ   € ØˆØ—M‘M×'Ñ'Ö)‰DˆAØ—x‘xÑ?°a·f±f´hÓ?Ó?ˆHØŸ(™(Ÿ-™-ˆKØ*¨eÓ3™¸2¸k×>OÑ>OÓ>QÐ=RÐRSÐTU×T`ÑT`ÓTbÐScÐcdÐ9eˆJØ,¬U¯^ª^¸AÓ->Ð,?¸yÈÈ
ÐS]ÐR^Ð^_Ð`ˆGØ×Ñ˜u q™y¨5Ñ0°7Ñ:Ö;ñ *ð —‘˜;Ó'ˆØˆr   c                ó   • [        S5      e)Nz BufferDict should not be called.)ÚRuntimeError)r   Úinputs     r   Ú__call__ÚBufferDict.__call__ž   s   € ÜÐ=Ó>Ð>r   r   )NF)r   Úbool)rK   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r    r#   r(   r-   r0   r3   r8   r,   r=   r@   r   ro   rt   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      s_   ø† ñ÷<!ñ !ò"òFòò"ò*ò$òò	ò$ò%ò&ò%"òN	÷?ð ?r   r   )Ú
__future__r   rF   r   re   Útorch.nnr   r   r6   r   r   Ú<module>r      s$   ðõ #ã Ý #ã Ý ôL?�õ L?r   