model-compression-toolkit 2.2.1__py3-none-any.whl → 2.2.2__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 (23) hide show
  1. model_compression_toolkit/__init__.py +1 -1
  2. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/target_platform_capabilities.py +0 -24
  3. {model_compression_toolkit-2.2.1.dist-info → model_compression_toolkit-2.2.2.dist-info}/METADATA +1 -1
  4. {model_compression_toolkit-2.2.1.dist-info → model_compression_toolkit-2.2.2.dist-info}/RECORD +7 -23
  5. {model_compression_toolkit-2.2.1.dist-info → model_compression_toolkit-2.2.2.dist-info}/WHEEL +1 -1
  6. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/__init__.py +0 -16
  7. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tp_model.py +0 -215
  8. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tpc_keras.py +0 -131
  9. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tpc_pytorch.py +0 -111
  10. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/__init__.py +0 -16
  11. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tp_model.py +0 -212
  12. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tpc_keras.py +0 -131
  13. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tpc_pytorch.py +0 -110
  14. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/__init__.py +0 -16
  15. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tp_model.py +0 -238
  16. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tpc_keras.py +0 -134
  17. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tpc_pytorch.py +0 -114
  18. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/__init__.py +0 -16
  19. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tp_model.py +0 -223
  20. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tpc_keras.py +0 -131
  21. model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tpc_pytorch.py +0 -111
  22. {model_compression_toolkit-2.2.1.dist-info → model_compression_toolkit-2.2.2.dist-info}/LICENSE.md +0 -0
  23. {model_compression_toolkit-2.2.1.dist-info → model_compression_toolkit-2.2.2.dist-info}/top_level.txt +0 -0
@@ -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.1"
30
+ __version__ = "2.2.2"
@@ -34,23 +34,11 @@ def get_tpc_dict_by_fw(fw_name):
34
34
  get_keras_tpc as get_keras_tpc_v1_lut
35
35
  from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v1_pot.tpc_keras import \
36
36
  get_keras_tpc as get_keras_tpc_v1_pot
37
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v2.tpc_keras import \
38
- get_keras_tpc as get_keras_tpc_v2
39
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v2_lut.tpc_keras import \
40
- get_keras_tpc as get_keras_tpc_v2_lut
41
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v3.tpc_keras import \
42
- get_keras_tpc as get_keras_tpc_v3
43
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v3_lut.tpc_keras import \
44
- get_keras_tpc as get_keras_tpc_v3_lut
45
37
 
46
38
  # Keras: TPC versioning
47
39
  tpc_models_dict = {'v1': get_keras_tpc_v1,
48
40
  'v1_lut': get_keras_tpc_v1_lut,
49
41
  'v1_pot': get_keras_tpc_v1_pot,
50
- 'v2': get_keras_tpc_v2,
51
- 'v2_lut': get_keras_tpc_v2_lut,
52
- 'v3': get_keras_tpc_v3,
53
- 'v3_lut': get_keras_tpc_v3_lut,
54
42
  LATEST: get_keras_tpc_latest}
55
43
  elif fw_name == PYTORCH:
56
44
  ###############################
@@ -65,23 +53,11 @@ def get_tpc_dict_by_fw(fw_name):
65
53
  get_pytorch_tpc as get_pytorch_tpc_v1_pot
66
54
  from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v1_lut.tpc_pytorch import \
67
55
  get_pytorch_tpc as get_pytorch_tpc_v1_lut
68
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v2.tpc_pytorch import \
69
- get_pytorch_tpc as get_pytorch_tpc_v2
70
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v2_lut.tpc_pytorch import \
71
- get_pytorch_tpc as get_pytorch_tpc_v2_lut
72
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v3.tpc_pytorch import \
73
- get_pytorch_tpc as get_pytorch_tpc_v3
74
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v3_lut.tpc_pytorch import \
75
- get_pytorch_tpc as get_pytorch_tpc_v3_lut
76
56
 
77
57
  # Pytorch: TPC versioning
78
58
  tpc_models_dict = {'v1': get_pytorch_tpc_v1,
79
59
  'v1_lut': get_pytorch_tpc_v1_lut,
80
60
  'v1_pot': get_pytorch_tpc_v1_pot,
81
- 'v2': get_pytorch_tpc_v2,
82
- 'v2_lut': get_pytorch_tpc_v2_lut,
83
- 'v3': get_pytorch_tpc_v3,
84
- 'v3_lut': get_pytorch_tpc_v3_lut,
85
61
  LATEST: get_pytorch_tpc_latest}
86
62
  if tpc_models_dict is not None:
87
63
  return tpc_models_dict
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: model-compression-toolkit
3
- Version: 2.2.1
3
+ Version: 2.2.2
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=8j2s7Nrg601DX3Gmz_dnBiQwAjGoHas2A_pUkktM030,1557
1
+ model_compression_toolkit/__init__.py,sha256=kcyZt5a8mo_xf356kzHK5Tqyf90r5Xlnc_4Am9FlziA,1557
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
@@ -441,7 +441,7 @@ model_compression_toolkit/target_platform_capabilities/target_platform/targetpla
441
441
  model_compression_toolkit/target_platform_capabilities/tpc_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
442
442
  model_compression_toolkit/target_platform_capabilities/tpc_models/get_target_platform_capabilities.py,sha256=CWind2Kd91lzBTRAh1A9sHuNw17xXhMb3gV436RpK8c,3033
443
443
  model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/__init__.py,sha256=lNJ29DYxaLUPDstRDA1PGI5r9Fulq_hvrZMlhst1Z5g,697
444
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/target_platform_capabilities.py,sha256=YxQC_JjnnB_ZEVgUVXAXZIrRKvAj9A7nWIVZTL2HDVA,5631
444
+ model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/target_platform_capabilities.py,sha256=ZxvDhEg4gN1IISftCBQxF4x0lZrxqpWxPEUhjK8ORgQ,3767
445
445
  model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/latest/__init__.py,sha256=eVIRpx5O0JQI7TSdw5JAWtwrG3MQ8-7hYThQvB9da5c,1528
446
446
  model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1/__init__.py,sha256=1mMOREEMoNHu_KTMGDp4crN61opKWX6aFn1DrDLvqcc,717
447
447
  model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1/tp_model.py,sha256=6mbv-fNVz559j5XCSX5e8aENUJACYuJzQcZBLPh12gU,11057
@@ -455,22 +455,6 @@ model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_
455
455
  model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_pot/tp_model.py,sha256=ypbOiVR0ZVHw78g6z9YIoPH0BZut6mPzqgrl6EOpIDI,10543
456
456
  model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_pot/tpc_keras.py,sha256=XyMjVY9APnzqf1A-tzSy-OcNyhoIQsAQKxOiUCx5DFE,6511
457
457
  model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v1_pot/tpc_pytorch.py,sha256=X853xDEF-3rcPoqxbrlYN28vvW3buSdM36c_eN_LKx8,5758
458
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/__init__.py,sha256=vKWAoQ2KkhuptS5HZB50zHG6KY8wHpHTxPugw_nGCRo,717
459
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tp_model.py,sha256=NI-QPOmg7YqPCQg8X5P1doP_mFIZ2kXm8NxcvzAg7aA,11132
460
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tpc_keras.py,sha256=J2lkRjmb-BXXpaHZ_OZDS9bbDKGY-Q1Inx_1asXElwo,6593
461
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2/tpc_pytorch.py,sha256=jAyTXhcChO124odtWC3bYKRH4ZyqLPkKQluJFOoyPIM,5726
462
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/__init__.py,sha256=wUk4Xsg7jpxOWYjq2K3WUwLcI185p_sVPK-ttG0ydhA,721
463
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tp_model.py,sha256=T8o20d-Kerr91l4RR09MFbqoTWAXgqjVUyW-nE43zDg,10865
464
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tpc_keras.py,sha256=EgDKcY-ba9cBmQmh0-sv45GLm-HP6Cc4Rgf-KxZXTgM,6601
465
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v2_lut/tpc_pytorch.py,sha256=dFQjzFlLDwoUqKNP1at1fS1N1WJadSSasRyzHl6vaB8,5733
466
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/__init__.py,sha256=gAeebYCKyIXH9-Qwze7FwvTihudzAHk_Qsg94fQbkjQ,717
467
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tp_model.py,sha256=purcM7kLdh2HyJaxzROAoVSwz1Xlo6GPEe8JQKfMcuM,12911
468
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tpc_keras.py,sha256=x_-lIQJ_Cv546EmXblZA2xjvcw8Yo5xg_cy43mhqsh0,6803
469
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tpc_pytorch.py,sha256=5Q54Qgi7_NTByRSJNVCfPUCJZ0lADT98UUZOhyHaV24,5986
470
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/__init__.py,sha256=C2kwyDE1-rtukkbNSoKRv9q8Nt2GOCaBbl0BdOr3goA,721
471
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tp_model.py,sha256=YANvT38YiwO9jE3dC04wHDZBGJQ34hGTvKygHwwbI_U,11751
472
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tpc_keras.py,sha256=XM6qBLIvzsmdFf-AZq5WOlORK2GXC_X-gulReNxHb9E,6601
473
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tpc_pytorch.py,sha256=nP05jqvh6uaj30a3W7zEkJfKtqfP0Nz5bobwRqbYrdM,5807
474
458
  model_compression_toolkit/target_platform_capabilities/tpc_models/qnnpack_tpc/__init__.py,sha256=cco4TmeIDIh32nj9ZZXVkws4dd9F2UDrmjKzTN8G0V0,697
475
459
  model_compression_toolkit/target_platform_capabilities/tpc_models/qnnpack_tpc/target_platform_capabilities.py,sha256=is00rNrDmmirYsyMtMkWz0DwOA92-x7hAJwpd6z1n2E,2806
476
460
  model_compression_toolkit/target_platform_capabilities/tpc_models/qnnpack_tpc/latest/__init__.py,sha256=CXC-HQolSDu7j8V-Xm-SWGCd74gXB3XnAkEhI_TVbIQ,1516
@@ -527,8 +511,8 @@ model_compression_toolkit/xquant/pytorch/model_analyzer.py,sha256=b93o800yVB3Z-i
527
511
  model_compression_toolkit/xquant/pytorch/pytorch_report_utils.py,sha256=bOc-hFL3gdoSM1Th_S2N_-9JJSlPGpZCTx_QLJHS6lg,3388
528
512
  model_compression_toolkit/xquant/pytorch/similarity_functions.py,sha256=CERxq5K8rqaiE-DlwhZBTUd9x69dtYJlkHOPLB54vm8,2354
529
513
  model_compression_toolkit/xquant/pytorch/tensorboard_utils.py,sha256=mkoEktLFFHtEKzzFRn_jCnxjhJolK12TZ5AQeDHzUO8,9767
530
- model_compression_toolkit-2.2.1.dist-info/LICENSE.md,sha256=aYSSIb-5AFPeITTvXm1UAoe0uYBiMmSS8flvXaaFUks,10174
531
- model_compression_toolkit-2.2.1.dist-info/METADATA,sha256=-ePUtPHstN96dm-TIbSR8mewneFNecbB3NsL1Gc8BXA,19719
532
- model_compression_toolkit-2.2.1.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
533
- model_compression_toolkit-2.2.1.dist-info/top_level.txt,sha256=gsYA8juk0Z-ZmQRKULkb3JLGdOdz8jW_cMRjisn9ga4,26
534
- model_compression_toolkit-2.2.1.dist-info/RECORD,,
514
+ model_compression_toolkit-2.2.2.dist-info/LICENSE.md,sha256=aYSSIb-5AFPeITTvXm1UAoe0uYBiMmSS8flvXaaFUks,10174
515
+ model_compression_toolkit-2.2.2.dist-info/METADATA,sha256=Ae08moamciZA5B3bFb0UpuE29ooP7gkDQ-ipYGqNitE,19719
516
+ model_compression_toolkit-2.2.2.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
517
+ model_compression_toolkit-2.2.2.dist-info/top_level.txt,sha256=gsYA8juk0Z-ZmQRKULkb3JLGdOdz8jW_cMRjisn9ga4,26
518
+ model_compression_toolkit-2.2.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.44.0)
2
+ Generator: bdist_wheel (0.45.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,16 +0,0 @@
1
- # Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- # ==============================================================================
15
-
16
- __version__ = 'v2'
@@ -1,215 +0,0 @@
1
- # Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- # ==============================================================================
15
- from typing import List, Tuple
16
-
17
- import model_compression_toolkit as mct
18
- from model_compression_toolkit.constants import FLOAT_BITWIDTH
19
- from model_compression_toolkit.target_platform_capabilities.constants import KERNEL_ATTR, BIAS_ATTR, WEIGHTS_N_BITS
20
- from model_compression_toolkit.target_platform_capabilities.target_platform import OpQuantizationConfig, \
21
- TargetPlatformModel, Signedness
22
- from model_compression_toolkit.target_platform_capabilities.target_platform.op_quantization_config import \
23
- AttributeQuantizationConfig
24
-
25
- tp = mct.target_platform
26
-
27
-
28
- def get_tp_model() -> TargetPlatformModel:
29
- """
30
- A method that generates a default target platform model, with base 8-bit quantization configuration and 8, 4, 2
31
- bits configuration list for mixed-precision quantization.
32
- NOTE: in order to generate a target platform model with different configurations but with the same Operators Sets
33
- (for tests, experiments, etc.), use this method implementation as a test-case, i.e., override the
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.
36
-
37
- Returns: A TargetPlatformModel object.
38
-
39
- """
40
- base_config, mixed_precision_cfg_list, default_config = get_op_quantization_configs()
41
- return generate_tp_model(default_config=default_config,
42
- base_config=base_config,
43
- mixed_precision_cfg_list=mixed_precision_cfg_list,
44
- name='imx500_tp_model')
45
-
46
-
47
- def get_op_quantization_configs() -> \
48
- Tuple[OpQuantizationConfig, List[OpQuantizationConfig], OpQuantizationConfig]:
49
- """
50
- Creates a default configuration object for 8-bit quantization, to be used to set a default TargetPlatformModel.
51
- In addition, creates a default configuration objects list (with 8, 4 and 2 bit quantization) to be used as
52
- default configuration for mixed-precision quantization.
53
-
54
- Returns: An OpQuantizationConfig config object and a list of OpQuantizationConfig objects.
55
-
56
- """
57
-
58
- # TODO: currently, we don't want to quantize any attribute but the kernel by default,
59
- # to preserve the current behavior of MCT, so quantization is disabled for all other attributes.
60
- # Other quantization parameters are set to what we eventually want to quantize by default
61
- # when we enable multi-attributes quantization - THIS NEED TO BE MODIFIED IN ALL TP MODELS!
62
-
63
- # define a default quantization config for all non-specified weights attributes.
64
- default_weight_attr_config = AttributeQuantizationConfig(
65
- weights_quantization_method=tp.QuantizationMethod.POWER_OF_TWO,
66
- weights_n_bits=8,
67
- weights_per_channel_threshold=False,
68
- enable_weights_quantization=False, # TODO: this will changed to True once implementing multi-attributes quantization
69
- lut_values_bitwidth=None)
70
-
71
- # define a quantization config to quantize the kernel (for layers where there is a kernel attribute).
72
- kernel_base_config = AttributeQuantizationConfig(
73
- weights_quantization_method=tp.QuantizationMethod.SYMMETRIC,
74
- weights_n_bits=8,
75
- weights_per_channel_threshold=True,
76
- enable_weights_quantization=True,
77
- lut_values_bitwidth=None)
78
-
79
- # define a quantization config to quantize the bias (for layers where there is a bias attribute).
80
- bias_config = AttributeQuantizationConfig(
81
- weights_quantization_method=tp.QuantizationMethod.POWER_OF_TWO,
82
- weights_n_bits=FLOAT_BITWIDTH,
83
- weights_per_channel_threshold=False,
84
- enable_weights_quantization=False,
85
- lut_values_bitwidth=None)
86
-
87
- # Create a quantization config.
88
- # A quantization configuration defines how an operator
89
- # should be quantized on the modeled hardware:
90
-
91
- # We define a default config for operation without kernel attribute.
92
- # This is the default config that should be used for non-linear operations.
93
- eight_bits_default = tp.OpQuantizationConfig(
94
- default_weight_attr_config=default_weight_attr_config,
95
- attr_weights_configs_mapping={},
96
- activation_quantization_method=tp.QuantizationMethod.POWER_OF_TWO,
97
- activation_n_bits=8,
98
- supported_input_activation_n_bits=8,
99
- enable_activation_quantization=True,
100
- quantization_preserving=False,
101
- fixed_scale=None,
102
- fixed_zero_point=None,
103
- simd_size=32,
104
- signedness=Signedness.AUTO)
105
-
106
- # We define an 8-bit config for linear operations quantization, that include a kernel and bias attributes.
107
- linear_eight_bits = tp.OpQuantizationConfig(
108
- default_weight_attr_config=default_weight_attr_config,
109
- attr_weights_configs_mapping={KERNEL_ATTR: kernel_base_config, BIAS_ATTR: bias_config},
110
- activation_quantization_method=tp.QuantizationMethod.POWER_OF_TWO,
111
- activation_n_bits=8,
112
- supported_input_activation_n_bits=8,
113
- enable_activation_quantization=True,
114
- quantization_preserving=False,
115
- fixed_scale=None,
116
- fixed_zero_point=None,
117
- simd_size=32,
118
- signedness=Signedness.AUTO)
119
-
120
- # To quantize a model using mixed-precision, create
121
- # a list with more than one OpQuantizationConfig.
122
- # In this example, we quantize some operations' weights
123
- # using 2, 4 or 8 bits, and when using 2 or 4 bits, it's possible
124
- # to quantize the operations' activations using LUT.
125
- four_bits = linear_eight_bits.clone_and_edit(attr_to_edit={KERNEL_ATTR: {WEIGHTS_N_BITS: 4}},
126
- simd_size=linear_eight_bits.simd_size * 2)
127
- two_bits = linear_eight_bits.clone_and_edit(attr_to_edit={KERNEL_ATTR: {WEIGHTS_N_BITS: 2}},
128
- simd_size=linear_eight_bits.simd_size * 4)
129
-
130
- mixed_precision_cfg_list = [linear_eight_bits, four_bits, two_bits]
131
-
132
- return linear_eight_bits, mixed_precision_cfg_list, eight_bits_default
133
-
134
-
135
- def generate_tp_model(default_config: OpQuantizationConfig,
136
- base_config: OpQuantizationConfig,
137
- mixed_precision_cfg_list: List[OpQuantizationConfig],
138
- name: str) -> TargetPlatformModel:
139
- """
140
- Generates TargetPlatformModel with default defined Operators Sets, based on the given base configuration and
141
- mixed-precision configurations options list.
142
-
143
- Args
144
- default_config: A default OpQuantizationConfig to set as the TP model default configuration.
145
- base_config: An OpQuantizationConfig to set as the TargetPlatformModel base configuration for mixed-precision purposes only.
146
- mixed_precision_cfg_list: A list of OpQuantizationConfig to be used as the TP model mixed-precision
147
- quantization configuration options.
148
- name: The name of the TargetPlatformModel.
149
-
150
- Returns: A TargetPlatformModel object.
151
-
152
- """
153
- # Create a QuantizationConfigOptions, which defines a set
154
- # of possible configurations to consider when quantizing a set of operations (in mixed-precision, for example).
155
- # If the QuantizationConfigOptions contains only one configuration,
156
- # this configuration will be used for the operation quantization:
157
- default_configuration_options = tp.QuantizationConfigOptions([default_config])
158
-
159
- # Create a TargetPlatformModel and set its default quantization config.
160
- # This default configuration will be used for all operations
161
- # unless specified otherwise (see OperatorsSet, for example):
162
- generated_tpm = tp.TargetPlatformModel(default_configuration_options, add_metadata=True, name=name)
163
-
164
- # To start defining the model's components (such as operator sets, and fusing patterns),
165
- # use 'with' the TargetPlatformModel instance, and create them as below:
166
- with generated_tpm:
167
- # Create an OperatorsSet to represent a set of operations.
168
- # Each OperatorsSet has a unique label.
169
- # If a quantization configuration options is passed, these options will
170
- # be used for operations that will be attached to this set's label.
171
- # Otherwise, it will be a configure-less set (used in fusing):
172
-
173
- generated_tpm.set_simd_padding(is_simd_padding=True)
174
-
175
- # May suit for operations like: Dropout, Reshape, etc.
176
- default_qco = tp.get_default_quantization_config_options()
177
- tp.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 = tp.QuantizationConfigOptions(mixed_precision_cfg_list,
183
- base_config=base_config)
184
-
185
- # Define operator sets that use mixed_precision_configuration_options:
186
- conv = tp.OperatorsSet("Conv", mixed_precision_configuration_options)
187
- fc = tp.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 = tp.OperatorsSet("AnyReLU")
192
- add = tp.OperatorsSet("Add")
193
- sub = tp.OperatorsSet("Sub")
194
- mul = tp.OperatorsSet("Mul")
195
- div = tp.OperatorsSet("Div")
196
- prelu = tp.OperatorsSet("PReLU")
197
- swish = tp.OperatorsSet("Swish")
198
- sigmoid = tp.OperatorsSet("Sigmoid")
199
- tanh = tp.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 = tp.OperatorSetConcat(any_relu, swish, prelu, sigmoid, tanh)
205
- activations_after_fc_to_fuse = tp.OperatorSetConcat(any_relu, swish, sigmoid)
206
- any_binary = tp.OperatorSetConcat(add, sub, mul, div)
207
-
208
- # ------------------- #
209
- # Fusions
210
- # ------------------- #
211
- tp.Fusing([conv, activations_after_conv_to_fuse])
212
- tp.Fusing([fc, activations_after_fc_to_fuse])
213
- tp.Fusing([any_binary, any_relu])
214
-
215
- return generated_tpm
@@ -1,131 +0,0 @@
1
- # Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- # ==============================================================================
15
- import tensorflow as tf
16
- from packaging import version
17
-
18
- from model_compression_toolkit.defaultdict import DefaultDict
19
- from model_compression_toolkit.verify_packages import FOUND_SONY_CUSTOM_LAYERS
20
- from model_compression_toolkit.target_platform_capabilities.constants import KERNEL_ATTR, KERAS_DEPTHWISE_KERNEL, \
21
- KERAS_KERNEL, BIAS_ATTR, BIAS
22
-
23
- if FOUND_SONY_CUSTOM_LAYERS:
24
- from sony_custom_layers.keras.object_detection.ssd_post_process import SSDPostProcess
25
-
26
- if version.parse(tf.__version__) >= version.parse("2.13"):
27
- from keras.src.layers import Conv2D, DepthwiseConv2D, Dense, Reshape, ZeroPadding2D, Dropout, \
28
- MaxPooling2D, Activation, ReLU, Add, Subtract, Multiply, PReLU, Flatten, Cropping2D, LeakyReLU, Permute, \
29
- Conv2DTranspose, Identity
30
- else:
31
- from keras.layers import Conv2D, DepthwiseConv2D, Dense, Reshape, ZeroPadding2D, Dropout, \
32
- MaxPooling2D, Activation, ReLU, Add, Subtract, Multiply, PReLU, Flatten, Cropping2D, LeakyReLU, Permute, \
33
- Conv2DTranspose, Identity
34
-
35
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v2.tp_model import get_tp_model
36
- import model_compression_toolkit as mct
37
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v2 import __version__ as TPC_VERSION
38
-
39
- tp = mct.target_platform
40
-
41
-
42
- def get_keras_tpc() -> tp.TargetPlatformCapabilities:
43
- """
44
- get a Keras TargetPlatformCapabilities object with default operation sets to layers mapping.
45
-
46
- Returns: a Keras TargetPlatformCapabilities object for the given TargetPlatformModel.
47
- """
48
- imx500_tpc_tp_model = get_tp_model()
49
- return generate_keras_tpc(name='imx500_tpc_keras_tpc', tp_model=imx500_tpc_tp_model)
50
-
51
-
52
- def generate_keras_tpc(name: str, tp_model: tp.TargetPlatformModel):
53
- """
54
- Generates a TargetPlatformCapabilities object with default operation sets to layers mapping.
55
-
56
- Args:
57
- name: Name of the TargetPlatformCapabilities.
58
- tp_model: TargetPlatformModel object.
59
-
60
- Returns: a TargetPlatformCapabilities object for the given TargetPlatformModel.
61
- """
62
-
63
- keras_tpc = tp.TargetPlatformCapabilities(tp_model, name=name, version=TPC_VERSION)
64
-
65
- no_quant_list = [Identity,
66
- tf.identity,
67
- Reshape,
68
- tf.reshape,
69
- Permute,
70
- tf.transpose,
71
- Flatten,
72
- Cropping2D,
73
- ZeroPadding2D,
74
- Dropout,
75
- MaxPooling2D,
76
- tf.split,
77
- tf.quantization.fake_quant_with_min_max_vars,
78
- tf.math.argmax,
79
- tf.shape,
80
- tf.math.equal,
81
- tf.gather,
82
- tf.cast,
83
- tf.unstack,
84
- tf.compat.v1.gather,
85
- tf.nn.top_k,
86
- tf.__operators__.getitem,
87
- tf.image.combined_non_max_suppression,
88
- tf.compat.v1.shape]
89
-
90
- if FOUND_SONY_CUSTOM_LAYERS:
91
- no_quant_list.append(SSDPostProcess)
92
-
93
- with keras_tpc:
94
- tp.OperationsSetToLayers("NoQuantization", no_quant_list)
95
- tp.OperationsSetToLayers("Conv",
96
- [Conv2D,
97
- DepthwiseConv2D,
98
- Conv2DTranspose,
99
- tf.nn.conv2d,
100
- tf.nn.depthwise_conv2d,
101
- tf.nn.conv2d_transpose],
102
- # we provide attributes mapping that maps each layer type in the operations set
103
- # that has weights attributes with provided quantization config (in the tp model) to
104
- # its framework-specific attribute name.
105
- # note that a DefaultDict should be provided if not all the layer types in the
106
- # operation set are provided separately in the mapping.
107
- attr_mapping={
108
- KERNEL_ATTR: DefaultDict({
109
- DepthwiseConv2D: KERAS_DEPTHWISE_KERNEL,
110
- tf.nn.depthwise_conv2d: KERAS_DEPTHWISE_KERNEL}, default_value=KERAS_KERNEL),
111
- BIAS_ATTR: DefaultDict(default_value=BIAS)})
112
- tp.OperationsSetToLayers("FullyConnected", [Dense],
113
- attr_mapping={KERNEL_ATTR: DefaultDict(default_value=KERAS_KERNEL),
114
- BIAS_ATTR: DefaultDict(default_value=BIAS)})
115
- tp.OperationsSetToLayers("AnyReLU", [tf.nn.relu,
116
- tf.nn.relu6,
117
- tf.nn.leaky_relu,
118
- ReLU,
119
- LeakyReLU,
120
- tp.LayerFilterParams(Activation, activation="relu"),
121
- tp.LayerFilterParams(Activation, activation="leaky_relu")])
122
- tp.OperationsSetToLayers("Add", [tf.add, Add])
123
- tp.OperationsSetToLayers("Sub", [tf.subtract, Subtract])
124
- tp.OperationsSetToLayers("Mul", [tf.math.multiply, Multiply])
125
- tp.OperationsSetToLayers("Div", [tf.math.divide, tf.math.truediv])
126
- tp.OperationsSetToLayers("PReLU", [PReLU])
127
- tp.OperationsSetToLayers("Swish", [tf.nn.swish, tp.LayerFilterParams(Activation, activation="swish")])
128
- tp.OperationsSetToLayers("Sigmoid", [tf.nn.sigmoid, tp.LayerFilterParams(Activation, activation="sigmoid")])
129
- tp.OperationsSetToLayers("Tanh", [tf.nn.tanh, tp.LayerFilterParams(Activation, activation="tanh")])
130
-
131
- return keras_tpc
@@ -1,111 +0,0 @@
1
- # Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- # ==============================================================================
15
-
16
- import operator
17
-
18
- import torch
19
- from torch import add, sub, mul, div, flatten, reshape, split, unsqueeze, dropout, sigmoid, tanh, chunk, unbind, topk, \
20
- gather, equal, transpose, permute, argmax, squeeze
21
- from torch.nn import Conv2d, Linear, ConvTranspose2d
22
- from torch.nn import Dropout, Flatten, Hardtanh, Identity
23
- from torch.nn import ReLU, ReLU6, PReLU, SiLU, Sigmoid, Tanh, Hardswish, LeakyReLU
24
- from torch.nn.functional import relu, relu6, prelu, silu, hardtanh, hardswish, leaky_relu
25
-
26
- from model_compression_toolkit.defaultdict import DefaultDict
27
- from model_compression_toolkit.target_platform_capabilities.constants import KERNEL_ATTR, BIAS_ATTR, PYTORCH_KERNEL, \
28
- BIAS
29
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v2.tp_model import get_tp_model
30
- import model_compression_toolkit as mct
31
- from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v2 import __version__ as TPC_VERSION
32
-
33
- tp = mct.target_platform
34
-
35
-
36
- def get_pytorch_tpc() -> tp.TargetPlatformCapabilities:
37
- """
38
- get a Pytorch TargetPlatformCapabilities object with default operation sets to layers mapping.
39
-
40
- Returns: a Pytorch TargetPlatformCapabilities object for the given TargetPlatformModel.
41
- """
42
- imx500_tpc_tp_model = get_tp_model()
43
- return generate_pytorch_tpc(name='imx500_tpc_pytorch_tpc', tp_model=imx500_tpc_tp_model)
44
-
45
-
46
- def generate_pytorch_tpc(name: str, tp_model: tp.TargetPlatformModel):
47
- """
48
- Generates a TargetPlatformCapabilities object with default operation sets to layers mapping.
49
- Args:
50
- name: Name of the TargetPlatformModel.
51
- tp_model: TargetPlatformModel object.
52
- Returns: a TargetPlatformCapabilities object for the given TargetPlatformModel.
53
- """
54
-
55
- pytorch_tpc = tp.TargetPlatformCapabilities(tp_model,
56
- name=name,
57
- version=TPC_VERSION)
58
-
59
- # we provide attributes mapping that maps each layer type in the operations set
60
- # that has weights attributes with provided quantization config (in the tp model) to
61
- # its framework-specific attribute name.
62
- # note that a DefaultDict should be provided if not all the layer types in the
63
- # operation set are provided separately in the mapping.
64
- pytorch_linear_attr_mapping = {KERNEL_ATTR: DefaultDict(default_value=PYTORCH_KERNEL),
65
- BIAS_ATTR: DefaultDict(default_value=BIAS)}
66
-
67
- with pytorch_tpc:
68
- tp.OperationsSetToLayers("NoQuantization", [Identity,
69
- Dropout,
70
- Flatten,
71
- dropout,
72
- flatten,
73
- split,
74
- operator.getitem,
75
- reshape,
76
- unsqueeze,
77
- chunk,
78
- unbind,
79
- torch.Tensor.size,
80
- permute,
81
- transpose,
82
- equal,
83
- argmax,
84
- gather,
85
- topk,
86
- squeeze])
87
-
88
- tp.OperationsSetToLayers("Conv", [Conv2d, ConvTranspose2d],
89
- attr_mapping=pytorch_linear_attr_mapping)
90
- tp.OperationsSetToLayers("FullyConnected", [Linear],
91
- attr_mapping=pytorch_linear_attr_mapping)
92
- tp.OperationsSetToLayers("AnyReLU", [torch.relu,
93
- ReLU,
94
- ReLU6,
95
- LeakyReLU,
96
- relu,
97
- relu6,
98
- leaky_relu,
99
- tp.LayerFilterParams(Hardtanh, min_val=0),
100
- tp.LayerFilterParams(hardtanh, min_val=0)])
101
-
102
- tp.OperationsSetToLayers("Add", [operator.add, add])
103
- tp.OperationsSetToLayers("Sub", [operator.sub, sub])
104
- tp.OperationsSetToLayers("Mul", [operator.mul, mul])
105
- tp.OperationsSetToLayers("Div", [operator.truediv, div])
106
- tp.OperationsSetToLayers("PReLU", [PReLU, prelu])
107
- tp.OperationsSetToLayers("Swish", [SiLU, silu, Hardswish, hardswish])
108
- tp.OperationsSetToLayers("Sigmoid", [Sigmoid, sigmoid])
109
- tp.OperationsSetToLayers("Tanh", [Tanh, tanh])
110
-
111
- return pytorch_tpc
@@ -1,16 +0,0 @@
1
- # Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- # ==============================================================================
15
-
16
- __version__ = 'v2_lut'