tico 0.1.0.dev250526__py3-none-any.whl → 0.1.0.dev250528__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.
tico/__init__.py CHANGED
@@ -22,7 +22,7 @@ from tico.config import CompileConfigV1, get_default_config
22
22
  from tico.utils.convert import convert, convert_from_exported_program, convert_from_pt2
23
23
 
24
24
  # THIS LINE IS AUTOMATICALLY GENERATED BY setup.py
25
- __version__ = "0.1.0.dev250526"
25
+ __version__ = "0.1.0.dev250528"
26
26
 
27
27
 
28
28
  if Version(torch.__version__) < Version("2.5.0"):
@@ -23,6 +23,7 @@ from tico.serialize.quant_param import QPARAM_KEY, QuantParam, to_qparam_dtype
23
23
  from tico.utils import logging
24
24
  from tico.utils.passes import PassBase, PassResult
25
25
  from tico.utils.trace_decorators import trace_graph_diff_on_pass
26
+ from tico.utils.utils import get_quant_dtype
26
27
  from tico.utils.validate_args_kwargs import (
27
28
  DequantizePerTensorArgs,
28
29
  QuantizePerTensorArgs,
@@ -81,8 +82,7 @@ class FoldQuantOps(PassBase):
81
82
  qparam = QuantParam()
82
83
  qparam.scale = [q_args.scale]
83
84
  qparam.zero_point = [q_args.zero_p]
84
- assert "val" in q.meta and hasattr(q.meta["val"], "dtype")
85
- qparam.dtype = to_qparam_dtype(q.meta["val"].dtype)
85
+ qparam.dtype = get_quant_dtype(q_args.quant_min, q_args.quant_max)
86
86
  op.meta[QPARAM_KEY] = qparam
87
87
 
88
88
  dq.replace_all_uses_with(op, propagate_meta=False)
@@ -116,12 +116,12 @@ class RemoveWeightDequantOp(PassBase):
116
116
  dq.target
117
117
  == torch.ops.quantized_decomposed.dequantize_per_channel.default
118
118
  ):
119
- dq_args = DequantizePerChannelArgs(*dq.args, *dq.kwargs)
119
+ dq_args = DequantizePerChannelArgs(*dq.args, **dq.kwargs)
120
120
  elif (
121
121
  dq.target
122
122
  == torch.ops.quantized_decomposed.dequantize_per_tensor.default
123
123
  ):
124
- dq_args = DequantizePerTensorArgs(*dq.args, *dq.kwargs)
124
+ dq_args = DequantizePerTensorArgs(*dq.args, **dq.kwargs)
125
125
  else:
126
126
  raise RuntimeError(f"Invalid DQ target: {dq.target}")
127
127
 
@@ -29,6 +29,10 @@ from tico.utils.validate_args_kwargs import FakeQuantizePerChannelArgs
29
29
 
30
30
 
31
31
  def get_quant_type(min: int, max: int) -> torch.dtype:
32
+ if min == 0 and max == 15:
33
+ # torch can't represent "uint4".
34
+ # Let's set torch.uint8 and infer dtype with quant_min/quant_max instead.
35
+ return torch.uint8
32
36
  if min == 0 and max == 255:
33
37
  return torch.uint8
34
38
  if min == -32768 and max == 32767:
@@ -36,7 +40,7 @@ def get_quant_type(min: int, max: int) -> torch.dtype:
36
40
  if min == -32767 and max == 32767:
37
41
  return torch.int16
38
42
 
39
- raise RuntimeError("Not supported min/max values")
43
+ raise RuntimeError(f"Not supported min/max values: {min}/{max}")
40
44
 
41
45
 
42
46
  @trace_graph_diff_on_pass
@@ -39,6 +39,10 @@ from tico.utils.validate_args_kwargs import FakeQuantizePerTensorTQParamArgs
39
39
 
40
40
 
41
41
  def get_quant_type(min: int, max: int) -> torch.dtype:
42
+ if min == 0 and max == 15:
43
+ # torch can't represent "uint4".
44
+ # Let's set torch.uint8 and infer dtype with quant_min/quant_max instead.
45
+ return torch.uint8
42
46
  if min == 0 and max == 255:
43
47
  return torch.uint8
44
48
  if min == -32768 and max == 32767:
@@ -98,7 +102,7 @@ def get_constant_from_tensor(
98
102
  lifted_tensor_constants = ep.graph_signature.inputs_to_lifted_tensor_constants
99
103
  assert lifted_tensor.name in lifted_tensor_constants
100
104
  tensor_name = lifted_tensor_constants[lifted_tensor.name]
101
- value = ep.constants[tensor_name].cpu().detach().numpy()
105
+ value = ep.constants[tensor_name].item()
102
106
  return value
103
107
  if node.target.__name__ in ["detach.default", "detach_.default"]:
104
108
  assert len(node.args) == 1
@@ -0,0 +1,53 @@
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
+ from typing import Dict, List, TYPE_CHECKING
16
+
17
+ if TYPE_CHECKING:
18
+ import torch._ops
19
+ import torch.fx
20
+ import torch
21
+ from circle_schema import circle
22
+
23
+ from tico.serialize.circle_graph import CircleSubgraph
24
+ from tico.serialize.operators.hashable_opcode import OpCode
25
+ from tico.serialize.operators.node_visitor import NodeVisitor, register_node_visitor
26
+ from tico.serialize.operators.utils import create_builtin_operator, get_op_index
27
+ from tico.utils.validate_args_kwargs import AbsArgs
28
+
29
+
30
+ @register_node_visitor
31
+ class AbsVisitor(NodeVisitor):
32
+ target: List[torch._ops.OpOverload] = [torch.ops.aten.abs.default]
33
+
34
+ def __init__(self, op_codes: Dict[OpCode, int], graph: CircleSubgraph):
35
+ super().__init__(op_codes, graph)
36
+
37
+ def define_node(
38
+ self,
39
+ node: torch.fx.Node,
40
+ ) -> circle.Operator.OperatorT:
41
+ op_index = get_op_index(
42
+ circle.BuiltinOperator.BuiltinOperator.ABS, self._op_codes
43
+ )
44
+
45
+ args = AbsArgs(*node.args, **node.kwargs) # type: ignore[arg-type]
46
+ input = args.input
47
+
48
+ inputs = [input]
49
+ outputs = [node]
50
+
51
+ operator = create_builtin_operator(self.graph, op_index, inputs, outputs)
52
+
53
+ return operator
tico/utils/utils.py CHANGED
@@ -312,3 +312,32 @@ def quant_min_max(dtype: str):
312
312
  return (-32768, 32767)
313
313
  else:
314
314
  raise NotImplementedError(f"NYI dtype: {dtype}")
315
+
316
+
317
+ def get_quant_dtype(qmin: int, qmax: int):
318
+ """
319
+ Returns the string representation of the quantized data type based on qmin and qmax.
320
+
321
+ Args:
322
+ qmin (int): Minimum quantized value.
323
+ qmax (int): Maximum quantized value.
324
+
325
+ Returns:
326
+ str: A string representing the quantized data type, such as "int8", "uint4", etc.
327
+
328
+ Raises:
329
+ ValueError: If the (qmin, qmax) pair is not supported.
330
+ """
331
+ known_ranges = {
332
+ (-32768, 32767): "int16",
333
+ (0, 65535): "uint16",
334
+ (-128, 127): "int8",
335
+ (0, 255): "uint8",
336
+ (-8, 7): "int4",
337
+ (0, 15): "uint4",
338
+ }
339
+
340
+ if (qmin, qmax) in known_ranges:
341
+ return known_ranges[(qmin, qmax)]
342
+ else:
343
+ raise ValueError(f"Unsupported quantization range: ({qmin}, {qmax})")
@@ -32,6 +32,16 @@ This file includes OpArgs classes that provide arguments with type annotations.
32
32
  """
33
33
 
34
34
 
35
+ @enforce_type
36
+ @dataclass
37
+ class AbsArgs:
38
+ """
39
+ abs(Tensor self) -> Tensor
40
+ """
41
+
42
+ input: torch.fx.Node
43
+
44
+
35
45
  @enforce_type
36
46
  @dataclass
37
47
  class AddTensorArgs:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tico
3
- Version: 0.1.0.dev250526
3
+ Version: 0.1.0.dev250528
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=J7IztYATVQ6bNxqcIRH34nulJS8hk_bEpQUvqvH4q_g,1181
1
+ tico/__init__.py,sha256=ESRk_QvvGAAqKS2h0vDY7LZoWVc0pYWSNbXIkcz2WSo,1181
2
2
  tico/pt2_to_circle.py,sha256=PPmFNw20jw2Z2VyM3ln9pX__jTzBOAZiv0gT5a-p-Y8,2666
3
3
  tico/config/__init__.py,sha256=xZzCXjZ84qE-CsBi-dfaL05bqpQ3stKKfTXhnrJRyVs,142
4
4
  tico/config/base.py,sha256=anwOiJFkUxUi7Cef573JgQcjk6S-FSi6O_TLjYASW-g,1244
@@ -50,11 +50,11 @@ tico/experimental/quantization/evaluation/executor/backend_executor.py,sha256=3k
50
50
  tico/experimental/quantization/evaluation/executor/circle_executor.py,sha256=eCCJ9wTwR0vUJ0oN7jxtQxZ9598GRw6P6KUxiuGsIIM,2685
51
51
  tico/experimental/quantization/evaluation/executor/triv24_executor.py,sha256=sUoXl6oOO2arAKaNjOBg7HiQja145_Jv6qgY7XtR7A8,5159
52
52
  tico/experimental/quantization/passes/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
53
- tico/experimental/quantization/passes/fold_quant_ops.py,sha256=Jq5wmQDhdjsXxae2p6TnZj2gY5UMBEQ-sHkTodgkfUs,3327
53
+ tico/experimental/quantization/passes/fold_quant_ops.py,sha256=OYUndHaSL3GiL8koIG9_pqavW-hghrs0kkpvounsh1g,3312
54
54
  tico/experimental/quantization/passes/insert_quantize_on_dtype_mismatch.py,sha256=i4rkM1vlN85fXA9oOrU25o8KWAaqA65NKngTX6MgctQ,12960
55
55
  tico/experimental/quantization/passes/propagate_qparam_backward.py,sha256=TGtyW0Z2qOTgVIasBdGRgbwH31YYd6ek7OvLTmCV614,3118
56
56
  tico/experimental/quantization/passes/propagate_qparam_forward.py,sha256=RhUHGCR2RpBO5KYkQ7Z8U5u7HEwDq2wdKHLKAJCi-5c,5138
57
- tico/experimental/quantization/passes/remove_weight_dequant_op.py,sha256=lNemHkr_IMg6kTIQjk4xLgW4DkDNBr0wTW3miNqmvkc,6450
57
+ tico/experimental/quantization/passes/remove_weight_dequant_op.py,sha256=ZIwzuRXyCg6xN5pEUVV1LXsZpu0NkTcTUI6gc1VTuXs,6452
58
58
  tico/interpreter/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
59
59
  tico/interpreter/infer.py,sha256=vJ3b69ce9HrxNT0gFwbEhHpAyvVyuiunTgAeiqn5t64,4350
60
60
  tico/interpreter/interpreter.py,sha256=tGbluCbrehTCqBu8mtGDNzby_ieJ2ry8_RH_eC0CQxk,3828
@@ -68,8 +68,8 @@ tico/passes/convert_repeat_to_expand_copy.py,sha256=fRUETNuFB2p-RLhe844pldm0l5oy
68
68
  tico/passes/convert_to_relu6.py,sha256=3sfKfggvjbl9N73pLOwgUTNyoecODsy367nwoX2S-EE,6404
69
69
  tico/passes/decompose_addmm.py,sha256=_yNX7wx1Y9HJI5ksUJI-UQLHpoNawbUbF8kcm2zGHw0,4221
70
70
  tico/passes/decompose_batch_norm.py,sha256=d1V9UOkm_5BV0NGLyuQfz4I9NpO7I3ZrRugt7EXM-XM,7016
71
- tico/passes/decompose_fake_quantize.py,sha256=7ZJyTIDj2iKgWa5q8mBSq6k0GX0vs_XyQdsIiWFJoTU,5175
72
- tico/passes/decompose_fake_quantize_tensor_qparams.py,sha256=kOQaODKl_GCE19h-UZGmxnTcHtlvphI63dVAmMQL_Bk,13823
71
+ tico/passes/decompose_fake_quantize.py,sha256=-OFOf0WSyRQ8ikS8KQm2mWXp-tHQDGWOFu3mn6pFfBs,5370
72
+ tico/passes/decompose_fake_quantize_tensor_qparams.py,sha256=R0hLlKdRXnAsOrbXOErfZEkSC7nv8_TdklNlI76TRMo,13988
73
73
  tico/passes/decompose_group_norm.py,sha256=xn1xnT-2e6BvelRAzX8O7wg9kBWURmPldkRvpfYFXHQ,9407
74
74
  tico/passes/decompose_grouped_conv2d.py,sha256=KJhH6PX7l9k9T8KBV8JDAvaSfJuUnRo_jtvGF2aM-LA,8277
75
75
  tico/passes/decompose_slice_scatter.py,sha256=ko9p8v-zY5rOx4aSpWomwSdSWb1lIF32gnU7ik5xgII,5604
@@ -101,6 +101,7 @@ tico/serialize/quant_param.py,sha256=s97GJyDOZULnqFUWPakHais31G_qqPuO0awPHCkZDvI
101
101
  tico/serialize/operators/__init__.py,sha256=LIvXsNnN4yUCS2CGNQ5XW8p8oXDTV_WHWuOEAw1t6WY,990
102
102
  tico/serialize/operators/hashable_opcode.py,sha256=sDVKNTgIQw4IBtMEjNH8tzssMPx1x8-U2oagomRjGF0,1368
103
103
  tico/serialize/operators/node_visitor.py,sha256=UYyCwXqSCeRyimThMShstHnt7vKM9tsuzQ_02uEwF9I,2356
104
+ tico/serialize/operators/op_abs.py,sha256=Y-vy7rcqPT-qD3QS5R8zbApWWTPpjY6xuMMVnbIhYmQ,1827
104
105
  tico/serialize/operators/op_add.py,sha256=otm062DMHVAThWmOtSTZdPyP3P5-2cv5VL_UWBJeLms,2346
105
106
  tico/serialize/operators/op_alias_copy.py,sha256=Xu9OiILbGf8oddh8yTqovvLfgVs8XYV7Cg4n6CesWcg,2175
106
107
  tico/serialize/operators/op_any.py,sha256=WMsHLq7WIcl6rD2G3QqpWRSCR-a6UYX6y5AjB6BDS3U,5049
@@ -187,15 +188,15 @@ tico/utils/padding.py,sha256=GGO27VbaOvtaMYLDrSaKv7uxjeet566aMJD0PyYeMvQ,1484
187
188
  tico/utils/passes.py,sha256=kGmDe__5cPaO6i5EDAoXSVe6yXEoX9hAny4ROb3ZEmQ,2409
188
189
  tico/utils/register_custom_op.py,sha256=iRQvdqlBqrJxq_pNkvJyDIJD_SYtCUl88wwbbuvSwlk,22952
189
190
  tico/utils/trace_decorators.py,sha256=ddLIiKQfSaQrxgF1kNpwjFTQnXENzeSfcr1kuAW4jGI,3221
190
- tico/utils/utils.py,sha256=pybDU1LoNhjEplANig11lboX9yzYRkvFCSmyYth_2Do,10359
191
- tico/utils/validate_args_kwargs.py,sha256=VDu4O331mV69gxTeWyPnb_kcYj33rTthpanoB-2V3eY,24939
191
+ tico/utils/utils.py,sha256=NAa3ZX5G-UCQwmz5WnFl0iCEra24PMY5wC0MyX7smUg,11156
192
+ tico/utils/validate_args_kwargs.py,sha256=P4aMnr9EhNCtc_AgJPpuezfQbqFfDn0lhJSWqmumLZ8,25054
192
193
  tico/utils/mx/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
193
194
  tico/utils/mx/elemwise_ops.py,sha256=V6glyAHsVR1joqpsgnNytatCD_ew92xNWZ19UFDoMTA,10281
194
195
  tico/utils/mx/formats.py,sha256=uzNWyu-1onUlwQfX5cZ6fZSUfHMRqorper7_T1k3jfk,3404
195
196
  tico/utils/mx/mx_ops.py,sha256=RcfUTYVi-wilGB2sC35OeARdwDqnixv7dG5iyZ-fQT8,8555
196
- tico-0.1.0.dev250526.dist-info/LICENSE,sha256=kp4JLII7bzRhPb0CPD5XTDZMh22BQ7h3k3B7t8TiSbw,12644
197
- tico-0.1.0.dev250526.dist-info/METADATA,sha256=3SKmlh6awI1s0MtPImCBvWuApN_T_M0A1VmlN80BTE4,8633
198
- tico-0.1.0.dev250526.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
199
- tico-0.1.0.dev250526.dist-info/entry_points.txt,sha256=kBKYSS_IYrSXmUYevmmepqIVPScq5vF8ulQRu3I_Zf0,59
200
- tico-0.1.0.dev250526.dist-info/top_level.txt,sha256=oqs7UPoNSKZEwqsX8B-KAWdQwfAa7i60pbxW_Jk7P3w,5
201
- tico-0.1.0.dev250526.dist-info/RECORD,,
197
+ tico-0.1.0.dev250528.dist-info/LICENSE,sha256=kp4JLII7bzRhPb0CPD5XTDZMh22BQ7h3k3B7t8TiSbw,12644
198
+ tico-0.1.0.dev250528.dist-info/METADATA,sha256=Ql9a9NvnYDJ7WHA_qx2TljzHnyvLfNoGEeCu6rByX6s,8633
199
+ tico-0.1.0.dev250528.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
200
+ tico-0.1.0.dev250528.dist-info/entry_points.txt,sha256=kBKYSS_IYrSXmUYevmmepqIVPScq5vF8ulQRu3I_Zf0,59
201
+ tico-0.1.0.dev250528.dist-info/top_level.txt,sha256=oqs7UPoNSKZEwqsX8B-KAWdQwfAa7i60pbxW_Jk7P3w,5
202
+ tico-0.1.0.dev250528.dist-info/RECORD,,