You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 10, 2025. It is now read-only.
@@ -158,7 +156,7 @@ We also want to provide an example of well-known compression algorithms. Here’
158
156
159
157
This is an APIfor a layer weight based compression algorithm.
160
158
161
-
First, we start from a pre-trained model which the model developer has. And then convert the pre-trained model to training phase model for compression fine-tuning training. During the convert to training phase model, We call `init_training_weights_repr`for each tensor that we want to compress which is specified from the `get_compressible_weights` method.
159
+
First, we start from a pre-trained model which the model developer has. And then convert the pre-trained model to training phase model for compression fine-tuning training. During the convert to training phase model, We call `init_training_weights`for each tensor that we want to compress which is specified from the `get_compressible_weights` method.
162
160
163
161
During the training phase, `project_training_weights` method is called for each training step. After fine-tuning training for compression is finished, we convert the training phase model to a compressed model. We only call the `compress_training_weights` function once for each compressible tensor for converting.
164
162
@@ -191,17 +189,21 @@ class WeightCompressionAlgorithm(metaclass=abc.ABCMeta):
"""Create training weight representations for initializing layer variables.
192
+
definit_training_weights(
193
+
self, pretrained_weight: tf.Tensor):
194
+
"""Initialize training weights for the training model. It calls the `add_training_weight` method several times to add training weights.
197
195
198
196
Args:
199
197
pretrained_weight: tf.Tensor of a pretrained weight of a layer that will
200
198
be compressed eventually.
199
+
"""
201
200
202
-
Returns:
203
-
A list of `WeightRepr`, a container for arguments to
204
-
`tf.keras.layers.Layer.add_weight`for each tf.Variable to create.
201
+
def add_training_weight(
202
+
self, *args, **kwargs):
203
+
"""Add training weight for the training model. This method is called from `init_training_weights`.
204
+
205
+
Args:
206
+
*args, **kwargs: args and kwargs for training_model.add_weight.
205
207
"""
206
208
207
209
@abc.abstractmethod
@@ -212,7 +214,7 @@ class WeightCompressionAlgorithm(metaclass=abc.ABCMeta):
212
214
Args:
213
215
*training_weights: tf.Tensors representing any variables used during
214
216
training, for a single compressible weight, in the order returned in
215
-
`init_training_weights_repr`.
217
+
`init_training_weights`.
216
218
217
219
Returns:
218
220
tf.Tensor to set the compressible weight to.
@@ -242,7 +244,7 @@ class WeightCompressionAlgorithm(metaclass=abc.ABCMeta):
242
244
Args:
243
245
*training_weights: tf.Tensors representing all variables used during
244
246
training, for a single compressible weight, in the order returned in
245
-
`init_training_weights_repr`.
247
+
`init_training_weights`.
246
248
247
249
Returns:
248
250
List of tf.Tensors to set to compressed or more compressible form.
@@ -384,16 +386,16 @@ Now we'll explain when each method is called and how many that method called for
384
386
`get_compressible_weights`is called when we want to get a list of variables that we will apply compression.
385
387
When we try to compress the pre-trained model, we just call this method for each layer in the pre-trained model. The number of the method calling is (# of layers).
`init_training_weights_repr`is called when we initialize the cloned training model from the pre-trained model. `optimize_training` method basically clones the model to create a training model for compression, wrapping compressible layers by the training wrapper to create training weights. The number of the method calling is (# of compressible weights).
398
+
`init_training_weights`is called when we initialize the cloned training model from the pre-trained model. `optimize_training` method basically clones the model to create a training model for compression, wrapping compressible layers by the training wrapper to create training weights. The number of the method calling is (# of compressible weights).
397
399
398
400
1. `project_training_weights`
399
401
<p align="center">
@@ -443,4 +445,3 @@ Note that every trainable variable that they want to train should be in training
443
445
444
446
It's not easy to find the bug there. Usually we get tensorflow bug messages with huge stack traces. We have to provide some bug messages for this API layer.
0 commit comments