Skip to content

Conversation

TamasArm
Copy link
Contributor

@TamasArm TamasArm commented May 6, 2021

  • small fix to stop centroids from drifting
  • unit test coverage for fix

Summary of change:
Ensure the sparsity mask is updated during training time in sparsity-preserving clustering. Due to cluster-weight associations updates, the location of zero weights may change during training. This patch updated the sparsity mask according to such changes. It also adds extra tests to ensure sparsity aware clustering works during distributed training.

* small fix to stop centroids from drifting
* unit test coverage for fix
@google-cla google-cla bot added the cla: yes PR contributor has signed CLA label May 6, 2021
@github-actions github-actions bot added the technique:clustering Regarding tfmot.clustering.keras APIs and docs label May 6, 2021
# Re-discover the sparsity masks to avoid drifting
self.sparsity_masks[weight_name] = (
tf.cast(tf.math.not_equal(clustered_weights, 0), dtype=tf.float32)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me that this could be wrong: we form mask here from clustered_weights and then we multiply them with this mask.

In clustering we have trainable: weights and centroids. They could move away from zeros during training. To keep sparsity, we need to 1. to apply original sparsity_mask that is built in the build function to the original_weights; 2. to assign the smallest centroid back to zero, if there are no zero centroids. Here there is a variation: we could let original_weights to train as they want, because we use them to compute gradients in the backpropagation and give them more freedom, but we need to apply sparsity mask before we compute pulling indices. However, I would update with the original sparsity_mask the original_weights during training.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to agree with Elena. With the currently proposed change, what prevents the mask to drift away from the original sparsity? To prevent the drift of the zero centroid, and keep the mask intact, why not apply the mask to the original weights before updating pulling_indices above, as Elena proposes. Alternatively (or in addition!?), we could find a way to force the "zero" centroid, currently hidden behind ClusteringAlgorithm abstraction, to stay at zero.

Any thoughts?

* modified unit tests to more extensive check of number of unique weights after sparsity preserve clustering
@google-cla
Copy link

google-cla bot commented May 25, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no PR contributor has not signed CLA and removed cla: yes PR contributor has signed CLA labels May 25, 2021
@github-actions github-actions bot added technique:pruning Regarding tfmot.sparsity.keras APIs and docs technique:qat Regarding tfmot.quantization.keras (for quantization-aware training) APIs and docs labels May 25, 2021
…s, extended mnist test for additional checks
@TamasArm TamasArm force-pushed the fix_sparsity_preserve_clustering branch from 4ca62bd to 45b15be Compare May 25, 2021 12:35
@google-cla
Copy link

google-cla bot commented May 25, 2021

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: yes PR contributor has signed CLA and removed cla: no PR contributor has not signed CLA labels May 25, 2021
@googlebot googlebot added the cla: yes PR contributor has signed CLA label May 25, 2021
@wwwind wwwind requested a review from akarmi May 25, 2021 12:52
@wwwind wwwind added the ready to pull Working to get PR submitted to internal repository, after which merging to Github happens. label May 25, 2021
@akarmi
Copy link
Contributor

akarmi commented May 25, 2021

Thank you @TamasArm for fixing this.

@TamasArm
Copy link
Contributor Author

TamasArm commented Jun 1, 2021

@daverim Hi David, could you please take a look at this and retrigger the pull request labeler if possible? Thank you in advance!

@daverim daverim added ready to pull Working to get PR submitted to internal repository, after which merging to Github happens. and removed ready to pull Working to get PR submitted to internal repository, after which merging to Github happens. labels Jun 7, 2021
@copybara-service copybara-service bot merged commit 3c8ff9f into tensorflow:master Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes PR contributor has signed CLA ready to pull Working to get PR submitted to internal repository, after which merging to Github happens. technique:clustering Regarding tfmot.clustering.keras APIs and docs technique:pruning Regarding tfmot.sparsity.keras APIs and docs technique:qat Regarding tfmot.quantization.keras (for quantization-aware training) APIs and docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants