mct-nightly 2.2.0.20240922.531__py3-none-any.whl → 2.2.0.20240924.500__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mct-nightly
3
- Version: 2.2.0.20240922.531
3
+ Version: 2.2.0.20240924.500
4
4
  Summary: A Model Compression Toolkit for neural networks
5
5
  Home-page: UNKNOWN
6
6
  License: UNKNOWN
@@ -1,4 +1,4 @@
1
- model_compression_toolkit/__init__.py,sha256=_e4Qr6XzxLK1myPixyImGS9eeKdlPUijnEQfDZa3iRY,1573
1
+ model_compression_toolkit/__init__.py,sha256=b0vKCDAtdImquoTxXFT-DqKFsjnvUU3tVHOzyTMgiAI,1573
2
2
  model_compression_toolkit/constants.py,sha256=i4wYheBkIdQmsQA-axIpcT3YiSO1USNc-jaNiNE8w6E,3920
3
3
  model_compression_toolkit/defaultdict.py,sha256=LSc-sbZYXENMCw3U9F4GiXuv67IKpdn0Qm7Fr11jy-4,2277
4
4
  model_compression_toolkit/logger.py,sha256=3DByV41XHRR3kLTJNbpaMmikL8icd9e1N-nkQAY9oDk,4567
@@ -228,7 +228,7 @@ model_compression_toolkit/core/pytorch/back2framework/factory_model_builder.py,s
228
228
  model_compression_toolkit/core/pytorch/back2framework/float_model_builder.py,sha256=tLrlUyYhxVKVjkad1ZAtbRra0HedB3iVfIkZ_dYnQ-4,3419
229
229
  model_compression_toolkit/core/pytorch/back2framework/instance_builder.py,sha256=BBHBfTqeWm7L3iDyPBpk0jxvj-rBg1QWI23imkjfIl0,1467
230
230
  model_compression_toolkit/core/pytorch/back2framework/mixed_precision_model_builder.py,sha256=D7lU1r9Uq_7fdNuKk2BMF8ho5GrsY-8gyGN6yYoHaVg,15060
231
- model_compression_toolkit/core/pytorch/back2framework/pytorch_model_builder.py,sha256=Oyro2qg7Bz8TFoimHtrn3JCwHEO9iCrTMy4HktaYZzg,18937
231
+ model_compression_toolkit/core/pytorch/back2framework/pytorch_model_builder.py,sha256=QfMulTLC6X_0Iwvk_VChFIoSdeoiEeJ_rf2IQi5TjBk,19353
232
232
  model_compression_toolkit/core/pytorch/back2framework/quantized_model_builder.py,sha256=qZNNOlNTTV4ZKPG3q5GDXkIVTPUEr8dvxAS_YiMORmg,3456
233
233
  model_compression_toolkit/core/pytorch/back2framework/quantization_wrapper/__init__.py,sha256=cco4TmeIDIh32nj9ZZXVkws4dd9F2UDrmjKzTN8G0V0,697
234
234
  model_compression_toolkit/core/pytorch/back2framework/quantization_wrapper/quantized_layer_wrapper.py,sha256=q2JDw10NKng50ee2i9faGzWZ-IydnR2aOMGSn9RoZmc,5773
@@ -325,7 +325,7 @@ model_compression_toolkit/exporter/model_exporter/keras/mctq_keras_exporter.py,s
325
325
  model_compression_toolkit/exporter/model_exporter/pytorch/__init__.py,sha256=uZ2RigbY9O2PJ0Il8wPpS_s7frgg9WUGd_SHeKGyl1A,699
326
326
  model_compression_toolkit/exporter/model_exporter/pytorch/base_pytorch_exporter.py,sha256=UPVkEUQCMZ4Lld6CRnEOPEmlfe5vcQZG0Q3FwRBodD4,4021
327
327
  model_compression_toolkit/exporter/model_exporter/pytorch/export_serialization_format.py,sha256=bPevy6OBqng41PqytBR55e6cBEuyrUS0H8dWX4zgjQ4,967
328
- model_compression_toolkit/exporter/model_exporter/pytorch/fakely_quant_onnx_pytorch_exporter.py,sha256=647EM7a_at-bGB81ES_6qBjValMnRF5-1TP7Uz6kWQg,6692
328
+ model_compression_toolkit/exporter/model_exporter/pytorch/fakely_quant_onnx_pytorch_exporter.py,sha256=07yCCypQaQ3FfhrxKhWwa03bnEgJ8lIknafqeYfvzCQ,6803
329
329
  model_compression_toolkit/exporter/model_exporter/pytorch/fakely_quant_torchscript_pytorch_exporter.py,sha256=ksWV2A-Njo-wAxQ_Ye2sLIZXBWJ_WNyjT7-qFFwvV2o,2897
330
330
  model_compression_toolkit/exporter/model_exporter/pytorch/pytorch_export_facade.py,sha256=8vYGKa58BkasvoHejYaPwubOJPcW0s-RY79_Kkw0Hy8,6236
331
331
  model_compression_toolkit/exporter/model_wrapper/__init__.py,sha256=7CF2zvpTrIEm8qnbuHnLZyTZkwBBxV24V8QA0oxGbh0,1187
@@ -339,7 +339,7 @@ model_compression_toolkit/exporter/model_wrapper/keras/builder/node_to_quantizer
339
339
  model_compression_toolkit/exporter/model_wrapper/pytorch/__init__.py,sha256=Rf1RcYmelmdZmBV5qOKvKWF575ofc06JFQSq83Jz99A,696
340
340
  model_compression_toolkit/exporter/model_wrapper/pytorch/validate_layer.py,sha256=vQUGbCi8_pGoN8DwQ0IblSeN6L9t6Cr0reZNuCbBpkM,3469
341
341
  model_compression_toolkit/exporter/model_wrapper/pytorch/builder/__init__.py,sha256=cco4TmeIDIh32nj9ZZXVkws4dd9F2UDrmjKzTN8G0V0,697
342
- model_compression_toolkit/exporter/model_wrapper/pytorch/builder/fully_quantized_model_builder.py,sha256=-4AmWgTG9p8sH2mpns-PaRmvM6J853mrhNc0wt-9ovs,6076
342
+ model_compression_toolkit/exporter/model_wrapper/pytorch/builder/fully_quantized_model_builder.py,sha256=0sx6PLcnJ42LHKn79Qx1FOH615YBqM9OJMF6S1W6plE,6255
343
343
  model_compression_toolkit/exporter/model_wrapper/pytorch/builder/node_to_quantizer.py,sha256=4sN5z-6BXrTE5Dp2FX_jKO9ty5iZ2r4RM7XvXtDVLSI,9348
344
344
  model_compression_toolkit/gptq/__init__.py,sha256=pEgkJvmf05KSw70iLDTz_6LI_2Oi5L8sTN0JsEUpnpk,1445
345
345
  model_compression_toolkit/gptq/runner.py,sha256=La12JTYjWyJW0YW4Al4TP1_Xi4JWBCEKw6FR_JQsxe0,5982
@@ -472,9 +472,9 @@ model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_
472
472
  model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tpc_keras.py,sha256=XM6qBLIvzsmdFf-AZq5WOlORK2GXC_X-gulReNxHb9E,6601
473
473
  model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tpc_pytorch.py,sha256=nP05jqvh6uaj30a3W7zEkJfKtqfP0Nz5bobwRqbYrdM,5807
474
474
  model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/__init__.py,sha256=tHTUvsaerSfbe22pU0kIDauPpFD7Pq5EmZytVIDkHz4,717
475
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tp_model.py,sha256=1XWIlnmrmEkKgEsEXlSzQOb8PEebC3O-AYHC9Z7EZ6k,14441
476
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tpc_keras.py,sha256=8wUlc-ZOHsKwh2hjsdofBIX8Q-iUuNtZd1dF2kZCr2c,7106
477
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tpc_pytorch.py,sha256=ZaFBnIHLuV1fpOcselo0AWu9NUPGfCuEbuvJ2wFtSHE,6125
475
+ model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tp_model.py,sha256=_LHQkGB0x12FQBDIkEA-Br8HSUL5ZmMXxI7lDpVWcQU,15422
476
+ model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tpc_keras.py,sha256=u8qD1XkHwU4LIoNbmC5mtZd8lZ8gZ4XFihZmoYwAulc,7641
477
+ model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tpc_pytorch.py,sha256=EaQERA7XnZcF7pO4xzBk0li96JnACRE7ppgK535EMXM,6698
478
478
  model_compression_toolkit/target_platform_capabilities/tpc_models/qnnpack_tpc/__init__.py,sha256=cco4TmeIDIh32nj9ZZXVkws4dd9F2UDrmjKzTN8G0V0,697
479
479
  model_compression_toolkit/target_platform_capabilities/tpc_models/qnnpack_tpc/target_platform_capabilities.py,sha256=is00rNrDmmirYsyMtMkWz0DwOA92-x7hAJwpd6z1n2E,2806
480
480
  model_compression_toolkit/target_platform_capabilities/tpc_models/qnnpack_tpc/latest/__init__.py,sha256=CXC-HQolSDu7j8V-Xm-SWGCd74gXB3XnAkEhI_TVbIQ,1516
@@ -550,8 +550,8 @@ tests_pytest/pytorch/gptq/test_annealing_cfg.py,sha256=hGC7L6mp3N1ygcJ3OctgS_Fz2
550
550
  tests_pytest/pytorch/gptq/test_gradual_act_quantization.py,sha256=tI01aFIUaiCILL5Qn--p1E_rLBUelxLdSY3k52lwcx0,4594
551
551
  tests_pytest/pytorch/trainable_infrastructure/__init__.py,sha256=RAe8mgIr1V8dRIQtLf_dSG5zTUCKuQzxyybYx1dzEAs,697
552
552
  tests_pytest/pytorch/trainable_infrastructure/test_linear_annealing.py,sha256=eNOpSp0GoLxtEdiRypBp8jaujXfdNxBwKh5Rd-P7WLs,1786
553
- mct_nightly-2.2.0.20240922.531.dist-info/LICENSE.md,sha256=aYSSIb-5AFPeITTvXm1UAoe0uYBiMmSS8flvXaaFUks,10174
554
- mct_nightly-2.2.0.20240922.531.dist-info/METADATA,sha256=szOhv_jXZsOv5E9Q2G8UK4jWeA5haiQtFjvLPgD9KEg,20813
555
- mct_nightly-2.2.0.20240922.531.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
556
- mct_nightly-2.2.0.20240922.531.dist-info/top_level.txt,sha256=csdfSXhtRnpWYRzjZ-dRLIhOmM2TEdVXUxG05A5fgb8,39
557
- mct_nightly-2.2.0.20240922.531.dist-info/RECORD,,
553
+ mct_nightly-2.2.0.20240924.500.dist-info/LICENSE.md,sha256=aYSSIb-5AFPeITTvXm1UAoe0uYBiMmSS8flvXaaFUks,10174
554
+ mct_nightly-2.2.0.20240924.500.dist-info/METADATA,sha256=tjeXI0teyqJv-zewp1zsb7mL8Jc91rIEzyE83F3SzP8,20813
555
+ mct_nightly-2.2.0.20240924.500.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
556
+ mct_nightly-2.2.0.20240924.500.dist-info/top_level.txt,sha256=csdfSXhtRnpWYRzjZ-dRLIhOmM2TEdVXUxG05A5fgb8,39
557
+ mct_nightly-2.2.0.20240924.500.dist-info/RECORD,,
@@ -27,4 +27,4 @@ from model_compression_toolkit import data_generation
27
27
  from model_compression_toolkit import pruning
28
28
  from model_compression_toolkit.trainable_infrastructure.keras.load_model import keras_load_quantized_model
29
29
 
30
- __version__ = "2.2.0.20240922.000531"
30
+ __version__ = "2.2.0.20240924.000500"
@@ -145,9 +145,14 @@ def _run_operation(n: BaseNode,
145
145
  else:
146
146
  out_tensors_of_n_float = op_func(input_tensors, *op_call_args, **functional_kwargs)
147
147
  else:
148
- merged_inputs, functional_kwargs = _merge_inputs(n, input_tensors, op_call_args, functional_kwargs.copy(),
149
- tensor_input_allocs=_tensor_input_allocs)
150
- out_tensors_of_n_float = op_func(*merged_inputs, **functional_kwargs)
148
+ if isinstance(op_func, PytorchQuantizationWrapper) and isinstance(n, FunctionalNode) and n.functional_op is not torch.gather:
149
+ # in wrapped nodes, the op args & kwargs are already in the PytorchQuantizationWrapper.
150
+ # Temporary patch: for torch.gather this is not the case, so need to merge inputs.
151
+ out_tensors_of_n_float = op_func(*input_tensors)
152
+ else:
153
+ merged_inputs, functional_kwargs = _merge_inputs(n, input_tensors, op_call_args, functional_kwargs.copy(),
154
+ tensor_input_allocs=_tensor_input_allocs)
155
+ out_tensors_of_n_float = op_func(*merged_inputs, **functional_kwargs)
151
156
 
152
157
  # Add a fake quant node if the node has an activation threshold.
153
158
  out_tensors_of_n = out_tensors_of_n_float
@@ -89,12 +89,12 @@ if FOUND_ONNX:
89
89
  else:
90
90
  Logger.info(f"Exporting fake-quant onnx model: {self.save_model_path}")
91
91
 
92
- model_input = to_torch_tensor(next(self.repr_dataset())[0])
92
+ model_input = to_torch_tensor(next(self.repr_dataset()))
93
93
 
94
94
  if hasattr(self.model, 'metadata'):
95
95
  onnx_bytes = BytesIO()
96
96
  torch.onnx.export(self.model,
97
- model_input,
97
+ tuple(model_input) if isinstance(model_input, list) else model_input,
98
98
  onnx_bytes,
99
99
  opset_version=self._onnx_opset_version,
100
100
  verbose=False,
@@ -107,7 +107,7 @@ if FOUND_ONNX:
107
107
  onnx.save_model(onnx_model, self.save_model_path)
108
108
  else:
109
109
  torch.onnx.export(self.model,
110
- model_input,
110
+ tuple(model_input) if isinstance(model_input, list) else model_input,
111
111
  self.save_model_path,
112
112
  opset_version=self._onnx_opset_version,
113
113
  verbose=False,
@@ -50,9 +50,11 @@ if FOUND_TORCH:
50
50
  for attr in weight_quantizers if isinstance(attr, int)}
51
51
  # When wrapping functional nodes, need to set call args\kwargs in wrapper, because they
52
52
  # are used during wrapper call method.
53
+ # Temporary patch: for torch.gather this is not the case, so args & kwargs shouldn't be
54
+ # saved in the warpper.
53
55
  func_node_kwargs = {OP_CALL_ARGS: node.op_call_args,
54
56
  OP_CALL_KWARGS: node.op_call_kwargs
55
- } if isinstance(node, FunctionalNode) else {}
57
+ } if isinstance(node, FunctionalNode) and not node.functional_op is torch.gather else {}
56
58
  return PytorchQuantizationWrapper(module, weight_quantizers, weights_values,
57
59
  is_inputs_as_list=node.inputs_as_list,
58
60
  **func_node_kwargs)
@@ -24,6 +24,23 @@ from model_compression_toolkit.target_platform_capabilities.target_platform.op_q
24
24
 
25
25
  tp = mct.target_platform
26
26
 
27
+ OPSET_NO_QUANTIZATION = "NoQuantization"
28
+ OPSET_QUANTIZATION_PRESERVING = "QuantizationPreserving"
29
+ OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS = "DimensionManipulationOpsWithWeights"
30
+ OPSET_DIMENSION_MANIPULATION_OPS = "DimensionManipulationOps"
31
+ OPSET_MERGE_OPS = "MergeOps"
32
+ OPSET_CONV = "Conv"
33
+ OPSET_FULLY_CONNECTED = "FullyConnected"
34
+ OPSET_ANY_RELU = "AnyReLU"
35
+ OPSET_ADD = "Add"
36
+ OPSET_SUB = "Sub"
37
+ OPSET_MUL = "Mul"
38
+ OPSET_DIV = "Div"
39
+ OPSET_PRELU = "PReLU"
40
+ OPSET_SWISH = "Swish"
41
+ OPSET_SIGMOID = "Sigmoid"
42
+ OPSET_TANH = "Tanh"
43
+
27
44
 
28
45
  def get_tp_model() -> TargetPlatformModel:
29
46
  """
@@ -189,6 +206,10 @@ def generate_tp_model(default_config: OpQuantizationConfig,
189
206
  const_config_input16_per_tensor],
190
207
  base_config=const_config_input16_per_tensor)
191
208
 
209
+ qpreserving_const_config = const_config.clone_and_edit(enable_activation_quantization=False,
210
+ quantization_preserving=True)
211
+ qpreserving_const_config_options = tp.QuantizationConfigOptions([qpreserving_const_config])
212
+
192
213
  # Create a TargetPlatformModel and set its default quantization config.
193
214
  # This default configuration will be used for all operations
194
215
  # unless specified otherwise (see OperatorsSet, for example):
@@ -207,39 +228,40 @@ def generate_tp_model(default_config: OpQuantizationConfig,
207
228
 
208
229
  # May suit for operations like: Dropout, Reshape, etc.
209
230
  default_qco = tp.get_default_quantization_config_options()
210
- tp.OperatorsSet("NoQuantization",
231
+ tp.OperatorsSet(OPSET_NO_QUANTIZATION,
211
232
  default_qco.clone_and_edit(enable_activation_quantization=False)
212
233
  .clone_and_edit_weight_attribute(enable_weights_quantization=False))
213
- tp.OperatorsSet("QuantizationPreserving",
234
+ tp.OperatorsSet(OPSET_QUANTIZATION_PRESERVING,
214
235
  default_qco.clone_and_edit(enable_activation_quantization=False,
215
236
  quantization_preserving=True)
216
237
  .clone_and_edit_weight_attribute(enable_weights_quantization=False))
217
- tp.OperatorsSet("DimensionManipulationOps",
238
+ tp.OperatorsSet(OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS, qpreserving_const_config_options)
239
+ tp.OperatorsSet(OPSET_DIMENSION_MANIPULATION_OPS,
218
240
  default_qco.clone_and_edit(enable_activation_quantization=False,
219
241
  quantization_preserving=True,
220
242
  supported_input_activation_n_bits=(8, 16))
221
243
  .clone_and_edit_weight_attribute(enable_weights_quantization=False))
222
- tp.OperatorsSet("MergeOps", const_configuration_options_inout16_per_tensor)
244
+ tp.OperatorsSet(OPSET_MERGE_OPS, const_configuration_options_inout16_per_tensor)
223
245
 
224
246
  # Create Mixed-Precision quantization configuration options from the given list of OpQuantizationConfig objects
225
247
  mixed_precision_configuration_options = tp.QuantizationConfigOptions(mixed_precision_cfg_list,
226
248
  base_config=base_config)
227
249
 
228
250
  # Define operator sets that use mixed_precision_configuration_options:
229
- conv = tp.OperatorsSet("Conv", mixed_precision_configuration_options)
230
- fc = tp.OperatorsSet("FullyConnected", mixed_precision_configuration_options)
251
+ conv = tp.OperatorsSet(OPSET_CONV, mixed_precision_configuration_options)
252
+ fc = tp.OperatorsSet(OPSET_FULLY_CONNECTED, mixed_precision_configuration_options)
231
253
 
232
254
  # Define operations sets without quantization configuration
233
255
  # options (useful for creating fusing patterns, for example):
234
- any_relu = tp.OperatorsSet("AnyReLU")
235
- add = tp.OperatorsSet("Add", const_configuration_options_inout16)
236
- sub = tp.OperatorsSet("Sub", const_configuration_options_inout16)
237
- mul = tp.OperatorsSet("Mul", const_configuration_options_inout16)
238
- div = tp.OperatorsSet("Div", const_configuration_options)
239
- prelu = tp.OperatorsSet("PReLU")
240
- swish = tp.OperatorsSet("Swish")
241
- sigmoid = tp.OperatorsSet("Sigmoid")
242
- tanh = tp.OperatorsSet("Tanh")
256
+ any_relu = tp.OperatorsSet(OPSET_ANY_RELU)
257
+ add = tp.OperatorsSet(OPSET_ADD, const_configuration_options_inout16)
258
+ sub = tp.OperatorsSet(OPSET_SUB, const_configuration_options_inout16)
259
+ mul = tp.OperatorsSet(OPSET_MUL, const_configuration_options_inout16)
260
+ div = tp.OperatorsSet(OPSET_DIV, const_configuration_options)
261
+ prelu = tp.OperatorsSet(OPSET_PRELU)
262
+ swish = tp.OperatorsSet(OPSET_SWISH)
263
+ sigmoid = tp.OperatorsSet(OPSET_SIGMOID)
264
+ tanh = tp.OperatorsSet(OPSET_TANH)
243
265
 
244
266
  # Combine multiple operators into a single operator to avoid quantization between
245
267
  # them. To do this we define fusing patterns using the OperatorsSets that were created.
@@ -35,6 +35,10 @@ else:
35
35
  from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v4.tp_model import get_tp_model
36
36
  import model_compression_toolkit as mct
37
37
  from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v4 import __version__ as TPC_VERSION
38
+ from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v4.tp_model import OPSET_NO_QUANTIZATION, \
39
+ OPSET_QUANTIZATION_PRESERVING, OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS, OPSET_DIMENSION_MANIPULATION_OPS, \
40
+ OPSET_MERGE_OPS, OPSET_CONV, OPSET_FULLY_CONNECTED, OPSET_ANY_RELU, OPSET_ADD, OPSET_SUB, OPSET_MUL, OPSET_DIV, \
41
+ OPSET_PRELU, OPSET_SWISH, OPSET_SIGMOID, OPSET_TANH
38
42
 
39
43
  tp = mct.target_platform
40
44
 
@@ -74,10 +78,8 @@ def generate_keras_tpc(name: str, tp_model: tp.TargetPlatformModel):
74
78
  Dropout,
75
79
  MaxPooling2D,
76
80
  tf.split,
77
- tf.gather,
78
81
  tf.cast,
79
82
  tf.unstack,
80
- tf.compat.v1.gather,
81
83
  tf.__operators__.getitem,
82
84
  tf.strided_slice]
83
85
  quantization_preserving_list_16bit_input = [Reshape,
@@ -90,11 +92,12 @@ def generate_keras_tpc(name: str, tp_model: tp.TargetPlatformModel):
90
92
  no_quant_list.append(SSDPostProcess)
91
93
 
92
94
  with keras_tpc:
93
- tp.OperationsSetToLayers("NoQuantization", no_quant_list)
94
- tp.OperationsSetToLayers("QuantizationPreserving", quantization_preserving)
95
- tp.OperationsSetToLayers("DimensionManipulationOps", quantization_preserving_list_16bit_input)
96
- tp.OperationsSetToLayers("MergeOps", [tf.stack, tf.concat, Concatenate])
97
- tp.OperationsSetToLayers("Conv",
95
+ tp.OperationsSetToLayers(OPSET_NO_QUANTIZATION, no_quant_list)
96
+ tp.OperationsSetToLayers(OPSET_QUANTIZATION_PRESERVING, quantization_preserving)
97
+ tp.OperationsSetToLayers(OPSET_DIMENSION_MANIPULATION_OPS, quantization_preserving_list_16bit_input)
98
+ tp.OperationsSetToLayers(OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS, [tf.gather, tf.compat.v1.gather])
99
+ tp.OperationsSetToLayers(OPSET_MERGE_OPS, [tf.stack, tf.concat, Concatenate])
100
+ tp.OperationsSetToLayers(OPSET_CONV,
98
101
  [Conv2D,
99
102
  DepthwiseConv2D,
100
103
  Conv2DTranspose,
@@ -111,23 +114,23 @@ def generate_keras_tpc(name: str, tp_model: tp.TargetPlatformModel):
111
114
  DepthwiseConv2D: KERAS_DEPTHWISE_KERNEL,
112
115
  tf.nn.depthwise_conv2d: KERAS_DEPTHWISE_KERNEL}, default_value=KERAS_KERNEL),
113
116
  BIAS_ATTR: DefaultDict(default_value=BIAS)})
114
- tp.OperationsSetToLayers("FullyConnected", [Dense],
117
+ tp.OperationsSetToLayers(OPSET_FULLY_CONNECTED, [Dense],
115
118
  attr_mapping={KERNEL_ATTR: DefaultDict(default_value=KERAS_KERNEL),
116
119
  BIAS_ATTR: DefaultDict(default_value=BIAS)})
117
- tp.OperationsSetToLayers("AnyReLU", [tf.nn.relu,
118
- tf.nn.relu6,
119
- tf.nn.leaky_relu,
120
- ReLU,
121
- LeakyReLU,
122
- tp.LayerFilterParams(Activation, activation="relu"),
123
- tp.LayerFilterParams(Activation, activation="leaky_relu")])
124
- tp.OperationsSetToLayers("Add", [tf.add, Add])
125
- tp.OperationsSetToLayers("Sub", [tf.subtract, Subtract])
126
- tp.OperationsSetToLayers("Mul", [tf.math.multiply, Multiply])
127
- tp.OperationsSetToLayers("Div", [tf.math.divide, tf.math.truediv])
128
- tp.OperationsSetToLayers("PReLU", [PReLU])
129
- tp.OperationsSetToLayers("Swish", [tf.nn.swish, tp.LayerFilterParams(Activation, activation="swish")])
130
- tp.OperationsSetToLayers("Sigmoid", [tf.nn.sigmoid, tp.LayerFilterParams(Activation, activation="sigmoid")])
131
- tp.OperationsSetToLayers("Tanh", [tf.nn.tanh, tp.LayerFilterParams(Activation, activation="tanh")])
120
+ tp.OperationsSetToLayers(OPSET_ANY_RELU, [tf.nn.relu,
121
+ tf.nn.relu6,
122
+ tf.nn.leaky_relu,
123
+ ReLU,
124
+ LeakyReLU,
125
+ tp.LayerFilterParams(Activation, activation="relu"),
126
+ tp.LayerFilterParams(Activation, activation="leaky_relu")])
127
+ tp.OperationsSetToLayers(OPSET_ADD, [tf.add, Add])
128
+ tp.OperationsSetToLayers(OPSET_SUB, [tf.subtract, Subtract])
129
+ tp.OperationsSetToLayers(OPSET_MUL, [tf.math.multiply, Multiply])
130
+ tp.OperationsSetToLayers(OPSET_DIV, [tf.math.divide, tf.math.truediv])
131
+ tp.OperationsSetToLayers(OPSET_PRELU, [PReLU])
132
+ tp.OperationsSetToLayers(OPSET_SWISH, [tf.nn.swish, tp.LayerFilterParams(Activation, activation="swish")])
133
+ tp.OperationsSetToLayers(OPSET_SIGMOID, [tf.nn.sigmoid, tp.LayerFilterParams(Activation, activation="sigmoid")])
134
+ tp.OperationsSetToLayers(OPSET_TANH, [tf.nn.tanh, tp.LayerFilterParams(Activation, activation="tanh")])
132
135
 
133
136
  return keras_tpc
@@ -29,6 +29,10 @@ from model_compression_toolkit.target_platform_capabilities.constants import KER
29
29
  from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v4.tp_model import get_tp_model
30
30
  import model_compression_toolkit as mct
31
31
  from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v4 import __version__ as TPC_VERSION
32
+ from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v4.tp_model import OPSET_NO_QUANTIZATION, \
33
+ OPSET_QUANTIZATION_PRESERVING, OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS, OPSET_DIMENSION_MANIPULATION_OPS, \
34
+ OPSET_MERGE_OPS, OPSET_CONV, OPSET_FULLY_CONNECTED, OPSET_ANY_RELU, OPSET_ADD, OPSET_SUB, OPSET_MUL, OPSET_DIV, \
35
+ OPSET_PRELU, OPSET_SWISH, OPSET_SIGMOID, OPSET_TANH
32
36
 
33
37
  tp = mct.target_platform
34
38
 
@@ -65,49 +69,49 @@ def generate_pytorch_tpc(name: str, tp_model: tp.TargetPlatformModel):
65
69
  BIAS_ATTR: DefaultDict(default_value=BIAS)}
66
70
 
67
71
  with pytorch_tpc:
68
- tp.OperationsSetToLayers("NoQuantization", [torch.Tensor.size,
69
- equal,
70
- argmax,
71
- topk])
72
- tp.OperationsSetToLayers("QuantizationPreserving", [Dropout,
73
- dropout,
74
- split,
75
- chunk,
76
- unbind,
77
- gather,
78
- MaxPool2d])
79
- tp.OperationsSetToLayers("DimensionManipulationOps", [Flatten,
80
- flatten,
81
- operator.getitem,
82
- reshape,
83
- unsqueeze,
84
- squeeze,
85
- permute,
86
- transpose])
87
- tp.OperationsSetToLayers("MergeOps",
72
+ tp.OperationsSetToLayers(OPSET_NO_QUANTIZATION, [torch.Tensor.size,
73
+ equal,
74
+ argmax,
75
+ topk])
76
+ tp.OperationsSetToLayers(OPSET_QUANTIZATION_PRESERVING, [Dropout,
77
+ dropout,
78
+ split,
79
+ chunk,
80
+ unbind,
81
+ MaxPool2d])
82
+ tp.OperationsSetToLayers(OPSET_DIMENSION_MANIPULATION_OPS, [Flatten,
83
+ flatten,
84
+ operator.getitem,
85
+ reshape,
86
+ unsqueeze,
87
+ squeeze,
88
+ permute,
89
+ transpose])
90
+ tp.OperationsSetToLayers(OPSET_DIMENSION_MANIPULATION_OPS_WITH_WEIGHTS, [gather])
91
+ tp.OperationsSetToLayers(OPSET_MERGE_OPS,
88
92
  [torch.stack, torch.cat, torch.concat, torch.concatenate])
89
93
 
90
- tp.OperationsSetToLayers("Conv", [Conv2d, ConvTranspose2d],
94
+ tp.OperationsSetToLayers(OPSET_CONV, [Conv2d, ConvTranspose2d],
91
95
  attr_mapping=pytorch_linear_attr_mapping)
92
- tp.OperationsSetToLayers("FullyConnected", [Linear],
96
+ tp.OperationsSetToLayers(OPSET_FULLY_CONNECTED, [Linear],
93
97
  attr_mapping=pytorch_linear_attr_mapping)
94
- tp.OperationsSetToLayers("AnyReLU", [torch.relu,
95
- ReLU,
96
- ReLU6,
97
- LeakyReLU,
98
- relu,
99
- relu6,
100
- leaky_relu,
101
- tp.LayerFilterParams(Hardtanh, min_val=0),
102
- tp.LayerFilterParams(hardtanh, min_val=0)])
98
+ tp.OperationsSetToLayers(OPSET_ANY_RELU, [torch.relu,
99
+ ReLU,
100
+ ReLU6,
101
+ LeakyReLU,
102
+ relu,
103
+ relu6,
104
+ leaky_relu,
105
+ tp.LayerFilterParams(Hardtanh, min_val=0),
106
+ tp.LayerFilterParams(hardtanh, min_val=0)])
103
107
 
104
- tp.OperationsSetToLayers("Add", [operator.add, add])
105
- tp.OperationsSetToLayers("Sub", [operator.sub, sub, subtract])
106
- tp.OperationsSetToLayers("Mul", [operator.mul, mul, multiply])
107
- tp.OperationsSetToLayers("Div", [operator.truediv, div, divide])
108
- tp.OperationsSetToLayers("PReLU", [PReLU, prelu])
109
- tp.OperationsSetToLayers("Swish", [SiLU, silu, Hardswish, hardswish])
110
- tp.OperationsSetToLayers("Sigmoid", [Sigmoid, sigmoid])
111
- tp.OperationsSetToLayers("Tanh", [Tanh, tanh])
108
+ tp.OperationsSetToLayers(OPSET_ADD, [operator.add, add])
109
+ tp.OperationsSetToLayers(OPSET_SUB, [operator.sub, sub, subtract])
110
+ tp.OperationsSetToLayers(OPSET_MUL, [operator.mul, mul, multiply])
111
+ tp.OperationsSetToLayers(OPSET_DIV, [operator.truediv, div, divide])
112
+ tp.OperationsSetToLayers(OPSET_PRELU, [PReLU, prelu])
113
+ tp.OperationsSetToLayers(OPSET_SWISH, [SiLU, silu, Hardswish, hardswish])
114
+ tp.OperationsSetToLayers(OPSET_SIGMOID, [Sigmoid, sigmoid])
115
+ tp.OperationsSetToLayers(OPSET_TANH, [Tanh, tanh])
112
116
 
113
117
  return pytorch_tpc