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.
Copy file name to clipboardExpand all lines: rfcs/20201221-tfmot-compression-api.md
+48-62Lines changed: 48 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,23 +49,21 @@ Our API also provides guidelines for testing and benchmark. For now, we only hav
49
49
We provide the tutorial for [SVD](https://en.wikipedia.org/wiki/Singular_value_decomposition) compression algorithm that shows how we implement the SVD algorithm using TFMOT compression API by colab. This tutorial includes:
50
50
51
51
#### Algorithm developer side
52
-
1.The algorithm developer implementing the SVD algorithm uses the `WeightCompressor` class.
52
+
The algorithm developer implementing the SVD algorithm uses the `WeightCompressor` class. It also includes a custom model developer API for the SVD algorithm.
53
53
54
54
```python
55
55
classSVD(algorithm.WeightCompressor):
56
56
"""SVD compression module config."""
57
57
58
-
def__init__(self, params):
59
-
self.params=params
58
+
def__init__(self, rank):
59
+
self.rank=rank
60
60
61
61
definit_training_weights(
62
62
self, pretrained_weight: tf.Tensor):
63
63
"""Init function from pre-trained model case."""
64
-
rank =self.params.rank
65
-
66
64
# Dense Layer
67
65
iflen(pretrained_weight.shape) ==2:
68
-
u, sv = tf_svd_factorization_2d(pretrained_weight, rank)
66
+
u, sv = tf_svd_factorization_2d(pretrained_weight, self.rank)
69
67
else:
70
68
raiseNotImplementedError('Only for dimension=2 is supported.')
71
69
@@ -84,45 +82,34 @@ class SVD(algorithm.WeightCompressor):
`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).
`compress_training_weights` is called when we convert the training model to the compressed model. The number of the method calling is (# of compressible weights).
0 commit comments