(module, threshold, parameter='weight')
Prunes module parameters based on magnitude (inplace).

    :param module: PyTorch module.
    :type module: `torch.nn.Module`
    :param threshold: Magnitude threshold for pruning.
    :type threshold: `float`
    :param parameter: Module parameter to prune (default: 'weight')
    :type parameter: str
Prunes module parameters based on magnitude (inplace).
Prunes module parameters based on magnitude ( inplace ) .
def prune(module, threshold, parameter='weight'):
    """
    Prunes module parameters based on magnitude (inplace).

    :param module: PyTorch module.
    :type module: `torch.nn.Module`
    :param threshold: Magnitude threshold for pruning.
    :type threshold: `float`
    :param parameter: Module parameter to prune (default: 'weight')
    :type parameter: str
    """
    __precheck(module)

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

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

    if not cfg.__CONDENSA_RECORD_MODE__:
        p = getattr(module, parameter)
        pdata = p.data.view(-1)
        mask = T.simple_mask(pdata, threshold).type(pdata.type())
        T.apply_mask_inplace(pdata, mask)
        p.data = pdata.view_as(p).data
def prune ( module , threshold , parameter = 'weight' ) : __precheck ( module ) if not hasattr ( module , parameter ) : raise ValueError ( 'Could not find parameter \'{}\' in module' , parameter ) if hasattr ( module , 'condense' ) : module . condense . add ( parameter ) else : module . condense = set ( [ parameter ] ) if not cfg . __CONDENSA_RECORD_MODE__ : p = getattr ( module , parameter ) pdata = p . data . view ( - 1 ) mask = T . simple_mask ( pdata , threshold ) . type ( pdata . type ( ) ) T . apply_mask_inplace ( pdata , mask ) p . data = pdata . view_as ( p ) . data