mct-nightly 2.2.0.20240923.519__py3-none-any.whl → 2.2.0.20240925.453__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.20240923.519.dist-info → mct_nightly-2.2.0.20240925.453.dist-info}/METADATA +1 -1
- {mct_nightly-2.2.0.20240923.519.dist-info → mct_nightly-2.2.0.20240925.453.dist-info}/RECORD +11 -11
- model_compression_toolkit/__init__.py +1 -1
- model_compression_toolkit/core/pytorch/back2framework/pytorch_model_builder.py +8 -3
- model_compression_toolkit/exporter/model_wrapper/pytorch/builder/fully_quantized_model_builder.py +3 -1
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tp_model.py +37 -15
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tpc_keras.py +26 -23
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tpc_pytorch.py +43 -39
- {mct_nightly-2.2.0.20240923.519.dist-info → mct_nightly-2.2.0.20240925.453.dist-info}/LICENSE.md +0 -0
- {mct_nightly-2.2.0.20240923.519.dist-info → mct_nightly-2.2.0.20240925.453.dist-info}/WHEEL +0 -0
- {mct_nightly-2.2.0.20240923.519.dist-info → mct_nightly-2.2.0.20240925.453.dist-info}/top_level.txt +0 -0
{mct_nightly-2.2.0.20240923.519.dist-info → mct_nightly-2.2.0.20240925.453.dist-info}/RECORD
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
model_compression_toolkit/__init__.py,sha256=
|
1
|
+
model_compression_toolkit/__init__.py,sha256=eI5QONSxEPDPEpc5TqZF43AfSWl8Om61_pe6SgWyCTk,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=
|
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
|
@@ -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
|
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=
|
476
|
-
model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tpc_keras.py,sha256=
|
477
|
-
model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tpc_pytorch.py,sha256=
|
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.
|
554
|
-
mct_nightly-2.2.0.
|
555
|
-
mct_nightly-2.2.0.
|
556
|
-
mct_nightly-2.2.0.
|
557
|
-
mct_nightly-2.2.0.
|
553
|
+
mct_nightly-2.2.0.20240925.453.dist-info/LICENSE.md,sha256=aYSSIb-5AFPeITTvXm1UAoe0uYBiMmSS8flvXaaFUks,10174
|
554
|
+
mct_nightly-2.2.0.20240925.453.dist-info/METADATA,sha256=-FYOCuanQ2MY1g5nj-LWf1WuTJEAqIpR5ymgLPAGe2I,20813
|
555
|
+
mct_nightly-2.2.0.20240925.453.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
556
|
+
mct_nightly-2.2.0.20240925.453.dist-info/top_level.txt,sha256=csdfSXhtRnpWYRzjZ-dRLIhOmM2TEdVXUxG05A5fgb8,39
|
557
|
+
mct_nightly-2.2.0.20240925.453.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.
|
30
|
+
__version__ = "2.2.0.20240925.000453"
|
@@ -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
|
-
|
149
|
-
|
150
|
-
|
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
|
model_compression_toolkit/exporter/model_wrapper/pytorch/builder/fully_quantized_model_builder.py
CHANGED
@@ -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(
|
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(
|
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(
|
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(
|
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(
|
230
|
-
fc = tp.OperatorsSet(
|
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(
|
235
|
-
add = tp.OperatorsSet(
|
236
|
-
sub = tp.OperatorsSet(
|
237
|
-
mul = tp.OperatorsSet(
|
238
|
-
div = tp.OperatorsSet(
|
239
|
-
prelu = tp.OperatorsSet(
|
240
|
-
swish = tp.OperatorsSet(
|
241
|
-
sigmoid = tp.OperatorsSet(
|
242
|
-
tanh = tp.OperatorsSet(
|
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.
|
model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tpc_keras.py
CHANGED
@@ -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(
|
94
|
-
tp.OperationsSetToLayers(
|
95
|
-
tp.OperationsSetToLayers(
|
96
|
-
tp.OperationsSetToLayers(
|
97
|
-
tp.OperationsSetToLayers(
|
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(
|
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(
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
tp.OperationsSetToLayers(
|
125
|
-
tp.OperationsSetToLayers(
|
126
|
-
tp.OperationsSetToLayers(
|
127
|
-
tp.OperationsSetToLayers(
|
128
|
-
tp.OperationsSetToLayers(
|
129
|
-
tp.OperationsSetToLayers(
|
130
|
-
tp.OperationsSetToLayers(
|
131
|
-
tp.OperationsSetToLayers(
|
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
|
model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v4/tpc_pytorch.py
CHANGED
@@ -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(
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
tp.OperationsSetToLayers(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
tp.OperationsSetToLayers(
|
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(
|
94
|
+
tp.OperationsSetToLayers(OPSET_CONV, [Conv2d, ConvTranspose2d],
|
91
95
|
attr_mapping=pytorch_linear_attr_mapping)
|
92
|
-
tp.OperationsSetToLayers(
|
96
|
+
tp.OperationsSetToLayers(OPSET_FULLY_CONNECTED, [Linear],
|
93
97
|
attr_mapping=pytorch_linear_attr_mapping)
|
94
|
-
tp.OperationsSetToLayers(
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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(
|
105
|
-
tp.OperationsSetToLayers(
|
106
|
-
tp.OperationsSetToLayers(
|
107
|
-
tp.OperationsSetToLayers(
|
108
|
-
tp.OperationsSetToLayers(
|
109
|
-
tp.OperationsSetToLayers(
|
110
|
-
tp.OperationsSetToLayers(
|
111
|
-
tp.OperationsSetToLayers(
|
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
|
{mct_nightly-2.2.0.20240923.519.dist-info → mct_nightly-2.2.0.20240925.453.dist-info}/LICENSE.md
RENAMED
File without changes
|
File without changes
|
{mct_nightly-2.2.0.20240923.519.dist-info → mct_nightly-2.2.0.20240925.453.dist-info}/top_level.txt
RENAMED
File without changes
|