§
    ŠŠtj�  ã            
       ó–  — d dl mZ d dl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dz  fd„Zdej
        dz  dedej
        dz  fd„Zdej
        dedeeef         fd„Z G d„ dej
        ¦  «        ZdS )é    )Úchain)ÚAny)Ú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          | ¦  «        r2t          ˆfd„| j                             ¦   «         D ¦   «         ¦  «        S dS )Nc              3   óN   •K  — | ]}t          ˆfd „|D ¦   «         ¦  «        V — Œ dS )c              3   ó8   •K  — | ]}t          |‰¦  «        V — Œd S ©N)Ú
isinstance)Ú.0Úparamr   s     €ú_/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/ao/pruning/sparsifier/utils.pyú	<genexpr>z2module_contains_param.<locals>.<genexpr>.<genexpr>   s-   øè è € ÐKÐK°u•
˜5 /Ñ2Ô2ÐKÐKÐKÐKÐKÐKó    N)Úany)r   Ú
param_listr   s     €r   r   z(module_contains_param.<locals>.<genexpr>   sT   øè è € ð 
ð 
àõ ÐKÐKÐKÐKÀ
ÐKÑKÔKÑKÔKð
ð 
ð 
ð 
ð 
ð 
r   F)r   r   ÚparametrizationsÚvalues)r   r   s    `r   r   r      sa   ø€ Ý�vÑÔð 
åð 
ð 
ð 
ð 
à$Ô5×<Ò<Ñ>Ô>ð
ñ 
ô 
ñ 
ô 
ð 	
ð ˆ5r   ÚmodÚmappingc                 óœ  — t          | ¦  «        |v �r9|t          | ¦  «                 }|                     | ¦  «        }| j                             ¦   «         D ]}|                     |¦  «         Œ| j                             ¦   «         D ]}|                     |¦  «         Œd„ t          |                      ¦   «         |  	                    ¦   «         ¦  «        D ¦   «         }t          |¦  «        dk    rt          d|› �¦  «        ‚t          |¦  «        dk    rt          t          |¦  «        ¦  «        nd}|r|                     |¦  «         |S | S )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
    c                 ó   — h | ]	}|j         ’Œ
S © )Údevice)r   Úps     r   ú	<setcomp>zswap_module.<locals>.<setcomp>7   s   € ÐLÐLÐL �1”8ÐLÐLÐLr   é   zOswap_module only works with cpu or single-device CUDA modules, but got devices r   N)r   Ú
from_denseÚ_forward_pre_hooksr   Úregister_forward_pre_hookÚ_forward_hooksÚregister_forward_hookr   Ú
parametersÚbuffersÚlenÚAssertionErrorÚnextÚiterÚto)r   r    Ú
sparse_modÚnew_modÚpre_hook_fnÚhook_fnÚdevicesr$   s           r   r	   r	      s^  € õ $ CÑ(Ô(¨GÐ3Ñ3ØÕ9¸#Ñ>Ô>Ô?ˆ
ð ×'Ò'¨Ñ,Ô,ˆð Ô1×8Ò8Ñ:Ô:ð 	;ð 	;ˆKØ×-Ò-¨kÑ:Ô:Ð:Ð:ð Ô)×0Ò0Ñ2Ô2ð 	3ð 	3ˆGØ×)Ò)¨'Ñ2Ô2Ð2Ð2ð MÐL¥U¨3¯>ª>Ñ+;Ô+;¸S¿[º[¹]¼]Ñ%KÔ%KÐLÑLÔLˆÝˆw‰<Œ<˜!ÒÐÝ ØkÐbiÐkÐkñô ð õ ),¨G©¬°qÒ(8Ð(8••d˜7‘m”mÑ$Ô$Ð$¸dˆØð 	Ø�JŠJ�vÑÔÐàˆð ˆ
r   Ú ÚmodelÚprefixNc                 ó¦   — || u rdS |                       ¦   «         D ]5\  }}t          ||d¦  «        }t          |t          ¦  «        r
||z   |z   c S Œ6dS )zS
    Returns the fqn for a module or None if module not a descendant of model.
    r9   ú.N)Únamed_childrenr
   r   Ústr)r:   r   r;   ÚnameÚchildÚfqns         r   r
   r
   F   ss   € ð �€€ØˆrØ×+Ò+Ñ-Ô-ð 'ð '‰ˆˆeÝ˜E 6¨3Ñ/Ô/ˆÝ�c�3ÑÔð 	'Ø˜D‘= 3Ñ&Ð&Ð&Ð&ð	'àˆ4r   Úpathc                 ód   — |dk    r)|                      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.
    r9   r=   N)ÚsplitÚgetattr)r:   rC   r@   s      r   r   r   S   s>   € ð
 ˆr‚z€zØ—J’J˜s‘O”Oð 	/ð 	/ˆDÝ˜E 4¨Ñ.Ô.ˆEˆEØ€Lr   Ú
tensor_fqnc                 ó¤   — |                      d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=   r'   )ÚmaxsplitéÿÿÿÿN)Ú
module_fqnr   Útensor_namerG   )Úrsplitr/   r   )r:   rG   rL   rK   r   s        r   r   r   ^   sr   € ð ×#Ò# C°!Ð#Ñ4Ô4°RÔ8€KØÐE�s ;Ñ/Ô/Ð/°3¸*Ð3DÑEÐ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                 ót   •— t          ¦   «                              ¦   «          |                      d|¦  «         d S )NÚmask)ÚsuperÚ__init__Úregister_buffer)ÚselfrP   Ú	__class__s     €r   rR   zFakeSparsity.__init__~   s5   ø€ Ý‰Œ×ÒÑÔÐØ×Ò˜V TÑ*Ô*Ð*Ð*Ð*r   c                 óŠ   — | j         j        |j        k    r%t          d| j         j        › d|j        › d�¦  «        ‚| j         |z  S )Nzmask shape (z) must match x shape (ú))rP   Úshaper0   )rT   Úxs     r   ÚforwardzFakeSparsity.forward‚   sO   € ØŒ9Œ?˜aœgÒ%Ð%Ý ØP˜tœyœÐPÐPÀaÄgÐPÐPÐPñô ð ð Œy˜1‰}Ðr   c                 ó   — i S r   r#   )rT   ÚargsÚkwargss      r   Ú
state_dictzFakeSparsity.state_dict‰   s	   € ð ˆ	r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rR   rZ   r^   Ú__classcell__)rU   s   @r   r   r   s   s`   ø€ € € € € ðð ð+ð +ð +ð +ð +ðð ð ðð ð ð ð ð ð r   r   )r9   )Ú	itertoolsr   Útypingr   Útorchr   Útorch.nn.utils.parametrizer   r   Ú__all__ÚModuleÚtypeÚboolr   Údictr	   r?   r
   r   r   r   r#   r   r   ú<module>rm      s¼  ðà Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø TÐ TÐ TÐ TÐ TÐ TÐ TÐ Tðð ð €ð "¤)ð ¸dÀ2Ä9¼oð ÐRVð ð ð ð ð&Ø	Œð&Ø! $ r¤y¤/°4¸¼	´?Ð"BÔCð&à„Yð&ð &ð &ð &ðR
ð 
˜œð 
¨B¬Ið 
¸sð 
ÈCÐRVÉJð 
ð 
ð 
ð 
ð˜œ TÑ)ð °ð ¸¼ÀTÑ9Ið ð ð ð ð¨¬	ð ¸sð ÀtÈCÐQTÈHÄ~ð ð ð ð ð*ð ð ð ð �2”9ñ ô ð ð ð r   