
    [Th              
          S SK Jr  S SKJrJr  S SKJr  S SKJrJ	r	  / SQr
S\R                  S\\R                     S\4S	 jrS
\R                  S\\\R                     \\R                     4   S\R                  4S jr SS\R                  S\R                  S\S\\   4S jjrS\\R                     S\S\\R                     4S jrS\R                  S\S\\\4   4S jr " S S\R                  5      rg)    )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                    ^ [        U 5      (       a-  [        U4S jU R                  R                  5        5       5      $ g)Nc              3   R   >#    U  H  u  p[        U4S  jU 5       5      v   M     g7f)c              3   <   >#    U  H  n[        UT5      v   M     g 7fN)
isinstance).0paramr   s     Y/var/www/auris/envauris/lib/python3.13/site-packages/torch/ao/pruning/sparsifier/utils.py	<genexpr>2module_contains_param.<locals>.<genexpr>.<genexpr>   s     K
u
5/22
s   N)any)r   key
param_listr   s      r   r   (module_contains_param.<locals>.<genexpr>   s(      
#B K
KKK#Bs   $'F)r   r   parametrizationsitems)r   r   s    `r   r	   r	      s<    v 
#)#:#:#@#@#B
 
 	
     modmappingc                 h   [        U 5      U;   Ga  U[        U 5         nUR                  U 5      nU R                  R                  5        H  nUR	                  U5        M     U R
                  R                  5        H  nUR                  U5        M     [        U R                  5       U R                  5       5       Vs1 s H  ofR                  iM     nn[        U5      S::  d
   SU 35       e[        U5      S:  a  [        [        U5      5      OSnU(       a  UR                  U5        U$ U $ s  snf )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2G))'2 3 &+3>>+;S[[]%KL%K88%KLLA	g\]d\ef	g(+Gq(8d7m$dJJv 
 Ms   >D/modelprefixc                     XL a  gU R                  5        H/  u  p4[        XAS5      n[        U[        5      (       d  M(  X#-   U-   s  $    g)zK
Returns the fqn for a module or None if module not a descendent of model.
 .N)named_childrenr   r   str)r:   r   r;   namechildfqns         r   r   r   D   sL     ++-E3/c3=3&& . r"   pathc                 Z    US:w  a$  UR                  S5       H  n[        XS5      n M     U $ )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)r:   rD   rA   s      r   r   r   S   s.    
 rzJJsODE.E $Lr"   
tensor_fqnc                 x    UR                  S5      S   nUS[        U5      * SU;   -
   n[        X5      nUUUUS.$ )zP
Uses tensor_fqn to obtain a dict containing module_fqn, module and tensor_name
r>   N)
module_fqnr   tensor_namerH   )rF   r0   r   )r:   rH   rL   rK   r   s        r   r   r   ^   sZ     ""3'+KEs;//3*3DEFJ5-F !" 	 r"   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )r   s   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U ]  5         U R                  SU5        g )Nmask)super__init__register_buffer)selfrP   	__class__s     r   rR   FakeSparsity.__init__~   s    VT*r"   c                 l    U R                   R                  UR                  :X  d   eU R                   U-  $ r   )rP   shape)rT   xs     r   forwardFakeSparsity.forward   s*    yy!'')))yy1}r"   c                     0 $ r    )rT   argskwargss      r   
state_dictFakeSparsity.state_dict   s	     	r"   r]   )
__name__
__module____qualname____firstlineno____doc__rR   rZ   r`   __static_attributes____classcell__)rU   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   r]   r"   r   <module>rr      s       T")) d299o RV $	$!$ryy/4		?"BC$YY$P 8:99 ii14c]")), C HRYY<O 		 s tCQTH~ *299 r"   