nncf/torch/pruning/filter_pruning/algo.py
def _set_binary_masks_for_pruned_modules_groupwise(self,
                                                       pruning_level: Union[float, Dict[int, float]]) -> None:
        """
        Set the binary mask values according to groupwise pruning level.
        If pruning_level is a float, set the pruning level uniformly across groups.
        If pruning_level is a dict, set specific pruning levels corresponding to each group.
        """
        nncf_logger.debug("Updating binary masks for pruned modules.")
        groupwise_pruning_levels_set = isinstance(pruning_level, dict)

        for group in self.pruned_module_groups_info.get_all_clusters():
            group_pruning_level = pruning_level[group.id] if groupwise_pruning_levels_set \
                else pruning_level

            filters_num = torch.tensor([get_filters_num(minfo.module) for minfo in group.elements])
            assert torch.all(filters_num == filters_num[0])
            device = group.elements[0].module.weight.device

            cumulative_filters_importance = torch.zeros(filters_num[0]).to(device)
            # 1. Calculate cumulative importance for all filters in group
            for minfo in group.elements:
                filters_importance = self.filter_importance(minfo.module.weight,
                                                            minfo.module.target_weight_dim_for_compression)
                cumulative_filters_importance += filters_importance

            # 2. Calculate threshold
            num_of_sparse_elems = get_rounded_pruned_element_number(cumulative_filters_importance.size(0),
                                                                    group_pruning_level)
            threshold = sorted(cumulative_filters_importance)[min(num_of_sparse_elems, filters_num[0] - 1)]
            mask = calculate_binary_mask(cumulative_filters_importance, threshold)

            # 3. Set binary masks for filter
            for minfo in group.elements:
                pruning_module = minfo.operand
                pruning_module.binary_filter_pruning_mask = mask

        # Calculate actual flops and weights number with new masks
        self._update_benchmark_statistics()

        Set the binary mask values according to groupwise pruning level.
        If pruning_level is a float, set the pruning level uniformly across groups.
        If pruning_level is a dict, set specific pruning levels corresponding to each group.
        
Set the binary mask values according to groupwise pruning level.
If pruning_level is a float, set the pruning level uniformly across groups.
If pruning_level is a dict, set specific pruning levels corresponding to each group.
Set the binary mask values according to groupwise pruning level . If pruning_level is a float set the pruning level uniformly across groups . If pruning_level is a dict set specific pruning levels corresponding to each group .
def _set_binary_masks_for_pruned_modules_groupwise(self,
                                                       pruning_level: Union[float, Dict[int, float]]) -> None:
        nncf_logger.debug("Updating binary masks for pruned modules.")
        groupwise_pruning_levels_set = isinstance(pruning_level, dict)
        for group in self.pruned_module_groups_info.get_all_clusters():
            group_pruning_level = pruning_level[group.id] if groupwise_pruning_levels_set \
                else pruning_level
            filters_num = torch.tensor([get_filters_num(minfo.module) for minfo in group.elements])
            assert torch.all(filters_num == filters_num[0])
            device = group.elements[0].module.weight.device
            cumulative_filters_importance = torch.zeros(filters_num[0]).to(device)
            for minfo in group.elements:
                filters_importance = self.filter_importance(minfo.module.weight,
                                                            minfo.module.target_weight_dim_for_compression)
                cumulative_filters_importance += filters_importance
            num_of_sparse_elems = get_rounded_pruned_element_number(cumulative_filters_importance.size(0),
                                                                    group_pruning_level)
            threshold = sorted(cumulative_filters_importance)[min(num_of_sparse_elems, filters_num[0] - 1)]
            mask = calculate_binary_mask(cumulative_filters_importance, threshold)
            for minfo in group.elements:
                pruning_module = minfo.operand
                pruning_module.binary_filter_pruning_mask = mask
        self._update_benchmark_statistics()
def _set_binary_masks_for_pruned_modules_groupwise ( self , pruning_level : Union [ float , Dict [ int , float ] ] ) -> None : nncf_logger . debug ( "Updating binary masks for pruned modules." ) groupwise_pruning_levels_set = isinstance ( pruning_level , dict ) for group in self . pruned_module_groups_info . get_all_clusters ( ) : group_pruning_level = pruning_level [ group . id ] if groupwise_pruning_levels_set else pruning_level filters_num = torch . tensor ( [ get_filters_num ( minfo . module ) for minfo in group . elements ] ) assert torch . all ( filters_num == filters_num [ 0 ] ) device = group . elements [ 0 ] . module . weight . device cumulative_filters_importance = torch . zeros ( filters_num [ 0 ] ) . to ( device ) for minfo in group . elements : filters_importance = self . filter_importance ( minfo . module . weight , minfo . module . target_weight_dim_for_compression ) cumulative_filters_importance += filters_importance num_of_sparse_elems = get_rounded_pruned_element_number ( cumulative_filters_importance . size ( 0 ) , group_pruning_level ) threshold = sorted ( cumulative_filters_importance ) [ min ( num_of_sparse_elems , filters_num [ 0 ] - 1 ) ] mask = calculate_binary_mask ( cumulative_filters_importance , threshold ) for minfo in group . elements : pruning_module = minfo . operand pruning_module . binary_filter_pruning_mask = mask self . _update_benchmark_statistics ( )
Set the binary mask values according to groupwise pruning level.
Set the binary mask values according to groupwise pruning level .
"""
        Set the binary mask values according to groupwise pruning level.
        If pruning_level is a float, set the pruning level uniformly across groups.
        If pruning_level is a dict, set specific pruning levels corresponding to each group.
        """ # 1. Calculate cumulative importance for all filters in group # 2. Calculate threshold # 3. Set binary masks for filter # Calculate actual flops and weights number with new masks
self
pruning_level
Union[float, Dict[int, float]]