mct-nightly 2.1.0.20240608.434__py3-none-any.whl → 2.1.0.20240610.442__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.1.0.20240608.434.dist-info → mct_nightly-2.1.0.20240610.442.dist-info}/METADATA +1 -1
- {mct_nightly-2.1.0.20240608.434.dist-info → mct_nightly-2.1.0.20240610.442.dist-info}/RECORD +26 -18
- model_compression_toolkit/__init__.py +1 -1
- model_compression_toolkit/core/common/graph/base_node.py +1 -4
- model_compression_toolkit/core/common/quantization/node_quantization_config.py +10 -6
- model_compression_toolkit/core/common/quantization/quantization_params_generation/lut_kmeans_params.py +15 -7
- model_compression_toolkit/core/common/quantization/quantization_params_generation/power_of_two_selection.py +30 -14
- model_compression_toolkit/core/common/quantization/quantization_params_generation/qparams_computation.py +8 -7
- model_compression_toolkit/core/common/quantization/quantization_params_generation/qparams_search.py +108 -87
- model_compression_toolkit/core/common/quantization/quantization_params_generation/qparams_weights_computation.py +15 -13
- model_compression_toolkit/core/common/quantization/quantization_params_generation/symmetric_selection.py +29 -14
- model_compression_toolkit/core/common/quantization/quantization_params_generation/uniform_selection.py +40 -14
- model_compression_toolkit/core/keras/reader/node_builder.py +3 -3
- model_compression_toolkit/core/pytorch/back2framework/pytorch_model_builder.py +25 -23
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/target_platform_capabilities.py +10 -0
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/__init__.py +16 -0
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tp_model.py +222 -0
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tpc_keras.py +131 -0
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3/tpc_pytorch.py +111 -0
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/__init__.py +16 -0
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tp_model.py +219 -0
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tpc_keras.py +131 -0
- model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tpc_pytorch.py +110 -0
- {mct_nightly-2.1.0.20240608.434.dist-info → mct_nightly-2.1.0.20240610.442.dist-info}/LICENSE.md +0 -0
- {mct_nightly-2.1.0.20240608.434.dist-info → mct_nightly-2.1.0.20240610.442.dist-info}/WHEEL +0 -0
- {mct_nightly-2.1.0.20240608.434.dist-info → mct_nightly-2.1.0.20240610.442.dist-info}/top_level.txt +0 -0
model_compression_toolkit/target_platform_capabilities/tpc_models/imx500_tpc/v3_lut/tpc_pytorch.py
ADDED
@@ -0,0 +1,110 @@
|
|
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, PYTORCH_KERNEL, BIAS_ATTR, \
|
28
|
+
BIAS
|
29
|
+
from model_compression_toolkit.target_platform_capabilities.tpc_models.imx500_tpc.v3_lut.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.v3_lut 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
|
+
Returns: a Pytorch TargetPlatformCapabilities object for the given TargetPlatformModel.
|
40
|
+
"""
|
41
|
+
imx500_tpc_tp_model = get_tp_model()
|
42
|
+
return generate_pytorch_tpc(name='imx500_tpc_pytorch_tpc', tp_model=imx500_tpc_tp_model)
|
43
|
+
|
44
|
+
|
45
|
+
def generate_pytorch_tpc(name: str, tp_model: tp.TargetPlatformModel):
|
46
|
+
"""
|
47
|
+
Generates a TargetPlatformCapabilities object with default operation sets to layers mapping.
|
48
|
+
Args:
|
49
|
+
name: Name of the TargetPlatformModel.
|
50
|
+
tp_model: TargetPlatformModel object.
|
51
|
+
Returns: a TargetPlatformCapabilities object for the given TargetPlatformModel.
|
52
|
+
"""
|
53
|
+
|
54
|
+
pytorch_tpc = tp.TargetPlatformCapabilities(tp_model,
|
55
|
+
name=name,
|
56
|
+
version=TPC_VERSION)
|
57
|
+
|
58
|
+
# we provide attributes mapping that maps each layer type in the operations set
|
59
|
+
# that has weights attributes with provided quantization config (in the tp model) to
|
60
|
+
# its framework-specific attribute name.
|
61
|
+
# note that a DefaultDict should be provided if not all the layer types in the
|
62
|
+
# operation set are provided separately in the mapping.
|
63
|
+
pytorch_linear_attr_mapping = {KERNEL_ATTR: DefaultDict(default_value=PYTORCH_KERNEL),
|
64
|
+
BIAS_ATTR: DefaultDict(default_value=BIAS)}
|
65
|
+
|
66
|
+
with pytorch_tpc:
|
67
|
+
tp.OperationsSetToLayers("NoQuantization", [Identity,
|
68
|
+
Dropout,
|
69
|
+
Flatten,
|
70
|
+
dropout,
|
71
|
+
flatten,
|
72
|
+
split,
|
73
|
+
operator.getitem,
|
74
|
+
reshape,
|
75
|
+
unsqueeze,
|
76
|
+
chunk,
|
77
|
+
unbind,
|
78
|
+
torch.Tensor.size,
|
79
|
+
permute,
|
80
|
+
transpose,
|
81
|
+
equal,
|
82
|
+
argmax,
|
83
|
+
gather,
|
84
|
+
topk,
|
85
|
+
squeeze])
|
86
|
+
|
87
|
+
tp.OperationsSetToLayers("Conv", [Conv2d, ConvTranspose2d],
|
88
|
+
attr_mapping=pytorch_linear_attr_mapping)
|
89
|
+
tp.OperationsSetToLayers("FullyConnected", [Linear],
|
90
|
+
attr_mapping=pytorch_linear_attr_mapping)
|
91
|
+
tp.OperationsSetToLayers("AnyReLU", [torch.relu,
|
92
|
+
ReLU,
|
93
|
+
ReLU6,
|
94
|
+
LeakyReLU,
|
95
|
+
relu,
|
96
|
+
relu6,
|
97
|
+
leaky_relu,
|
98
|
+
tp.LayerFilterParams(Hardtanh, min_val=0),
|
99
|
+
tp.LayerFilterParams(hardtanh, min_val=0)])
|
100
|
+
|
101
|
+
tp.OperationsSetToLayers("Add", [operator.add, add])
|
102
|
+
tp.OperationsSetToLayers("Sub", [operator.sub, sub])
|
103
|
+
tp.OperationsSetToLayers("Mul", [operator.mul, mul])
|
104
|
+
tp.OperationsSetToLayers("Div", [operator.truediv, div])
|
105
|
+
tp.OperationsSetToLayers("PReLU", [PReLU, prelu])
|
106
|
+
tp.OperationsSetToLayers("Swish", [SiLU, silu, Hardswish, hardswish])
|
107
|
+
tp.OperationsSetToLayers("Sigmoid", [Sigmoid, sigmoid])
|
108
|
+
tp.OperationsSetToLayers("Tanh", [Tanh, tanh])
|
109
|
+
|
110
|
+
return pytorch_tpc
|
{mct_nightly-2.1.0.20240608.434.dist-info → mct_nightly-2.1.0.20240610.442.dist-info}/LICENSE.md
RENAMED
File without changes
|
File without changes
|
{mct_nightly-2.1.0.20240608.434.dist-info → mct_nightly-2.1.0.20240610.442.dist-info}/top_level.txt
RENAMED
File without changes
|