mct-nightly 2.2.0.20240908.528__py3-none-any.whl → 2.2.0.20240909.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.20240908.528.dist-info → mct_nightly-2.2.0.20240909.453.dist-info}/METADATA +1 -1
- {mct_nightly-2.2.0.20240908.528.dist-info → mct_nightly-2.2.0.20240909.453.dist-info}/RECORD +11 -11
- model_compression_toolkit/__init__.py +1 -1
- model_compression_toolkit/gptq/pytorch/quantizer/quantization_builder.py +7 -7
- model_compression_toolkit/trainable_infrastructure/common/base_trainable_quantizer.py +8 -7
- model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/ste/symmetric_ste.py +7 -5
- model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/ste/uniform_ste.py +7 -6
- model_compression_toolkit/trainable_infrastructure/pytorch/base_pytorch_quantizer.py +8 -0
- {mct_nightly-2.2.0.20240908.528.dist-info → mct_nightly-2.2.0.20240909.453.dist-info}/LICENSE.md +0 -0
- {mct_nightly-2.2.0.20240908.528.dist-info → mct_nightly-2.2.0.20240909.453.dist-info}/WHEEL +0 -0
- {mct_nightly-2.2.0.20240908.528.dist-info → mct_nightly-2.2.0.20240909.453.dist-info}/top_level.txt +0 -0
{mct_nightly-2.2.0.20240908.528.dist-info → mct_nightly-2.2.0.20240909.453.dist-info}/RECORD
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
model_compression_toolkit/__init__.py,sha256=
|
1
|
+
model_compression_toolkit/__init__.py,sha256=msE8-6YmO3FQaiZRSwN96Pup9KiZoPuXlMDgqzD6fEI,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
|
@@ -375,7 +375,7 @@ model_compression_toolkit/gptq/pytorch/quantization_facade.py,sha256=TMus5LYJnTn
|
|
375
375
|
model_compression_toolkit/gptq/pytorch/quantizer/__init__.py,sha256=ZHNHo1yzye44m9_ht4UUZfTpK01RiVR3Tr74-vtnOGI,968
|
376
376
|
model_compression_toolkit/gptq/pytorch/quantizer/base_pytorch_gptq_quantizer.py,sha256=fKg-PNOhGBiL-4eySS9Fyw0GkA76Pq8jT_HbJuJ8iZU,4143
|
377
377
|
model_compression_toolkit/gptq/pytorch/quantizer/quant_utils.py,sha256=OocYYRqvl7rZ37QT0hTzfJnWGiNCPskg7cziTlR7TRk,3893
|
378
|
-
model_compression_toolkit/gptq/pytorch/quantizer/quantization_builder.py,sha256=
|
378
|
+
model_compression_toolkit/gptq/pytorch/quantizer/quantization_builder.py,sha256=5EyAzvlU01vLyXmMwY_8dNyb7GwYktXmnrvUON8n8WI,4696
|
379
379
|
model_compression_toolkit/gptq/pytorch/quantizer/regularization_factory.py,sha256=mDWZERLwtDzqWeJUwHMVyGdlS8wPLjJ3NvZiKBP6BNA,1959
|
380
380
|
model_compression_toolkit/gptq/pytorch/quantizer/soft_rounding/__init__.py,sha256=lNJ29DYxaLUPDstRDA1PGI5r9Fulq_hvrZMlhst1Z5g,697
|
381
381
|
model_compression_toolkit/gptq/pytorch/quantizer/soft_rounding/soft_quantizer_reg.py,sha256=oO7WgsAHMnWoXNm_gTKAAe-Nd79mGL_m677ai-ui424,4132
|
@@ -486,7 +486,7 @@ model_compression_toolkit/target_platform_capabilities/tpc_models/tflite_tpc/v1/
|
|
486
486
|
model_compression_toolkit/target_platform_capabilities/tpc_models/tflite_tpc/v1/tpc_pytorch.py,sha256=YVJJvqGPBdkKnug99p9bjqtbfecDXZKIB2iWVCe7RUY,5960
|
487
487
|
model_compression_toolkit/trainable_infrastructure/__init__.py,sha256=uewpvlPkH9mBFt8IxoAgIfz6iEcvWbOImm_fb6_BxD8,1543
|
488
488
|
model_compression_toolkit/trainable_infrastructure/common/__init__.py,sha256=huHoBUcKNB6BnY6YaUCcFvdyBtBI172ZoUD8ZYeNc6o,696
|
489
|
-
model_compression_toolkit/trainable_infrastructure/common/base_trainable_quantizer.py,sha256=
|
489
|
+
model_compression_toolkit/trainable_infrastructure/common/base_trainable_quantizer.py,sha256=IF50ASBUvVrOVqlJ1nHNxZxKXSuCanjhUX0YjMB-rRg,7946
|
490
490
|
model_compression_toolkit/trainable_infrastructure/common/constants.py,sha256=HN120boJxAnEXNrLSj-o_s-VX4o6C-1ap_KZ4840sd0,875
|
491
491
|
model_compression_toolkit/trainable_infrastructure/common/get_quantizer_config.py,sha256=Jxd4IjS_t0FwnA_S_WmZeVbh4VM6Da9ahKGPLp6ZhQo,6983
|
492
492
|
model_compression_toolkit/trainable_infrastructure/common/get_quantizers.py,sha256=KoX-6LJMsRzXy0i72ve4buJ32cGNQVHVLqHJxhv0lPQ,3428
|
@@ -500,7 +500,7 @@ model_compression_toolkit/trainable_infrastructure/keras/load_model.py,sha256=DJ
|
|
500
500
|
model_compression_toolkit/trainable_infrastructure/keras/quantize_wrapper.py,sha256=eVB5FSE3OmTLrhfLUcP2knwN1z2_unQLM-xFEGwdafA,5587
|
501
501
|
model_compression_toolkit/trainable_infrastructure/keras/quantizer_utils.py,sha256=MVwXNymmFRB2NXIBx4e2mdJ1RfoHxRPYRgjb1MQP5kY,1797
|
502
502
|
model_compression_toolkit/trainable_infrastructure/pytorch/__init__.py,sha256=huHoBUcKNB6BnY6YaUCcFvdyBtBI172ZoUD8ZYeNc6o,696
|
503
|
-
model_compression_toolkit/trainable_infrastructure/pytorch/base_pytorch_quantizer.py,sha256=
|
503
|
+
model_compression_toolkit/trainable_infrastructure/pytorch/base_pytorch_quantizer.py,sha256=lWc5EG3ptrP85n69EHGKFkIadnrKEBMKnB5YXQ5AmXo,2745
|
504
504
|
model_compression_toolkit/trainable_infrastructure/pytorch/quantizer_utils.py,sha256=1yOXKghUYfw2hmzbqTuNagIXBoM-wR2bP-ul66-mnDw,7767
|
505
505
|
model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/__init__.py,sha256=73CXhqqNTvDpsvlJXclrGJq-vsCUYCI64ILu1y2mtvw,1056
|
506
506
|
model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/base_activation_quantizer.py,sha256=X6E6mewWQot_aAkz3UxW5X0-Fjl_aMMjs3A-Af5eL6w,972
|
@@ -508,8 +508,8 @@ model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers
|
|
508
508
|
model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/lsq/symmetric_lsq.py,sha256=0UGoFHAR-RP9aFbAOILbM8kAG9OwUJJZ_g3Rz58SGlY,5462
|
509
509
|
model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/lsq/uniform_lsq.py,sha256=BPeunWrYNmbduZGXiZKy5t1ubYREX7QqWOXv2Dt85lk,5285
|
510
510
|
model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/ste/__init__.py,sha256=RAe8mgIr1V8dRIQtLf_dSG5zTUCKuQzxyybYx1dzEAs,697
|
511
|
-
model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/ste/symmetric_ste.py,sha256=
|
512
|
-
model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/ste/uniform_ste.py,sha256=
|
511
|
+
model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/ste/symmetric_ste.py,sha256=p11HY91muyovTXaKLEPQ48WOi8ge_Z1K7KdX9Y56mgw,5443
|
512
|
+
model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/ste/uniform_ste.py,sha256=8zjzP-dxF1FEQ-qnFcFhWpbndNeVtvaPL3uEPQpbdLk,5202
|
513
513
|
model_compression_toolkit/xquant/__init__.py,sha256=vdmr8sQw3jIBLF9ck7qrskPoXzDKtksHWlMOkU1JUnQ,1003
|
514
514
|
model_compression_toolkit/xquant/common/__init__.py,sha256=ycb1Xt7PtixY2Uabr94JGSwBMcct66O8ZMVf3Qa3ud8,719
|
515
515
|
model_compression_toolkit/xquant/common/constants.py,sha256=k-9LOEv1n_m8dV4chX0dNOTWyhhF7S00E0lkUxtO84E,1592
|
@@ -536,8 +536,8 @@ model_compression_toolkit/xquant/pytorch/model_analyzer.py,sha256=b93o800yVB3Z-i
|
|
536
536
|
model_compression_toolkit/xquant/pytorch/pytorch_report_utils.py,sha256=bOc-hFL3gdoSM1Th_S2N_-9JJSlPGpZCTx_QLJHS6lg,3388
|
537
537
|
model_compression_toolkit/xquant/pytorch/similarity_functions.py,sha256=CERxq5K8rqaiE-DlwhZBTUd9x69dtYJlkHOPLB54vm8,2354
|
538
538
|
model_compression_toolkit/xquant/pytorch/tensorboard_utils.py,sha256=mkoEktLFFHtEKzzFRn_jCnxjhJolK12TZ5AQeDHzUO8,9767
|
539
|
-
mct_nightly-2.2.0.
|
540
|
-
mct_nightly-2.2.0.
|
541
|
-
mct_nightly-2.2.0.
|
542
|
-
mct_nightly-2.2.0.
|
543
|
-
mct_nightly-2.2.0.
|
539
|
+
mct_nightly-2.2.0.20240909.453.dist-info/LICENSE.md,sha256=aYSSIb-5AFPeITTvXm1UAoe0uYBiMmSS8flvXaaFUks,10174
|
540
|
+
mct_nightly-2.2.0.20240909.453.dist-info/METADATA,sha256=smPztOdlwS0FQKktb9hXWTvuuliw7uO4689U-ondGtg,20813
|
541
|
+
mct_nightly-2.2.0.20240909.453.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
542
|
+
mct_nightly-2.2.0.20240909.453.dist-info/top_level.txt,sha256=gsYA8juk0Z-ZmQRKULkb3JLGdOdz8jW_cMRjisn9ga4,26
|
543
|
+
mct_nightly-2.2.0.20240909.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.20240909.000453"
|
@@ -25,8 +25,9 @@ from mct_quantizers.common.get_quantizers import get_inferable_quantizer_class
|
|
25
25
|
from mct_quantizers.pytorch.quantizers import BasePyTorchInferableQuantizer
|
26
26
|
|
27
27
|
from model_compression_toolkit.logger import Logger
|
28
|
+
from model_compression_toolkit.trainable_infrastructure import TrainingMethod, BasePytorchActivationTrainableQuantizer
|
28
29
|
from model_compression_toolkit.trainable_infrastructure.common.get_quantizer_config import \
|
29
|
-
get_trainable_quantizer_weights_config
|
30
|
+
get_trainable_quantizer_weights_config, get_trainable_quantizer_activation_config
|
30
31
|
from model_compression_toolkit.trainable_infrastructure.common.get_quantizers import \
|
31
32
|
get_trainable_quantizer_class
|
32
33
|
|
@@ -68,12 +69,11 @@ def quantization_builder(n: common.BaseNode,
|
|
68
69
|
|
69
70
|
quant_method = n.final_activation_quantization_cfg.activation_quantization_method
|
70
71
|
|
71
|
-
quantizer_class =
|
72
|
+
quantizer_class = get_trainable_quantizer_class(quant_target=QuantizationTarget.Activation,
|
73
|
+
quantizer_id=TrainingMethod.STE,
|
72
74
|
quant_method=quant_method,
|
73
|
-
quantizer_base_class=
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
activation_quantizers.append(quantizer_class(**kwargs))
|
75
|
+
quantizer_base_class=BasePytorchActivationTrainableQuantizer)
|
76
|
+
cfg = get_trainable_quantizer_activation_config(n, None)
|
77
|
+
activation_quantizers.append(quantizer_class(cfg, freeze_quant_params=True))
|
78
78
|
|
79
79
|
return weights_quantizers, activation_quantizers
|
@@ -14,18 +14,16 @@
|
|
14
14
|
# ==============================================================================
|
15
15
|
from abc import ABC, abstractmethod
|
16
16
|
from enum import Enum
|
17
|
-
from typing import Union, List, Any
|
18
17
|
from inspect import signature
|
19
|
-
|
20
|
-
from model_compression_toolkit.logger import Logger
|
18
|
+
from typing import Union, List, Any
|
21
19
|
|
22
20
|
from mct_quantizers.common.base_inferable_quantizer import BaseInferableQuantizer, \
|
23
21
|
QuantizationTarget
|
24
|
-
from model_compression_toolkit.trainable_infrastructure.common.trainable_quantizer_config import \
|
25
|
-
TrainableQuantizerActivationConfig, TrainableQuantizerWeightsConfig
|
26
22
|
from mct_quantizers.common.constants import QUANTIZATION_METHOD, \
|
27
23
|
QUANTIZATION_TARGET
|
28
|
-
|
24
|
+
from model_compression_toolkit.logger import Logger
|
25
|
+
from model_compression_toolkit.trainable_infrastructure.common.trainable_quantizer_config import \
|
26
|
+
TrainableQuantizerActivationConfig, TrainableQuantizerWeightsConfig
|
29
27
|
|
30
28
|
VAR = 'var'
|
31
29
|
GROUP = 'group'
|
@@ -43,12 +41,14 @@ class VariableGroup(Enum):
|
|
43
41
|
|
44
42
|
class BaseTrainableQuantizer(BaseInferableQuantizer, ABC):
|
45
43
|
def __init__(self,
|
46
|
-
quantization_config: Union[TrainableQuantizerActivationConfig, TrainableQuantizerWeightsConfig]
|
44
|
+
quantization_config: Union[TrainableQuantizerActivationConfig, TrainableQuantizerWeightsConfig],
|
45
|
+
freeze_quant_params: bool = False):
|
47
46
|
"""
|
48
47
|
This class is a base quantizer which validates the provided quantization config and defines an abstract function which any quantizer needs to implment.
|
49
48
|
|
50
49
|
Args:
|
51
50
|
quantization_config: quantizer config class contains all the information about the quantizer configuration.
|
51
|
+
freeze_quant_params: whether to freeze all learnable quantization parameters during training.
|
52
52
|
"""
|
53
53
|
|
54
54
|
# verify the quantizer class that inherits this class only has a config argument and key-word arguments
|
@@ -85,6 +85,7 @@ class BaseTrainableQuantizer(BaseInferableQuantizer, ABC):
|
|
85
85
|
f"Unrecognized 'QuantizationTarget': {static_quantization_target}.") # pragma: no cover
|
86
86
|
|
87
87
|
self.quantizer_parameters = {}
|
88
|
+
self.freeze_quant_params = freeze_quant_params
|
88
89
|
|
89
90
|
@classmethod
|
90
91
|
def get_sig(cls):
|
@@ -18,7 +18,8 @@ import numpy as np
|
|
18
18
|
import torch
|
19
19
|
from torch import nn
|
20
20
|
|
21
|
-
from mct_quantizers import mark_quantizer, QuantizationTarget, QuantizationMethod, PytorchQuantizationWrapper
|
21
|
+
from mct_quantizers import mark_quantizer, QuantizationTarget, QuantizationMethod, PytorchQuantizationWrapper, \
|
22
|
+
PytorchActivationQuantizationHolder
|
22
23
|
from mct_quantizers.pytorch.quantizers import ActivationPOTInferableQuantizer, ActivationSymmetricInferableQuantizer
|
23
24
|
from model_compression_toolkit import constants as C
|
24
25
|
from model_compression_toolkit.core.pytorch.utils import to_torch_tensor
|
@@ -39,14 +40,15 @@ class STESymmetricActivationTrainableQuantizer(BasePytorchActivationTrainableQua
|
|
39
40
|
Trainable constrained quantizer to quantize a layer activations.
|
40
41
|
"""
|
41
42
|
|
42
|
-
def __init__(self, quantization_config: TrainableQuantizerActivationConfig):
|
43
|
+
def __init__(self, quantization_config: TrainableQuantizerActivationConfig, freeze_quant_params: bool = False):
|
43
44
|
"""
|
44
45
|
Initialize a STESymmetricActivationTrainableQuantizer object with parameters to use for symmetric or power of two quantization.
|
45
46
|
|
46
47
|
Args:
|
47
48
|
quantization_config: trainable quantizer config class
|
49
|
+
freeze_quant_params: whether to freeze learnable quantization parameters
|
48
50
|
"""
|
49
|
-
super().__init__(quantization_config)
|
51
|
+
super().__init__(quantization_config, freeze_quant_params)
|
50
52
|
self.power_of_two = quantization_config.activation_quantization_method == QuantizationMethod.POWER_OF_TWO
|
51
53
|
self.sign = quantization_config.activation_quantization_params['is_signed']
|
52
54
|
np_threshold_values = quantization_config.activation_quantization_params[C.THRESHOLD]
|
@@ -56,7 +58,7 @@ class STESymmetricActivationTrainableQuantizer(BasePytorchActivationTrainableQua
|
|
56
58
|
def initialize_quantization(self,
|
57
59
|
tensor_shape: torch.Size,
|
58
60
|
name: str,
|
59
|
-
layer:
|
61
|
+
layer: PytorchActivationQuantizationHolder):
|
60
62
|
"""
|
61
63
|
Add quantizer parameters to the quantizer parameters dictionary
|
62
64
|
|
@@ -66,7 +68,7 @@ class STESymmetricActivationTrainableQuantizer(BasePytorchActivationTrainableQua
|
|
66
68
|
layer: Layer to quantize.
|
67
69
|
"""
|
68
70
|
layer.register_parameter(name, nn.Parameter(to_torch_tensor(self.threshold_tensor),
|
69
|
-
requires_grad=
|
71
|
+
requires_grad=not self.freeze_quant_params))
|
70
72
|
|
71
73
|
# save the quantizer added parameters for later calculations
|
72
74
|
self.add_quantizer_variable(THRESHOLD_TENSOR, layer.get_parameter(name), VariableGroup.QPARAMS)
|
model_compression_toolkit/trainable_infrastructure/pytorch/activation_quantizers/ste/uniform_ste.py
CHANGED
@@ -36,14 +36,15 @@ class STEUniformActivationTrainableQuantizer(BasePytorchActivationTrainableQuant
|
|
36
36
|
Trainable constrained quantizer to quantize a layer activations.
|
37
37
|
"""
|
38
38
|
|
39
|
-
def __init__(self, quantization_config: TrainableQuantizerActivationConfig):
|
39
|
+
def __init__(self, quantization_config: TrainableQuantizerActivationConfig, freeze_quant_params: bool = False):
|
40
40
|
"""
|
41
41
|
Initialize a STEUniformActivationTrainableQuantizer object with parameters to use for uniform quantization.
|
42
42
|
|
43
43
|
Args:
|
44
|
-
quantization_config: trainable quantizer config class
|
44
|
+
quantization_config: trainable quantizer config class.
|
45
|
+
freeze_quant_params: whether to freeze learnable quantization parameters.
|
45
46
|
"""
|
46
|
-
super().__init__(quantization_config)
|
47
|
+
super().__init__(quantization_config, freeze_quant_params)
|
47
48
|
|
48
49
|
np_min_range = quantization_config.activation_quantization_params[C.RANGE_MIN]
|
49
50
|
np_max_range = quantization_config.activation_quantization_params[C.RANGE_MAX]
|
@@ -56,7 +57,7 @@ class STEUniformActivationTrainableQuantizer(BasePytorchActivationTrainableQuant
|
|
56
57
|
name: str,
|
57
58
|
layer: PytorchQuantizationWrapper):
|
58
59
|
"""
|
59
|
-
Add quantizer parameters to the quantizer parameters dictionary
|
60
|
+
Add quantizer parameters to the quantizer parameters dictionary.
|
60
61
|
|
61
62
|
Args:
|
62
63
|
tensor_shape: tensor shape of the quantized tensor.
|
@@ -64,9 +65,9 @@ class STEUniformActivationTrainableQuantizer(BasePytorchActivationTrainableQuant
|
|
64
65
|
layer: Layer to quantize.
|
65
66
|
"""
|
66
67
|
layer.register_parameter(name+"_"+FQ_MIN, nn.Parameter(to_torch_tensor(self.min_range_tensor),
|
67
|
-
requires_grad=
|
68
|
+
requires_grad=not self.freeze_quant_params))
|
68
69
|
layer.register_parameter(name+"_"+FQ_MAX, nn.Parameter(to_torch_tensor(self.max_range_tensor),
|
69
|
-
requires_grad=
|
70
|
+
requires_grad=not self.freeze_quant_params))
|
70
71
|
|
71
72
|
# Save the quantizer parameters for later calculations
|
72
73
|
self.add_quantizer_variable(FQ_MIN, layer.get_parameter(name+"_"+FQ_MIN), VariableGroup.QPARAMS)
|
@@ -46,6 +46,14 @@ if FOUND_TORCH:
|
|
46
46
|
quantizer_parameter, parameter_group = parameter_dict[VAR], parameter_dict[GROUP]
|
47
47
|
if quantizer_parameter.requires_grad and parameter_group == group:
|
48
48
|
quantizer_trainable.append(quantizer_parameter)
|
49
|
+
|
50
|
+
# sanity check to catch inconsistent initialization
|
51
|
+
if self.freeze_quant_params and group == VariableGroup.QPARAMS and quantizer_trainable:
|
52
|
+
Logger.critical(
|
53
|
+
'Found trainable quantization params despite self.freeze_quant_params=True. '
|
54
|
+
'Quantization parameters were probably not initialized correctly in the Quantizer.'
|
55
|
+
) # pragma: no cover
|
56
|
+
|
49
57
|
return quantizer_trainable
|
50
58
|
|
51
59
|
else:
|
{mct_nightly-2.2.0.20240908.528.dist-info → mct_nightly-2.2.0.20240909.453.dist-info}/LICENSE.md
RENAMED
File without changes
|
File without changes
|
{mct_nightly-2.2.0.20240908.528.dist-info → mct_nightly-2.2.0.20240909.453.dist-info}/top_level.txt
RENAMED
File without changes
|