Skip to content
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

allow registering custom layers in prune and clustering registries. #1070

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
from tensorflow_model_optimization.python.core.clustering.keras.clustering_algorithm import ClusteringAlgorithm
from tensorflow_model_optimization.python.core.clustering.keras.clustering_callbacks import ClusteringSummaries
from tensorflow_model_optimization.python.core.clustering.keras.clusterable_layer import ClusterableLayer
from tensorflow_model_optimization.python.core.clustering.keras.clustering_registry import ClusteringRegistry
# pylint: enable=g-bad-import-order
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@
from tensorflow_model_optimization.python.core.sparsity.keras.pruning_policy import PruningPolicy
from tensorflow_model_optimization.python.core.sparsity.keras.pruning_policy import PruneForLatencyOnXNNPack

from tensorflow_model_optimization.python.core.sparsity.keras.prune_registry import PruneRegistry

# pylint: enable=g-bad-import-order
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,7 @@ def get_clusterable_weights_mha(): # pylint: disable=missing-docstring
layer.get_clusterable_weights = get_clusterable_weights

return layer

@classmethod
def register_clusterable_layer(cls, layer: layers.Layer, clusterable_weights: list[str]):
cls._LAYERS_WEIGHTS_MAP[layer] = clusterable_weights
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

from tensorflow_model_optimization.python.core.sparsity.keras import prunable_layer

# TODO(b/139939526): move to public API.

layers = tf.keras.layers
layers_compat_v1 = tf.compat.v1.keras.layers

Expand Down Expand Up @@ -226,3 +224,7 @@ def get_prunable_weights_mha_weight(weight_name):
layer.get_prunable_weights = get_prunable_weights

return layer

@classmethod
def register_prunable_layer(cls, layer: layers.Layer, prunable_weights: list[str]):
cls._LAYERS_WEIGHTS_MAP[layer] = prunable_weights