tico 0.1.0.dev250922__py3-none-any.whl → 0.1.0.dev250923__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.

Potentially problematic release.


This version of tico might be problematic. Click here for more details.

tico/__init__.py CHANGED
@@ -29,7 +29,7 @@ __all__ = [
29
29
  ]
30
30
 
31
31
  # THIS LINE IS AUTOMATICALLY GENERATED BY setup.py
32
- __version__ = "0.1.0.dev250922"
32
+ __version__ = "0.1.0.dev250923"
33
33
 
34
34
  MINIMUM_SUPPORTED_VERSION = "2.5.0"
35
35
  SECURE_TORCH_VERSION = "2.6.0"
@@ -27,6 +27,7 @@ from tico.experimental.quantization.algorithm.gptq.utils import (
27
27
  )
28
28
  from tico.experimental.quantization.config.gptq import GPTQConfig
29
29
  from tico.experimental.quantization.quantizer import BaseQuantizer
30
+ from tico.experimental.quantization.quantizer_registry import register_quantizer
30
31
 
31
32
 
32
33
  class StopForward(Exception):
@@ -35,6 +36,7 @@ class StopForward(Exception):
35
36
  pass
36
37
 
37
38
 
39
+ @register_quantizer(GPTQConfig)
38
40
  class GPTQQuantizer(BaseQuantizer):
39
41
  """
40
42
  Quantizer for applying the GPTQ algorithm (typically for weight quantization).
@@ -22,9 +22,12 @@ from tico.experimental.quantization.algorithm.pt2e.annotation.annotator import (
22
22
  get_asymmetric_quantization_config,
23
23
  PT2EAnnotator,
24
24
  )
25
+ from tico.experimental.quantization.config.pt2e import PT2EConfig
25
26
  from tico.experimental.quantization.quantizer import BaseQuantizer
27
+ from tico.experimental.quantization.quantizer_registry import register_quantizer
26
28
 
27
29
 
30
+ @register_quantizer(PT2EConfig)
28
31
  class PT2EQuantizer(BaseQuantizer):
29
32
  """
30
33
  Quantizer for applying pytorch 2.0 export quantization (typically for activation quantization).
@@ -25,8 +25,10 @@ from tico.experimental.quantization.algorithm.smoothquant.smooth_quant import (
25
25
  )
26
26
  from tico.experimental.quantization.config.smoothquant import SmoothQuantConfig
27
27
  from tico.experimental.quantization.quantizer import BaseQuantizer
28
+ from tico.experimental.quantization.quantizer_registry import register_quantizer
28
29
 
29
30
 
31
+ @register_quantizer(SmoothQuantConfig)
30
32
  class SmoothQuantQuantizer(BaseQuantizer):
31
33
  """
32
34
  Quantizer for applying the SmoothQuant algorithm
@@ -38,4 +38,4 @@ class SmoothQuantConfig(BaseConfig):
38
38
 
39
39
  @property
40
40
  def name(self) -> str:
41
- return "smooth_quant"
41
+ return "smoothquant"
@@ -13,25 +13,17 @@
13
13
  # limitations under the License.
14
14
 
15
15
  import copy
16
- from typing import Any, Dict, Optional, Type
16
+ from typing import Any, Dict, Optional
17
17
 
18
18
  import torch
19
19
 
20
20
  from tico.experimental.quantization.algorithm.gptq.quantizer import GPTQQuantizer
21
21
  from tico.experimental.quantization.algorithm.pt2e.quantizer import PT2EQuantizer
22
- from tico.experimental.quantization.algorithm.smoothquant.quantizer import (
23
- SmoothQuantQuantizer,
24
- )
25
22
  from tico.experimental.quantization.config.base import BaseConfig
26
23
  from tico.experimental.quantization.quantizer import BaseQuantizer
24
+ from tico.experimental.quantization.quantizer_registry import get_quantizer
27
25
 
28
26
 
29
- config_to_quantizer: Dict[str, Type[BaseQuantizer]] = {
30
- "pt2e": PT2EQuantizer,
31
- "gptq": GPTQQuantizer,
32
- "smooth_quant": SmoothQuantQuantizer,
33
- }
34
-
35
27
  QUANTIZER_ATTRIBUTE_NAME = "tico_quantizer"
36
28
 
37
29
 
@@ -61,14 +53,15 @@ def prepare(
61
53
  """
62
54
  if hasattr(model, QUANTIZER_ATTRIBUTE_NAME):
63
55
  raise RuntimeError("prepare() already has been called.")
64
- if quant_config.name == "pt2e" and inplace:
56
+ quantizer = get_quantizer(quant_config)
57
+
58
+ if isinstance(quantizer, PT2EQuantizer) and inplace:
65
59
  raise RuntimeError(
66
60
  "In-place is not supported for PT2E quantization due to limitation in the underlying Torch APIs. Please set 'inplace=False' to proceed."
67
61
  )
68
62
 
69
63
  model = model if inplace else copy.deepcopy(model)
70
64
 
71
- quantizer = config_to_quantizer[quant_config.name](quant_config)
72
65
  model = quantizer.prepare(model, args, kwargs)
73
66
  setattr(model, QUANTIZER_ATTRIBUTE_NAME, quantizer)
74
67
 
@@ -0,0 +1,72 @@
1
+ # Copyright (c) 2025 Samsung Electronics Co., Ltd. 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 importlib
16
+ from typing import Dict, Optional, Type, TypeVar
17
+
18
+ from tico.experimental.quantization.config.base import BaseConfig
19
+ from tico.experimental.quantization.quantizer import BaseQuantizer
20
+
21
+ TQ = TypeVar("TQ", bound=BaseQuantizer)
22
+
23
+ # Mapping: Config type -> Quantizer type
24
+ _REGISTRY: Dict[Type[BaseConfig], Type[BaseQuantizer]] = {}
25
+
26
+
27
+ def register_quantizer(config_cls: Type[BaseConfig]):
28
+ """
29
+ Decorator to register a quantizer for a given config class.
30
+ Usage:
31
+ @register_quantizer(GPTQConfig)
32
+ class GPTQQuantizer(BaseQuantizer): ...
33
+ """
34
+
35
+ def wrapper(quantizer_cls: Type[TQ]) -> Type[TQ]:
36
+ _REGISTRY[config_cls] = quantizer_cls
37
+ return quantizer_cls
38
+
39
+ return wrapper
40
+
41
+
42
+ def _lookup(cfg: BaseConfig) -> Optional[Type[BaseQuantizer]]:
43
+ """Return a quantizer class only if the exact config type is registered."""
44
+ return _REGISTRY.get(type(cfg))
45
+
46
+
47
+ def get_quantizer(cfg: BaseConfig) -> BaseQuantizer:
48
+ """Factory to return a quantizer instance for the given config."""
49
+ qcls = _lookup(cfg)
50
+ if qcls is not None:
51
+ return qcls(cfg)
52
+
53
+ # Lazy import by naming convention
54
+ name = getattr(cfg, "name", None)
55
+ if name:
56
+ try:
57
+ importlib.import_module(
58
+ f"tico.experimental.quantization.algorithm.{name}.quantizer"
59
+ )
60
+ except Exception as e:
61
+ raise RuntimeError(
62
+ f"Failed to import quantizer module for config name='{name}': {e}"
63
+ )
64
+
65
+ qcls = _lookup(cfg)
66
+ if qcls is not None:
67
+ return qcls(cfg)
68
+
69
+ raise RuntimeError(
70
+ f"No quantizer registered for config type {type(cfg).__name__} "
71
+ f"(name='{getattr(cfg,'name',None)}')."
72
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tico
3
- Version: 0.1.0.dev250922
3
+ Version: 0.1.0.dev250923
4
4
  Summary: Convert exported Torch module to circle
5
5
  Home-page: UNKNOWN
6
6
  License: UNKNOWN
@@ -1,4 +1,4 @@
1
- tico/__init__.py,sha256=aXzPnAgp_3hFd-ia92oDhfjfZ1NABlYkgUlEbFs5Pb0,1883
1
+ tico/__init__.py,sha256=SQIp1AUtHO6svZTLOBdHKzr7ss9Z3l9yh8cyySsGZOo,1883
2
2
  tico/pt2_to_circle.py,sha256=gu3MD4Iqc0zMZcCZ2IT8oGbyj21CTSbT3Rgd9s2B_9A,2767
3
3
  tico/config/__init__.py,sha256=xZzCXjZ84qE-CsBi-dfaL05bqpQ3stKKfTXhnrJRyVs,142
4
4
  tico/config/base.py,sha256=q5xMqGxTUZs4mFqt5c7i_y9U00fYgdMGl9nUqIVMlCo,1248
@@ -6,16 +6,17 @@ tico/config/factory.py,sha256=il0zqB6Lm5NX2LnG-TUhmiP9vVeZ_3TucJMorVZIodY,1324
6
6
  tico/config/v1.py,sha256=lEyKemeKGrJ0bA5w-LPkMWVlnAiJRDm9mM48TJle-e4,1296
7
7
  tico/experimental/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
8
8
  tico/experimental/quantization/__init__.py,sha256=IaJPZegVJp0P3luutBo907Kp5sOJensE1Mm-XBG_jBs,122
9
- tico/experimental/quantization/public_interface.py,sha256=y-iwaeuedBvHwTh5hflQg4u2ZCdqf46IlTl9ntHq8pU,4425
9
+ tico/experimental/quantization/public_interface.py,sha256=TGo3bTapwLA8KpsoEwBhuzI0LQUO6y3-sUM1VZvkLo8,4220
10
10
  tico/experimental/quantization/quantizer.py,sha256=pDTQGzR-BcQJeGZ7O4cXRQdCme4q_POpxHetwnv0bYg,2370
11
+ tico/experimental/quantization/quantizer_registry.py,sha256=7wm2JcuPRribu7c8dCSZeYVcVqWQO1S-tHoinDDt11s,2345
11
12
  tico/experimental/quantization/algorithm/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
12
13
  tico/experimental/quantization/algorithm/gptq/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
13
14
  tico/experimental/quantization/algorithm/gptq/gptq.py,sha256=Qn9b_2ki7B64DcVEY25NMkww3PdZ5EqYQQXfYhNDQ6I,5555
14
15
  tico/experimental/quantization/algorithm/gptq/quant.py,sha256=Rl4wAOCmlE0U09BtNCDbccaSNohRHCNLwFi3zCqZfNo,5127
15
- tico/experimental/quantization/algorithm/gptq/quantizer.py,sha256=ZKeQQWm6eMUyRgntQxVR-QVjxJOc2pW4Dc_mrEPZA64,11686
16
+ tico/experimental/quantization/algorithm/gptq/quantizer.py,sha256=CDAo7M5Xi8Oa2EjzNtCb9i6IWwpkxWzfP2fe8_VTM8M,11799
16
17
  tico/experimental/quantization/algorithm/gptq/utils.py,sha256=leGKayf-xbSjVwwAGTA5RsxUKrhDiklOQdlsLifjdrs,1811
17
18
  tico/experimental/quantization/algorithm/pt2e/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
18
- tico/experimental/quantization/algorithm/pt2e/quantizer.py,sha256=mdTvsG87bo8fu0GaWqSM8iBCs-4f4EfUlVtk-Ko6M34,2546
19
+ tico/experimental/quantization/algorithm/pt2e/quantizer.py,sha256=PXfCQWCDYjMHTmEA6txHKh5miwruEZwDGsgjPYFBB9o,2725
19
20
  tico/experimental/quantization/algorithm/pt2e/utils.py,sha256=URjTGgsnDdhUC2Nr0-YJ9GWbVOKmjElfLr83Y8eCz-M,4806
20
21
  tico/experimental/quantization/algorithm/pt2e/annotation/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
21
22
  tico/experimental/quantization/algorithm/pt2e/annotation/annotator.py,sha256=lFfblxglPxcN2IcrjAVYq7GOECIAQ4rr7M4euPp3yWc,7551
@@ -37,13 +38,13 @@ tico/experimental/quantization/algorithm/pt2e/transformation/__init__.py,sha256=
37
38
  tico/experimental/quantization/algorithm/pt2e/transformation/convert_scalars_to_attrs.py,sha256=Idtoya2RcGKlgUJgC9WqNz0jH3gf6ViuPmsD9ySHbls,2253
38
39
  tico/experimental/quantization/algorithm/smoothquant/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
39
40
  tico/experimental/quantization/algorithm/smoothquant/observer.py,sha256=OWBKQ3ox6PqeqgevxOjpXvb7uApoqE4YbUBelGhVSN8,3435
40
- tico/experimental/quantization/algorithm/smoothquant/quantizer.py,sha256=14-QrKAW-Rw6pIbbNaD5eORcH2fqi40-TNFGaWVakIg,3649
41
+ tico/experimental/quantization/algorithm/smoothquant/quantizer.py,sha256=VHc-_23VZWKCKZlcZvG5ESRKALgH4zU_Q9Tr-EEW4mk,3769
41
42
  tico/experimental/quantization/algorithm/smoothquant/smooth_quant.py,sha256=fxCy4m-BsSjraciSVPFlPhgsOT46RjrOgczQGb7B9TA,11561
42
43
  tico/experimental/quantization/config/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
43
44
  tico/experimental/quantization/config/base.py,sha256=xg_HCDSuMgYvMd6ENZe4Sm2SYJgMaCBj4cmqaz_lhAs,816
44
45
  tico/experimental/quantization/config/gptq.py,sha256=IUIEz5bLhsTXqoBCE1rfPec99zsRjwgpDbPW5YJqOPg,973
45
46
  tico/experimental/quantization/config/pt2e.py,sha256=9HCrraTGGZeKEN9puKV-ODi7ncV2Wjc3oe_JCO1D_Rs,850
46
- tico/experimental/quantization/config/smoothquant.py,sha256=fcyhu3YlOTM7fDW9lGTXh-uJOUD6CeykZj7AMCNVbak,1415
47
+ tico/experimental/quantization/config/smoothquant.py,sha256=b92dz4-MiBbkaLzXb47bVoO29d2P416woFQUZ1wpO_s,1414
47
48
  tico/experimental/quantization/evaluation/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
48
49
  tico/experimental/quantization/evaluation/backend.py,sha256=CZL9rZOA0t8cH7PHp6u9l7dGqWNvTj9bKOvwo0PVul0,692
49
50
  tico/experimental/quantization/evaluation/evaluate.py,sha256=kfa_GvFaX6DoSTAmuCImMJqF2jgqtnor5UpC7wVmGPI,7877
@@ -259,9 +260,9 @@ tico/utils/mx/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
259
260
  tico/utils/mx/elemwise_ops.py,sha256=V6glyAHsVR1joqpsgnNytatCD_ew92xNWZ19UFDoMTA,10281
260
261
  tico/utils/mx/formats.py,sha256=uzNWyu-1onUlwQfX5cZ6fZSUfHMRqorper7_T1k3jfk,3404
261
262
  tico/utils/mx/mx_ops.py,sha256=RcfUTYVi-wilGB2sC35OeARdwDqnixv7dG5iyZ-fQT8,8555
262
- tico-0.1.0.dev250922.dist-info/LICENSE,sha256=kp4JLII7bzRhPb0CPD5XTDZMh22BQ7h3k3B7t8TiSbw,12644
263
- tico-0.1.0.dev250922.dist-info/METADATA,sha256=2JnBgGh089dLyvlk3CyDQyTraHh_vDRRcPZla7pmuus,8450
264
- tico-0.1.0.dev250922.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
265
- tico-0.1.0.dev250922.dist-info/entry_points.txt,sha256=kBKYSS_IYrSXmUYevmmepqIVPScq5vF8ulQRu3I_Zf0,59
266
- tico-0.1.0.dev250922.dist-info/top_level.txt,sha256=oqs7UPoNSKZEwqsX8B-KAWdQwfAa7i60pbxW_Jk7P3w,5
267
- tico-0.1.0.dev250922.dist-info/RECORD,,
263
+ tico-0.1.0.dev250923.dist-info/LICENSE,sha256=kp4JLII7bzRhPb0CPD5XTDZMh22BQ7h3k3B7t8TiSbw,12644
264
+ tico-0.1.0.dev250923.dist-info/METADATA,sha256=YFowPhlSZB_-sCJe9E7tmXhQdMo0EWQ-H9fPL57i6SQ,8450
265
+ tico-0.1.0.dev250923.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
266
+ tico-0.1.0.dev250923.dist-info/entry_points.txt,sha256=kBKYSS_IYrSXmUYevmmepqIVPScq5vF8ulQRu3I_Zf0,59
267
+ tico-0.1.0.dev250923.dist-info/top_level.txt,sha256=oqs7UPoNSKZEwqsX8B-KAWdQwfAa7i60pbxW_Jk7P3w,5
268
+ tico-0.1.0.dev250923.dist-info/RECORD,,