mct-nightly 2.2.0.20241221.519__py3-none-any.whl → 2.2.0.20241223.525__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.
Files changed (28) hide show
  1. {mct_nightly-2.2.0.20241221.519.dist-info → mct_nightly-2.2.0.20241223.525.dist-info}/METADATA +1 -1
  2. {mct_nightly-2.2.0.20241221.519.dist-info → mct_nightly-2.2.0.20241223.525.dist-info}/RECORD +26 -28
  3. model_compression_toolkit/__init__.py +1 -1
  4. model_compression_toolkit/core/common/graph/base_graph.py +1 -1
  5. model_compression_toolkit/core/common/graph/base_node.py +3 -3
  6. model_compression_toolkit/core/common/quantization/set_node_quantization_config.py +4 -4
  7. model_compression_toolkit/core/common/substitutions/shift_negative_activation.py +2 -2
  8. model_compression_toolkit/target_platform_capabilities/schema/mct_current_schema.py +1 -0
  9. model_compression_toolkit/target_platform_capabilities/schema/schema_functions.py +4 -5
  10. model_compression_toolkit/target_platform_capabilities/schema/v1.py +63 -170
  11. model_compression_toolkit/target_platform_capabilities/target_platform/__init__.py +0 -1
  12. model_compression_toolkit/target_platform_capabilities/target_platform/targetplatform2framework/operations_to_layers.py +1 -1
  13. model_compression_toolkit/target_platform_capabilities/target_platform/targetplatform2framework/target_platform_capabilities.py +7 -4
  14. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1/tp_model.py +50 -51
  15. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_lut/tp_model.py +54 -52
  16. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_pot/tp_model.py +57 -53
  17. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tp_model.py +52 -51
  18. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tp_model.py +53 -51
  19. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tp_model.py +59 -57
  20. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tp_model.py +54 -52
  21. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tp_model.py +90 -83
  22. model_compression_toolkit/target_platform_capabilities/tpc_models/qnnpack_tpc/v1/tp_model.py +26 -24
  23. model_compression_toolkit/target_platform_capabilities/tpc_models/tflite_tpc/v1/tp_model.py +57 -55
  24. model_compression_toolkit/target_platform_capabilities/target_platform/current_tp_model.py +0 -67
  25. model_compression_toolkit/target_platform_capabilities/target_platform/target_platform_model.py +0 -30
  26. {mct_nightly-2.2.0.20241221.519.dist-info → mct_nightly-2.2.0.20241223.525.dist-info}/LICENSE.md +0 -0
  27. {mct_nightly-2.2.0.20241221.519.dist-info → mct_nightly-2.2.0.20241223.525.dist-info}/WHEEL +0 -0
  28. {mct_nightly-2.2.0.20241221.519.dist-info → mct_nightly-2.2.0.20241223.525.dist-info}/top_level.txt +0 -0
@@ -19,7 +19,8 @@ import model_compression_toolkit.target_platform_capabilities.schema.mct_current
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, WEIGHTS_N_BITS, \
21
21
  WEIGHTS_QUANTIZATION_METHOD, IMX500_TP_MODEL
22
- from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, Signedness, \
22
+ from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, \
23
+ Signedness, \
23
24
  AttributeQuantizationConfig, OpQuantizationConfig
24
25
 
25
26
  tp = mct.target_platform
@@ -150,7 +151,56 @@ def generate_tp_model(default_config: OpQuantizationConfig,
150
151
  # of possible configurations to consider when quantizing a set of operations (in mixed-precision, for example).
151
152
  # If the QuantizationConfigOptions contains only one configuration,
152
153
  # this configuration will be used for the operation quantization:
153
- default_configuration_options = schema.QuantizationConfigOptions([default_config])
154
+ default_configuration_options = schema.QuantizationConfigOptions(tuple([default_config]))
155
+
156
+ # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
157
+ mixed_precision_configuration_options = schema.QuantizationConfigOptions(tuple(mixed_precision_cfg_list),
158
+ base_config=base_config)
159
+
160
+ # Create an OperatorsSet to represent a set of operations.
161
+ # Each OperatorsSet has a unique label.
162
+ # If a quantization configuration options is passed, these options will
163
+ # be used for operations that will be attached to this set's label.
164
+ # Otherwise, it will be a configure-less set (used in fusing):
165
+ operator_set = []
166
+ fusing_patterns = []
167
+
168
+ # May suit for operations like: Dropout, Reshape, etc.
169
+ operator_set.append(schema.OperatorsSet("NoQuantization",
170
+ default_configuration_options.clone_and_edit(
171
+ enable_activation_quantization=False)
172
+ .clone_and_edit_weight_attribute(enable_weights_quantization=False)))
173
+
174
+ # Define operator sets that use mixed_precision_configuration_options:
175
+ conv = schema.OperatorsSet("Conv", mixed_precision_configuration_options)
176
+ fc = schema.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
177
+
178
+ # Define operations sets without quantization configuration
179
+ # options (useful for creating fusing patterns, for example):
180
+ any_relu = schema.OperatorsSet("AnyReLU")
181
+ add = schema.OperatorsSet("Add")
182
+ sub = schema.OperatorsSet("Sub")
183
+ mul = schema.OperatorsSet("Mul")
184
+ div = schema.OperatorsSet("Div")
185
+ prelu = schema.OperatorsSet("PReLU")
186
+ swish = schema.OperatorsSet("Swish")
187
+ sigmoid = schema.OperatorsSet("Sigmoid")
188
+ tanh = schema.OperatorsSet("Tanh")
189
+
190
+ operator_set.extend([conv, fc, any_relu, add, sub, mul, div, prelu, swish, sigmoid, tanh])
191
+ # Combine multiple operators into a single operator to avoid quantization between
192
+ # them. To do this we define fusing patterns using the OperatorsSets that were created.
193
+ # To group multiple sets with regard to fusing, an OperatorSetConcat can be created
194
+ activations_after_conv_to_fuse = schema.OperatorSetConcat([any_relu, swish, prelu, sigmoid, tanh])
195
+ activations_after_fc_to_fuse = schema.OperatorSetConcat([any_relu, swish, sigmoid])
196
+ any_binary = schema.OperatorSetConcat([add, sub, mul, div])
197
+
198
+ # ------------------- #
199
+ # Fusions
200
+ # ------------------- #
201
+ fusing_patterns.append(schema.Fusing((conv, activations_after_conv_to_fuse)))
202
+ fusing_patterns.append(schema.Fusing((fc, activations_after_fc_to_fuse)))
203
+ fusing_patterns.append(schema.Fusing((any_binary, any_relu)))
154
204
 
155
205
  # Create a TargetPlatformModel and set its default quantization config.
156
206
  # This default configuration will be used for all operations
@@ -160,56 +210,8 @@ def generate_tp_model(default_config: OpQuantizationConfig,
160
210
  tpc_minor_version=1,
161
211
  tpc_patch_version=0,
162
212
  tpc_platform_type=IMX500_TP_MODEL,
213
+ operator_set=tuple(operator_set),
214
+ fusing_patterns=tuple(fusing_patterns),
163
215
  add_metadata=False,
164
216
  name=name)
165
-
166
- # To start defining the model's components (such as operator sets, and fusing patterns),
167
- # use 'with' the TargetPlatformModel instance, and create them as below:
168
- with generated_tpc:
169
- # Create an OperatorsSet to represent a set of operations.
170
- # Each OperatorsSet has a unique label.
171
- # If a quantization configuration options is passed, these options will
172
- # be used for operations that will be attached to this set's label.
173
- # Otherwise, it will be a configure-less set (used in fusing):
174
-
175
- # May suit for operations like: Dropout, Reshape, etc.
176
- default_qco = tp.get_default_quantization_config_options()
177
- schema.OperatorsSet("NoQuantization",
178
- default_qco.clone_and_edit(enable_activation_quantization=False)
179
- .clone_and_edit_weight_attribute(enable_weights_quantization=False))
180
-
181
- # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
182
- mixed_precision_configuration_options = schema.QuantizationConfigOptions(mixed_precision_cfg_list,
183
- base_config=base_config)
184
-
185
- # Define operator sets that use mixed_precision_configuration_options:
186
- conv = schema.OperatorsSet("Conv", mixed_precision_configuration_options)
187
- fc = schema.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
188
-
189
- # Define operations sets without quantization configuration
190
- # options (useful for creating fusing patterns, for example):
191
- any_relu = schema.OperatorsSet("AnyReLU")
192
- add = schema.OperatorsSet("Add")
193
- sub = schema.OperatorsSet("Sub")
194
- mul = schema.OperatorsSet("Mul")
195
- div = schema.OperatorsSet("Div")
196
- prelu = schema.OperatorsSet("PReLU")
197
- swish = schema.OperatorsSet("Swish")
198
- sigmoid = schema.OperatorsSet("Sigmoid")
199
- tanh = schema.OperatorsSet("Tanh")
200
-
201
- # Combine multiple operators into a single operator to avoid quantization between
202
- # them. To do this we define fusing patterns using the OperatorsSets that were created.
203
- # To group multiple sets with regard to fusing, an OperatorSetConcat can be created
204
- activations_after_conv_to_fuse = schema.OperatorSetConcat([any_relu, swish, prelu, sigmoid, tanh])
205
- activations_after_fc_to_fuse = schema.OperatorSetConcat([any_relu, swish, sigmoid])
206
- any_binary = schema.OperatorSetConcat([add, sub, mul, div])
207
-
208
- # ------------------- #
209
- # Fusions
210
- # ------------------- #
211
- schema.Fusing([conv, activations_after_conv_to_fuse])
212
- schema.Fusing([fc, activations_after_fc_to_fuse])
213
- schema.Fusing([any_binary, any_relu])
214
-
215
217
  return generated_tpc
@@ -19,7 +19,8 @@ import model_compression_toolkit.target_platform_capabilities.schema.mct_current
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, WEIGHTS_N_BITS, \
21
21
  IMX500_TP_MODEL
22
- from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, Signedness, \
22
+ from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, \
23
+ Signedness, \
23
24
  AttributeQuantizationConfig, OpQuantizationConfig
24
25
 
25
26
  tp = mct.target_platform
@@ -146,7 +147,57 @@ def generate_tp_model(default_config: OpQuantizationConfig,
146
147
  # of possible configurations to consider when quantizing a set of operations (in mixed-precision, for example).
147
148
  # If the QuantizationConfigOptions contains only one configuration,
148
149
  # this configuration will be used for the operation quantization:
149
- default_configuration_options = schema.QuantizationConfigOptions([default_config])
150
+ default_configuration_options = schema.QuantizationConfigOptions(tuple([default_config]))
151
+
152
+ # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
153
+ mixed_precision_configuration_options = schema.QuantizationConfigOptions(tuple(mixed_precision_cfg_list),
154
+ base_config=base_config)
155
+
156
+ # Create an OperatorsSet to represent a set of operations.
157
+ # Each OperatorsSet has a unique label.
158
+ # If a quantization configuration options is passed, these options will
159
+ # be used for operations that will be attached to this set's label.
160
+ # Otherwise, it will be a configure-less set (used in fusing):
161
+ operator_set = []
162
+ fusing_patterns = []
163
+
164
+ # May suit for operations like: Dropout, Reshape, etc.
165
+ operator_set.append(schema.OperatorsSet("NoQuantization",
166
+ default_configuration_options.clone_and_edit(
167
+ enable_activation_quantization=False)
168
+ .clone_and_edit_weight_attribute(enable_weights_quantization=False)))
169
+
170
+ # Define operator sets that use mixed_precision_configuration_options:
171
+ conv = schema.OperatorsSet("Conv", mixed_precision_configuration_options)
172
+ fc = schema.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
173
+
174
+ # Define operations sets without quantization configuration
175
+ # options (useful for creating fusing patterns, for example):
176
+ any_relu = schema.OperatorsSet("AnyReLU")
177
+ add = schema.OperatorsSet("Add")
178
+ sub = schema.OperatorsSet("Sub")
179
+ mul = schema.OperatorsSet("Mul")
180
+ div = schema.OperatorsSet("Div")
181
+ prelu = schema.OperatorsSet("PReLU")
182
+ swish = schema.OperatorsSet("Swish")
183
+ sigmoid = schema.OperatorsSet("Sigmoid")
184
+ tanh = schema.OperatorsSet("Tanh")
185
+
186
+ operator_set.extend([conv, fc, any_relu, add, sub, mul, div, prelu, swish, sigmoid, tanh])
187
+
188
+ # Combine multiple operators into a single operator to avoid quantization between
189
+ # them. To do this we define fusing patterns using the OperatorsSets that were created.
190
+ # To group multiple sets with regard to fusing, an OperatorSetConcat can be created
191
+ activations_after_conv_to_fuse = schema.OperatorSetConcat([any_relu, swish, prelu, sigmoid, tanh])
192
+ activations_after_fc_to_fuse = schema.OperatorSetConcat([any_relu, swish, sigmoid])
193
+ any_binary = schema.OperatorSetConcat([add, sub, mul, div])
194
+
195
+ # ------------------- #
196
+ # Fusions
197
+ # ------------------- #
198
+ fusing_patterns.append(schema.Fusing((conv, activations_after_conv_to_fuse)))
199
+ fusing_patterns.append(schema.Fusing((fc, activations_after_fc_to_fuse)))
200
+ fusing_patterns.append(schema.Fusing((any_binary, any_relu)))
150
201
 
151
202
  # Create a TargetPlatformModel and set its default quantization config.
152
203
  # This default configuration will be used for all operations
@@ -156,56 +207,9 @@ def generate_tp_model(default_config: OpQuantizationConfig,
156
207
  tpc_minor_version=1,
157
208
  tpc_patch_version=0,
158
209
  tpc_platform_type=IMX500_TP_MODEL,
210
+ operator_set=tuple(operator_set),
211
+ fusing_patterns=tuple(fusing_patterns),
212
+ name=name,
159
213
  add_metadata=False,
160
- name=name)
161
-
162
- # To start defining the model's components (such as operator sets, and fusing patterns),
163
- # use 'with' the TargetPlatformModel instance, and create them as below:
164
- with generated_tpc:
165
- # Create an OperatorsSet to represent a set of operations.
166
- # Each OperatorsSet has a unique label.
167
- # If a quantization configuration options is passed, these options will
168
- # be used for operations that will be attached to this set's label.
169
- # Otherwise, it will be a configure-less set (used in fusing):
170
-
171
- # May suit for operations like: Dropout, Reshape, etc.
172
- default_qco = tp.get_default_quantization_config_options()
173
- schema.OperatorsSet("NoQuantization",
174
- default_qco.clone_and_edit(enable_activation_quantization=False)
175
- .clone_and_edit_weight_attribute(enable_weights_quantization=False))
176
-
177
- # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
178
- mixed_precision_configuration_options = schema.QuantizationConfigOptions(mixed_precision_cfg_list,
179
- base_config=base_config)
180
-
181
- # Define operator sets that use mixed_precision_configuration_options:
182
- conv = schema.OperatorsSet("Conv", mixed_precision_configuration_options)
183
- fc = schema.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
184
-
185
- # Define operations sets without quantization configuration
186
- # options (useful for creating fusing patterns, for example):
187
- any_relu = schema.OperatorsSet("AnyReLU")
188
- add = schema.OperatorsSet("Add")
189
- sub = schema.OperatorsSet("Sub")
190
- mul = schema.OperatorsSet("Mul")
191
- div = schema.OperatorsSet("Div")
192
- prelu = schema.OperatorsSet("PReLU")
193
- swish = schema.OperatorsSet("Swish")
194
- sigmoid = schema.OperatorsSet("Sigmoid")
195
- tanh = schema.OperatorsSet("Tanh")
196
-
197
- # Combine multiple operators into a single operator to avoid quantization between
198
- # them. To do this we define fusing patterns using the OperatorsSets that were created.
199
- # To group multiple sets with regard to fusing, an OperatorSetConcat can be created
200
- activations_after_conv_to_fuse = schema.OperatorSetConcat([any_relu, swish, prelu, sigmoid, tanh])
201
- activations_after_fc_to_fuse = schema.OperatorSetConcat([any_relu, swish, sigmoid])
202
- any_binary = schema.OperatorSetConcat([add, sub, mul, div])
203
-
204
- # ------------------- #
205
- # Fusions
206
- # ------------------- #
207
- schema.Fusing([conv, activations_after_conv_to_fuse])
208
- schema.Fusing([fc, activations_after_fc_to_fuse])
209
- schema.Fusing([any_binary, any_relu])
210
-
214
+ is_simd_padding=True)
211
215
  return generated_tpc
@@ -19,7 +19,8 @@ import model_compression_toolkit.target_platform_capabilities.schema.mct_current
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, WEIGHTS_N_BITS, \
21
21
  IMX500_TP_MODEL
22
- from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, Signedness, \
22
+ from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, \
23
+ Signedness, \
23
24
  AttributeQuantizationConfig, OpQuantizationConfig
24
25
 
25
26
  tp = mct.target_platform
@@ -155,7 +156,54 @@ def generate_tp_model(default_config: OpQuantizationConfig,
155
156
  # of possible configurations to consider when quantizing a set of operations (in mixed-precision, for example).
156
157
  # If the QuantizationConfigOptions contains only one configuration,
157
158
  # this configuration will be used for the operation quantization:
158
- default_configuration_options = schema.QuantizationConfigOptions([default_config])
159
+ default_configuration_options = schema.QuantizationConfigOptions(tuple([default_config]))
160
+
161
+ # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
162
+ mixed_precision_configuration_options = schema.QuantizationConfigOptions(tuple(mixed_precision_cfg_list),
163
+ base_config=base_config)
164
+
165
+ # Create an OperatorsSet to represent a set of operations.
166
+ # Each OperatorsSet has a unique label.
167
+ # If a quantization configuration options is passed, these options will
168
+ # be used for operations that will be attached to this set's label.
169
+ # Otherwise, it will be a configure-less set (used in fusing):
170
+ operator_set = []
171
+ fusing_patterns = []
172
+ # May suit for operations like: Dropout, Reshape, etc.
173
+ operator_set.append(schema.OperatorsSet("NoQuantization", default_configuration_options.clone_and_edit(
174
+ enable_activation_quantization=False).clone_and_edit_weight_attribute(enable_weights_quantization=False)))
175
+
176
+ # Define operator sets that use mixed_precision_configuration_options:
177
+ conv = schema.OperatorsSet("Conv", mixed_precision_configuration_options)
178
+ fc = schema.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
179
+
180
+ # Define operations sets without quantization configuration
181
+ # options (useful for creating fusing patterns, for example):
182
+ any_relu = schema.OperatorsSet("AnyReLU")
183
+ add = schema.OperatorsSet("Add")
184
+ sub = schema.OperatorsSet("Sub")
185
+ mul = schema.OperatorsSet("Mul")
186
+ div = schema.OperatorsSet("Div")
187
+ prelu = schema.OperatorsSet("PReLU")
188
+ swish = schema.OperatorsSet("Swish")
189
+ sigmoid = schema.OperatorsSet("Sigmoid")
190
+ tanh = schema.OperatorsSet("Tanh")
191
+
192
+ operator_set.extend([conv, fc, any_relu, add, sub, mul, div, prelu, swish, sigmoid, tanh])
193
+
194
+ # Combine multiple operators into a single operator to avoid quantization between
195
+ # them. To do this we define fusing patterns using the OperatorsSets that were created.
196
+ # To group multiple sets with regard to fusing, an OperatorSetConcat can be created
197
+ activations_after_conv_to_fuse = schema.OperatorSetConcat([any_relu, swish, prelu, sigmoid, tanh])
198
+ activations_after_fc_to_fuse = schema.OperatorSetConcat([any_relu, swish, sigmoid])
199
+ any_binary = schema.OperatorSetConcat([add, sub, mul, div])
200
+
201
+ # ------------------- #
202
+ # Fusions
203
+ # ------------------- #
204
+ fusing_patterns.append(schema.Fusing((conv, activations_after_conv_to_fuse)))
205
+ fusing_patterns.append(schema.Fusing((fc, activations_after_fc_to_fuse)))
206
+ fusing_patterns.append(schema.Fusing((any_binary, any_relu)))
159
207
 
160
208
  # Create a TargetPlatformModel and set its default quantization config.
161
209
  # This default configuration will be used for all operations
@@ -165,57 +213,10 @@ def generate_tp_model(default_config: OpQuantizationConfig,
165
213
  tpc_minor_version=2,
166
214
  tpc_patch_version=0,
167
215
  tpc_platform_type=IMX500_TP_MODEL,
216
+ operator_set=tuple(operator_set),
217
+ fusing_patterns=tuple(fusing_patterns),
168
218
  add_metadata=True,
169
219
  name=name,
170
220
  is_simd_padding=True)
171
221
 
172
- # To start defining the model's components (such as operator sets, and fusing patterns),
173
- # use 'with' the TargetPlatformModel instance, and create them as below:
174
- with generated_tpm:
175
- # Create an OperatorsSet to represent a set of operations.
176
- # Each OperatorsSet has a unique label.
177
- # If a quantization configuration options is passed, these options will
178
- # be used for operations that will be attached to this set's label.
179
- # Otherwise, it will be a configure-less set (used in fusing):
180
-
181
- # May suit for operations like: Dropout, Reshape, etc.
182
- default_qco = tp.get_default_quantization_config_options()
183
- schema.OperatorsSet("NoQuantization",
184
- default_qco.clone_and_edit(enable_activation_quantization=False)
185
- .clone_and_edit_weight_attribute(enable_weights_quantization=False))
186
-
187
- # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
188
- mixed_precision_configuration_options = schema.QuantizationConfigOptions(mixed_precision_cfg_list,
189
- base_config=base_config)
190
-
191
- # Define operator sets that use mixed_precision_configuration_options:
192
- conv = schema.OperatorsSet("Conv", mixed_precision_configuration_options)
193
- fc = schema.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
194
-
195
- # Define operations sets without quantization configuration
196
- # options (useful for creating fusing patterns, for example):
197
- any_relu = schema.OperatorsSet("AnyReLU")
198
- add = schema.OperatorsSet("Add")
199
- sub = schema.OperatorsSet("Sub")
200
- mul = schema.OperatorsSet("Mul")
201
- div = schema.OperatorsSet("Div")
202
- prelu = schema.OperatorsSet("PReLU")
203
- swish = schema.OperatorsSet("Swish")
204
- sigmoid = schema.OperatorsSet("Sigmoid")
205
- tanh = schema.OperatorsSet("Tanh")
206
-
207
- # Combine multiple operators into a single operator to avoid quantization between
208
- # them. To do this we define fusing patterns using the OperatorsSets that were created.
209
- # To group multiple sets with regard to fusing, an OperatorSetConcat can be created
210
- activations_after_conv_to_fuse = schema.OperatorSetConcat([any_relu, swish, prelu, sigmoid, tanh])
211
- activations_after_fc_to_fuse = schema.OperatorSetConcat([any_relu, swish, sigmoid])
212
- any_binary = schema.OperatorSetConcat([add, sub, mul, div])
213
-
214
- # ------------------- #
215
- # Fusions
216
- # ------------------- #
217
- schema.Fusing([conv, activations_after_conv_to_fuse])
218
- schema.Fusing([fc, activations_after_fc_to_fuse])
219
- schema.Fusing([any_binary, any_relu])
220
-
221
222
  return generated_tpm
@@ -19,7 +19,8 @@ import model_compression_toolkit.target_platform_capabilities.schema.mct_current
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, WEIGHTS_N_BITS, \
21
21
  WEIGHTS_QUANTIZATION_METHOD, IMX500_TP_MODEL
22
- from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, Signedness, \
22
+ from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, \
23
+ Signedness, \
23
24
  AttributeQuantizationConfig, OpQuantizationConfig
24
25
 
25
26
  tp = mct.target_platform
@@ -152,7 +153,55 @@ def generate_tp_model(default_config: OpQuantizationConfig,
152
153
  # of possible configurations to consider when quantizing a set of operations (in mixed-precision, for example).
153
154
  # If the QuantizationConfigOptions contains only one configuration,
154
155
  # this configuration will be used for the operation quantization:
155
- default_configuration_options = schema.QuantizationConfigOptions([default_config])
156
+ default_configuration_options = schema.QuantizationConfigOptions(tuple([default_config]))
157
+
158
+ # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
159
+ mixed_precision_configuration_options = schema.QuantizationConfigOptions(tuple(mixed_precision_cfg_list),
160
+ base_config=base_config)
161
+
162
+ # Create an OperatorsSet to represent a set of operations.
163
+ # Each OperatorsSet has a unique label.
164
+ # If a quantization configuration options is passed, these options will
165
+ # be used for operations that will be attached to this set's label.
166
+ # Otherwise, it will be a configure-less set (used in fusing):
167
+ operator_set = []
168
+ fusing_patterns = []
169
+ # May suit for operations like: Dropout, Reshape, etc.
170
+ operator_set.append(schema.OperatorsSet("NoQuantization",
171
+ default_configuration_options.clone_and_edit(
172
+ enable_activation_quantization=False)
173
+ .clone_and_edit_weight_attribute(enable_weights_quantization=False)))
174
+
175
+ # Define operator sets that use mixed_precision_configuration_options:
176
+ conv = schema.OperatorsSet("Conv", mixed_precision_configuration_options)
177
+ fc = schema.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
178
+
179
+ # Define operations sets without quantization configuration
180
+ # options (useful for creating fusing patterns, for example):
181
+ any_relu = schema.OperatorsSet("AnyReLU")
182
+ add = schema.OperatorsSet("Add")
183
+ sub = schema.OperatorsSet("Sub")
184
+ mul = schema.OperatorsSet("Mul")
185
+ div = schema.OperatorsSet("Div")
186
+ prelu = schema.OperatorsSet("PReLU")
187
+ swish = schema.OperatorsSet("Swish")
188
+ sigmoid = schema.OperatorsSet("Sigmoid")
189
+ tanh = schema.OperatorsSet("Tanh")
190
+
191
+ operator_set.extend([conv, fc, any_relu, add, sub, mul, div, prelu, swish, sigmoid, tanh])
192
+ # Combine multiple operators into a single operator to avoid quantization between
193
+ # them. To do this we define fusing patterns using the OperatorsSets that were created.
194
+ # To group multiple sets with regard to fusing, an OperatorSetConcat can be created
195
+ activations_after_conv_to_fuse = schema.OperatorSetConcat([any_relu, swish, prelu, sigmoid, tanh])
196
+ activations_after_fc_to_fuse = schema.OperatorSetConcat([any_relu, swish, sigmoid])
197
+ any_binary = schema.OperatorSetConcat([add, sub, mul, div])
198
+
199
+ # ------------------- #
200
+ # Fusions
201
+ # ------------------- #
202
+ fusing_patterns.append(schema.Fusing((conv, activations_after_conv_to_fuse)))
203
+ fusing_patterns.append(schema.Fusing((fc, activations_after_fc_to_fuse)))
204
+ fusing_patterns.append(schema.Fusing((any_binary, any_relu)))
156
205
 
157
206
  # Create a TargetPlatformModel and set its default quantization config.
158
207
  # This default configuration will be used for all operations
@@ -162,56 +211,9 @@ def generate_tp_model(default_config: OpQuantizationConfig,
162
211
  tpc_minor_version=2,
163
212
  tpc_patch_version=0,
164
213
  tpc_platform_type=IMX500_TP_MODEL,
214
+ operator_set=tuple(operator_set),
215
+ fusing_patterns=tuple(fusing_patterns),
165
216
  add_metadata=True,
166
217
  name=name)
167
218
 
168
- # To start defining the model's components (such as operator sets, and fusing patterns),
169
- # use 'with' the TargetPlatformModel instance, and create them as below:
170
- with generated_tpm:
171
- # Create an OperatorsSet to represent a set of operations.
172
- # Each OperatorsSet has a unique label.
173
- # If a quantization configuration options is passed, these options will
174
- # be used for operations that will be attached to this set's label.
175
- # Otherwise, it will be a configure-less set (used in fusing):
176
-
177
- # May suit for operations like: Dropout, Reshape, etc.
178
- default_qco = tp.get_default_quantization_config_options()
179
- schema.OperatorsSet("NoQuantization",
180
- default_qco.clone_and_edit(enable_activation_quantization=False)
181
- .clone_and_edit_weight_attribute(enable_weights_quantization=False))
182
-
183
- # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
184
- mixed_precision_configuration_options = schema.QuantizationConfigOptions(mixed_precision_cfg_list,
185
- base_config=base_config)
186
-
187
- # Define operator sets that use mixed_precision_configuration_options:
188
- conv = schema.OperatorsSet("Conv", mixed_precision_configuration_options)
189
- fc = schema.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
190
-
191
- # Define operations sets without quantization configuration
192
- # options (useful for creating fusing patterns, for example):
193
- any_relu = schema.OperatorsSet("AnyReLU")
194
- add = schema.OperatorsSet("Add")
195
- sub = schema.OperatorsSet("Sub")
196
- mul = schema.OperatorsSet("Mul")
197
- div = schema.OperatorsSet("Div")
198
- prelu = schema.OperatorsSet("PReLU")
199
- swish = schema.OperatorsSet("Swish")
200
- sigmoid = schema.OperatorsSet("Sigmoid")
201
- tanh = schema.OperatorsSet("Tanh")
202
-
203
- # Combine multiple operators into a single operator to avoid quantization between
204
- # them. To do this we define fusing patterns using the OperatorsSets that were created.
205
- # To group multiple sets with regard to fusing, an OperatorSetConcat can be created
206
- activations_after_conv_to_fuse = schema.OperatorSetConcat([any_relu, swish, prelu, sigmoid, tanh])
207
- activations_after_fc_to_fuse = schema.OperatorSetConcat([any_relu, swish, sigmoid])
208
- any_binary = schema.OperatorSetConcat([add, sub, mul, div])
209
-
210
- # ------------------- #
211
- # Fusions
212
- # ------------------- #
213
- schema.Fusing([conv, activations_after_conv_to_fuse])
214
- schema.Fusing([fc, activations_after_fc_to_fuse])
215
- schema.Fusing([any_binary, any_relu])
216
-
217
219
  return generated_tpm
@@ -19,7 +19,8 @@ import model_compression_toolkit.target_platform_capabilities.schema.mct_current
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, WEIGHTS_N_BITS, \
21
21
  IMX500_TP_MODEL
22
- from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, Signedness, \
22
+ from model_compression_toolkit.target_platform_capabilities.schema.mct_current_schema import TargetPlatformModel, \
23
+ Signedness, \
23
24
  AttributeQuantizationConfig, OpQuantizationConfig
24
25
 
25
26
  tp = mct.target_platform
@@ -155,7 +156,7 @@ def generate_tp_model(default_config: OpQuantizationConfig,
155
156
  # of possible configurations to consider when quantizing a set of operations (in mixed-precision, for example).
156
157
  # If the QuantizationConfigOptions contains only one configuration,
157
158
  # this configuration will be used for the operation quantization:
158
- default_configuration_options = schema.QuantizationConfigOptions([default_config])
159
+ default_configuration_options = schema.QuantizationConfigOptions(tuple([default_config]))
159
160
 
160
161
  # Create a QuantizationConfigOptions for quantizing constants in functional ops.
161
162
  # Constant configuration is similar to the default eight bit configuration except for PoT
@@ -166,7 +167,7 @@ def generate_tp_model(default_config: OpQuantizationConfig,
166
167
  default_weight_attr_config=default_config.default_weight_attr_config.clone_and_edit(
167
168
  enable_weights_quantization=True, weights_per_channel_threshold=True,
168
169
  weights_quantization_method=tp.QuantizationMethod.POWER_OF_TWO))
169
- const_configuration_options = schema.QuantizationConfigOptions([const_config])
170
+ const_configuration_options = schema.QuantizationConfigOptions(tuple([const_config]))
170
171
 
171
172
  # 16 bits inputs and outputs. Currently, only defined for consts since they are used in operators that
172
173
  # support 16 bit as input and output.
@@ -174,9 +175,59 @@ def generate_tp_model(default_config: OpQuantizationConfig,
174
175
  supported_input_activation_n_bits=(8, 16))
175
176
  const_config_input16_output16 = const_config_input16.clone_and_edit(
176
177
  activation_n_bits=16, signedness=Signedness.SIGNED)
177
- const_configuration_options_inout16 = schema.QuantizationConfigOptions([const_config_input16_output16,
178
- const_config_input16],
179
- base_config=const_config_input16)
178
+ const_configuration_options_inout16 = schema.QuantizationConfigOptions(tuple([const_config_input16_output16,
179
+ const_config_input16]),
180
+ base_config=const_config_input16)
181
+
182
+ # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
183
+ mixed_precision_configuration_options = schema.QuantizationConfigOptions(tuple(mixed_precision_cfg_list),
184
+ base_config=base_config)
185
+
186
+ # Create an OperatorsSet to represent a set of operations.
187
+ # Each OperatorsSet has a unique label.
188
+ # If a quantization configuration options is passed, these options will
189
+ # be used for operations that will be attached to this set's label.
190
+ # Otherwise, it will be a configure-less set (used in fusing):
191
+ operator_set = []
192
+ fusing_patterns = []
193
+ # May suit for operations like: Dropout, Reshape, etc.
194
+ operator_set.append(schema.OperatorsSet("NoQuantization",
195
+ default_configuration_options.clone_and_edit(
196
+ enable_activation_quantization=False,
197
+ supported_input_activation_n_bits=(8, 16))
198
+ .clone_and_edit_weight_attribute(enable_weights_quantization=False)))
199
+ operator_set.append(schema.OperatorsSet("Default16BitInout", const_configuration_options_inout16))
200
+
201
+ # Define operator sets that use mixed_precision_configuration_options:
202
+ conv = schema.OperatorsSet("Conv", mixed_precision_configuration_options)
203
+ fc = schema.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
204
+
205
+ # Define operations sets without quantization configuration
206
+ # options (useful for creating fusing patterns, for example):
207
+ any_relu = schema.OperatorsSet("AnyReLU")
208
+ add = schema.OperatorsSet("Add", const_configuration_options_inout16)
209
+ sub = schema.OperatorsSet("Sub", const_configuration_options_inout16)
210
+ mul = schema.OperatorsSet("Mul", const_configuration_options_inout16)
211
+ div = schema.OperatorsSet("Div", const_configuration_options)
212
+ prelu = schema.OperatorsSet("PReLU")
213
+ swish = schema.OperatorsSet("Swish")
214
+ sigmoid = schema.OperatorsSet("Sigmoid")
215
+ tanh = schema.OperatorsSet("Tanh")
216
+
217
+ operator_set.extend([conv, fc, any_relu, add, sub, mul, div, prelu, swish, sigmoid, tanh])
218
+ # Combine multiple operators into a single operator to avoid quantization between
219
+ # them. To do this we define fusing patterns using the OperatorsSets that were created.
220
+ # To group multiple sets with regard to fusing, an OperatorSetConcat can be created
221
+ activations_after_conv_to_fuse = schema.OperatorSetConcat([any_relu, swish, prelu, sigmoid, tanh])
222
+ activations_after_fc_to_fuse = schema.OperatorSetConcat([any_relu, swish, sigmoid])
223
+ any_binary = schema.OperatorSetConcat([add, sub, mul, div])
224
+
225
+ # ------------------- #
226
+ # Fusions
227
+ # ------------------- #
228
+ fusing_patterns.append(schema.Fusing((conv, activations_after_conv_to_fuse)))
229
+ fusing_patterns.append(schema.Fusing((fc, activations_after_fc_to_fuse)))
230
+ fusing_patterns.append(schema.Fusing((any_binary, any_relu)))
180
231
 
181
232
  # Create a TargetPlatformModel and set its default quantization config.
182
233
  # This default configuration will be used for all operations
@@ -186,59 +237,10 @@ def generate_tp_model(default_config: OpQuantizationConfig,
186
237
  tpc_minor_version=3,
187
238
  tpc_patch_version=0,
188
239
  tpc_platform_type=IMX500_TP_MODEL,
240
+ operator_set=tuple(operator_set),
241
+ fusing_patterns=tuple(fusing_patterns),
189
242
  add_metadata=True,
190
243
  name=name,
191
244
  is_simd_padding=True)
192
245
 
193
- # To start defining the model's components (such as operator sets, and fusing patterns),
194
- # use 'with' the TargetPlatformModel instance, and create them as below:
195
- with generated_tpm:
196
- # Create an OperatorsSet to represent a set of operations.
197
- # Each OperatorsSet has a unique label.
198
- # If a quantization configuration options is passed, these options will
199
- # be used for operations that will be attached to this set's label.
200
- # Otherwise, it will be a configure-less set (used in fusing):
201
-
202
- # May suit for operations like: Dropout, Reshape, etc.
203
- default_qco = tp.get_default_quantization_config_options()
204
- schema.OperatorsSet("NoQuantization",
205
- default_qco.clone_and_edit(enable_activation_quantization=False,
206
- supported_input_activation_n_bits=(8, 16))
207
- .clone_and_edit_weight_attribute(enable_weights_quantization=False))
208
- schema.OperatorsSet("Default16BitInout", const_configuration_options_inout16)
209
-
210
- # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
211
- mixed_precision_configuration_options = schema.QuantizationConfigOptions(mixed_precision_cfg_list,
212
- base_config=base_config)
213
-
214
- # Define operator sets that use mixed_precision_configuration_options:
215
- conv = schema.OperatorsSet("Conv", mixed_precision_configuration_options)
216
- fc = schema.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
217
-
218
- # Define operations sets without quantization configuration
219
- # options (useful for creating fusing patterns, for example):
220
- any_relu = schema.OperatorsSet("AnyReLU")
221
- add = schema.OperatorsSet("Add", const_configuration_options_inout16)
222
- sub = schema.OperatorsSet("Sub", const_configuration_options_inout16)
223
- mul = schema.OperatorsSet("Mul", const_configuration_options_inout16)
224
- div = schema.OperatorsSet("Div", const_configuration_options)
225
- prelu = schema.OperatorsSet("PReLU")
226
- swish = schema.OperatorsSet("Swish")
227
- sigmoid = schema.OperatorsSet("Sigmoid")
228
- tanh = schema.OperatorsSet("Tanh")
229
-
230
- # Combine multiple operators into a single operator to avoid quantization between
231
- # them. To do this we define fusing patterns using the OperatorsSets that were created.
232
- # To group multiple sets with regard to fusing, an OperatorSetConcat can be created
233
- activations_after_conv_to_fuse = schema.OperatorSetConcat([any_relu, swish, prelu, sigmoid, tanh])
234
- activations_after_fc_to_fuse = schema.OperatorSetConcat([any_relu, swish, sigmoid])
235
- any_binary = schema.OperatorSetConcat([add, sub, mul, div])
236
-
237
- # ------------------- #
238
- # Fusions
239
- # ------------------- #
240
- schema.Fusing([conv, activations_after_conv_to_fuse])
241
- schema.Fusing([fc, activations_after_fc_to_fuse])
242
- schema.Fusing([any_binary, any_relu])
243
-
244
246
  return generated_tpm