Skip to content

Commit bb78040

Browse files
alanchiaotensorflower-gardener
authored andcommitted
Disable all quantize layers where we don't have a tested conversion path to full-integer deployment, assuming TFLite enables uint8 inputs and outputs.
Will reenable once path is confirmed. PiperOrigin-RevId: 304478647
1 parent 57dc232 commit bb78040

File tree

2 files changed

+42
-37
lines changed

2 files changed

+42
-37
lines changed

tensorflow_model_optimization/python/core/quantization/keras/default_8bit/default_8bit_quantize_registry.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def _get_rnn_cells(self, rnn_layer):
7272
class QuantizeRegistry(quantize_registry.QuantizeRegistry, _RNNHelper):
7373
"""QuantizationRegistry for built-in Keras classes for default 8-bit scheme."""
7474

75+
# TODO(tfmot): expand layers test in quantize_functional_test.py
76+
# to add more layers to whitelist.
7577
_LAYER_QUANTIZE_INFO = [
7678

7779
# Activation Layers
@@ -84,16 +86,18 @@ class QuantizeRegistry(quantize_registry.QuantizeRegistry, _RNNHelper):
8486
# layers.ThresholdedReLU,
8587

8688
# Convolution Layers
87-
_QuantizeInfo(layers.Conv1D, ['kernel'], ['activation']),
88-
_QuantizeInfo(layers.Conv3D, ['kernel'], ['activation']),
89-
# TODO(pulkitb): Verify Transpose layers.
90-
_QuantizeInfo(layers.Conv2DTranspose, ['kernel'], ['activation']),
91-
_QuantizeInfo(layers.Conv3DTranspose, ['kernel'], ['activation']),
89+
# _QuantizeInfo(layers.Conv1D, ['kernel'], ['activation']),
90+
91+
# layers.Conv2D is supported and handled in code below.
92+
93+
# _QuantizeInfo(layers.Conv3D, ['kernel'], ['activation']),
94+
# _QuantizeInfo(layers.Conv2DTranspose, ['kernel'], ['activation']),
95+
# _QuantizeInfo(layers.Conv3DTranspose, ['kernel'], ['activation']),
9296
_no_quantize(layers.Cropping1D),
9397
_no_quantize(layers.Cropping2D),
9498
_no_quantize(layers.Cropping3D),
9599
_no_quantize(layers.UpSampling1D),
96-
_no_quantize(layers.UpSampling2D),
100+
# _no_quantize(layers.UpSampling2D),
97101
_no_quantize(layers.UpSampling3D),
98102
_no_quantize(layers.ZeroPadding1D),
99103
_no_quantize(layers.ZeroPadding2D),
@@ -107,7 +111,7 @@ class QuantizeRegistry(quantize_registry.QuantizeRegistry, _RNNHelper):
107111
_QuantizeInfo(layers.Dense, ['kernel'], ['activation']),
108112
_no_quantize(layers.Dropout),
109113
_no_quantize(layers.Flatten),
110-
_no_quantize(layers.Masking),
114+
# _no_quantize(layers.Masking),
111115
_no_quantize(layers.Permute),
112116
_no_quantize(layers.RepeatVector),
113117
_no_quantize(layers.Reshape),
@@ -119,7 +123,7 @@ class QuantizeRegistry(quantize_registry.QuantizeRegistry, _RNNHelper):
119123
# Pooling Layers
120124
_QuantizeInfo(layers.AveragePooling1D, [], [], True),
121125
_QuantizeInfo(layers.AveragePooling2D, [], [], True),
122-
_QuantizeInfo(layers.AveragePooling3D, [], [], True),
126+
# _QuantizeInfo(layers.AveragePooling3D, [], [], True),
123127
_QuantizeInfo(layers.GlobalAveragePooling1D, [], [], True),
124128
_QuantizeInfo(layers.GlobalAveragePooling2D, [], [], True),
125129
_QuantizeInfo(layers.GlobalAveragePooling3D, [], [], True),
@@ -128,11 +132,10 @@ class QuantizeRegistry(quantize_registry.QuantizeRegistry, _RNNHelper):
128132
_no_quantize(layers.GlobalMaxPooling3D),
129133
_no_quantize(layers.MaxPooling1D),
130134
_no_quantize(layers.MaxPooling2D),
131-
_no_quantize(layers.MaxPooling3D),
135+
# _no_quantize(layers.MaxPooling3D),
132136

133-
# TODO(pulkitb): Verify Locally Connected layers.
134-
_QuantizeInfo(layers.LocallyConnected1D, ['kernel'], ['activation']),
135-
_QuantizeInfo(layers.LocallyConnected2D, ['kernel'], ['activation']),
137+
# _QuantizeInfo(layers.LocallyConnected1D, ['kernel'], ['activation']),
138+
# _QuantizeInfo(layers.LocallyConnected2D, ['kernel'], ['activation']),
136139
_QuantizeInfo(layers.Add, [], [], True),
137140

138141
# Enable once verified with TFLite behavior.

tensorflow_model_optimization/python/core/quantization/keras/quantize_wrapper_test.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,41 +68,43 @@ def testQuantizesWeightsInLayer(self):
6868
# 1. Only layers with 'kernel' attribute work. Need to extend to others.
6969
# 2. Activations are not tested currently.
7070
# 3. RNN layers need to be added
71-
71+
# TODO(tfmot): reenable some of these once added back to whitelist
72+
# after testing in quantize_functional_test.py.
7273
@parameterized.parameters(
73-
(layers.Conv1D, (3, 6), {
74-
'filters': 4,
75-
'kernel_size': 2
76-
}),
74+
# (layers.Conv1D, (3, 6), {
75+
# 'filters': 4,
76+
# 'kernel_size': 2
77+
# }),
7778
(layers.Conv2D, (4, 6, 1), {
7879
'filters': 4,
7980
'kernel_size': (2, 2)
8081
}),
81-
(layers.Conv2DTranspose, (7, 6, 3), {
82-
'filters': 2,
83-
'kernel_size': (3, 3)
84-
}),
85-
(layers.Conv3D, (5, 7, 6, 3), {
86-
'filters': 2,
87-
'kernel_size': (3, 3, 3)
88-
}),
89-
(layers.Conv3DTranspose, (5, 7, 6, 3), {
90-
'filters': 2,
91-
'kernel_size': (3, 3, 3)
92-
}),
82+
# (layers.Conv2DTranspose, (7, 6, 3), {
83+
# 'filters': 2,
84+
# 'kernel_size': (3, 3)
85+
# }),
86+
# (layers.Conv3D, (5, 7, 6, 3), {
87+
# 'filters': 2,
88+
# 'kernel_size': (3, 3, 3)
89+
# }),
90+
# (layers.Conv3DTranspose, (5, 7, 6, 3), {
91+
# 'filters': 2,
92+
# 'kernel_size': (3, 3, 3)
93+
# }),
9394
# TODO(pulkitb): Add missing SeparableConv layers. The initializers are
9495
# different, so will need a change.
9596
(layers.Dense, (3,), {
9697
'units': 2
9798
}),
98-
(layers.LocallyConnected1D, (3, 6), {
99-
'filters': 4,
100-
'kernel_size': 2
101-
}),
102-
(layers.LocallyConnected2D, (4, 6, 1), {
103-
'filters': 4,
104-
'kernel_size': (2, 2)
105-
}))
99+
# (layers.LocallyConnected1D, (3, 6), {
100+
# 'filters': 4,
101+
# 'kernel_size': 2
102+
# }),
103+
# (layers.LocallyConnected2D, (4, 6, 1), {
104+
# 'filters': 4,
105+
# 'kernel_size': (2, 2)
106+
# })
107+
)
106108
def testQuantizesWeights_KerasLayers(self, layer_type, input_shape, kwargs):
107109
self.weights = None
108110

0 commit comments

Comments
 (0)