Ë
    g^(hÂ  ã            
       óî  — d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	 g d¢Z
dej                  deej                     defd	„Zd
ej                  deeej                     eej                     f   dej                  fd„Z	 ddej                  dej                  dedee   fd„Zdeej                     dedeej                     fd„Zdej                  dedeeef   fd„Z G d„ dej                  «      Zy)é    )Úchain)ÚAnyÚOptional)Únn)Úis_parametrizedÚtype_before_parametrizations)Úmodule_contains_paramÚswap_moduleÚmodule_to_fqnÚfqn_to_moduleÚget_arg_info_from_tensor_fqnÚFakeSparsityÚmoduleÚparametrizationÚreturnc                 ót   ‡— t        | «      r,t        ˆfd„| j                  j                  «       D «       «      S y)Nc              3   óL   •K  — | ]  \  }}t        ˆfd „|D «       «      –— Œ y­w)c              3   ó6   •K  — | ]  }t        |‰«      –— Œ y ­w©N)Ú
isinstance)Ú.0Úparamr   s     €ú_/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/ao/pruning/sparsifier/utils.pyú	<genexpr>z2module_contains_param.<locals>.<genexpr>.<genexpr>   s   øè ø€ ÒK°u”
˜5 /×2ÑKùs   ƒN)Úany)r   ÚkeyÚ
param_listr   s      €r   r   z(module_contains_param.<locals>.<genexpr>   s(   øè ø€ ò 
á��Zô ÓKÀ
ÔK×Kñ
ùs   ƒ!$F)r   r   ÚparametrizationsÚitems)r   r   s    `r   r	   r	      s9   ø€ Ü�vÔäó 
à#)×#:Ñ#:×#@Ñ#@Ó#Bô
ó 
ð 	
ð ó    ÚmodÚmappingc                 óJ  — t        | «      |v �r|t        | «         }|j                  | «      }| j                  j                  «       D ]  }|j	                  |«       Œ | j
                  j                  «       D ]  }|j                  |«       Œ t        | j                  «       | j                  «       «      D �ch c]  }|j                  ’Œ }}t        |«      dk  s
J d|› �«       ‚t        |«      dkD  rt        t        |«      «      nd}|r|j                  |«       |S | S c c}w )a%  Swaps the module using from_dense according to the mapping passed in.
    Args:
        mod: input module
        mapping: a dictionary that maps from nn module to sparse nn module
    Return:
        The corresponding sparse module of `mod` according to mapping, created using from_dense
    é   zOswap_module only works with cpu or single-device CUDA modules, but got devices r   N)r   Ú
from_denseÚ_forward_pre_hooksÚvaluesÚregister_forward_pre_hookÚ_forward_hooksÚregister_forward_hookr   Ú
parametersÚbuffersÚdeviceÚlenÚnextÚiterÚto)	r!   r"   Ú
sparse_modÚnew_modÚpre_hook_fnÚhook_fnÚpÚdevicesr-   s	            r   r
   r
      s  € ô $ CÓ(¨GÒ3ØÔ9¸#Ó>Ñ?ˆ
ð ×'Ñ'¨Ó,ˆð ×1Ñ1×8Ñ8Ó:ò 	;ˆKØ×-Ñ-¨kÕ:ð	;ð ×)Ñ)×0Ñ0Ó2ò 	3ˆGØ×)Ñ)¨'Õ2ð	3ô &+¨3¯>©>Ó+;¸S¿[¹[»]Ó%KÖL �1—8“8ÐLˆÐLä�‹L˜AÒð	gà\Ð]dÐ\eÐfó	gØä(+¨G«°qÒ(8””d˜7“mÔ$¸dˆÙØ�J‰J�vÔàˆð ˆ
ùò Ms   Â8D ÚmodelÚprefixc                 óŒ   — || u ry| j                  «       D ],  \  }}t        ||d«      }t        |t        «      sŒ$||z   |z   c S  y)zS
    Returns the fqn for a module or None if module not a descendent of model.
    Ú ú.N)Únamed_childrenr   r   Ústr)r8   r   r9   ÚnameÚchildÚfqns         r   r   r   D   sV   € ð ��ØØ×+Ñ+Ó-ò '‰ˆˆeÜ˜E 6¨3Ó/ˆÜ�cœ3ÕØ˜D‘= 3Ñ&Ò&ð'ð r    Úpathc                 óV   — |dk7  r#|j                  d«      D ]  }t        | |d«      } Œ | S )zÅ
    Given an fqn, returns the corresponding module or tensor or None if the fqn given by `path`
    doesn't correspond to anything. Similar to model.get_submodule(path) but works for tensors.
    r;   r<   N)ÚsplitÚgetattr)r8   rB   r?   s      r   r   r   S   s5   € ð
 ˆr‚zØ—J‘J˜s“Oò 	/ˆDÜ˜E 4¨Ó.‰Eð	/à€Lr    Ú
tensor_fqnc                 óx   — |j                  d«      d   }|dt        |«       d|v z
   }t        | |«      }||||dœS )zX
    Uses tensor_fqn to obtain a dict containing module_fqn, module and tensor_name
    r<   éÿÿÿÿN)Ú
module_fqnr   Útensor_namerF   )rD   r.   r   )r8   rF   rJ   rI   r   s        r   r   r   ^   s\   € ð ×"Ñ" 3Ó'¨Ñ+€KØÐEœs ;Ó/Ð/°3¸*Ð3DÑEÐF€Jä˜5 *Ó-€Fð !ØØ"Ø ñ	ð r    c                   ó.   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zˆ xZS )r   a;  Parametrization for the weights. Should be attached to the 'weight' or
    any other parameter that requires a mask applied to it.

    Note::

        Once the mask is passed, the variable should not change the id. The
        contents of the mask can change, but the mask reference itself should
        not.
    c                 óF   •— t         ‰| �  «        | j                  d|«       y )NÚmask)ÚsuperÚ__init__Úregister_buffer)ÚselfrM   Ú	__class__s     €r   rO   zFakeSparsity.__init__~   s   ø€ Ü‰ÑÔØ×Ñ˜V TÕ*r    c                 ój   — | j                   j                  |j                  k(  sJ ‚| j                   |z  S r   )rM   Úshape)rQ   Úxs     r   ÚforwardzFakeSparsity.forward‚   s*   € Ø�y‰y�‰ !§'¡'Ò)Ð)Ð)Ø�y‰y˜1‰}Ðr    c                 ó   — i S r   © )rQ   ÚargsÚkwargss      r   Ú
state_dictzFakeSparsity.state_dict†   s	   € ð ˆ	r    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rO   rV   r[   Ú__classcell__)rR   s   @r   r   r   s   s   ø„ ñô+òör    r   N)r;   )Ú	itertoolsr   Útypingr   r   Útorchr   Útorch.nn.utils.parametrizer   r   Ú__all__ÚModuleÚtypeÚboolr	   Údictr
   r>   r   r   r   r   rX   r    r   ú<module>rj      s  ðå ß  å ß Tò€ð "§)¡)ð ¸dÀ2Ç9Á9¹oð ÐRVó ð$Ø	�‰ð$Ø! $ r§y¡y¡/°4¸¿	¹	±?Ð"BÑCð$à‡Y�Yó$ðP 8:ñØ�9‰9ðØ Ÿi™iðØ14ðàˆc�]óð˜ "§)¡)Ñ,ð °Cð ¸HÀRÇYÁYÑ<Oó ð¨¯	©	ð ¸sð ÀtÈCÐQTÈHÁ~ó ô*�2—9‘9õ r    