U
    dd                     @   s4   d dl mZ d
ddZdd ZG dd dejZd	S )    )nn c                 C   sP   |   D ]B\}}|d | }||kr,|  S t|||d}|d k	r|  S qd S )N.)prefix)Znamed_childrenmodule_to_fqn)modelZlayerr   namechildnew_nameZ
child_path r   F/tmp/pip-unpacked-wheel-ua33x9lu/torch/ao/sparsity/sparsifier/utils.pyr      s    
r   c                 C   s2   | d}|D ]}t| |d } | d kr d S q| S )Nr   )splitgetattr)r   pathr   r   r   r   fqn_to_module   s    
r   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )FakeSparsitya:  Parametrization for the weights. Should be attached to the 'weight' or
    any other parmeter 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                    s   t    | d| d S )Nmask)super__init__Zregister_buffer)selfr   	__class__r   r   r       s    
zFakeSparsity.__init__c                 C   s   | j j|jkst| j | S N)r   shapeAssertionError)r   xr   r   r   forward$   s    zFakeSparsity.forwardc                 O   s   t  S r   )dict)r   argskwargsr   r   r   
state_dict(   s    zFakeSparsity.state_dict)__name__
__module____qualname____doc__r   r   r    __classcell__r   r   r   r   r      s   	r   N)r   )Ztorchr   r   r   Moduler   r   r   r   r   <module>   s   

	