mct-nightly 2.2.0.20241222.533__py3-none-any.whl → 2.2.0.20241224.532__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mct_nightly-2.2.0.20241222.533.dist-info → mct_nightly-2.2.0.20241224.532.dist-info}/METADATA +1 -1
- {mct_nightly-2.2.0.20241222.533.dist-info → mct_nightly-2.2.0.20241224.532.dist-info}/RECORD +29 -28
- model_compression_toolkit/__init__.py +1 -1
- model_compression_toolkit/core/common/graph/base_graph.py +1 -1
- model_compression_toolkit/core/common/graph/base_node.py +3 -3
- model_compression_toolkit/core/common/quantization/set_node_quantization_config.py +4 -4
- model_compression_toolkit/core/common/substitutions/shift_negative_activation.py +2 -2
- model_compression_toolkit/target_platform_capabilities/schema/mct_current_schema.py +1 -0
- model_compression_toolkit/target_platform_capabilities/schema/schema_functions.py +4 -5
- model_compression_toolkit/target_platform_capabilities/schema/v1.py +66 -172
- model_compression_toolkit/target_platform_capabilities/target_platform/__init__.py +0 -1
- model_compression_toolkit/target_platform_capabilities/target_platform/targetplatform2framework/attach2fw.py +56 -0
- model_compression_toolkit/target_platform_capabilities/target_platform/targetplatform2framework/attach2keras.py +107 -0
- model_compression_toolkit/target_platform_capabilities/target_platform/targetplatform2framework/attach2pytorch.py +91 -0
- model_compression_toolkit/target_platform_capabilities/target_platform/targetplatform2framework/operations_to_layers.py +1 -1
- model_compression_toolkit/target_platform_capabilities/target_platform/targetplatform2framework/target_platform_capabilities.py +7 -4
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1/tp_model.py +50 -51
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_lut/tp_model.py +54 -52
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_pot/tp_model.py +57 -53
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tp_model.py +52 -51
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tp_model.py +53 -51
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tp_model.py +59 -57
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tp_model.py +54 -52
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tp_model.py +90 -83
- model_compression_toolkit/target_platform_capabilities/tpc_models/qnnpack_tpc/v1/tp_model.py +26 -24
- model_compression_toolkit/target_platform_capabilities/tpc_models/tflite_tpc/v1/tp_model.py +57 -55
- model_compression_toolkit/target_platform_capabilities/target_platform/current_tp_model.py +0 -67
- model_compression_toolkit/target_platform_capabilities/target_platform/target_platform_model.py +0 -30
- {mct_nightly-2.2.0.20241222.533.dist-info → mct_nightly-2.2.0.20241224.532.dist-info}/LICENSE.md +0 -0
- {mct_nightly-2.2.0.20241222.533.dist-info → mct_nightly-2.2.0.20241224.532.dist-info}/WHEEL +0 -0
- {mct_nightly-2.2.0.20241222.533.dist-info → mct_nightly-2.2.0.20241224.532.dist-info}/top_level.txt +0 -0
model_compression_toolkit/target_platform_capabilities/tpc_models/qnnpack_tpc/v1/tp_model.py
CHANGED
@@ -18,7 +18,8 @@ import model_compression_toolkit as mct
|
|
18
18
|
import model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema as schema
|
19
19
|
from model_compression_toolkit.constants import FLOAT_BITWIDTH
|
20
20
|
from model_compression_toolkit.target_platform_capabilities.constants import KERNEL_ATTR, BIAS_ATTR, QNNPACK_TP_MODEL
|
21
|
-
from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel,
|
21
|
+
from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, \
|
22
|
+
Signedness, \
|
22
23
|
AttributeQuantizationConfig, OpQuantizationConfig
|
23
24
|
|
24
25
|
tp = mct.target_platform
|
@@ -138,8 +139,28 @@ def generate_tp_model(default_config: OpQuantizationConfig,
|
|
138
139
|
# of possible configurations to consider when quantizing a set of operations (in mixed-precision, for example).
|
139
140
|
# If the QuantizationConfigOptions contains only one configuration,
|
140
141
|
# this configuration will be used for the operation quantization:
|
141
|
-
default_configuration_options = schema.QuantizationConfigOptions([default_config])
|
142
|
-
|
142
|
+
default_configuration_options = schema.QuantizationConfigOptions(tuple([default_config]))
|
143
|
+
|
144
|
+
# Combine operations/modules into a single module.
|
145
|
+
# Pytorch supports the next fusing patterns:
|
146
|
+
# [Conv, Relu], [Conv, BatchNorm], [Conv, BatchNorm, Relu], [Linear, Relu]
|
147
|
+
# Source: # https://pytorch.org/docs/stable/quantization.html#model-preparation-for-quantization-eager-mode
|
148
|
+
operator_set = []
|
149
|
+
fusing_patterns = []
|
150
|
+
|
151
|
+
conv = schema.OperatorsSet("Conv")
|
152
|
+
batchnorm = schema.OperatorsSet("BatchNorm")
|
153
|
+
relu = schema.OperatorsSet("Relu")
|
154
|
+
linear = schema.OperatorsSet("Linear")
|
155
|
+
|
156
|
+
operator_set.extend([conv, batchnorm, relu, linear])
|
157
|
+
# ------------------- #
|
158
|
+
# Fusions
|
159
|
+
# ------------------- #
|
160
|
+
fusing_patterns.append(schema.Fusing((conv, batchnorm, relu)))
|
161
|
+
fusing_patterns.append(schema.Fusing((conv, batchnorm)))
|
162
|
+
fusing_patterns.append(schema.Fusing((conv, relu)))
|
163
|
+
fusing_patterns.append(schema.Fusing((linear, relu)))
|
143
164
|
# Create a TargetPlatformModel and set its default quantization config.
|
144
165
|
# This default configuration will be used for all operations
|
145
166
|
# unless specified otherwise (see OperatorsSet, for example):
|
@@ -148,27 +169,8 @@ def generate_tp_model(default_config: OpQuantizationConfig,
|
|
148
169
|
tpc_minor_version=1,
|
149
170
|
tpc_patch_version=0,
|
150
171
|
tpc_platform_type=QNNPACK_TP_MODEL,
|
172
|
+
operator_set=tuple(operator_set),
|
173
|
+
fusing_patterns=tuple(fusing_patterns),
|
151
174
|
add_metadata=False,
|
152
175
|
name=name)
|
153
|
-
|
154
|
-
# To start defining the model's components (such as operator sets, and fusing patterns),
|
155
|
-
# use 'with' the target platform model instance, and create them as below:
|
156
|
-
with generated_tpc:
|
157
|
-
# Combine operations/modules into a single module.
|
158
|
-
# Pytorch supports the next fusing patterns:
|
159
|
-
# [Conv, Relu], [Conv, BatchNorm], [Conv, BatchNorm, Relu], [Linear, Relu]
|
160
|
-
# Source: # https://pytorch.org/docs/stable/quantization.html#model-preparation-for-quantization-eager-mode
|
161
|
-
conv = schema.OperatorsSet("Conv")
|
162
|
-
batchnorm = schema.OperatorsSet("BatchNorm")
|
163
|
-
relu = schema.OperatorsSet("Relu")
|
164
|
-
linear = schema.OperatorsSet("Linear")
|
165
|
-
|
166
|
-
# ------------------- #
|
167
|
-
# Fusions
|
168
|
-
# ------------------- #
|
169
|
-
schema.Fusing([conv, batchnorm, relu])
|
170
|
-
schema.Fusing([conv, batchnorm])
|
171
|
-
schema.Fusing([conv, relu])
|
172
|
-
schema.Fusing([linear, relu])
|
173
|
-
|
174
176
|
return generated_tpc
|
@@ -136,7 +136,61 @@ def generate_tp_model(default_config: OpQuantizationConfig,
|
|
136
136
|
# of possible configurations to consider when quantizing a set of operations (in mixed-precision, for example).
|
137
137
|
# If the QuantizationConfigOptions contains only one configuration,
|
138
138
|
# this configuration will be used for the operation quantization:
|
139
|
-
default_configuration_options = schema.QuantizationConfigOptions([default_config])
|
139
|
+
default_configuration_options = schema.QuantizationConfigOptions(tuple([default_config]))
|
140
|
+
|
141
|
+
# In TFLite, the quantized operator specifications constraint operators quantization
|
142
|
+
# differently. For more details:
|
143
|
+
# https://www.tensorflow.org/lite/performance/quantization_spec#int8_quantized_operator_specifications
|
144
|
+
operator_set = []
|
145
|
+
fusing_patterns = []
|
146
|
+
|
147
|
+
operator_set.append(schema.OperatorsSet("NoQuantization",
|
148
|
+
default_configuration_options.clone_and_edit(
|
149
|
+
quantization_preserving=True)))
|
150
|
+
|
151
|
+
fc = schema.OperatorsSet("FullyConnected",
|
152
|
+
default_configuration_options.clone_and_edit_weight_attribute(weights_per_channel_threshold=False))
|
153
|
+
|
154
|
+
operator_set.append(schema.OperatorsSet("L2Normalization",
|
155
|
+
default_configuration_options.clone_and_edit(
|
156
|
+
fixed_zero_point=0, fixed_scale=1 / 128)))
|
157
|
+
operator_set.append(schema.OperatorsSet("LogSoftmax",
|
158
|
+
default_configuration_options.clone_and_edit(
|
159
|
+
fixed_zero_point=127, fixed_scale=16 / 256)))
|
160
|
+
operator_set.append(schema.OperatorsSet("Tanh",
|
161
|
+
default_configuration_options.clone_and_edit(
|
162
|
+
fixed_zero_point=0, fixed_scale=1 / 128)))
|
163
|
+
operator_set.append(schema.OperatorsSet("Softmax",
|
164
|
+
default_configuration_options.clone_and_edit(
|
165
|
+
fixed_zero_point=-128, fixed_scale=1 / 256)))
|
166
|
+
operator_set.append(schema.OperatorsSet("Logistic",
|
167
|
+
default_configuration_options.clone_and_edit(
|
168
|
+
fixed_zero_point=-128, fixed_scale=1 / 256)))
|
169
|
+
|
170
|
+
conv2d = schema.OperatorsSet("Conv2d")
|
171
|
+
kernel = schema.OperatorSetConcat([conv2d, fc])
|
172
|
+
|
173
|
+
relu = schema.OperatorsSet("Relu")
|
174
|
+
elu = schema.OperatorsSet("Elu")
|
175
|
+
activations_to_fuse = schema.OperatorSetConcat([relu, elu])
|
176
|
+
|
177
|
+
batch_norm = schema.OperatorsSet("BatchNorm")
|
178
|
+
bias_add = schema.OperatorsSet("BiasAdd")
|
179
|
+
add = schema.OperatorsSet("Add")
|
180
|
+
squeeze = schema.OperatorsSet("Squeeze",
|
181
|
+
qc_options=default_configuration_options.clone_and_edit(
|
182
|
+
quantization_preserving=True))
|
183
|
+
operator_set.extend([fc, conv2d, kernel, relu, elu, batch_norm, bias_add, add, squeeze])
|
184
|
+
# ------------------- #
|
185
|
+
# Fusions
|
186
|
+
# ------------------- #
|
187
|
+
# Source: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/grappler/optimizers/remapper
|
188
|
+
fusing_patterns.append(schema.Fusing((kernel, bias_add)))
|
189
|
+
fusing_patterns.append(schema.Fusing((kernel, bias_add, activations_to_fuse)))
|
190
|
+
fusing_patterns.append(schema.Fusing((conv2d, batch_norm, activations_to_fuse)))
|
191
|
+
fusing_patterns.append(schema.Fusing((conv2d, squeeze, activations_to_fuse)))
|
192
|
+
fusing_patterns.append(schema.Fusing((batch_norm, activations_to_fuse)))
|
193
|
+
fusing_patterns.append(schema.Fusing((batch_norm, add, activations_to_fuse)))
|
140
194
|
|
141
195
|
# Create a TargetPlatformModel and set its default quantization config.
|
142
196
|
# This default configuration will be used for all operations
|
@@ -145,62 +199,10 @@ def generate_tp_model(default_config: OpQuantizationConfig,
|
|
145
199
|
default_configuration_options,
|
146
200
|
tpc_minor_version=1,
|
147
201
|
tpc_patch_version=0,
|
202
|
+
operator_set=tuple(operator_set),
|
203
|
+
fusing_patterns=tuple(fusing_patterns),
|
148
204
|
tpc_platform_type=TFLITE_TP_MODEL,
|
149
205
|
add_metadata=False,
|
150
206
|
name=name)
|
151
207
|
|
152
|
-
# To start defining the model's components (such as operator sets, and fusing patterns),
|
153
|
-
# use 'with' the TargetPlatformModel instance, and create them as below:
|
154
|
-
with generated_tpc:
|
155
|
-
# In TFLite, the quantized operator specifications constraint operators quantization
|
156
|
-
# differently. For more details:
|
157
|
-
# https://www.tensorflow.org/lite/performance/quantization_spec#int8_quantized_operator_specifications
|
158
|
-
schema.OperatorsSet("NoQuantization",
|
159
|
-
tp.get_default_quantization_config_options().clone_and_edit(
|
160
|
-
quantization_preserving=True))
|
161
|
-
|
162
|
-
fc_qco = tp.get_default_quantization_config_options()
|
163
|
-
fc = schema.OperatorsSet("FullyConnected",
|
164
|
-
fc_qco.clone_and_edit_weight_attribute(weights_per_channel_threshold=False))
|
165
|
-
|
166
|
-
schema.OperatorsSet("L2Normalization",
|
167
|
-
tp.get_default_quantization_config_options().clone_and_edit(
|
168
|
-
fixed_zero_point=0, fixed_scale=1 / 128))
|
169
|
-
schema.OperatorsSet("LogSoftmax",
|
170
|
-
tp.get_default_quantization_config_options().clone_and_edit(
|
171
|
-
fixed_zero_point=127, fixed_scale=16 / 256))
|
172
|
-
schema.OperatorsSet("Tanh",
|
173
|
-
tp.get_default_quantization_config_options().clone_and_edit(
|
174
|
-
fixed_zero_point=0, fixed_scale=1 / 128))
|
175
|
-
schema.OperatorsSet("Softmax",
|
176
|
-
tp.get_default_quantization_config_options().clone_and_edit(
|
177
|
-
fixed_zero_point=-128, fixed_scale=1 / 256))
|
178
|
-
schema.OperatorsSet("Logistic",
|
179
|
-
tp.get_default_quantization_config_options().clone_and_edit(
|
180
|
-
fixed_zero_point=-128, fixed_scale=1 / 256))
|
181
|
-
|
182
|
-
conv2d = schema.OperatorsSet("Conv2d")
|
183
|
-
kernel = schema.OperatorSetConcat([conv2d, fc])
|
184
|
-
|
185
|
-
relu = schema.OperatorsSet("Relu")
|
186
|
-
elu = schema.OperatorsSet("Elu")
|
187
|
-
activations_to_fuse = schema.OperatorSetConcat([relu, elu])
|
188
|
-
|
189
|
-
batch_norm = schema.OperatorsSet("BatchNorm")
|
190
|
-
bias_add = schema.OperatorsSet("BiasAdd")
|
191
|
-
add = schema.OperatorsSet("Add")
|
192
|
-
squeeze = schema.OperatorsSet("Squeeze",
|
193
|
-
qc_options=tp.get_default_quantization_config_options().clone_and_edit(
|
194
|
-
quantization_preserving=True))
|
195
|
-
# ------------------- #
|
196
|
-
# Fusions
|
197
|
-
# ------------------- #
|
198
|
-
# Source: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/grappler/optimizers/remapper
|
199
|
-
schema.Fusing([kernel, bias_add])
|
200
|
-
schema.Fusing([kernel, bias_add, activations_to_fuse])
|
201
|
-
schema.Fusing([conv2d, batch_norm, activations_to_fuse])
|
202
|
-
schema.Fusing([conv2d, squeeze, activations_to_fuse])
|
203
|
-
schema.Fusing([batch_norm, activations_to_fuse])
|
204
|
-
schema.Fusing([batch_norm, add, activations_to_fuse])
|
205
|
-
|
206
208
|
return generated_tpc
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# Copyright 2022 Sony Semiconductor Israel, Inc. All rights reserved.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
# ==============================================================================
|
15
|
-
|
16
|
-
from model_compression_toolkit.logger import Logger
|
17
|
-
|
18
|
-
def get_current_tp_model():
|
19
|
-
"""
|
20
|
-
|
21
|
-
Returns: The current TargetPlatformModel that is being used and accessed.
|
22
|
-
|
23
|
-
"""
|
24
|
-
return _current_tp_model.get()
|
25
|
-
|
26
|
-
|
27
|
-
class CurrentTPModel:
|
28
|
-
"""
|
29
|
-
Wrapper of the current TargetPlatformModel object that is being accessed and defined.
|
30
|
-
"""
|
31
|
-
|
32
|
-
def __init__(self):
|
33
|
-
super(CurrentTPModel, self).__init__()
|
34
|
-
self.tp_model = None
|
35
|
-
|
36
|
-
def get(self):
|
37
|
-
"""
|
38
|
-
|
39
|
-
Returns: The current TargetPlatformModel that is being defined.
|
40
|
-
|
41
|
-
"""
|
42
|
-
if self.tp_model is None:
|
43
|
-
Logger.critical('Target platform model is not initialized.') # pragma: no cover
|
44
|
-
return self.tp_model
|
45
|
-
|
46
|
-
def reset(self):
|
47
|
-
"""
|
48
|
-
|
49
|
-
Reset the current TargetPlatformModel so a new TargetPlatformModel can be wrapped and
|
50
|
-
used as the current TargetPlatformModel object.
|
51
|
-
|
52
|
-
"""
|
53
|
-
self.tp_model = None
|
54
|
-
|
55
|
-
def set(self, tp_model):
|
56
|
-
"""
|
57
|
-
Set and wrap a TargetPlatformModel as the current TargetPlatformModel.
|
58
|
-
|
59
|
-
Args:
|
60
|
-
tp_model: TargetPlatformModel to set as the current TargetPlatformModel to access and use.
|
61
|
-
|
62
|
-
"""
|
63
|
-
self.tp_model = tp_model
|
64
|
-
|
65
|
-
|
66
|
-
# Use a single instance for the current model.
|
67
|
-
_current_tp_model = CurrentTPModel()
|
model_compression_toolkit/target_platform_capabilities/target_platform/target_platform_model.py
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# Copyright 2022 Sony Semiconductor Israel, Inc. All rights reserved.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
# ==============================================================================
|
15
|
-
|
16
|
-
from model_compression_toolkit.target_platform_capabilities.target_platform.current_tp_model import get_current_tp_model
|
17
|
-
from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import QuantizationConfigOptions
|
18
|
-
|
19
|
-
|
20
|
-
def get_default_quantization_config_options() -> QuantizationConfigOptions:
|
21
|
-
"""
|
22
|
-
|
23
|
-
Returns: The default QuantizationConfigOptions of the model. This is the options
|
24
|
-
to use when a layer's options is queried and it wasn't specified in the TargetPlatformCapabilities.
|
25
|
-
The default QuantizationConfigOptions always contains a single option.
|
26
|
-
|
27
|
-
"""
|
28
|
-
return get_current_tp_model().default_qco
|
29
|
-
|
30
|
-
|
{mct_nightly-2.2.0.20241222.533.dist-info → mct_nightly-2.2.0.20241224.532.dist-info}/LICENSE.md
RENAMED
File without changes
|
File without changes
|
{mct_nightly-2.2.0.20241222.533.dist-info → mct_nightly-2.2.0.20241224.532.dist-info}/top_level.txt
RENAMED
File without changes
|