tico 0.1.0.dev250727__py3-none-any.whl → 0.1.0.dev250728__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
@@ -29,7 +29,7 @@ __all__ = [
29
29
  ]
30
30
 
31
31
  # THIS LINE IS AUTOMATICALLY GENERATED BY setup.py
32
- __version__ = "0.1.0.dev250727"
32
+ __version__ = "0.1.0.dev250728"
33
33
 
34
34
  MINIMUM_SUPPORTED_VERSION = "2.5.0"
35
35
  SECURE_TORCH_VERSION = "2.6.0"
@@ -376,6 +376,12 @@ def _relu_handler(node, logger):
376
376
  quantize.meta[QPARAM_KEY] = copy.deepcopy(node.meta[QPARAM_KEY])
377
377
  node.meta[QPARAM_KEY] = _u8_to_i16(node.meta[QPARAM_KEY])
378
378
  logger.debug(f"quantize_per_tensor.default is inserted after {node.name}.")
379
+ elif qparam_dtype(inp) == "uint8" and qparam_dtype(node) == "int16":
380
+ quantize = _insert_quantize_op_after(node)
381
+
382
+ quantize.meta[QPARAM_KEY] = copy.deepcopy(node.meta[QPARAM_KEY])
383
+ node.meta[QPARAM_KEY] = _i16_to_u8(node.meta[QPARAM_KEY])
384
+ logger.debug(f"quantize_per_tensor.default is inserted after {node.name}.")
379
385
  else:
380
386
  raise NotYetSupportedError("Unsupported dtype")
381
387
 
@@ -151,7 +151,7 @@ class CircleSubgraph(circle.SubGraph.SubGraphT):
151
151
  self.name_to_node[tensor.name] = node
152
152
  assert node.meta.get("val") is not None
153
153
  tensor.type = extract_circle_dtype(node)
154
- tensor.shape, tensor.shapeSignature = extract_circle_shape(node)
154
+ tensor.shape, tensor.shapeSignature = extract_circle_shape(node) # type: ignore[assignment]
155
155
 
156
156
  if QPARAM_KEY in node.meta:
157
157
  tensor.quantization = to_circle_qparam(node.meta[QPARAM_KEY])
@@ -134,16 +134,53 @@ def extract_circle_shape(node: torch.fx.Node) -> Tuple[List[int], Optional[List[
134
134
 
135
135
  def to_circle_shape(torch_shape: torch.Size) -> Tuple[List[int], Optional[List[int]]]:
136
136
  shape: List[int] = list(torch_shape)
137
- shapeSignature: Optional[List[int]] = None
137
+ shape_signature: Optional[List[int]] = None
138
138
 
139
139
  if any(isinstance(s, torch.SymInt) for s in shape):
140
- shapeSignature = shape.copy()
140
+ shape_signature = shape.copy()
141
141
  for idx, s in enumerate(shape):
142
142
  if isinstance(s, torch.SymInt):
143
143
  shape[idx] = 1
144
- shapeSignature[idx] = -1
144
+ shape_signature[idx] = -1
145
145
 
146
- return shape, shapeSignature
146
+ return shape, shape_signature
147
+
148
+
149
+ def validate_circle_shape(shape: List[int], shape_signature: Optional[List[int]]):
150
+ """
151
+ Validate circle tensor shape and shape_signature.
152
+ @ref https://github.com/Samsung/TICO/issues/244
153
+ """
154
+ if shape_signature is not None:
155
+ if len(shape_signature) == 0:
156
+ raise ValueError(
157
+ "Invalid circle shape: shape_signature must not be an empty list. "
158
+ "For static shapes, use None instead of []."
159
+ )
160
+ if len(shape) != len(shape_signature):
161
+ raise ValueError(
162
+ f"Invalid circle shape: shape and shape_signature must have same length: {shape} {shape_signature}"
163
+ )
164
+ if not all(isinstance(s, int) for s in shape_signature):
165
+ raise ValueError(
166
+ f"circle tensor shape_signature must be all integer values. {shape_signature}"
167
+ )
168
+ for s, ss in zip(shape, shape_signature):
169
+ if ss == -1:
170
+ # dynamic shape dimension
171
+ if s != 1:
172
+ raise ValueError(
173
+ f"Invalid circle shape: {s} {ss} {shape} {shape_signature}"
174
+ )
175
+ else:
176
+ # static shape dimension
177
+ if s != ss:
178
+ raise ValueError(
179
+ f"Invalid circle shape: {s} {ss} {shape} {shape_signature}"
180
+ )
181
+
182
+ if not all(isinstance(s, int) for s in shape):
183
+ raise ValueError(f"circle tensor shape must be all integer values. {shape}")
147
184
 
148
185
 
149
186
  # Return stride of node
@@ -26,7 +26,7 @@ from tico.serialize.circle_graph import CircleModel, CircleSubgraph
26
26
  from tico.serialize.operators.hashable_opcode import OpCode
27
27
  from tico.serialize.operators.node_visitor import get_node_visitors
28
28
  from tico.utils import logging
29
- from tico.utils.serialize import finalise_tensor_names
29
+ from tico.utils.serialize import finalise_tensor_names, validate_tensor_shapes
30
30
 
31
31
 
32
32
  multiple_output_ops = [
@@ -104,8 +104,10 @@ def build_circle(ep: ExportedProgram) -> bytes:
104
104
  graph.add_operator(circle_op)
105
105
  logger.debug(f"call_function: {node.name} ({opcode}) Op exported.")
106
106
 
107
- # Register subgraph
108
107
  finalise_tensor_names(graph)
108
+ validate_tensor_shapes(graph)
109
+
110
+ # Register subgraph
109
111
  model.subgraphs.append(graph)
110
112
 
111
113
  # Encode operator codes
@@ -110,7 +110,7 @@ class CopyVisitor(NodeVisitor):
110
110
  # To connect 'dst' to Reshape node in the graph, 'dst' must be converted to Shape op.
111
111
  dst_tensor: circle.Tensor.TensorT = self.graph.get_tensor(dst)
112
112
  dst_shape: List[int] = dst_tensor.shape
113
- dst_shape_signature: List[int] = dst_tensor.shapeSignature
113
+ dst_shape_signature: Optional[List[int]] = dst_tensor.shapeSignature
114
114
 
115
115
  if dst_shape_signature is not None:
116
116
  # TODO: support dynamic shape
@@ -134,7 +134,7 @@ class CopyVisitor(NodeVisitor):
134
134
 
135
135
  src_tensor: circle.Tensor.TensorT = self.graph.get_tensor(src)
136
136
  src_shape: List[int] = src_tensor.shape
137
- src_shape_signature: List[int] = src_tensor.shapeSignature
137
+ src_shape_signature: Optional[List[int]] = src_tensor.shapeSignature
138
138
 
139
139
  if src_shape_signature is not None:
140
140
  # TODO: support dynamic shape
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import Dict, List, TYPE_CHECKING
15
+ from typing import Dict, List, Optional, TYPE_CHECKING
16
16
 
17
17
  if TYPE_CHECKING:
18
18
  import torch._ops
@@ -57,7 +57,7 @@ class CumsumVisitor(NodeVisitor):
57
57
  if input_dtype == torch.int32:
58
58
  input_tensor: circle.Tensor.TensorT = self.graph.get_tensor(input)
59
59
  input_shape: List[int] = input_tensor.shape
60
- input_shape_signature: List[int] = input_tensor.shapeSignature
60
+ input_shape_signature: Optional[List[int]] = input_tensor.shapeSignature
61
61
  cast_op_index = get_op_index(
62
62
  circle.BuiltinOperator.BuiltinOperator.CAST, self._op_codes
63
63
  )
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import Dict, List, TYPE_CHECKING
15
+ from typing import Dict, List, Optional, TYPE_CHECKING
16
16
 
17
17
  if TYPE_CHECKING:
18
18
  import torch._ops
@@ -36,7 +36,7 @@ class BasePowVisitor(NodeVisitor):
36
36
  assert isinstance(node, torch.fx.Node), type(node)
37
37
  node_tensor: circle.Tensor.TensorT = self.graph.get_tensor(node)
38
38
  node_shape: List[int] = node_tensor.shape
39
- node_shape_signature: List[int] = node_tensor.shapeSignature
39
+ node_shape_signature: Optional[List[int]] = node_tensor.shapeSignature
40
40
  op_index = get_op_index(
41
41
  circle.BuiltinOperator.BuiltinOperator.CAST, self._op_codes
42
42
  )
tico/utils/serialize.py CHANGED
@@ -14,6 +14,7 @@
14
14
 
15
15
 
16
16
  from tico.serialize.circle_graph import CircleSubgraph
17
+ from tico.serialize.circle_mapping import validate_circle_shape
17
18
  from tico.utils.graph import get_module_name_chain
18
19
 
19
20
 
@@ -37,3 +38,13 @@ def finalise_tensor_names(
37
38
  for tensor in graph.tensors:
38
39
  if tensor.name in graph.name_to_node:
39
40
  tensor.name = f"{get_module_name_chain(graph.name_to_node[tensor.name])}::{tensor.name}"
41
+
42
+
43
+ def validate_tensor_shapes(
44
+ graph: CircleSubgraph,
45
+ ) -> None:
46
+ """
47
+ Let's validate all tensors' shapes against their shape signatures.
48
+ """
49
+ for tensor in graph.tensors:
50
+ validate_circle_shape(tensor.shape, tensor.shapeSignature)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tico
3
- Version: 0.1.0.dev250727
3
+ Version: 0.1.0.dev250728
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=37Am_n1sr3CrCWSfMslOBX7P-iHXyaZ9IjQWSLozypc,1883
1
+ tico/__init__.py,sha256=kZCpd8rEcyfgQB3nr_jtFyjo2VEY_NHzI1gBgPCFAIQ,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
@@ -51,7 +51,7 @@ tico/experimental/quantization/evaluation/executor/circle_executor.py,sha256=eCC
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
53
  tico/experimental/quantization/passes/fold_quant_ops.py,sha256=bRHYSeHdSTaz3261skIkK5Aso2Lbv7ql0zFI9ICmbDY,7028
54
- tico/experimental/quantization/passes/insert_quantize_on_dtype_mismatch.py,sha256=4xwOzUrnMH4MQfdOHBHHXQo1EyWSkqNNVfBg47J5UCg,14721
54
+ tico/experimental/quantization/passes/insert_quantize_on_dtype_mismatch.py,sha256=AtfK9kDnWyIWyVlwD4a0EEx_-5rW5Hmo5DuKZ-HyXH0,15069
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
57
  tico/experimental/quantization/passes/quantize_bias.py,sha256=T7YxJ70N0tSK0FF9VJZA5iP0sHdnnsX9GX4AT4JDFSk,4325
@@ -96,9 +96,9 @@ tico/passes/remove_redundant_to_copy.py,sha256=tKy4XKkO2l33fMxVPQ_iFkUeFvP15kbPv
96
96
  tico/passes/restore_linear.py,sha256=xGJdNb-1CrkOKS9BnLbcblkZc6P2vVjKIi-7lRcs7Bk,4111
97
97
  tico/passes/segment_index_select.py,sha256=VVCKNLtYRkr9n5lGnlzEuQsQ0WVxEYXGchFrDnB1C40,5189
98
98
  tico/serialize/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
99
- tico/serialize/circle_graph.py,sha256=GSrrv6UGs2-sH5wJ19M-JLNimC-ZDsPzAO_ZswlHEU4,11945
100
- tico/serialize/circle_mapping.py,sha256=FEOGme-ewmZyTl_V34ErF7CI-KnDb98xmK_OcOKl4PA,6417
101
- tico/serialize/circle_serializer.py,sha256=bVKxAex_Nmc4O9RUFWIB_KhAuubVbhhA19CS3x967y8,10891
99
+ tico/serialize/circle_graph.py,sha256=gEb-vubY1qcPqaUdINabYvqTSpGNsfRKLeFV3_2NVBA,11973
100
+ tico/serialize/circle_mapping.py,sha256=lH5VxYMQc8xJfRG3wC_Td-wRFEJWhlAwgxVMDetz1C8,7958
101
+ tico/serialize/circle_serializer.py,sha256=BGK9tltKkoL1h4rcrJUgDJIGlHst7aF3cZAKJk_GPWc,10950
102
102
  tico/serialize/pack.py,sha256=5HZ9kX3x6C6CyT_FWS6FRmvx_P7Dx21orjUNQxJ2xlo,1297
103
103
  tico/serialize/quant_param.py,sha256=6nbGKdqwMI9Cx9BLXJ9A9JU4qb770S8vTM1vCZRX3Eo,1342
104
104
  tico/serialize/operators/__init__.py,sha256=LIvXsNnN4yUCS2CGNQ5XW8p8oXDTV_WHWuOEAw1t6WY,990
@@ -117,9 +117,9 @@ tico/serialize/operators/op_clamp.py,sha256=RRQVrzayDfN3PioCVJqa_yYOtcYwb5HHwkMe
117
117
  tico/serialize/operators/op_clone.py,sha256=vzDYJ8TS3tc2BAyd_z8nt5VqT1inpymSseMEhd9dva0,2394
118
118
  tico/serialize/operators/op_constant_pad_nd.py,sha256=OpP4AP-d1IFcWZolNa-o9ZxzXJQkMdG9WQ66soX3s-E,2675
119
119
  tico/serialize/operators/op_conv2d.py,sha256=I9OgOr1cBGFkx1Q6eyLLvY5DmKdaieMSNmVAuZ8pBa0,6842
120
- tico/serialize/operators/op_copy.py,sha256=z0GCaRP4dyJdJ1ajQ45BKmBRJlirWUPqYfnrqBtbeUM,6921
120
+ tico/serialize/operators/op_copy.py,sha256=boXHfl0bcvdBVl0tpzPMA_KBonh80vVqv61N3H5-PRU,6941
121
121
  tico/serialize/operators/op_cos.py,sha256=N12bNyuTQIxRnD0eHRPdFVzRQPMy1NFM4iM8oQ4lYzw,2034
122
- tico/serialize/operators/op_cumsum.py,sha256=Y8eVvtX57uPA4NIwS-Vbfjoiz_rPpc_wmViTQtCoz6s,3928
122
+ tico/serialize/operators/op_cumsum.py,sha256=px9ZGUDDsdWjrql8Z1FdXfF-7CJhditxyNz5QRZbLiM,3948
123
123
  tico/serialize/operators/op_depthwise_conv2d.py,sha256=S2naBMWAoUL3nJiV7RVg97bUvuQdB5VldE_r--rX0hA,7297
124
124
  tico/serialize/operators/op_dequantize_per_channel.py,sha256=aPcVxjdgvfSFoLnv9NL-RxO5vZYj8ulqriMP5LHIWs0,3133
125
125
  tico/serialize/operators/op_dequantize_per_tensor.py,sha256=u9aK_Xle9rDN0EHLE0YrCTlXY4Q53Ch9Di4qmx7ynps,2304
@@ -153,7 +153,7 @@ tico/serialize/operators/op_mul.py,sha256=si_VdYNyFbULb50SnXHOINh0dZQ2PhRB6Fzl54
153
153
  tico/serialize/operators/op_ne.py,sha256=xa2WJL2tYksxw7fIJic_D9ltLEseyCII8HpR32Oq8Do,1900
154
154
  tico/serialize/operators/op_neg.py,sha256=fkI3ExyD3QF-qtxBcXqQutPNDbNL8g7lZYE7CyD2wLk,2046
155
155
  tico/serialize/operators/op_permute.py,sha256=5DfX3pfZ5FDNmrSqx3-hRwPA7vm36z7BfG-nuyyBTsM,2282
156
- tico/serialize/operators/op_pow.py,sha256=G_GpdddmlE3opaCJtcfkV0qAWMau5uBa1sEB46qrNdo,5553
156
+ tico/serialize/operators/op_pow.py,sha256=a-Nyy_s8d9nCIEAb5DacB1quDVmDu1VOHyAkD75u7Ts,5573
157
157
  tico/serialize/operators/op_prelu.py,sha256=0ZybL5pNvBrRvQGy4M6gELrjiEXEsb2wBDdU8x4D75I,1874
158
158
  tico/serialize/operators/op_quantize_per_tensor.py,sha256=w-vYxSPnN2gtx-pEkkcMGU0ZjiwaS4y1sxy56pKEq3E,3004
159
159
  tico/serialize/operators/op_reciprocal.py,sha256=6b9_bxjg_0EvgAitSv1MgBi4PJSEgm-21s5qtWI1UR4,2394
@@ -196,7 +196,7 @@ tico/utils/padding.py,sha256=0iEcS5G3gSFySPzBz1m5nxHYZ6MlLzG_KdAFJRauwIg,3279
196
196
  tico/utils/passes.py,sha256=kGmDe__5cPaO6i5EDAoXSVe6yXEoX9hAny4ROb3ZEmQ,2409
197
197
  tico/utils/pytree_utils.py,sha256=jrk3N6X6LiUnBCX_gM1K9nywbVAJBVnszlTAgeIeDUc,5219
198
198
  tico/utils/register_custom_op.py,sha256=3-Yl6iYmx1qQA2igNHt4hYhQhQMkdPb7gF50LIY8yvc,27350
199
- tico/utils/serialize.py,sha256=cBtEUfi_SU_9_v0cq2CNikzn8GnzEz2RwRvUH2NkWu4,1378
199
+ tico/utils/serialize.py,sha256=zAzylTEEgYc_9PZie7TlNY6umQol0Ris9omrzvtBdm0,1697
200
200
  tico/utils/torch_compat.py,sha256=oc6PztVsXdHcQ3iaVR90wLLxrGaj6zFHWZ8K9rRS6q8,1795
201
201
  tico/utils/trace_decorators.py,sha256=ddLIiKQfSaQrxgF1kNpwjFTQnXENzeSfcr1kuAW4jGI,3221
202
202
  tico/utils/utils.py,sha256=A5p3iAAxRGDsZJh4ybp-Qo3MX3vk5RrmSY-R3rXqVeI,12976
@@ -205,9 +205,9 @@ tico/utils/mx/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
205
205
  tico/utils/mx/elemwise_ops.py,sha256=V6glyAHsVR1joqpsgnNytatCD_ew92xNWZ19UFDoMTA,10281
206
206
  tico/utils/mx/formats.py,sha256=uzNWyu-1onUlwQfX5cZ6fZSUfHMRqorper7_T1k3jfk,3404
207
207
  tico/utils/mx/mx_ops.py,sha256=RcfUTYVi-wilGB2sC35OeARdwDqnixv7dG5iyZ-fQT8,8555
208
- tico-0.1.0.dev250727.dist-info/LICENSE,sha256=kp4JLII7bzRhPb0CPD5XTDZMh22BQ7h3k3B7t8TiSbw,12644
209
- tico-0.1.0.dev250727.dist-info/METADATA,sha256=gE7opbcJdg8CiBvfdcjjvCuyrfQvy-q4BaBt8meVP84,8430
210
- tico-0.1.0.dev250727.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
211
- tico-0.1.0.dev250727.dist-info/entry_points.txt,sha256=kBKYSS_IYrSXmUYevmmepqIVPScq5vF8ulQRu3I_Zf0,59
212
- tico-0.1.0.dev250727.dist-info/top_level.txt,sha256=oqs7UPoNSKZEwqsX8B-KAWdQwfAa7i60pbxW_Jk7P3w,5
213
- tico-0.1.0.dev250727.dist-info/RECORD,,
208
+ tico-0.1.0.dev250728.dist-info/LICENSE,sha256=kp4JLII7bzRhPb0CPD5XTDZMh22BQ7h3k3B7t8TiSbw,12644
209
+ tico-0.1.0.dev250728.dist-info/METADATA,sha256=dffUxDeJCYb5AUxiLN9WbXQF8yRm0aQaYz12ScXxrao,8430
210
+ tico-0.1.0.dev250728.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
211
+ tico-0.1.0.dev250728.dist-info/entry_points.txt,sha256=kBKYSS_IYrSXmUYevmmepqIVPScq5vF8ulQRu3I_Zf0,59
212
+ tico-0.1.0.dev250728.dist-info/top_level.txt,sha256=oqs7UPoNSKZEwqsX8B-KAWdQwfAa7i60pbxW_Jk7P3w,5
213
+ tico-0.1.0.dev250728.dist-info/RECORD,,