(w, wc)
return stats
Retrieve various statistics for compressed model.

    :param w: Original model
    :type w: `torch.nn.Module`
    :param wc: Compressed model
    :type wc: `torch.nn.Module`
    :return: Dictionary of compressed model statistics
    :rtype: `dict`
Retrieve various statistics for compressed model.
Retrieve various statistics for compressed model .
def compressed_model_stats(w, wc):
    """
    Retrieve various statistics for compressed model.

    :param w: Original model
    :type w: `torch.nn.Module`
    :param wc: Compressed model
    :type wc: `torch.nn.Module`
    :return: Dictionary of compressed model statistics
    :rtype: `dict`
    """
    stats = dict()
    nparams_w = dict()
    nparams_wc = dict()

    nparams_w['total_nnz'] = torch.nn.utils.parameters_to_vector(
        w.parameters()).view(-1).nonzero().numel()
    nparams_wc['total_nnz'] = torch.nn.utils.parameters_to_vector(
        wc.parameters()).view(-1).nonzero().numel()

    for (name_w, m_w), (name_wc, m_wc) in zip(w.named_modules(),
                                              wc.named_modules()):
        if type(m_w) == torch.nn.Linear or type(m_w) == torch.nn.Conv2d:
            nparams_w[name_w] = torch.nn.utils.parameters_to_vector(
                m_w.parameters()).view(-1).nonzero().numel()
            nparams_wc[name_wc] = torch.nn.utils.parameters_to_vector(
                m_wc.parameters()).view(-1).nonzero().numel()

    stats['num_params'] = nparams_w
    stats['num_params_compressed'] = nparams_wc
    return stats
def compressed_model_stats ( w , wc ) : stats = dict ( ) nparams_w = dict ( ) nparams_wc = dict ( ) nparams_w [ 'total_nnz' ] = torch . nn . utils . parameters_to_vector ( w . parameters ( ) ) . view ( - 1 ) . nonzero ( ) . numel ( ) nparams_wc [ 'total_nnz' ] = torch . nn . utils . parameters_to_vector ( wc . parameters ( ) ) . view ( - 1 ) . nonzero ( ) . numel ( ) for ( name_w , m_w ) , ( name_wc , m_wc ) in zip ( w . named_modules ( ) , wc . named_modules ( ) ) : if type ( m_w ) == torch . nn . Linear or type ( m_w ) == torch . nn . Conv2d : nparams_w [ name_w ] = torch . nn . utils . parameters_to_vector ( m_w . parameters ( ) ) . view ( - 1 ) . nonzero ( ) . numel ( ) nparams_wc [ name_wc ] = torch . nn . utils . parameters_to_vector ( m_wc . parameters ( ) ) . view ( - 1 ) . nonzero ( ) . numel ( ) stats [ 'num_params' ] = nparams_w stats [ 'num_params_compressed' ] = nparams_wc return stats