+
    "Ý³j¦  ã                   óÆ   € ^ RI Ht ^ RIHtHtHtHtHt ^ RIt^ RI	H
t
 ^ RIHt ]! R R 4       4      tR R ltR R	 ltRR
 R lltRR R lltRR R lltR R ltR tR# )é    )Údefaultdict)ÚDictÚListÚOptionalÚTupleÚUnionN)Úconvert_bytesc              #   ór   "  € T F-  p\        \        V4      '       g   K  \        \        V4      x € K/  	  R # 5i)N)ÚhasattrÚtorchÚgetattr)Ú.0Únames   & ÚU/home/luca/screen-checking/.venv/lib/python3.14/site-packages/gptqmodel/utils/vram.pyÚ	<genexpr>r      s3   é € ð $ñˆô Œu�d×ô „GŒE�4×Ðóùs   ‚7Ÿ7c                ó8   € V ^8„  d   QhR\         P                  /# )é   Údtype)r   r   )Úformats   "r   Ú__annotate__r      s   € ÷ Dñ Dœ5Ÿ;™;ñ Dó    c                óN  € V \         P                  8X  d   R# V R8X  d   R# V R8X  d   R# V R8X  d   ^# V \        9   d   ^# V \         P                  8X  g   V \         P                  8X  d   ^# V \         P
                  8X  g   V \         P                  8X  d   ^# \        RV  R24      h)	z‚
Returns the size (in bytes) occupied by one parameter of type `dtype`.

Example:

```py
>>> dtype_byte_size(torch.float32)
4
```
Úint2Úint4Úfp8z`dtype` is not a valid dtype: Ú.g      À?g      Ð?g      à?)r   ÚboolÚ_ONE_BYTE_FLOATX_DTYPESÚfloat16Úbfloat16Úfloat32Úint32Ú
ValueError©r   s   &r   Údtype_byte_sizer%      sŒ   € ð ”—
‘
ÔØˆØ	�&ŒØˆØ	�&ŒØˆØ	�%ŒÙØ	Ô)Ô	)ÙØ	”%—-‘-Ô	 5¬E¯N©NÔ#:ÙØ	”%—-‘-Ô	 5¬E¯K©KÔ#7ÙäÐ9¸%¸ÀÐBÓCÐCr   c                óz   € V ^8„  d   QhR\         \        \        P                  3,          R\        P                  /# )r   r   Úreturn)r   Ústrr   Údevicer   )r   s   "r   r   r   8   s,   € ÷ ñ œU¤3¬¯©Ð#4Õ5ð ¼%¿+¹+ñ r   c                óv   € \        V \        4      '       d#   V P                  RR4      p \        \        V 4      p V # )z,
Just does torch.dtype(dtype) if necessary.
ztorch.Ú )Ú
isinstancer(   Úreplacer   r   r$   s   &r   Ú_get_proper_dtyper.   8   s2   € ô �%œ×Òà—‘˜h¨Ó+ˆÜœ˜uÓ%ˆØ€Lr   c                ó\   € V ^8„  d   QhR\         P                  R\        R\        R\        /# )r   ÚmoduleÚinclude_buffersÚrecurseÚremove_non_persistent©ÚnnÚModuler   )r   s   "r   r   r   B   s0   € ÷ #ñ #Ü�I‰Ið#Ü(,ð#Ü>Bð#Ücgñ#r   c              #  óè   "  € V P                  VR7       Rj  x€L
  V'       dJ   \        4       pV'       d   \        WR7      pV P                  VR7       F  pVw  rgWd9  g   K  Vx € K  	  R# R#  LW5i)a  
A helper function that gathers all the tensors (parameters + buffers) of a given module. If `include_buffers=True`
it's the same as doing `module.named_parameters(recurse=recurse) + module.named_buffers(recurse=recurse)`.

Args:
    module (`torch.nn.Module`):
        The module we want the tensors on.
    include_buffer (`bool`, *optional*, defaults to `True`):
        Whether or not to include the buffers in the result.
    recurse (`bool`, *optional`, defaults to `False`):
        Whether or not to go look in every submodule or just return the direct parameters and buffers.
    remove_non_persistent (`bool`, *optional*, defaults to `False`):
        Whether or not to remove the non persistent buffer from the buffers. Useful only when include_buffers =
        True
©r2   N)Únamed_parametersÚsetÚget_non_persistent_buffersÚnamed_buffers)r0   r1   r2   r3   Únon_persistent_buffersÚnamed_bufferr   Ú_s   &&&&    r   Únamed_module_tensorsr@   B   sm   é € ð$ ×&Ñ&¨wÐ&Ó7×7Ð7çÜ!$£Ðß Ü%?ÀÔ%XÐ"Ø"×0Ñ0¸Ð0ÖAˆLØ"‰GˆDØÖ1Ø"Ô"ó Bñ	 ñ 8ùs   ‚A2˜A0™A2¥:A2Á$A2c                óD   € V ^8„  d   QhR\         P                  R\        /# )r   r0   r2   r4   )r   s   "r   r   r   _   s   € ÷ &ñ &¤r§y¡yð &¼4ñ &r   c                ó„   € V P                   pV'       d,   V P                  4        F  w  r4W$P                   ,          pK  	  V# )a:  
Gather all non persistent buffers of a given modules into a set

Args:
    module (`nn.Module`):
        The module we want the non persistent buffers on.
    recurse (`bool`, *optional*, defaults to `False`):
        Whether or not to go look in every submodule or just return the direct non persistent buffers.
)Ú_non_persistent_buffers_setÚnamed_modules)r0   r2   Únon_persistent_buffers_setr?   Úms   &&   r   r;   r;   _   s?   € ð "(×!CÑ!CÐßØ×(Ñ(Ö*‰DˆAØ&×*GÑ*GÕGÒ&ñ +ð &Ð%r   c                ó  € V ^8„  d   QhR\         P                  R\        \        \        \
        P                  3,          ,          R\        \        \        \        \        \
        P                  3,          3,          ,          R\        /# )r   Úmodelr   Úspecial_dtypesÚbuffers_only)	r5   r6   r   r   r(   r   r)   r   r   )r   s   "r   r   r   r   sd   € ÷ %ñ %Ü�9‰9ð%ä”Eœ#œuŸ|™|Ð+Õ,Õ-ð%ô œT¤#¤u¬S´%·,±,Ð->Õ'?Ð"?Õ@ÕAð%ô ñ	%r   c                ó  € Ve   \        V4      p\        V4      pVe[   VP                  4        UUu/ uF  w  rVV\        V4      bK  	  pppVP                  4        UUu/ uF  w  rVV\        V4      bK  	  ppp\        \        4      pV'       g   \        V RR7      p	MV P                  RR7      p	V	 EFA  w  r«Ve&   W¢9   d    VP                  4       XV
,          ,          pM¸Vf,   VP                  4       \        VP                  4      ,          pM‰\        VP                  4      P                  R4      '       d,   VP                  4       \        VP                  4      ,          pM4VP                  4       \        X\        VP                  4      4      ,          pV
P                  R4      p\        \        V4      ^,           4       F*  pVRP                  VRV 4      ;;,          V,          uu&   K,  	  EKD  	  V# u uppi u uppi )z6
Compute the size of each submodule of a given model.
NTr8   r   )z
torch.uintz	torch.intz
torch.bool)r.   r%   Úitemsr   Úintr@   r<   Únumelr   r(   Ú
startswithÚminÚsplitÚrangeÚlenÚjoin)rH   r   rI   rJ   Ú
dtype_sizeÚkeyÚdtypÚspecial_dtypes_sizeÚmodule_sizesÚmodule_listr   ÚtensorÚsizeÚ
name_partsÚidxs   &&&&           r   Úcompute_module_sizesr_   r   sŸ  € ð ÒÜ! %Ó(ˆÜ$ UÓ+ˆ
ØÒ!ØHV×H\ÑH\ÔH^Ô_ÑH^¹9¸3˜#Ô0°Ó6Ò6ÑH^ˆÑ_ØKY×K_ÑK_ÔKaÔbÑKa¹i¸c˜s¤O°DÓ$9Ò9ÑKaÐÑbÜœsÓ#€LçÜ*¨5¸$Ô?‰à×)Ñ)°$Ð)Ó7ˆä#‰ˆØÒ%¨$Ô*@Ø—<‘<“>Ð$7¸Õ$=Õ=‰DØŠ]Ø—<‘<“>¤O°F·L±LÓ$AÕA‰DÜ�—‘Ó×)Ñ)Ð*S×TÒTð —<‘<“>¤O°F·L±LÓ$AÕA‰Dà—<‘<“>¤C¨
´OÀFÇLÁLÓ4QÓ$RÕRˆDØ—Z‘Z “_ˆ
Üœ˜Z›¨1Õ,Ö-ˆCØ˜Ÿ™ *¨T¨cÐ"2Ó3×4¸Õ<Õ4ô .ñ $ð Ðùó1 `ùÛbs   ²G:ÁH c                óÔ   € V ^8„  d   QhR\         \        \        \        P                  P
                  3,          ,          R\        \        \        3,          R\         \        ,          /# )r   ÚmodulesrY   Úno_split_module_classes)r   r   r(   r   r5   r6   r   rM   )r   s   "r   r   r   ™   sI   € ÷ !ñ !Ü”%œœUŸX™XŸ_™_Ð,Õ-Õ.ð!Ü>BÄ3ÌÀ8½nð!ÜgkÔloÕgpñ!r   c                óô  € . pV P                  4       p\        V4      ^ 8”  dÐ   VP                  ^ 4      w  rV\        V\        P
                  P                  4      '       d   \        VP                  4       4      M. p\        V4      ^ 8X  g   VP                  P                  V9   d'   W,          pVP                  V\        V4      34       K¹  V U	U
u. uF  w  ršV RV	 2V
3NK  	  up
p	V,           pKß  V# u up
p	i )a+  
from accelerate.utils get_max_layer_size
Utility function that will scan a list of named modules and return the maximum size used by one full layer. The
definition of a layer being:
- a module with no direct children (just parameters and buffers)
- a module whose class name is in the list `no_split_module_classes`

Args:
    modules (`List[Tuple[str, torch.nn.Module]]`):
        The list of named modules where we want to determine the maximum layer size.
    module_sizes (`Dict[str, int]`):
        A dictionary mapping each layer name to its size (as generated by `compute_module_sizes`).
    no_split_module_classes (`List[str]`):
        A list of class names for layers we don't want to be split.

Returns:
    `List[Tuple[str, str]]`: The size of all layer with the list of layer names and size str.
r   )ÚcopyrS   Úpopr,   r   r5   r6   ÚlistÚnamed_childrenÚ	__class__Ú__name__Úappendr	   )ra   rY   rb   Úlayer_sizesÚmodules_to_treatÚmodule_namer0   Úmodules_childrenr\   ÚnÚvs   &&&        r   Úget_all_layer_sizerq   ™   sÞ   € ð, €KØ—|‘|“~ÐÜ
ÐÓ
 !Ô
#Ø.×2Ñ2°1Ó5ÑˆÜ<FÀvÌuÏxÉxÏÉ×<_Ò<_œ4 × 5Ñ 5Ó 7Ô8ÐegÐÜÐÓ  AÔ%¨×)9Ñ)9×)BÑ)BÐF]Ô)]ØÕ,ˆDØ×Ñ ¬]¸4Ó-@ÐAÖBáFVÔWÑFV¹d¸a K =°°!°Ð!5°qÓ 9ÑFVÒWÐZjÕjÒàÐùó  Xs   ÃC4c                 ó6  € \        V R R4      pVf   . p\        V P                  RR7      4      \        V P                  4       4      ,           \        V P	                  RR7      4      ,           p\        V 4      pVR,          p\        V4      p\        W#V4      pWE3# )Ú_no_split_modulesNFr8   r+   )r   rf   r9   rg   r<   r_   r	   rq   )rH   Úno_split_modulesrl   ÚsizesÚ
total_sizeÚ
all_layerss   &     r   Úget_vramrx   ¼   s    € Ü˜uÐ&9¸4Ó@ÐØÒØÐä�×'Ñ'°Ð'Ó6Ó7Ü�5×'Ñ'Ó)Ó*õ+ä�5×&Ñ&¨uÐ&Ó5Ó6õ7ð ô
 ! Ó'€EØ�r•€Jä˜zÓ*€Jä#Ð$4Ð=MÓN€JàÐ!Ð!r   )Úfloat8_e4m3fnÚfloat8_e5m2Úfloat8_e4m3fnuzÚfloat8_e5m2fnuzÚfloat8_e8m0fnuÚfloat4_e2m1fn_x2)TFF)F)NNF)Úcollectionsr   Útypingr   r   r   r   r   r   Útorch.nnr5   Úaccelerate.utilsr	   Ú	frozensetr   r%   r.   r@   r;   r_   rq   rx   © r   r   Ú<module>r…      s[   ðõ $ß 5Õ 5ã Ý Ý *ñ $ñ $ñó$ó Ð õDõ8÷#÷:&÷&%õN!ôF"r   