Beispiel #1
0
    def to_str(self) -> str:
        model_string = create_table(
            header=['Statistic\'s name', 'Value'],
            rows=[
                ['Sparsity level of the whole model', self.sparsity_level],
                [
                    'Sparsity level of all sparsified layers',
                    self.sparsity_level_for_layers
                ],
            ])

        layers_string = create_table(header=[
            'Layer\'s name', 'Weight\'s shape', 'Sparsity level',
            'Weight\'s percentage'
        ],
                                     rows=[[
                                         s.name, s.weight_shape,
                                         s.sparsity_level, s.weight_percentage
                                     ] for s in self.sparsified_layers_summary
                                           ])

        pretty_string = (
            f'Statistics of the sparsified model:\n{model_string}\n\n'
            f'Statistics by sparsified layers:\n{layers_string}')
        return pretty_string
Beispiel #2
0
    def _get_bitwidth_distribution_str(self) -> str:
        wq_total_num = sum(self.num_wq_per_bitwidth.values())
        aq_total_num = sum(self.num_aq_per_bitwidth.values())
        q_total_num = wq_total_num + aq_total_num

        bitwidths = self.num_wq_per_bitwidth.keys(
        ) | self.num_aq_per_bitwidth.keys()  # union of all bitwidths
        bitwidths = sorted(bitwidths, reverse=True)

        # Table creation
        header = [
            'Num bits (N)', 'N-bits WQs / Placed WQs',
            'N-bits AQs / Placed AQs', 'N-bits Qs / Placed Qs'
        ]
        rows = []
        for bitwidth in bitwidths:
            wq_num = self.num_wq_per_bitwidth.get(bitwidth,
                                                  0)  # for current bitwidth
            aq_num = self.num_aq_per_bitwidth.get(bitwidth,
                                                  0)  # for current bitwidth
            q_num = wq_num + aq_num  # for current bitwidth

            rows.append([
                bitwidth,
                _proportion_str(wq_num, wq_total_num),
                _proportion_str(aq_num, aq_total_num),
                _proportion_str(q_num, q_total_num)
            ])

        table = create_table(header, rows)
        pretty_string = f'Statistics of the bitwidth distribution:\n{table}'
        return pretty_string
Beispiel #3
0
    def to_str(self) -> str:
        memory_consumption_string = create_table(
            header=['Statistic\'s name', 'Value'],
            rows=[
                [
                    'Memory consumption for full-precision weights (Mbyte)',
                    self.fp32_weight_size
                ],
                [
                    'Memory consumption for quantized weights (Mbyte)',
                    self.quantized_weight_size
                ],
                [
                    'Max memory consumption for an activation tensor in FP32 model (Mbyte)',
                    self.max_fp32_activation_size
                ],
                [
                    'Max memory consumption for an activation tensor in compressed model (Mbyte)',
                    self.max_compressed_activation_size
                ],
                [
                    'Memory consumption decrease for weights',
                    self.weight_memory_consumption_decrease
                ],
            ])

        pretty_string = f'Statistics of the memory consumption:\n{memory_consumption_string}'
        return pretty_string
Beispiel #4
0
    def to_str(self) -> str:
        algorithm_string = create_table(
            header=['Statistic\'s name', 'Value'],
            rows=[
                [
                    'Pruned layers count / prunable layers count',
                    f'{self.pruned_layers_num} /'
                    f' {self.prunable_layers_num}'
                ],
                [
                    'GFLOPS minimum possible after pruning / total',
                    f'{self.minimum_possible_flops / self._giga:.3f} /'
                    f' {self.total_flops / self._giga:.3f}'
                ],
                [
                    'MParams minimum possible after pruning / total',
                    f'{self.minimum_possible_params / self._mega:.3f} /'
                    f' {self.total_params / self._mega:.3f}'
                ],
            ])

        pretty_string = (
            f'Theoretical borderline of the filter pruning algorithm\nfor current model:\n{algorithm_string}'
        )
        return pretty_string
Beispiel #5
0
    def _get_quantization_share_str(self) -> str:
        header = ['Statistic\'s name', 'Value']

        rows = []
        rows.extend(_quantizers_counter_to_rows(self.wq_counter, 'WQ'))
        rows.extend(_quantizers_counter_to_rows(self.aq_counter, 'AQ'))

        table = create_table(header, rows)
        pretty_string = f'Statistics of the quantization share:\n{table}'
        return pretty_string
Beispiel #6
0
 def to_str(self) -> str:
     header = ['Statistic\'s name', 'Value']
     rows = [[
         'Share edges of the quantized data path',
         _proportion_str(self.quantized_edges_in_cfg,
                         self.total_edges_in_cfg)
     ]]
     qc_string = create_table(header, rows)
     pretty_string = f'Statistics of the quantization configuration:\n{qc_string}'
     return pretty_string
Beispiel #7
0
    def to_str(self) -> str:
        thresholds_string = create_table(
            ['Layer\'s name', 'Sparsity threshold'],
            [[s.name, s.threshold] for s in self.thresholds])

        algorithm_string = create_table(
            header=['Statistic\'s name', 'Value'],
            rows=[
                [
                    'A target level of the sparsity for the algorithm for the current epoch',
                    self.target_sparsity_level
                ],
            ])

        pretty_string = (
            f'{self.model_statistics.to_str()}\n\n'
            f'Statistics of the magnitude sparsity algorithm:\n{algorithm_string}\n{thresholds_string}'
        )
        return pretty_string
Beispiel #8
0
    def to_str(self) -> str:
        model_string = create_table(
            header=['#', 'Full', 'Current', 'Pruning level'],
            rows=[
                [
                    'GFLOPS', f'{self.full_flops / self._giga:.3f}',
                    f'{self.current_flops / self._giga:.3f}',
                    self.flops_pruning_level
                ],
                [
                    'MParams', f'{self.full_params_num / self._mega:.3f}',
                    f'{self.current_params_num / self._mega:.3f}',
                    self.params_pruning_level
                ],
                [
                    'Filters', self.full_filters_num, self.current_filters_num,
                    self.filter_pruning_level
                ],
            ])

        header = [
            'Layer\'s name', 'Weight\'s shape', 'Mask\'s shape',
            'Filter pruning level'
        ]
        rows = []
        for s in self.pruned_layers_summary:
            rows.append(
                [s.name, s.weight_shape, s.mask_shape, s.filter_pruning_level])

        layers_string = create_table(header, rows)

        pruning_level_desc = 'Prompt: statistic pruning level = 1 - statistic current / statistic full.'
        pretty_string = (f'Statistics by pruned layers:\n{layers_string}\n'
                         f'Statistics of the pruned model:\n{model_string}\n' +
                         pruning_level_desc)

        return pretty_string
Beispiel #9
0
    def to_str(self) -> str:
        pretty_strings = []

        table = create_table(header=['Statistic\'s name', 'Value'],
                             rows=[[
                                 'Ratio of enabled quantizations',
                                 self.ratio_of_enabled_quantizations
                             ]])

        pretty_strings.append(
            f'Statistics of the quantization algorithm:\n{table}')
        pretty_strings.append(self._get_quantization_share_str())
        pretty_strings.append(self._get_bitwidth_distribution_str())
        pretty_string = '\n\n'.join(pretty_strings)
        return pretty_string
Beispiel #10
0
    def to_str(self) -> str:
        algorithm_string = create_table(
            header=['Statistic\'s name', 'Value'],
            rows=[
                [
                    'A target level of the sparsity for the algorithm for the current epoch',
                    self.target_sparsity_level
                ],
                [
                    'The probability that one weight will be zeroed',
                    self.mean_sparse_prob
                ],
            ])

        pretty_string = (
            f'{self.model_statistics.to_str()}\n\n'
            f'Statistics of the RB-sparsity algorithm:\n{algorithm_string}')
        return pretty_string
Beispiel #11
0
    def to_str(self) -> str:
        pruning_mode = 'FLOPS' if self.prune_flops else 'filter'
        algorithm_string = create_table(
            header=['Statistic\'s name', 'Value'],
            rows=[
                [
                    f'{pruning_mode.capitalize()} pruning level in current epoch',
                    self.current_pruning_level
                ],
                [
                    f'Target {pruning_mode} pruning level',
                    self.target_pruning_level
                ],
            ])

        pretty_string = (
            f'{self.model_statistics.to_str()}\n'
            f'Statistics of the filter pruning algorithm:\n{algorithm_string}')
        return pretty_string