mct-nightly 2.0.0.20240418.439__py3-none-any.whl → 2.0.0.20240419.358__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.0.0.20240418.439.dist-info → mct_nightly-2.0.0.20240419.358.dist-info}/METADATA +1 -1
- {mct_nightly-2.0.0.20240418.439.dist-info → mct_nightly-2.0.0.20240419.358.dist-info}/RECORD +39 -39
- model_compression_toolkit/__init__.py +1 -1
- model_compression_toolkit/core/common/graph/base_graph.py +2 -2
- model_compression_toolkit/core/common/graph/base_node.py +25 -8
- model_compression_toolkit/core/common/graph/functional_node.py +18 -1
- model_compression_toolkit/core/common/network_editors/node_filters.py +4 -3
- model_compression_toolkit/core/common/quantization/node_quantization_config.py +0 -5
- model_compression_toolkit/core/common/quantization/quantization_params_generation/lut_kmeans_params.py +4 -3
- model_compression_toolkit/core/common/similarity_analyzer.py +2 -2
- model_compression_toolkit/core/keras/back2framework/keras_model_builder.py +4 -1
- model_compression_toolkit/core/keras/graph_substitutions/substitutions/batchnorm_folding.py +7 -7
- model_compression_toolkit/core/keras/graph_substitutions/substitutions/linear_collapsing.py +1 -1
- model_compression_toolkit/core/keras/graph_substitutions/substitutions/residual_collapsing.py +1 -1
- model_compression_toolkit/core/keras/keras_implementation.py +10 -10
- model_compression_toolkit/core/keras/keras_node_prior_info.py +4 -4
- model_compression_toolkit/core/keras/pruning/pruning_keras_implementation.py +4 -5
- model_compression_toolkit/core/keras/reader/common.py +2 -2
- model_compression_toolkit/core/keras/reader/node_builder.py +28 -9
- model_compression_toolkit/core/keras/tf_tensor_numpy.py +5 -2
- model_compression_toolkit/core/pytorch/back2framework/pytorch_model_builder.py +34 -21
- model_compression_toolkit/core/pytorch/graph_substitutions/substitutions/batchnorm_folding.py +8 -8
- model_compression_toolkit/core/pytorch/graph_substitutions/substitutions/const_holder_conv.py +2 -2
- model_compression_toolkit/core/pytorch/graph_substitutions/substitutions/linear_collapsing.py +1 -1
- model_compression_toolkit/core/pytorch/graph_substitutions/substitutions/relu_bound_to_power_of_2.py +4 -4
- model_compression_toolkit/core/pytorch/graph_substitutions/substitutions/residual_collapsing.py +1 -1
- model_compression_toolkit/core/pytorch/pruning/pruning_pytorch_implementation.py +8 -8
- model_compression_toolkit/core/pytorch/pytorch_implementation.py +4 -5
- model_compression_toolkit/core/pytorch/pytorch_node_prior_info.py +2 -2
- model_compression_toolkit/exporter/model_wrapper/keras/builder/fully_quantized_model_builder.py +5 -1
- model_compression_toolkit/exporter/model_wrapper/pytorch/builder/fully_quantized_model_builder.py +9 -2
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_lut/tp_model.py +1 -1
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tp_model.py +20 -6
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tpc_keras.py +1 -1
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tp_model.py +22 -8
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tpc_keras.py +1 -1
- {mct_nightly-2.0.0.20240418.439.dist-info → mct_nightly-2.0.0.20240419.358.dist-info}/LICENSE.md +0 -0
- {mct_nightly-2.0.0.20240418.439.dist-info → mct_nightly-2.0.0.20240419.358.dist-info}/WHEEL +0 -0
- {mct_nightly-2.0.0.20240418.439.dist-info → mct_nightly-2.0.0.20240419.358.dist-info}/top_level.txt +0 -0
model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_lut/tp_model.py
CHANGED
|
@@ -56,7 +56,7 @@ def get_op_quantization_configs() -> Tuple[OpQuantizationConfig, List[OpQuantiza
|
|
|
56
56
|
|
|
57
57
|
# We define a default quantization config for all non-specified weights attributes.
|
|
58
58
|
default_weight_attr_config = AttributeQuantizationConfig(
|
|
59
|
-
weights_quantization_method=tp.QuantizationMethod.
|
|
59
|
+
weights_quantization_method=tp.QuantizationMethod.POWER_OF_TWO,
|
|
60
60
|
weights_n_bits=8,
|
|
61
61
|
weights_per_channel_threshold=False,
|
|
62
62
|
enable_weights_quantization=False,
|
|
@@ -32,7 +32,7 @@ def get_tp_model() -> TargetPlatformModel:
|
|
|
32
32
|
NOTE: in order to generate a target platform model with different configurations but with the same Operators Sets
|
|
33
33
|
(for tests, experiments, etc.), use this method implementation as a test-case, i.e., override the
|
|
34
34
|
'get_op_quantization_configs' method and use its output to call 'generate_tp_model' with your configurations.
|
|
35
|
-
This version enables metadata by default
|
|
35
|
+
This version enables metadata by default.
|
|
36
36
|
|
|
37
37
|
Returns: A TargetPlatformModel object.
|
|
38
38
|
|
|
@@ -44,7 +44,8 @@ def get_tp_model() -> TargetPlatformModel:
|
|
|
44
44
|
name='imx500_tp_model')
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
def get_op_quantization_configs() ->
|
|
47
|
+
def get_op_quantization_configs() -> \
|
|
48
|
+
Tuple[OpQuantizationConfig, List[OpQuantizationConfig], OpQuantizationConfig]:
|
|
48
49
|
"""
|
|
49
50
|
Creates a default configuration object for 8-bit quantization, to be used to set a default TargetPlatformModel.
|
|
50
51
|
In addition, creates a default configuration objects list (with 8, 4 and 2 bit quantization) to be used as
|
|
@@ -151,6 +152,19 @@ def generate_tp_model(default_config: OpQuantizationConfig,
|
|
|
151
152
|
# this configuration will be used for the operation quantization:
|
|
152
153
|
default_configuration_options = tp.QuantizationConfigOptions([default_config])
|
|
153
154
|
|
|
155
|
+
# Create a QuantizationConfigOptions for quantizing constants in functional ops.
|
|
156
|
+
# Constant configuration is similar to the default eight bit configuration except for PoT
|
|
157
|
+
# quantization method for the constant.
|
|
158
|
+
# Since the constants are not named attributes of the layer, we use the default_weight_attr_config to
|
|
159
|
+
# define the desired quantization properties for them.
|
|
160
|
+
const_config = default_config.clone_and_edit(
|
|
161
|
+
default_weight_attr_config=default_config.default_weight_attr_config.clone_and_edit(
|
|
162
|
+
enable_weights_quantization=True))
|
|
163
|
+
if not (const_config.default_weight_attr_config.weights_quantization_method == tp.QuantizationMethod.POWER_OF_TWO and
|
|
164
|
+
const_config.default_weight_attr_config.weights_per_channel_threshold is False):
|
|
165
|
+
mct.logger.Logger.error('Constant quantization config should be per-tensor PoT.')
|
|
166
|
+
const_configuration_options = tp.QuantizationConfigOptions([const_config])
|
|
167
|
+
|
|
154
168
|
# Create a TargetPlatformModel and set its default quantization config.
|
|
155
169
|
# This default configuration will be used for all operations
|
|
156
170
|
# unless specified otherwise (see OperatorsSet, for example):
|
|
@@ -184,10 +198,10 @@ def generate_tp_model(default_config: OpQuantizationConfig,
|
|
|
184
198
|
# Define operations sets without quantization configuration
|
|
185
199
|
# options (useful for creating fusing patterns, for example):
|
|
186
200
|
any_relu = tp.OperatorsSet("AnyReLU")
|
|
187
|
-
add = tp.OperatorsSet("Add")
|
|
188
|
-
sub = tp.OperatorsSet("Sub")
|
|
189
|
-
mul = tp.OperatorsSet("Mul")
|
|
190
|
-
div = tp.OperatorsSet("Div")
|
|
201
|
+
add = tp.OperatorsSet("Add", const_configuration_options)
|
|
202
|
+
sub = tp.OperatorsSet("Sub", const_configuration_options)
|
|
203
|
+
mul = tp.OperatorsSet("Mul", const_configuration_options)
|
|
204
|
+
div = tp.OperatorsSet("Div", const_configuration_options)
|
|
191
205
|
prelu = tp.OperatorsSet("PReLU")
|
|
192
206
|
swish = tp.OperatorsSet("Swish")
|
|
193
207
|
sigmoid = tp.OperatorsSet("Sigmoid")
|
model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tpc_keras.py
CHANGED
|
@@ -122,7 +122,7 @@ def generate_keras_tpc(name: str, tp_model: tp.TargetPlatformModel):
|
|
|
122
122
|
tp.OperationsSetToLayers("Add", [tf.add, Add])
|
|
123
123
|
tp.OperationsSetToLayers("Sub", [tf.subtract, Subtract])
|
|
124
124
|
tp.OperationsSetToLayers("Mul", [tf.math.multiply, Multiply])
|
|
125
|
-
tp.OperationsSetToLayers("Div", [tf.math.divide])
|
|
125
|
+
tp.OperationsSetToLayers("Div", [tf.math.divide, tf.math.truediv])
|
|
126
126
|
tp.OperationsSetToLayers("PReLU", [PReLU])
|
|
127
127
|
tp.OperationsSetToLayers("Swish", [tf.nn.swish, tp.LayerFilterParams(Activation, activation="swish")])
|
|
128
128
|
tp.OperationsSetToLayers("Sigmoid", [tf.nn.sigmoid, tp.LayerFilterParams(Activation, activation="sigmoid")])
|
model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tp_model.py
CHANGED
|
@@ -33,7 +33,7 @@ def get_tp_model() -> TargetPlatformModel:
|
|
|
33
33
|
NOTE: in order to generate a target platform model with different configurations but with the same Operators Sets
|
|
34
34
|
(for tests, experiments, etc.), use this method implementation as a test-case, i.e., override the
|
|
35
35
|
'get_op_quantization_configs' method and use its output to call 'generate_tp_model' with your configurations.
|
|
36
|
-
This version enables metadata by default
|
|
36
|
+
This version enables metadata by default.
|
|
37
37
|
|
|
38
38
|
Returns: A TargetPlatformModel object.
|
|
39
39
|
|
|
@@ -45,7 +45,8 @@ def get_tp_model() -> TargetPlatformModel:
|
|
|
45
45
|
name='imx500_lut_tp_model')
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
def get_op_quantization_configs() ->
|
|
48
|
+
def get_op_quantization_configs() -> \
|
|
49
|
+
Tuple[OpQuantizationConfig, List[OpQuantizationConfig], OpQuantizationConfig]:
|
|
49
50
|
"""
|
|
50
51
|
Creates a default configuration object for 8-bit quantization, to be used to set a default TargetPlatformModel.
|
|
51
52
|
In addition, creates a default configuration objects list (with 8, 4 and 2 bit quantization) to be used as
|
|
@@ -57,13 +58,13 @@ def get_op_quantization_configs() -> Tuple[OpQuantizationConfig, List[OpQuantiza
|
|
|
57
58
|
|
|
58
59
|
# We define a default quantization config for all non-specified weights attributes.
|
|
59
60
|
default_weight_attr_config = AttributeQuantizationConfig(
|
|
60
|
-
weights_quantization_method=tp.QuantizationMethod.
|
|
61
|
+
weights_quantization_method=tp.QuantizationMethod.POWER_OF_TWO,
|
|
61
62
|
weights_n_bits=8,
|
|
62
63
|
weights_per_channel_threshold=False,
|
|
63
64
|
enable_weights_quantization=False,
|
|
64
65
|
lut_values_bitwidth=None)
|
|
65
66
|
|
|
66
|
-
#
|
|
67
|
+
# define a quantization config to quantize the kernel (for layers where there is a kernel attribute).
|
|
67
68
|
kernel_base_config = AttributeQuantizationConfig(
|
|
68
69
|
weights_quantization_method=tp.QuantizationMethod.SYMMETRIC,
|
|
69
70
|
weights_n_bits=8,
|
|
@@ -150,6 +151,19 @@ def generate_tp_model(default_config: OpQuantizationConfig,
|
|
|
150
151
|
# this configuration will be used for the operation quantization:
|
|
151
152
|
default_configuration_options = tp.QuantizationConfigOptions([default_config])
|
|
152
153
|
|
|
154
|
+
# Create a QuantizationConfigOptions for quantizing constants in functional ops.
|
|
155
|
+
# Constant configuration is similar to the default eight bit configuration except for PoT
|
|
156
|
+
# quantization method for the constant.
|
|
157
|
+
# Since the constants are not named attributes of the layer, we use the default_weight_attr_config to
|
|
158
|
+
# define the desired quantization properties for them.
|
|
159
|
+
const_config = default_config.clone_and_edit(
|
|
160
|
+
default_weight_attr_config=default_config.default_weight_attr_config.clone_and_edit(
|
|
161
|
+
enable_weights_quantization=True))
|
|
162
|
+
if not (const_config.default_weight_attr_config.weights_quantization_method == tp.QuantizationMethod.POWER_OF_TWO and
|
|
163
|
+
const_config.default_weight_attr_config.weights_per_channel_threshold is False):
|
|
164
|
+
mct.logger.Logger.error('Constant quantization config should be per-tensor PoT.')
|
|
165
|
+
const_configuration_options = tp.QuantizationConfigOptions([const_config])
|
|
166
|
+
|
|
153
167
|
# Create a TargetPlatformModel and set its default quantization config.
|
|
154
168
|
# This default configuration will be used for all operations
|
|
155
169
|
# unless specified otherwise (see OperatorsSet, for example):
|
|
@@ -181,10 +195,10 @@ def generate_tp_model(default_config: OpQuantizationConfig,
|
|
|
181
195
|
# Define operations sets without quantization configuration
|
|
182
196
|
# options (useful for creating fusing patterns, for example):
|
|
183
197
|
any_relu = tp.OperatorsSet("AnyReLU")
|
|
184
|
-
add = tp.OperatorsSet("Add")
|
|
185
|
-
sub = tp.OperatorsSet("Sub")
|
|
186
|
-
mul = tp.OperatorsSet("Mul")
|
|
187
|
-
div = tp.OperatorsSet("Div")
|
|
198
|
+
add = tp.OperatorsSet("Add", const_configuration_options)
|
|
199
|
+
sub = tp.OperatorsSet("Sub", const_configuration_options)
|
|
200
|
+
mul = tp.OperatorsSet("Mul", const_configuration_options)
|
|
201
|
+
div = tp.OperatorsSet("Div", const_configuration_options)
|
|
188
202
|
prelu = tp.OperatorsSet("PReLU")
|
|
189
203
|
swish = tp.OperatorsSet("Swish")
|
|
190
204
|
sigmoid = tp.OperatorsSet("Sigmoid")
|
model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tpc_keras.py
CHANGED
|
@@ -122,7 +122,7 @@ def generate_keras_tpc(name: str, tp_model: tp.TargetPlatformModel):
|
|
|
122
122
|
tp.OperationsSetToLayers("Add", [tf.add, Add])
|
|
123
123
|
tp.OperationsSetToLayers("Sub", [tf.subtract, Subtract])
|
|
124
124
|
tp.OperationsSetToLayers("Mul", [tf.math.multiply, Multiply])
|
|
125
|
-
tp.OperationsSetToLayers("Div", [tf.math.divide])
|
|
125
|
+
tp.OperationsSetToLayers("Div", [tf.math.divide, tf.math.truediv])
|
|
126
126
|
tp.OperationsSetToLayers("PReLU", [PReLU])
|
|
127
127
|
tp.OperationsSetToLayers("Swish", [tf.nn.swish, tp.LayerFilterParams(Activation, activation="swish")])
|
|
128
128
|
tp.OperationsSetToLayers("Sigmoid", [tf.nn.sigmoid, tp.LayerFilterParams(Activation, activation="sigmoid")])
|
{mct_nightly-2.0.0.20240418.439.dist-info → mct_nightly-2.0.0.20240419.358.dist-info}/LICENSE.md
RENAMED
|
File without changes
|
|
File without changes
|
{mct_nightly-2.0.0.20240418.439.dist-info → mct_nightly-2.0.0.20240419.358.dist-info}/top_level.txt
RENAMED
|
File without changes
|