-
Notifications
You must be signed in to change notification settings - Fork 332
Re-factoring of the clustering example #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-factoring of the clustering example #562
Conversation
# Train model | ||
model = train_model(model, x_train, y_train, x_test, y_test) | ||
# Cluster and fine-tune model | ||
clustered_model = cluster_model(model, x_train, y_train, x_test, y_test) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More of a question than a comment:
Have you tried to apply the clustering wrapper on the inference graph rather than the training graph of a small example like mnist? If yes, what does the curve of the training loss look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by "inference graph" and "training graph". Could you explain this a bit further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, yes. An inference graph usually refers to a training graph after modifications targeted at inference. For instance, you can take a look at a TensorFlow legacy tool explaining some typical graph transforms (e.g. fold_batch_norms, merge_duplicate_nodes, remove_control_dependencies). I will write a summary on the internal site soon.
In our application context, I was just curious whether clustering behaves differently on a toy model, when tested with an inference graph rather than a training graph, in a similar way to a realistic model. If so, it could help our future debugging for upcoming new features with all the nice visualization you have done. We can check this later and this is not essential for this PR.
Just a note of status: while testing this, discovered that clustering_callbacks.py is not included into the pip package. I will review this again after the fix for that problem is available. |
We don't demonstrate in this example the benefits of clustering: the model size has been reduced. |
Unless the model is really extremely small clustering should still be beneficial. I just ran a small test with the example. It looks like we still get a decent compression ratio despite the reduced model size. Here are some model sizes at different stages of the example (note: clustered_model is the unstripped clustered model):
|
@benkli01 Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Showing the compression benefits of clustering would add a new "feature" to this sample, and is not the purpose of this PR, if I understand it correctly.
On the other hand, I think in pruning samples a dedicated end-to-end example is used to show off the effect on the model size. However, if I recall it correctly, it has been replaced by the end-to-end tutorial and should probably be deprecated/removed. @alanchiao, what are your thoughts - should we remove the end-to-end example from pruning, or add a similar one to clustering?
I'd agree that the end-to-end tutorials and comprehensive guides (for whatever model optimization technique) mostly replace the need for the python scripts.
There are cases when a script may be easier for a developer (to share early stage examples such as the current pruning mnist_e2e.py for sparse TFLite kernels, or to iterate on a non-easily testable feature such as a Tensorboard visualization). It would make sense to remove certain aspects of the examples (e.g. there isn't much of a benefit in pruning to enumerate all model types) and perhaps rename examples/ to scripts/ to deprecate them as things for end users to use and mostly keep them for the convenience of developers in some cases. What do you all think? It's been a while since I've personally used anything under examples/ but I know there has been a minor amount of usage elsewhere. |
Hi @alanchiao, Thanks for your comment. It would be nice to have a uniform experience across the techniques, because currently if I install tfmot, then I have a directory examples/ with only quantization/ subdirectory with scripts. It will be good to have none or scripts for all techniques. As a developer, for debugging purpose, personally, I use integration tests as they are much faster. Re: discussion regarding examples in the tfmot package: |
@wwwind: yes the experience should be uniform. Including the examples/quantization was a mistake - people are looking to install the library as opposed to the examples themselves. core/api doesn't seem to import any of the symbols from there, so there is probably some accidental extra BUILD line (or spurious dependency) on examples/quantization. |
Re-factor the clustering example for a better readability and overview. These changes were originally meant for #508 which had to be abandoned because of technical issues.