tico 0.1.0__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.
Files changed (206) hide show
  1. tico/__init__.py +42 -0
  2. tico/config/__init__.py +4 -0
  3. tico/config/base.py +37 -0
  4. tico/config/factory.py +41 -0
  5. tico/config/v1.py +35 -0
  6. tico/experimental/__init__.py +1 -0
  7. tico/experimental/quantization/__init__.py +1 -0
  8. tico/experimental/quantization/algorithm/__init__.py +1 -0
  9. tico/experimental/quantization/algorithm/gptq/__init__.py +1 -0
  10. tico/experimental/quantization/algorithm/gptq/gptq.py +172 -0
  11. tico/experimental/quantization/algorithm/gptq/quant.py +153 -0
  12. tico/experimental/quantization/algorithm/gptq/quantizer.py +225 -0
  13. tico/experimental/quantization/algorithm/gptq/utils.py +65 -0
  14. tico/experimental/quantization/algorithm/pt2e/__init__.py +1 -0
  15. tico/experimental/quantization/algorithm/pt2e/annotation/__init__.py +1 -0
  16. tico/experimental/quantization/algorithm/pt2e/annotation/annotator.py +215 -0
  17. tico/experimental/quantization/algorithm/pt2e/annotation/config.py +26 -0
  18. tico/experimental/quantization/algorithm/pt2e/annotation/op/__init__.py +21 -0
  19. tico/experimental/quantization/algorithm/pt2e/annotation/op/adaptive_avg_pool2d.py +65 -0
  20. tico/experimental/quantization/algorithm/pt2e/annotation/op/add.py +57 -0
  21. tico/experimental/quantization/algorithm/pt2e/annotation/op/conv2d.py +92 -0
  22. tico/experimental/quantization/algorithm/pt2e/annotation/op/div.py +57 -0
  23. tico/experimental/quantization/algorithm/pt2e/annotation/op/linear.py +94 -0
  24. tico/experimental/quantization/algorithm/pt2e/annotation/op/mean.py +53 -0
  25. tico/experimental/quantization/algorithm/pt2e/annotation/op/mul.py +57 -0
  26. tico/experimental/quantization/algorithm/pt2e/annotation/op/relu6.py +53 -0
  27. tico/experimental/quantization/algorithm/pt2e/annotation/op/rsqrt.py +53 -0
  28. tico/experimental/quantization/algorithm/pt2e/annotation/op/sub.py +57 -0
  29. tico/experimental/quantization/algorithm/pt2e/annotation/spec.py +47 -0
  30. tico/experimental/quantization/algorithm/pt2e/annotation/utils.py +88 -0
  31. tico/experimental/quantization/algorithm/pt2e/quantizer.py +78 -0
  32. tico/experimental/quantization/algorithm/pt2e/transformation/__init__.py +1 -0
  33. tico/experimental/quantization/algorithm/pt2e/transformation/convert_scalars_to_attrs.py +58 -0
  34. tico/experimental/quantization/algorithm/pt2e/utils.py +138 -0
  35. tico/experimental/quantization/algorithm/smoothquant/__init__.py +1 -0
  36. tico/experimental/quantization/algorithm/smoothquant/observer.py +78 -0
  37. tico/experimental/quantization/algorithm/smoothquant/quantizer.py +81 -0
  38. tico/experimental/quantization/algorithm/smoothquant/smooth_quant.py +164 -0
  39. tico/experimental/quantization/config.py +68 -0
  40. tico/experimental/quantization/evaluation/__init__.py +1 -0
  41. tico/experimental/quantization/evaluation/backend.py +20 -0
  42. tico/experimental/quantization/evaluation/evaluate.py +223 -0
  43. tico/experimental/quantization/evaluation/executor/__init__.py +1 -0
  44. tico/experimental/quantization/evaluation/executor/backend_executor.py +54 -0
  45. tico/experimental/quantization/evaluation/executor/circle_executor.py +75 -0
  46. tico/experimental/quantization/evaluation/executor/triv24_executor.py +128 -0
  47. tico/experimental/quantization/evaluation/metric.py +109 -0
  48. tico/experimental/quantization/evaluation/utils.py +185 -0
  49. tico/experimental/quantization/passes/__init__.py +1 -0
  50. tico/experimental/quantization/passes/fold_quant_ops.py +154 -0
  51. tico/experimental/quantization/passes/insert_quantize_on_dtype_mismatch.py +345 -0
  52. tico/experimental/quantization/passes/propagate_qparam_backward.py +91 -0
  53. tico/experimental/quantization/passes/propagate_qparam_forward.py +141 -0
  54. tico/experimental/quantization/passes/quantize_bias.py +123 -0
  55. tico/experimental/quantization/passes/remove_weight_dequant_op.py +177 -0
  56. tico/experimental/quantization/public_interface.py +108 -0
  57. tico/experimental/quantization/quantizer.py +71 -0
  58. tico/interpreter/__init__.py +1 -0
  59. tico/interpreter/infer.py +116 -0
  60. tico/interpreter/interpreter.py +93 -0
  61. tico/passes/__init__.py +1 -0
  62. tico/passes/cast_aten_where_arg_type.py +191 -0
  63. tico/passes/cast_mixed_type_args.py +187 -0
  64. tico/passes/const_prop_pass.py +307 -0
  65. tico/passes/convert_conv1d_to_conv2d.py +160 -0
  66. tico/passes/convert_layout_op_to_reshape.py +85 -0
  67. tico/passes/convert_repeat_to_expand_copy.py +89 -0
  68. tico/passes/convert_to_relu6.py +181 -0
  69. tico/passes/decompose_addmm.py +124 -0
  70. tico/passes/decompose_batch_norm.py +192 -0
  71. tico/passes/decompose_fake_quantize.py +134 -0
  72. tico/passes/decompose_fake_quantize_tensor_qparams.py +294 -0
  73. tico/passes/decompose_group_norm.py +275 -0
  74. tico/passes/decompose_grouped_conv2d.py +209 -0
  75. tico/passes/decompose_slice_scatter.py +169 -0
  76. tico/passes/extract_dtype_kwargs.py +122 -0
  77. tico/passes/fill_meta_val.py +57 -0
  78. tico/passes/fuse_leading_unsqueeze_reshape.py +112 -0
  79. tico/passes/fuse_redundant_reshape_to_mean.py +102 -0
  80. tico/passes/legalize_causal_mask_value.py +108 -0
  81. tico/passes/legalize_predefined_layout_operators.py +386 -0
  82. tico/passes/lower_pow2_to_mul.py +75 -0
  83. tico/passes/lower_to_resize_nearest_neighbor.py +235 -0
  84. tico/passes/lower_to_slice.py +230 -0
  85. tico/passes/merge_consecutive_cat.py +80 -0
  86. tico/passes/ops.py +78 -0
  87. tico/passes/remove_nop.py +84 -0
  88. tico/passes/remove_redundant_assert_nodes.py +51 -0
  89. tico/passes/remove_redundant_expand.py +66 -0
  90. tico/passes/remove_redundant_permute.py +122 -0
  91. tico/passes/remove_redundant_reshape.py +436 -0
  92. tico/passes/remove_redundant_slice.py +62 -0
  93. tico/passes/remove_redundant_to_copy.py +86 -0
  94. tico/passes/restore_linear.py +115 -0
  95. tico/passes/segment_index_select.py +145 -0
  96. tico/pt2_to_circle.py +105 -0
  97. tico/serialize/__init__.py +1 -0
  98. tico/serialize/circle_graph.py +319 -0
  99. tico/serialize/circle_mapping.py +177 -0
  100. tico/serialize/circle_serializer.py +240 -0
  101. tico/serialize/operators/__init__.py +28 -0
  102. tico/serialize/operators/hashable_opcode.py +43 -0
  103. tico/serialize/operators/node_visitor.py +80 -0
  104. tico/serialize/operators/op_abs.py +53 -0
  105. tico/serialize/operators/op_add.py +69 -0
  106. tico/serialize/operators/op_alias_copy.py +64 -0
  107. tico/serialize/operators/op_any.py +150 -0
  108. tico/serialize/operators/op_arange_start_step.py +61 -0
  109. tico/serialize/operators/op_argmax.py +62 -0
  110. tico/serialize/operators/op_avg_pool2d.py +192 -0
  111. tico/serialize/operators/op_bmm.py +62 -0
  112. tico/serialize/operators/op_cat.py +66 -0
  113. tico/serialize/operators/op_clamp.py +126 -0
  114. tico/serialize/operators/op_clone.py +71 -0
  115. tico/serialize/operators/op_constant_pad_nd.py +72 -0
  116. tico/serialize/operators/op_conv2d.py +186 -0
  117. tico/serialize/operators/op_copy.py +164 -0
  118. tico/serialize/operators/op_cos.py +59 -0
  119. tico/serialize/operators/op_cumsum.py +95 -0
  120. tico/serialize/operators/op_depthwise_conv2d.py +199 -0
  121. tico/serialize/operators/op_dequantize_per_channel.py +82 -0
  122. tico/serialize/operators/op_dequantize_per_tensor.py +64 -0
  123. tico/serialize/operators/op_div.py +62 -0
  124. tico/serialize/operators/op_embedding.py +60 -0
  125. tico/serialize/operators/op_eq.py +64 -0
  126. tico/serialize/operators/op_exp.py +60 -0
  127. tico/serialize/operators/op_expand.py +91 -0
  128. tico/serialize/operators/op_full.py +48 -0
  129. tico/serialize/operators/op_full_like.py +55 -0
  130. tico/serialize/operators/op_ge.py +54 -0
  131. tico/serialize/operators/op_gelu.py +59 -0
  132. tico/serialize/operators/op_gt.py +54 -0
  133. tico/serialize/operators/op_index.py +82 -0
  134. tico/serialize/operators/op_index_select.py +64 -0
  135. tico/serialize/operators/op_instance_norm.py +91 -0
  136. tico/serialize/operators/op_leaky_relu.py +60 -0
  137. tico/serialize/operators/op_linear.py +70 -0
  138. tico/serialize/operators/op_log.py +53 -0
  139. tico/serialize/operators/op_log1p.py +86 -0
  140. tico/serialize/operators/op_logical_and.py +63 -0
  141. tico/serialize/operators/op_logical_not.py +62 -0
  142. tico/serialize/operators/op_lt.py +61 -0
  143. tico/serialize/operators/op_max_dim.py +70 -0
  144. tico/serialize/operators/op_max_pool2d_with_indices.py +155 -0
  145. tico/serialize/operators/op_maximum.py +53 -0
  146. tico/serialize/operators/op_mean.py +66 -0
  147. tico/serialize/operators/op_minimum.py +53 -0
  148. tico/serialize/operators/op_mm.py +177 -0
  149. tico/serialize/operators/op_mul.py +99 -0
  150. tico/serialize/operators/op_ne.py +54 -0
  151. tico/serialize/operators/op_neg.py +59 -0
  152. tico/serialize/operators/op_permute.py +65 -0
  153. tico/serialize/operators/op_pow.py +141 -0
  154. tico/serialize/operators/op_prelu.py +54 -0
  155. tico/serialize/operators/op_quantize_per_tensor.py +79 -0
  156. tico/serialize/operators/op_reciprocal.py +64 -0
  157. tico/serialize/operators/op_relu.py +53 -0
  158. tico/serialize/operators/op_relu6.py +52 -0
  159. tico/serialize/operators/op_repeat.py +100 -0
  160. tico/serialize/operators/op_reshape.py +73 -0
  161. tico/serialize/operators/op_resize_nearest_neighbor.py +70 -0
  162. tico/serialize/operators/op_rsqrt.py +53 -0
  163. tico/serialize/operators/op_scalar_tensor.py +51 -0
  164. tico/serialize/operators/op_select_copy.py +65 -0
  165. tico/serialize/operators/op_sigmoid.py +56 -0
  166. tico/serialize/operators/op_sin.py +53 -0
  167. tico/serialize/operators/op_slice.py +155 -0
  168. tico/serialize/operators/op_softmax.py +100 -0
  169. tico/serialize/operators/op_split_with_sizes.py +99 -0
  170. tico/serialize/operators/op_sqrt.py +55 -0
  171. tico/serialize/operators/op_squeeze.py +73 -0
  172. tico/serialize/operators/op_sub.py +71 -0
  173. tico/serialize/operators/op_sum.py +63 -0
  174. tico/serialize/operators/op_tanh.py +54 -0
  175. tico/serialize/operators/op_to_copy.py +105 -0
  176. tico/serialize/operators/op_unsqueeze.py +66 -0
  177. tico/serialize/operators/op_view.py +74 -0
  178. tico/serialize/operators/op_where.py +82 -0
  179. tico/serialize/operators/utils.py +94 -0
  180. tico/serialize/pack.py +35 -0
  181. tico/serialize/quant_param.py +42 -0
  182. tico/utils/__init__.py +1 -0
  183. tico/utils/convert.py +296 -0
  184. tico/utils/define.py +35 -0
  185. tico/utils/diff_graph.py +181 -0
  186. tico/utils/errors.py +35 -0
  187. tico/utils/graph.py +282 -0
  188. tico/utils/logging.py +45 -0
  189. tico/utils/model.py +37 -0
  190. tico/utils/mx/__init__.py +1 -0
  191. tico/utils/mx/elemwise_ops.py +267 -0
  192. tico/utils/mx/formats.py +125 -0
  193. tico/utils/mx/mx_ops.py +270 -0
  194. tico/utils/padding.py +47 -0
  195. tico/utils/passes.py +76 -0
  196. tico/utils/register_custom_op.py +609 -0
  197. tico/utils/serialize.py +42 -0
  198. tico/utils/trace_decorators.py +101 -0
  199. tico/utils/utils.py +406 -0
  200. tico/utils/validate_args_kwargs.py +1149 -0
  201. tico-0.1.0.dist-info/LICENSE +241 -0
  202. tico-0.1.0.dist-info/METADATA +354 -0
  203. tico-0.1.0.dist-info/RECORD +206 -0
  204. tico-0.1.0.dist-info/WHEEL +5 -0
  205. tico-0.1.0.dist-info/entry_points.txt +3 -0
  206. tico-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,241 @@
1
+ This file provides full text of licenses used in this project
2
+
3
+ - Apache License 2.0
4
+ - BSD 3-Clause
5
+
6
+ ...............................................................................
7
+
8
+ Apache License
9
+ Version 2.0, January 2004
10
+ http://www.apache.org/licenses/
11
+
12
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
13
+
14
+ 1. Definitions.
15
+
16
+ "License" shall mean the terms and conditions for use, reproduction,
17
+ and distribution as defined by Sections 1 through 9 of this document.
18
+
19
+ "Licensor" shall mean the copyright owner or entity authorized by
20
+ the copyright owner that is granting the License.
21
+
22
+ "Legal Entity" shall mean the union of the acting entity and all
23
+ other entities that control, are controlled by, or are under common
24
+ control with that entity. For the purposes of this definition,
25
+ "control" means (i) the power, direct or indirect, to cause the
26
+ direction or management of such entity, whether by contract or
27
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
28
+ outstanding shares, or (iii) beneficial ownership of such entity.
29
+
30
+ "You" (or "Your") shall mean an individual or Legal Entity
31
+ exercising permissions granted by this License.
32
+
33
+ "Source" form shall mean the preferred form for making modifications,
34
+ including but not limited to software source code, documentation
35
+ source, and configuration files.
36
+
37
+ "Object" form shall mean any form resulting from mechanical
38
+ transformation or translation of a Source form, including but
39
+ not limited to compiled object code, generated documentation,
40
+ and conversions to other media types.
41
+
42
+ "Work" shall mean the work of authorship, whether in Source or
43
+ Object form, made available under the License, as indicated by a
44
+ copyright notice that is included in or attached to the work
45
+ (an example is provided in the Appendix below).
46
+
47
+ "Derivative Works" shall mean any work, whether in Source or Object
48
+ form, that is based on (or derived from) the Work and for which the
49
+ editorial revisions, annotations, elaborations, or other modifications
50
+ represent, as a whole, an original work of authorship. For the purposes
51
+ of this License, Derivative Works shall not include works that remain
52
+ separable from, or merely link (or bind by name) to the interfaces of,
53
+ the Work and Derivative Works thereof.
54
+
55
+ "Contribution" shall mean any work of authorship, including
56
+ the original version of the Work and any modifications or additions
57
+ to that Work or Derivative Works thereof, that is intentionally
58
+ submitted to Licensor for inclusion in the Work by the copyright owner
59
+ or by an individual or Legal Entity authorized to submit on behalf of
60
+ the copyright owner. For the purposes of this definition, "submitted"
61
+ means any form of electronic, verbal, or written communication sent
62
+ to the Licensor or its representatives, including but not limited to
63
+ communication on electronic mailing lists, source code control systems,
64
+ and issue tracking systems that are managed by, or on behalf of, the
65
+ Licensor for the purpose of discussing and improving the Work, but
66
+ excluding communication that is conspicuously marked or otherwise
67
+ designated in writing by the copyright owner as "Not a Contribution."
68
+
69
+ "Contributor" shall mean Licensor and any individual or Legal Entity
70
+ on behalf of whom a Contribution has been received by Licensor and
71
+ subsequently incorporated within the Work.
72
+
73
+ 2. Grant of Copyright License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ copyright license to reproduce, prepare Derivative Works of,
77
+ publicly display, publicly perform, sublicense, and distribute the
78
+ Work and such Derivative Works in Source or Object form.
79
+
80
+ 3. Grant of Patent License. Subject to the terms and conditions of
81
+ this License, each Contributor hereby grants to You a perpetual,
82
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
83
+ (except as stated in this section) patent license to make, have made,
84
+ use, offer to sell, sell, import, and otherwise transfer the Work,
85
+ where such license applies only to those patent claims licensable
86
+ by such Contributor that are necessarily infringed by their
87
+ Contribution(s) alone or by combination of their Contribution(s)
88
+ with the Work to which such Contribution(s) was submitted. If You
89
+ institute patent litigation against any entity (including a
90
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
91
+ or a Contribution incorporated within the Work constitutes direct
92
+ or contributory patent infringement, then any patent licenses
93
+ granted to You under this License for that Work shall terminate
94
+ as of the date such litigation is filed.
95
+
96
+ 4. Redistribution. You may reproduce and distribute copies of the
97
+ Work or Derivative Works thereof in any medium, with or without
98
+ modifications, and in Source or Object form, provided that You
99
+ meet the following conditions:
100
+
101
+ (a) You must give any other recipients of the Work or
102
+ Derivative Works a copy of this License; and
103
+
104
+ (b) You must cause any modified files to carry prominent notices
105
+ stating that You changed the files; and
106
+
107
+ (c) You must retain, in the Source form of any Derivative Works
108
+ that You distribute, all copyright, patent, trademark, and
109
+ attribution notices from the Source form of the Work,
110
+ excluding those notices that do not pertain to any part of
111
+ the Derivative Works; and
112
+
113
+ (d) If the Work includes a "NOTICE" text file as part of its
114
+ distribution, then any Derivative Works that You distribute must
115
+ include a readable copy of the attribution notices contained
116
+ within such NOTICE file, excluding those notices that do not
117
+ pertain to any part of the Derivative Works, in at least one
118
+ of the following places: within a NOTICE text file distributed
119
+ as part of the Derivative Works; within the Source form or
120
+ documentation, if provided along with the Derivative Works; or,
121
+ within a display generated by the Derivative Works, if and
122
+ wherever such third-party notices normally appear. The contents
123
+ of the NOTICE file are for informational purposes only and
124
+ do not modify the License. You may add Your own attribution
125
+ notices within Derivative Works that You distribute, alongside
126
+ or as an addendum to the NOTICE text from the Work, provided
127
+ that such additional attribution notices cannot be construed
128
+ as modifying the License.
129
+
130
+ You may add Your own copyright statement to Your modifications and
131
+ may provide additional or different license terms and conditions
132
+ for use, reproduction, or distribution of Your modifications, or
133
+ for any such Derivative Works as a whole, provided Your use,
134
+ reproduction, and distribution of the Work otherwise complies with
135
+ the conditions stated in this License.
136
+
137
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
138
+ any Contribution intentionally submitted for inclusion in the Work
139
+ by You to the Licensor shall be under the terms and conditions of
140
+ this License, without any additional terms or conditions.
141
+ Notwithstanding the above, nothing herein shall supersede or modify
142
+ the terms of any separate license agreement you may have executed
143
+ with Licensor regarding such Contributions.
144
+
145
+ 6. Trademarks. This License does not grant permission to use the trade
146
+ names, trademarks, service marks, or product names of the Licensor,
147
+ except as required for reasonable and customary use in describing the
148
+ origin of the Work and reproducing the content of the NOTICE file.
149
+
150
+ 7. Disclaimer of Warranty. Unless required by applicable law or
151
+ agreed to in writing, Licensor provides the Work (and each
152
+ Contributor provides its Contributions) on an "AS IS" BASIS,
153
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
154
+ implied, including, without limitation, any warranties or conditions
155
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
156
+ PARTICULAR PURPOSE. You are solely responsible for determining the
157
+ appropriateness of using or redistributing the Work and assume any
158
+ risks associated with Your exercise of permissions under this License.
159
+
160
+ 8. Limitation of Liability. In no event and under no legal theory,
161
+ whether in tort (including negligence), contract, or otherwise,
162
+ unless required by applicable law (such as deliberate and grossly
163
+ negligent acts) or agreed to in writing, shall any Contributor be
164
+ liable to You for damages, including any direct, indirect, special,
165
+ incidental, or consequential damages of any character arising as a
166
+ result of this License or out of the use or inability to use the
167
+ Work (including but not limited to damages for loss of goodwill,
168
+ work stoppage, computer failure or malfunction, or any and all
169
+ other commercial damages or losses), even if such Contributor
170
+ has been advised of the possibility of such damages.
171
+
172
+ 9. Accepting Warranty or Additional Liability. While redistributing
173
+ the Work or Derivative Works thereof, You may choose to offer,
174
+ and charge a fee for, acceptance of support, warranty, indemnity,
175
+ or other liability obligations and/or rights consistent with this
176
+ License. However, in accepting such obligations, You may act only
177
+ on Your own behalf and on Your sole responsibility, not on behalf
178
+ of any other Contributor, and only if You agree to indemnify,
179
+ defend, and hold each Contributor harmless for any liability
180
+ incurred by, or claims asserted against, such Contributor by reason
181
+ of your accepting any such warranty or additional liability.
182
+
183
+ END OF TERMS AND CONDITIONS
184
+
185
+ APPENDIX: How to apply the Apache License to your work.
186
+
187
+ To apply the Apache License to your work, attach the following
188
+ boilerplate notice, with the fields enclosed by brackets "[]"
189
+ replaced with your own identifying information. (Don't include
190
+ the brackets!) The text should be enclosed in the appropriate
191
+ comment syntax for the file format. We also recommend that a
192
+ file or class name and description of purpose be included on the
193
+ same "printed page" as the copyright notice for easier
194
+ identification within third-party archives.
195
+
196
+
197
+ Copyright [yyyy] [name of copyright owner]
198
+
199
+ Licensed under the Apache License, Version 2.0 (the "License");
200
+ you may not use this file except in compliance with the License.
201
+ You may obtain a copy of the License at
202
+
203
+ http://www.apache.org/licenses/LICENSE-2.0
204
+
205
+ Unless required by applicable law or agreed to in writing, software
206
+ distributed under the License is distributed on an "AS IS" BASIS,
207
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208
+ See the License for the specific language governing permissions and
209
+ limitations under the License.
210
+
211
+ ...............................................................................
212
+
213
+ The BSD 3-Clause License
214
+
215
+ Redistribution and use in source and binary forms, with or without
216
+ modification, are permitted provided that the following conditions are
217
+ met:
218
+
219
+ * Redistributions of source code must retain the above copyright
220
+ notice, this list of conditions and the following disclaimer.
221
+ * Redistributions in binary form must reproduce the above
222
+ copyright notice, this list of conditions and the following disclaimer
223
+ in the documentation and/or other materials provided with the
224
+ distribution.
225
+ * Neither the name of Google Inc. nor the names of its
226
+ contributors may be used to endorse or promote products derived from
227
+ this software without specific prior written permission.
228
+
229
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
230
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
231
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
232
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
233
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
234
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
235
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
237
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
238
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
239
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
240
+
241
+ .............................................................................
@@ -0,0 +1,354 @@
1
+ Metadata-Version: 2.1
2
+ Name: tico
3
+ Version: 0.1.0
4
+ Summary: Convert exported Torch module to circle
5
+ Home-page: UNKNOWN
6
+ License: UNKNOWN
7
+ Platform: UNKNOWN
8
+ Requires-Python: >=3.10.0
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: cffi
12
+ Requires-Dist: circle-schema
13
+ Requires-Dist: packaging
14
+ Requires-Dist: pyyaml
15
+ Requires-Dist: torch
16
+
17
+ # TICO
18
+
19
+ _TICO_ (Torch IR to Circle [ONE](https://github.com/Samsung/ONE)) is a python library for converting
20
+ Pytorch modules into a circle model that is a lightweight and efficient representation in ONE
21
+ designed for optimized on-device neural network inference.
22
+
23
+ ## Table of Contents
24
+
25
+ ### For Users
26
+
27
+ - [Installation](#installation)
28
+ - [Getting Started](#getting-started)
29
+ - [From torch module](#from-torch-module)
30
+ - [From .pt2](#from-pt2)
31
+ - [Running circle models directly in Python](#running-circle-models-directly-in-python)
32
+
33
+ ### For Developers
34
+
35
+ - [Testing & Code Formatting](#testing--code-formatting)
36
+ - [Testing](#testing)
37
+ - [Code Formatting](#code-formatting)
38
+
39
+ ## For Users
40
+
41
+ ### Installation
42
+
43
+ 0. Prerequisites
44
+
45
+ - Python 3.10
46
+ - [one-compiler nightly](https://github.com/Samsung/TICO/issues/2)
47
+ - This project depends on [ONE](https://github.com/Samsung/ONE) Compiler, and it uses
48
+ nightly features that are not yet available in the official release. Until one-compiler 1.30.0
49
+ is released, you must use a prebuilt nighlty version of ONE Compiler.
50
+
51
+ We highly recommend to use a virtual env, e.g., conda.
52
+
53
+ 1. Clone this repo
54
+
55
+ 2. Build python package
56
+
57
+ ```bash
58
+ ./ccex build
59
+ ```
60
+
61
+ This will generate `build` and `dist` directories in the root directory.
62
+
63
+ 3. Install generated package
64
+
65
+ ```bash
66
+ ./ccex install
67
+ ```
68
+
69
+ **Available options**
70
+ - `--dist` To install the package from .whl (without this option, _TICO_ is installed in an editable mode)
71
+ - `--torch_ver <torch version>` To install a specific torch version (default: 2.6).
72
+ - Available <torch version>: 2.5, 2.6, nightly
73
+
74
+ 4. Now you can convert a torch module to a `.circle`.
75
+
76
+ ### Getting started
77
+
78
+ This tutorial explains how you can use _TICO_ to generate a circle model from a torch module.
79
+
80
+ Let's assume we have a torch module.
81
+
82
+ ```python
83
+ import tico
84
+ import torch
85
+
86
+ class AddModule(torch.nn.Module):
87
+ def __init__(self):
88
+ super().__init__()
89
+
90
+ def forward(self, x, y):
91
+ return x + y
92
+ ```
93
+
94
+ **NOTE**
95
+ _TICO_ internally uses [torch.export](https://pytorch.org/docs/stable/export.html#torch-export).
96
+ Therefore, the torch module must be 'export'able. Please see
97
+ [this document](https://pytorch.org/docs/stable/export.html#limitations-of-torch-export)
98
+ if you have any trouble to export.
99
+
100
+ #### From torch module
101
+
102
+ You can convert a torch module to a circle model with these steps.
103
+
104
+ ```python
105
+ torch_module = AddModule()
106
+ example_inputs = (torch.ones(4), torch.ones(4))
107
+
108
+ circle_model = tico.convert(torch_module.eval(), example_inputs)
109
+ circle_model.save('add.circle')
110
+ ```
111
+
112
+ **NOTE**
113
+ Please make sure to call `eval()` on the PyTorch module before passing it to our API.
114
+ This ensures the model runs in inference mode, disabling layers like dropout and
115
+ batch normalization updates.
116
+
117
+ **Compile with configuration**
118
+
119
+ ```python
120
+ from test.modules.op.add import AddWithCausalMaskFolded
121
+
122
+ torch_module = AddWithCausalMaskFolded()
123
+ example_inputs = torch_module.get_example_inputs()
124
+
125
+ config = tico.CompileConfigV1()
126
+ config.legalize_causal_mask_value = True
127
+ circle_model = tico.convert(torch_module, example_inputs, config = config)
128
+ circle_model.save('add_causal_mask_m120.circle')
129
+ ```
130
+
131
+ With `legalize_causal_mask_value` option on, causal mask value is converted from
132
+ -inf to -120, creating a more quantization-friendly circle model with the cost of
133
+ slight accuracy drop.
134
+
135
+ #### From .pt2
136
+
137
+ The torch module can be exported and saved as `.pt2` file (from PyTorch 2.1).
138
+
139
+ ```python
140
+ module = AddModule()
141
+ example_inputs = (torch.ones(4), torch.ones(4))
142
+
143
+ exported_program = torch.export.export(module, example_inputs)
144
+ torch.export.save(exported_program, 'add.pt2')
145
+ ```
146
+
147
+ There are two ways to convert `.pt2` file: python api, command line tool.
148
+
149
+ - Python API
150
+
151
+ ```python
152
+ circle_model = tico.convert_from_pt2('add.pt2')
153
+ circle_model.save('add.circle')
154
+ ```
155
+
156
+ - Command Line Tool
157
+
158
+ ```bash
159
+ pt2-to-circle -i add.pt2 -o add.circle
160
+ ```
161
+
162
+ - Command Line Tool with configuration
163
+
164
+ ```bash
165
+ pt2-to-circle -i add.pt2 -o add.circle -c config.yaml
166
+ ```
167
+
168
+ ```yaml
169
+ # config.yaml
170
+
171
+ version: '1.0' # You must specify the config version.
172
+ legalize_causal_mask_value: True
173
+ ```
174
+
175
+ #### Running circle models directly in Python
176
+
177
+ After circle export, you can run the model directly in Python.
178
+
179
+ Note that you should install one-compiler package first.
180
+
181
+ The output types are numpy.ndarray.
182
+
183
+ ```python
184
+ torch_module = AddModule()
185
+ example_inputs = (torch.ones(4), torch.ones(4))
186
+
187
+ circle_model = tico.convert(torch_module, example_inputs)
188
+ circle_model(*example_inputs)
189
+ # numpy.ndarray([2., 2., 2., 2.], dtype=float32)
190
+ ```
191
+
192
+ ## For Developers
193
+
194
+ ### Testing & Code Formatting
195
+
196
+ Run below commands to configure testing or formatting environment.
197
+
198
+ Refer to the dedicated section to have more fine-grained control.
199
+
200
+ ```bash
201
+ $ ./ccex configure # to set up testing & formatting environment
202
+ $ ./ccex configure format # to set up only formatting environment
203
+ $ ./ccex configure test # to set up only testing environment
204
+ ```
205
+
206
+ **Available options**
207
+ - `--torch_ver <torch version>` To install a specific torch family package(ex. torchvision) version (default: 2.6)
208
+ - Available <torch version>: '2.5', '2.6', 'nightly'
209
+
210
+ ```bash
211
+ $ ./ccex configure # to set up testing & formatting environment with stable2.6.x version
212
+ $ ./ccex configure test # to set up only testing environment with stable 2.6.x version
213
+ $ ./ccex configure test --torch_ver 2.5 # to set up only testing environment with stable 2.5.x version
214
+ $ ./ccex configure test --torch_ver nightly # to set up only testing environment with nightly version
215
+ ```
216
+
217
+ ### Testing
218
+
219
+ #### Test congifure
220
+
221
+ Run below commands to install requirements for testing.
222
+
223
+ **NOTE** `TICO` will be installed in an editable mode.
224
+
225
+ ```bash
226
+ ./ccex configure test
227
+
228
+ # without editable install
229
+ ./ccex configure test --dist
230
+ ```
231
+
232
+ #### Test All
233
+
234
+ Run below commands to run the all unit tests.
235
+
236
+ **NOTE** Unit tests don't include model test.
237
+
238
+ ```bash
239
+ ./ccex test
240
+ # OR
241
+ ./ccex test run-all-tests
242
+ ```
243
+
244
+ #### Test Subset
245
+
246
+ To run subset of `test.modules.*`,
247
+ Run `./ccex test -k <keyword>`
248
+
249
+
250
+ For example, to run tests in specific sub-directory (op, net, ..)
251
+ ```bash
252
+ # To run tests in specific sub-directory (op/, net/ ..)
253
+ ./ccex test -k op
254
+ ./ccex test -k net
255
+
256
+ # To run tests in one file (single/op/add, single/op/sub, ...)
257
+ ./ccex test -k add
258
+ ./ccex test -k sub
259
+
260
+ # To run SimpleAdd test in test/modules/single/op/add.py
261
+ ./ccex test -k SimpleAdd
262
+ ```
263
+
264
+ To see the full debug log, add `-v` or `TICO_LOG=4`.
265
+
266
+ ```bash
267
+ TICO_LOG=4 ./ccex test -k add
268
+ # OR
269
+ ./ccex test -v -k add
270
+ ```
271
+
272
+ #### Test Model
273
+
274
+ If you want to test them locally, you can do so by navigating to each model directory,
275
+ installing the dependencies listed in its `requirements.txt`, and running the tests one by one.
276
+ ```bash
277
+ $ pip install -r test/modules/model/<model_name>/requirements.txt
278
+ # Run test for a single model
279
+ $ ./ccex test -m <model_name>
280
+ ```
281
+
282
+ For example, to run a single model
283
+ ```
284
+ ./ccex test -m InceptionV3
285
+ ```
286
+
287
+ #### Runtime Options
288
+
289
+ By default, `./ccex test` runs all modules with the `circle-interpreter` engine.
290
+ You can override this and run tests using the `onert` runtime instead.
291
+
292
+
293
+ ##### 0. Installing ONERT Nightly
294
+
295
+ Some ONERT features are only available in the nightly build until the next official release.
296
+ To install the ONERT wheel from the issue comment:
297
+
298
+ 1. Download the `.whl` file linked
299
+ in [the relevant Github issue comment](https://github.com/Samsung/TICO/issues/2#issuecomment-2841487306).
300
+ 2. Install it with pip, for example:
301
+
302
+ ```bash
303
+ pip install /path/to/onert_nightly.whl
304
+ ```
305
+
306
+ ##### 1. Command-Line Flag
307
+
308
+ Use the `--runtime` (or `-r`) flag to select a runtime:
309
+
310
+ ```bash
311
+ # Run with the default circle-interpreter
312
+ ./ccex test
313
+
314
+ # Run all tests with onert
315
+ ./ccex test --runtime onert
316
+ # or
317
+ ./ccex test -r onert
318
+ ```
319
+
320
+ ##### 2. Environment Variable
321
+
322
+ You can also set the `CCEX_RUNTIME` environment variable:
323
+
324
+ ```bash
325
+ # Temporarily override for one command
326
+ CCEX_RUNTIME=onert ./ccex test
327
+
328
+ # Persist in your shell session
329
+ export CCEX_RUNTIME=onert
330
+ ./ccex test
331
+ ```
332
+
333
+ ##### Supported Runtimes
334
+
335
+ - circle-interpreter (default): uses the Circle interpreter for inference.
336
+ - onert: uses the ONERT package for inference, useful when the Circle interpreter
337
+ cannot run a given module.
338
+
339
+ ### Code Formatting
340
+
341
+ #### Format configure
342
+
343
+ Run below commands to install requirements for formatting.
344
+
345
+ ```bash
346
+ ./ccex configure format
347
+ ```
348
+
349
+ #### Format run
350
+
351
+ ```bash
352
+ ./ccex format
353
+ ```
354
+