Skip to content

Commit

Permalink
Fixed mean_sparse_prob calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-churkin committed May 15, 2021
1 parent a400890 commit ac19dc6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
3 changes: 1 addition & 2 deletions beta/nncf/tensorflow/sparsity/rb/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def statistics(self, quickly_collected_only: bool = False) -> RBSparsityStatisti
sparsity_rate_for_sparsified_modules = (total_sparsified_weights_number / total_weights_number).numpy()
model_weights_number = count_params(self._model.weights) - total_weights_number
sparsity_rate_for_model = (total_sparsified_weights_number / model_weights_number).numpy()
mean_sparse_prob = (sparse_prob_sum / tf.cast(total_weights_number, tf.float32)).numpy()
mean_sparse_prob = 1.0 - (sparse_prob_sum / tf.cast(total_weights_number, tf.float32)).numpy()

sparsity_levels = tf.keras.backend.batch_get_value(sparsity_levels)
weights_percentages = [weights_number / total_weights_number * 100
Expand All @@ -171,5 +171,4 @@ def statistics(self, quickly_collected_only: bool = False) -> RBSparsityStatisti
# TODO(andrey-churkin): Should be calculated when the distributed mode will be supported
masks_consistency = 1.0

# TODO(andrey-churkin): Check that `mean_sparse_prob` is calculated correctly
return RBSparsityStatistics(model_statistics, masks_consistency, target_level, mean_sparse_prob)
1 change: 0 additions & 1 deletion nncf/sparsity/rb/algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def statistics(self, quickly_collected_only=False):
model_statistics = super().statistics(quickly_collected_only)

target_level = self.loss.target_sparsity_rate
# TODO(andrey-churkin): Check that `mean_sparse_prob` is calculated correctly
mean_sparse_prob = 1.0 - self.loss.mean_sparse_prob

masks_consistency = 1.0
Expand Down

0 comments on commit ac19dc6

Please sign in to comment.