/usr/local/lib64/python3.6/site-packages/torch/nn/utils/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/nn/utils/__pycache__/prune.cpython-36.pyc (45557B)
3
Eg| @ s> d Z ddlZddlmZmZ ddlmZ ddlmZ ddl Z G dd deZ
G dd d e
ZG d
d de
ZG dd
d
e
Z
G dd de
ZG dd de
ZG dd de
ZG dd de
Zdd Zdd Zd4ddZdd Zd5ddZd6d d!Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Z dS )7z
Pruning methods
N)ABCabstractmethod)Iterable)Tuplec @ s^ e Zd ZU dZedd Zdd Zedd Z dd Z
ed
ddd
ZdddZ
dd Zd
S )BasePruningMethodzAbstract base class for creation of new pruning techniques.
Provides a skeleton for customization requiring the overriding of methods
such as :meth:`compute_mask` and :meth:`apply`.
c C s d S )N )selfr r @/usr/local/lib64/python3.6/site-packages/torch/nn/utils/prune.py__init__ s zBasePruningMethod.__init__c C s t || j| j| dS )aW Multiplies the mask (stored in ``module[name + '_mask']``)
into the original tensor (stored in ``module[name + '_orig']``)
and stores the result into ``module[name]`` by using
:meth:`apply_mask`.
Args:
module (nn.Module): module containing the tensor to prune
inputs: not used.
N)setattr_tensor_name
apply_mask)r moduleinputsr r r __call__ s
zBasePruningMethod.__call__c C s dS )a Computes and returns a mask for the input tensor ``t``.
Starting from a base ``default_mask`` (which should be a mask of ones
if the tensor has not been pruned yet), generate a random mask to
apply on top of the ``default_mask`` according to the specific pruning
method recipe.
Args:
t (torch.Tensor): tensor representing the importance scores of the
parameter to prune.
default_mask (torch.Tensor): Base mask from previous pruning
iterations, that need to be respected after the new mask is
applied. Same dims as ``t``.
Returns:
mask (torch.Tensor): mask to apply to ``t``, of same dims as ``t``
Nr )r tdefault_maskr r r compute_mask# s zBasePruningMethod.compute_maskc C sN | j dk stdj|t|| j d }t|| j d }|j|jd| }|S )a Simply handles the multiplication between the parameter being
pruned and the generated mask.
Fetches the mask and the original tensor from the module
and returns the pruned version of the tensor.
Args:
module (nn.Module): module containing the tensor to prune
Returns:
pruned_tensor (torch.Tensor): pruned version of the input tensor
NzModule {} has to be pruned_mask_orig)dtype)r AssertionErrorformatgetattrtor )r r maskorigZ
pruned_tensorr r r r
7 s zBasePruningMethod.apply_maskN)importance_scoresc O s8 dd }|| ||f||}t ||}|dk rL|j|jksPtdj||n|}t|ts~|j|d | |j|= tj |} nt ||d j
jtjd} y>|j
|| d}
|j|d |
t|||j| |j| W nZ tk
r2 } z