nncf/torch/pruning/filter_pruning/algo.py
def _set_binary_masks_for_pruned_modules_globally(self, pruning_level: float) -> None:
        """
        Set the binary mask values for layer groups according to the global pruning level.
        Filter importance scores in each group are merged into a single global list and a
        threshold value separating the pruning_level proportion of the least important filters
        in the model is calculated. Filters are pruned globally according to the threshold value.
        """
        nncf_logger.debug("Setting new binary masks for all pruned modules together.")
        filter_importances = []
        # 1. Calculate importances for all groups of  filters
        for group in self.pruned_module_groups_info.get_all_clusters():
            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)
            # Calculate cumulative importance for all filters in this group
            for minfo in group.elements:
                normalized_weight = self.weights_normalizer(minfo.module.weight)
                filters_importance = self.filter_importance(normalized_weight,
                                                            minfo.module.target_weight_dim_for_compression)
                cumulative_filters_importance += filters_importance

            filter_importances.append(cumulative_filters_importance)

        # 2. Calculate one threshold for all weights
        importances = torch.cat(filter_importances)
        threshold = sorted(importances)[int(pruning_level * importances.size(0))]

        # 3. Set binary masks for filters in groups
        for i, group in enumerate(self.pruned_module_groups_info.get_all_clusters()):
            mask = calculate_binary_mask(filter_importances[i], threshold)
            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 for layer groups according to the global pruning level.
        Filter importance scores in each group are merged into a single global list and a
        threshold value separating the pruning_level proportion of the least important filters
        in the model is calculated. Filters are pruned globally according to the threshold value.
        
Set the binary mask values for layer groups according to the global pruning level.
Filter importance scores in each group are merged into a single global list and a
threshold value separating the pruning_level proportion of the least important filters
in the model is calculated. Filters are pruned globally according to the threshold value.
Set the binary mask values for layer groups according to the global pruning level . Filter importance scores in each group are merged into a single global list and a threshold value separating the pruning_level proportion of the least important filters in the model is calculated . Filters are pruned globally according to the threshold value .
def _set_binary_masks_for_pruned_modules_globally(self, pruning_level: float) -> None:
        nncf_logger.debug("Setting new binary masks for all pruned modules together.")
        filter_importances = []
        for group in self.pruned_module_groups_info.get_all_clusters():
            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:
                normalized_weight = self.weights_normalizer(minfo.module.weight)
                filters_importance = self.filter_importance(normalized_weight,
                                                            minfo.module.target_weight_dim_for_compression)
                cumulative_filters_importance += filters_importance
            filter_importances.append(cumulative_filters_importance)
        importances = torch.cat(filter_importances)
        threshold = sorted(importances)[int(pruning_level * importances.size(0))]
        for i, group in enumerate(self.pruned_module_groups_info.get_all_clusters()):
            mask = calculate_binary_mask(filter_importances[i], 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_globally ( self , pruning_level : float ) -> None : nncf_logger . debug ( "Setting new binary masks for all pruned modules together." ) filter_importances = [ ] for group in self . pruned_module_groups_info . get_all_clusters ( ) : 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 : normalized_weight = self . weights_normalizer ( minfo . module . weight ) filters_importance = self . filter_importance ( normalized_weight , minfo . module . target_weight_dim_for_compression ) cumulative_filters_importance += filters_importance filter_importances . append ( cumulative_filters_importance ) importances = torch . cat ( filter_importances ) threshold = sorted ( importances ) [ int ( pruning_level * importances . size ( 0 ) ) ] for i , group in enumerate ( self . pruned_module_groups_info . get_all_clusters ( ) ) : mask = calculate_binary_mask ( filter_importances [ i ] , 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 for layer groups according to the global pruning level.
Set the binary mask values for layer groups according to the global pruning level .
"""
        Set the binary mask values for layer groups according to the global pruning level.
        Filter importance scores in each group are merged into a single global list and a
        threshold value separating the pruning_level proportion of the least important filters
        in the model is calculated. Filters are pruned globally according to the threshold value.
        """ # 1. Calculate importances for all groups of  filters # Calculate cumulative importance for all filters in this group # 2. Calculate one threshold for all weights # 3. Set binary masks for filters in groups # Calculate actual flops and weights number with new masks
self
pruning_level
float