(module, threshold, criteria, align=None, prune_bias=True)
Prunes neurons based on magnitude (inplace).

    :param module: PyTorch module.
    :type module: `torch.nn.Module`
    :param threshold: Magnitude threshold for pruning.
    :type threshold: `float`
    :param criteria: Aggregation function for thresholding.
    :type criteria: `condensa.functional`
    :param align: Alignment of compressed parameters.
    :type align: `int`
    :param prune_bias: Whether to prune corresponding biases.
    :type prune_bias: `bool`
Prunes neurons based on magnitude (inplace).
Prunes neurons based on magnitude ( inplace ) .
def neuron_prune(module, threshold, criteria, align=None, prune_bias=True):
    """
    Prunes neurons based on magnitude (inplace).

    :param module: PyTorch module.
    :type module: `torch.nn.Module`
    :param threshold: Magnitude threshold for pruning.
    :type threshold: `float`
    :param criteria: Aggregation function for thresholding.
    :type criteria: `condensa.functional`
    :param align: Alignment of compressed parameters.
    :type align: `int`
    :param prune_bias: Whether to prune corresponding biases.
    :type prune_bias: `bool`
    """
    __precheck(module)

    parameter = 'weight'
    if not hasattr(module, parameter):
        raise ValueError('Could not find parameter \'{}\' in module',
                         parameter)

    shape = getattr(module, parameter).data.shape
    if len(shape) != 2:
        raise NotImplementedError(
            'Row pruning currently only supported for 2D parameters')

    if hasattr(module, 'condense'): module.condense.add(parameter)
    else: module.condense = set([parameter])

    if not cfg.__CONDENSA_RECORD_MODE__:
        block_size = (1, shape[1])
        mask = blockprune(module, threshold, block_size, criteria, align,
                          parameter)
        # Prune corresponding bias tensor
        if module.bias is not None and prune_bias is True:
            assert mask.ndimension() == 2
            T.apply_mask_inplace(module.bias.data, mask[:, 0])
def neuron_prune ( module , threshold , criteria , align = None , prune_bias = True ) : __precheck ( module ) parameter = 'weight' if not hasattr ( module , parameter ) : raise ValueError ( 'Could not find parameter \'{}\' in module' , parameter ) shape = getattr ( module , parameter ) . data . shape if len ( shape ) != 2 : raise NotImplementedError ( 'Row pruning currently only supported for 2D parameters' ) if hasattr ( module , 'condense' ) : module . condense . add ( parameter ) else : module . condense = set ( [ parameter ] ) if not cfg . __CONDENSA_RECORD_MODE__ : block_size = ( 1 , shape [ 1 ] ) mask = blockprune ( module , threshold , block_size , criteria , align , parameter ) # Prune corresponding bias tensor if module . bias is not None and prune_bias is True : assert mask . ndimension ( ) == 2 T . apply_mask_inplace ( module . bias . data , mask [ : , 0 ] )