tico 0.1.0.dev250623__py3-none-any.whl → 0.1.0.dev250625__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 +1 -1
- tico/experimental/quantization/passes/fold_quant_ops.py +54 -24
- {tico-0.1.0.dev250623.dist-info → tico-0.1.0.dev250625.dist-info}/METADATA +1 -1
- {tico-0.1.0.dev250623.dist-info → tico-0.1.0.dev250625.dist-info}/RECORD +8 -8
- {tico-0.1.0.dev250623.dist-info → tico-0.1.0.dev250625.dist-info}/LICENSE +0 -0
- {tico-0.1.0.dev250623.dist-info → tico-0.1.0.dev250625.dist-info}/WHEEL +0 -0
- {tico-0.1.0.dev250623.dist-info → tico-0.1.0.dev250625.dist-info}/entry_points.txt +0 -0
- {tico-0.1.0.dev250623.dist-info → tico-0.1.0.dev250625.dist-info}/top_level.txt +0 -0
tico/__init__.py
CHANGED
@@ -21,7 +21,7 @@ from tico.config import CompileConfigV1, get_default_config
|
|
21
21
|
from tico.utils.convert import convert, convert_from_exported_program, convert_from_pt2
|
22
22
|
|
23
23
|
# THIS LINE IS AUTOMATICALLY GENERATED BY setup.py
|
24
|
-
__version__ = "0.1.0.
|
24
|
+
__version__ = "0.1.0.dev250625"
|
25
25
|
|
26
26
|
MINIMUM_SUPPORTED_VERSION = "2.5.0"
|
27
27
|
SECURE_TORCH_VERSION = "2.6.0"
|
@@ -21,9 +21,8 @@ import copy
|
|
21
21
|
import torch
|
22
22
|
from torch.export import ExportedProgram
|
23
23
|
|
24
|
-
from tico.serialize.quant_param import QPARAM_KEY, QuantParam
|
24
|
+
from tico.serialize.quant_param import QPARAM_KEY, QuantParam
|
25
25
|
from tico.utils import logging
|
26
|
-
from tico.utils.graph import create_node
|
27
26
|
from tico.utils.passes import PassBase, PassResult
|
28
27
|
from tico.utils.trace_decorators import trace_graph_diff_on_pass
|
29
28
|
from tico.utils.utils import get_quant_dtype
|
@@ -42,11 +41,33 @@ class FoldQuantOps(PassBase):
|
|
42
41
|
To export quantized circle, this pass removes (Q - DQ) nodes and saves those quantization info
|
43
42
|
to previous op's metadata.
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
────────────────────────────────────────────────────────────────
|
45
|
+
BEFORE AFTER
|
46
|
+
────────────────────────────────────────────────────────────────
|
47
|
+
op(float) ─ Q ─ DQ ─ … op(float, meta[QPARAM])
|
48
|
+
|
49
|
+
op ─ Q1 ─ DQ1 ─ Q2 ─ DQ2 op(meta[QPARAM]) ─ Q2
|
50
|
+
▲ ▲
|
51
|
+
│ (Q1, DQ1 folded) │ (re-quantization kept)
|
52
|
+
|
53
|
+
op ─ Q ─┬─ DQ0 op(meta[QPARAM])
|
54
|
+
├─ DQ1 (each DQ* folded, Q dropped when orphaned)
|
55
|
+
└─ DQ2
|
56
|
+
────────────────────────────────────────────────────────────────
|
57
|
+
|
58
|
+
Algorithm
|
59
|
+
---------
|
60
|
+
1. Iterate over *all* Dequantize nodes.
|
61
|
+
2. For each DQ, verify it is driven by a Quantize node `q` and that
|
62
|
+
`q` and `dq` share identical (scale, zero-point, dtype).
|
63
|
+
3. a) If the producer op has **no** QPARAM, attach one, then replace
|
64
|
+
*this* DQ's usages with the producer op.
|
65
|
+
b) If the producer is already quantized with a different dtype,
|
66
|
+
this is a *re-quantization*: attach QPARAM to `q` and keep it,
|
67
|
+
but still remove the DQ.
|
68
|
+
4. After all replacements, run `graph.eliminate_dead_code()`.
|
69
|
+
Any Quantize that became orphaned because *all* its DQs were folded
|
70
|
+
is deleted automatically.
|
50
71
|
"""
|
51
72
|
|
52
73
|
def __init__(self):
|
@@ -81,15 +102,9 @@ class FoldQuantOps(PassBase):
|
|
81
102
|
if q_args.dtype != dq_args.dtype:
|
82
103
|
continue
|
83
104
|
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
# 2.1. op_dtype == qdq_dtype
|
88
|
-
# - Just skip (NOTE Need requantization?)
|
89
|
-
# 2.2. op_dtype != qdq_dtype
|
90
|
-
# - Insert Quantize operator
|
91
|
-
|
92
|
-
# Case 1
|
105
|
+
# ───────────────────────────────────────────
|
106
|
+
# Case 1: op not yet quantized
|
107
|
+
# ───────────────────────────────────────────
|
93
108
|
if QPARAM_KEY not in op.meta:
|
94
109
|
qparam = QuantParam()
|
95
110
|
qparam.scale = [q_args.scale]
|
@@ -100,21 +115,36 @@ class FoldQuantOps(PassBase):
|
|
100
115
|
dq.replace_all_uses_with(op, propagate_meta=False)
|
101
116
|
|
102
117
|
logger.debug(f"{q.name} and {dq.name} are folded to {op.name}.")
|
118
|
+
# ───────────────────────────────────────────
|
119
|
+
# Case 2: op already quantized
|
120
|
+
# 2.1 same dtype → nothing to do
|
121
|
+
# 2.2 diff dtype → leave Q in place
|
122
|
+
# ───────────────────────────────────────────
|
103
123
|
else:
|
104
124
|
op_qparam: QuantParam = op.meta[QPARAM_KEY]
|
105
125
|
qdq_dtype = get_quant_dtype(q_args.quant_min, q_args.quant_max)
|
106
|
-
|
126
|
+
|
107
127
|
if op_qparam.dtype != qdq_dtype:
|
108
|
-
#
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
128
|
+
# Attach QPARAM to Q once
|
129
|
+
if QPARAM_KEY not in q.meta:
|
130
|
+
qparam = QuantParam()
|
131
|
+
qparam.scale = [q_args.scale]
|
132
|
+
qparam.zero_point = [q_args.zero_p]
|
133
|
+
qparam.dtype = qdq_dtype
|
134
|
+
q.meta[QPARAM_KEY] = qparam
|
135
|
+
assert len(q.users) == 1, "Fix me unless"
|
115
136
|
|
116
137
|
dq.replace_all_uses_with(q, propagate_meta=False)
|
117
138
|
logger.debug(f"{dq.name} is folded ({q.name} is left).")
|
139
|
+
else:
|
140
|
+
# Same dtype → the Quantize–Dequantize pair is redundant.
|
141
|
+
assert op_qparam.scale and op_qparam.scale[0] == q_args.scale
|
142
|
+
assert (
|
143
|
+
op_qparam.zero_point
|
144
|
+
and op_qparam.zero_point[0] == q_args.zero_p
|
145
|
+
)
|
146
|
+
dq.replace_all_uses_with(op, propagate_meta=False)
|
147
|
+
logger.debug(f"Removed redundant {dq.name}")
|
118
148
|
|
119
149
|
graph.eliminate_dead_code()
|
120
150
|
graph.lint()
|
@@ -1,4 +1,4 @@
|
|
1
|
-
tico/__init__.py,sha256=
|
1
|
+
tico/__init__.py,sha256=doEv0YyghxyOT9H264hpfuazFicVamcLVaGtfVzXDNc,1743
|
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=anwOiJFkUxUi7Cef573JgQcjk6S-FSi6O_TLjYASW-g,1244
|
@@ -50,7 +50,7 @@ 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=
|
53
|
+
tico/experimental/quantization/passes/fold_quant_ops.py,sha256=iaBMyO49CwVkhebMz3rjkHWfWE2LhwH6fORe7n4S6XQ,7040
|
54
54
|
tico/experimental/quantization/passes/insert_quantize_on_dtype_mismatch.py,sha256=AbNcI7rfIwHsQna_rFuwqFdOzFAU2lIB3sMK-vns8Dc,13072
|
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
|
@@ -198,9 +198,9 @@ tico/utils/mx/__init__.py,sha256=IO6FP_xYbGy0dW0HL26GXD3ouxARaxCK7bz9dn4blPQ,26
|
|
198
198
|
tico/utils/mx/elemwise_ops.py,sha256=V6glyAHsVR1joqpsgnNytatCD_ew92xNWZ19UFDoMTA,10281
|
199
199
|
tico/utils/mx/formats.py,sha256=uzNWyu-1onUlwQfX5cZ6fZSUfHMRqorper7_T1k3jfk,3404
|
200
200
|
tico/utils/mx/mx_ops.py,sha256=RcfUTYVi-wilGB2sC35OeARdwDqnixv7dG5iyZ-fQT8,8555
|
201
|
-
tico-0.1.0.
|
202
|
-
tico-0.1.0.
|
203
|
-
tico-0.1.0.
|
204
|
-
tico-0.1.0.
|
205
|
-
tico-0.1.0.
|
206
|
-
tico-0.1.0.
|
201
|
+
tico-0.1.0.dev250625.dist-info/LICENSE,sha256=kp4JLII7bzRhPb0CPD5XTDZMh22BQ7h3k3B7t8TiSbw,12644
|
202
|
+
tico-0.1.0.dev250625.dist-info/METADATA,sha256=bCYr0NfPjTLo4lCwgJS_mwIMzDRJjpIUF9cRGrQRKOk,8846
|
203
|
+
tico-0.1.0.dev250625.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
204
|
+
tico-0.1.0.dev250625.dist-info/entry_points.txt,sha256=kBKYSS_IYrSXmUYevmmepqIVPScq5vF8ulQRu3I_Zf0,59
|
205
|
+
tico-0.1.0.dev250625.dist-info/top_level.txt,sha256=oqs7UPoNSKZEwqsX8B-KAWdQwfAa7i60pbxW_Jk7P3w,5
|
206
|
+
tico-0.1.0.dev250625.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|