tico 0.1.0.dev251106__py3-none-any.whl → 0.2.0.dev260122__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 (56) hide show
  1. tico/__init__.py +2 -2
  2. tico/_version.py +1 -0
  3. tico/passes/convert_conv3d_to_conv2d.py +435 -0
  4. tico/passes/convert_sym_size_to_circle_shape.py +99 -0
  5. tico/passes/decompose_batch_norm.py +9 -5
  6. tico/passes/lower_copy.py +95 -0
  7. tico/passes/ops.py +4 -0
  8. tico/quantization/algorithm/fpi_gptq/fpi_gptq.py +251 -0
  9. tico/quantization/algorithm/fpi_gptq/quantizer.py +180 -0
  10. tico/quantization/algorithm/gptq/gptq.py +231 -11
  11. tico/quantization/algorithm/gptq/quantizer.py +18 -6
  12. tico/quantization/config/{pt2e.py → fpi_gptq.py} +11 -4
  13. tico/quantization/config/gptq.py +27 -4
  14. tico/quantization/public_interface.py +0 -10
  15. tico/quantization/wrapq/quantizer.py +2 -0
  16. tico/quantization/wrapq/wrappers/quant_elementwise.py +51 -11
  17. tico/serialize/operators/adapters/onert/llama_attention.py +51 -0
  18. tico/serialize/operators/op_attention.py +58 -0
  19. tico/serialize/operators/op_circle_shape.py +64 -0
  20. tico/serialize/operators/op_dequantize_per_channel.py +1 -0
  21. tico/serialize/operators/op_dequantize_per_tensor.py +1 -0
  22. tico/serialize/operators/op_transpose_conv.py +66 -50
  23. tico/utils/convert.py +16 -1
  24. tico/utils/padding.py +13 -5
  25. tico/utils/record_input.py +2 -2
  26. tico/utils/register_custom_op.py +63 -0
  27. tico/utils/validate_args_kwargs.py +49 -4
  28. tico-0.2.0.dev260122.dist-info/METADATA +631 -0
  29. {tico-0.1.0.dev251106.dist-info → tico-0.2.0.dev260122.dist-info}/RECORD +35 -46
  30. {tico-0.1.0.dev251106.dist-info → tico-0.2.0.dev260122.dist-info}/WHEEL +1 -1
  31. {tico-0.1.0.dev251106.dist-info → tico-0.2.0.dev260122.dist-info}/entry_points.txt +0 -1
  32. tico/quantization/algorithm/pt2e/annotation/annotator.py +0 -208
  33. tico/quantization/algorithm/pt2e/annotation/config.py +0 -26
  34. tico/quantization/algorithm/pt2e/annotation/op/__init__.py +0 -21
  35. tico/quantization/algorithm/pt2e/annotation/op/adaptive_avg_pool2d.py +0 -63
  36. tico/quantization/algorithm/pt2e/annotation/op/add.py +0 -55
  37. tico/quantization/algorithm/pt2e/annotation/op/conv2d.py +0 -90
  38. tico/quantization/algorithm/pt2e/annotation/op/div.py +0 -55
  39. tico/quantization/algorithm/pt2e/annotation/op/linear.py +0 -92
  40. tico/quantization/algorithm/pt2e/annotation/op/mean.py +0 -51
  41. tico/quantization/algorithm/pt2e/annotation/op/mul.py +0 -55
  42. tico/quantization/algorithm/pt2e/annotation/op/relu6.py +0 -51
  43. tico/quantization/algorithm/pt2e/annotation/op/rsqrt.py +0 -51
  44. tico/quantization/algorithm/pt2e/annotation/op/sub.py +0 -55
  45. tico/quantization/algorithm/pt2e/annotation/spec.py +0 -45
  46. tico/quantization/algorithm/pt2e/annotation/utils.py +0 -88
  47. tico/quantization/algorithm/pt2e/quantizer.py +0 -81
  48. tico/quantization/algorithm/pt2e/transformation/__init__.py +0 -1
  49. tico/quantization/algorithm/pt2e/transformation/convert_scalars_to_attrs.py +0 -58
  50. tico/quantization/algorithm/pt2e/utils.py +0 -135
  51. tico/serialize/operators/op_copy.py +0 -187
  52. tico-0.1.0.dev251106.dist-info/METADATA +0 -392
  53. /tico/quantization/algorithm/{pt2e → fpi_gptq}/__init__.py +0 -0
  54. /tico/{quantization/algorithm/pt2e/annotation → serialize/operators/adapters/onert}/__init__.py +0 -0
  55. {tico-0.1.0.dev251106.dist-info → tico-0.2.0.dev260122.dist-info/licenses}/LICENSE +0 -0
  56. {tico-0.1.0.dev251106.dist-info → tico-0.2.0.dev260122.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,631 @@
1
+ Metadata-Version: 2.4
2
+ Name: tico
3
+ Version: 0.2.0.dev260122
4
+ Summary: Convert Exported Torch Module To Circle
5
+ License: This file provides full text of licenses used in this project
6
+
7
+ - Apache License 2.0
8
+ - BSD 3-Clause
9
+
10
+ ...............................................................................
11
+
12
+ Apache License
13
+ Version 2.0, January 2004
14
+ http://www.apache.org/licenses/
15
+
16
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
17
+
18
+ 1. Definitions.
19
+
20
+ "License" shall mean the terms and conditions for use, reproduction,
21
+ and distribution as defined by Sections 1 through 9 of this document.
22
+
23
+ "Licensor" shall mean the copyright owner or entity authorized by
24
+ the copyright owner that is granting the License.
25
+
26
+ "Legal Entity" shall mean the union of the acting entity and all
27
+ other entities that control, are controlled by, or are under common
28
+ control with that entity. For the purposes of this definition,
29
+ "control" means (i) the power, direct or indirect, to cause the
30
+ direction or management of such entity, whether by contract or
31
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
32
+ outstanding shares, or (iii) beneficial ownership of such entity.
33
+
34
+ "You" (or "Your") shall mean an individual or Legal Entity
35
+ exercising permissions granted by this License.
36
+
37
+ "Source" form shall mean the preferred form for making modifications,
38
+ including but not limited to software source code, documentation
39
+ source, and configuration files.
40
+
41
+ "Object" form shall mean any form resulting from mechanical
42
+ transformation or translation of a Source form, including but
43
+ not limited to compiled object code, generated documentation,
44
+ and conversions to other media types.
45
+
46
+ "Work" shall mean the work of authorship, whether in Source or
47
+ Object form, made available under the License, as indicated by a
48
+ copyright notice that is included in or attached to the work
49
+ (an example is provided in the Appendix below).
50
+
51
+ "Derivative Works" shall mean any work, whether in Source or Object
52
+ form, that is based on (or derived from) the Work and for which the
53
+ editorial revisions, annotations, elaborations, or other modifications
54
+ represent, as a whole, an original work of authorship. For the purposes
55
+ of this License, Derivative Works shall not include works that remain
56
+ separable from, or merely link (or bind by name) to the interfaces of,
57
+ the Work and Derivative Works thereof.
58
+
59
+ "Contribution" shall mean any work of authorship, including
60
+ the original version of the Work and any modifications or additions
61
+ to that Work or Derivative Works thereof, that is intentionally
62
+ submitted to Licensor for inclusion in the Work by the copyright owner
63
+ or by an individual or Legal Entity authorized to submit on behalf of
64
+ the copyright owner. For the purposes of this definition, "submitted"
65
+ means any form of electronic, verbal, or written communication sent
66
+ to the Licensor or its representatives, including but not limited to
67
+ communication on electronic mailing lists, source code control systems,
68
+ and issue tracking systems that are managed by, or on behalf of, the
69
+ Licensor for the purpose of discussing and improving the Work, but
70
+ excluding communication that is conspicuously marked or otherwise
71
+ designated in writing by the copyright owner as "Not a Contribution."
72
+
73
+ "Contributor" shall mean Licensor and any individual or Legal Entity
74
+ on behalf of whom a Contribution has been received by Licensor and
75
+ subsequently incorporated within the Work.
76
+
77
+ 2. Grant of Copyright License. Subject to the terms and conditions of
78
+ this License, each Contributor hereby grants to You a perpetual,
79
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
80
+ copyright license to reproduce, prepare Derivative Works of,
81
+ publicly display, publicly perform, sublicense, and distribute the
82
+ Work and such Derivative Works in Source or Object form.
83
+
84
+ 3. Grant of Patent License. Subject to the terms and conditions of
85
+ this License, each Contributor hereby grants to You a perpetual,
86
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
87
+ (except as stated in this section) patent license to make, have made,
88
+ use, offer to sell, sell, import, and otherwise transfer the Work,
89
+ where such license applies only to those patent claims licensable
90
+ by such Contributor that are necessarily infringed by their
91
+ Contribution(s) alone or by combination of their Contribution(s)
92
+ with the Work to which such Contribution(s) was submitted. If You
93
+ institute patent litigation against any entity (including a
94
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
95
+ or a Contribution incorporated within the Work constitutes direct
96
+ or contributory patent infringement, then any patent licenses
97
+ granted to You under this License for that Work shall terminate
98
+ as of the date such litigation is filed.
99
+
100
+ 4. Redistribution. You may reproduce and distribute copies of the
101
+ Work or Derivative Works thereof in any medium, with or without
102
+ modifications, and in Source or Object form, provided that You
103
+ meet the following conditions:
104
+
105
+ (a) You must give any other recipients of the Work or
106
+ Derivative Works a copy of this License; and
107
+
108
+ (b) You must cause any modified files to carry prominent notices
109
+ stating that You changed the files; and
110
+
111
+ (c) You must retain, in the Source form of any Derivative Works
112
+ that You distribute, all copyright, patent, trademark, and
113
+ attribution notices from the Source form of the Work,
114
+ excluding those notices that do not pertain to any part of
115
+ the Derivative Works; and
116
+
117
+ (d) If the Work includes a "NOTICE" text file as part of its
118
+ distribution, then any Derivative Works that You distribute must
119
+ include a readable copy of the attribution notices contained
120
+ within such NOTICE file, excluding those notices that do not
121
+ pertain to any part of the Derivative Works, in at least one
122
+ of the following places: within a NOTICE text file distributed
123
+ as part of the Derivative Works; within the Source form or
124
+ documentation, if provided along with the Derivative Works; or,
125
+ within a display generated by the Derivative Works, if and
126
+ wherever such third-party notices normally appear. The contents
127
+ of the NOTICE file are for informational purposes only and
128
+ do not modify the License. You may add Your own attribution
129
+ notices within Derivative Works that You distribute, alongside
130
+ or as an addendum to the NOTICE text from the Work, provided
131
+ that such additional attribution notices cannot be construed
132
+ as modifying the License.
133
+
134
+ You may add Your own copyright statement to Your modifications and
135
+ may provide additional or different license terms and conditions
136
+ for use, reproduction, or distribution of Your modifications, or
137
+ for any such Derivative Works as a whole, provided Your use,
138
+ reproduction, and distribution of the Work otherwise complies with
139
+ the conditions stated in this License.
140
+
141
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
142
+ any Contribution intentionally submitted for inclusion in the Work
143
+ by You to the Licensor shall be under the terms and conditions of
144
+ this License, without any additional terms or conditions.
145
+ Notwithstanding the above, nothing herein shall supersede or modify
146
+ the terms of any separate license agreement you may have executed
147
+ with Licensor regarding such Contributions.
148
+
149
+ 6. Trademarks. This License does not grant permission to use the trade
150
+ names, trademarks, service marks, or product names of the Licensor,
151
+ except as required for reasonable and customary use in describing the
152
+ origin of the Work and reproducing the content of the NOTICE file.
153
+
154
+ 7. Disclaimer of Warranty. Unless required by applicable law or
155
+ agreed to in writing, Licensor provides the Work (and each
156
+ Contributor provides its Contributions) on an "AS IS" BASIS,
157
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
158
+ implied, including, without limitation, any warranties or conditions
159
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
160
+ PARTICULAR PURPOSE. You are solely responsible for determining the
161
+ appropriateness of using or redistributing the Work and assume any
162
+ risks associated with Your exercise of permissions under this License.
163
+
164
+ 8. Limitation of Liability. In no event and under no legal theory,
165
+ whether in tort (including negligence), contract, or otherwise,
166
+ unless required by applicable law (such as deliberate and grossly
167
+ negligent acts) or agreed to in writing, shall any Contributor be
168
+ liable to You for damages, including any direct, indirect, special,
169
+ incidental, or consequential damages of any character arising as a
170
+ result of this License or out of the use or inability to use the
171
+ Work (including but not limited to damages for loss of goodwill,
172
+ work stoppage, computer failure or malfunction, or any and all
173
+ other commercial damages or losses), even if such Contributor
174
+ has been advised of the possibility of such damages.
175
+
176
+ 9. Accepting Warranty or Additional Liability. While redistributing
177
+ the Work or Derivative Works thereof, You may choose to offer,
178
+ and charge a fee for, acceptance of support, warranty, indemnity,
179
+ or other liability obligations and/or rights consistent with this
180
+ License. However, in accepting such obligations, You may act only
181
+ on Your own behalf and on Your sole responsibility, not on behalf
182
+ of any other Contributor, and only if You agree to indemnify,
183
+ defend, and hold each Contributor harmless for any liability
184
+ incurred by, or claims asserted against, such Contributor by reason
185
+ of your accepting any such warranty or additional liability.
186
+
187
+ END OF TERMS AND CONDITIONS
188
+
189
+ APPENDIX: How to apply the Apache License to your work.
190
+
191
+ To apply the Apache License to your work, attach the following
192
+ boilerplate notice, with the fields enclosed by brackets "[]"
193
+ replaced with your own identifying information. (Don't include
194
+ the brackets!) The text should be enclosed in the appropriate
195
+ comment syntax for the file format. We also recommend that a
196
+ file or class name and description of purpose be included on the
197
+ same "printed page" as the copyright notice for easier
198
+ identification within third-party archives.
199
+
200
+
201
+ Copyright [yyyy] [name of copyright owner]
202
+
203
+ Licensed under the Apache License, Version 2.0 (the "License");
204
+ you may not use this file except in compliance with the License.
205
+ You may obtain a copy of the License at
206
+
207
+ http://www.apache.org/licenses/LICENSE-2.0
208
+
209
+ Unless required by applicable law or agreed to in writing, software
210
+ distributed under the License is distributed on an "AS IS" BASIS,
211
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
212
+ See the License for the specific language governing permissions and
213
+ limitations under the License.
214
+
215
+ ...............................................................................
216
+
217
+ The BSD 3-Clause License
218
+
219
+ Redistribution and use in source and binary forms, with or without
220
+ modification, are permitted provided that the following conditions are
221
+ met:
222
+
223
+ * Redistributions of source code must retain the above copyright
224
+ notice, this list of conditions and the following disclaimer.
225
+ * Redistributions in binary form must reproduce the above
226
+ copyright notice, this list of conditions and the following disclaimer
227
+ in the documentation and/or other materials provided with the
228
+ distribution.
229
+ * Neither the name of Google Inc. nor the names of its
230
+ contributors may be used to endorse or promote products derived from
231
+ this software without specific prior written permission.
232
+
233
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
234
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
235
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
236
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
237
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
238
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
239
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
240
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
243
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
244
+
245
+ .............................................................................
246
+
247
+ Requires-Python: >=3.10.0
248
+ Description-Content-Type: text/markdown
249
+ License-File: LICENSE
250
+ Requires-Dist: circle-schema
251
+ Requires-Dist: packaging
252
+ Requires-Dist: cffi
253
+ Requires-Dist: torch
254
+ Requires-Dist: pyyaml
255
+ Requires-Dist: tqdm
256
+ Dynamic: license-file
257
+
258
+ # TICO
259
+
260
+ _TICO_ (Torch IR to Circle [ONE](https://github.com/Samsung/ONE)) is a python library for converting
261
+ Pytorch modules into a circle model that is a lightweight and efficient representation in ONE
262
+ designed for optimized on-device neural network inference.
263
+
264
+ ## Table of Contents
265
+
266
+ ### For Users
267
+
268
+ - [Installation](#installation)
269
+ - [Getting Started](#getting-started)
270
+ - [From torch module](#from-torch-module)
271
+ - [From .pt2](#from-pt2)
272
+ - [Running circle models directly in Python](#running-circle-models-directly-in-python)
273
+ - [Quantization](#quantization)
274
+
275
+ ### For Developers
276
+
277
+ - [Testing & Code Formatting](#testing--code-formatting)
278
+ - [Testing](#testing)
279
+ - [Code Formatting](#code-formatting)
280
+
281
+ ## For Users
282
+
283
+ ### Installation
284
+
285
+ 0. Prerequisites
286
+
287
+ - Python 3.10
288
+ - (Optional) [one-compiler 1.30.0](https://github.com/Samsung/ONE/releases/tag/1.30.0)
289
+ - It is only required if you intend to run inference with the converted Circle model. If you are only converting models without running them, this dependency is not needed.
290
+
291
+ We highly recommend to use a virtual env, e.g., conda.
292
+
293
+ 1. Clone this repo
294
+
295
+ 2. Build python package
296
+
297
+ ```bash
298
+ ./ccex build
299
+ ```
300
+
301
+ This will generate `build` and `dist` directories in the root directory.
302
+
303
+ 3. Install generated package
304
+
305
+ ```bash
306
+ ./ccex install
307
+ ```
308
+
309
+ **Available options**
310
+ - `--dist` To install the package from .whl (without this option, _TICO_ is installed in an editable mode)
311
+ - `--torch_ver <torch version>` To install a specific torch version (default: 2.6).
312
+ - Available <torch version>: 2.5, 2.6, 2.7, 2.8, nightly
313
+
314
+ 4. Now you can convert a torch module to a `.circle`.
315
+
316
+ ### Getting started
317
+
318
+ This tutorial explains how you can use _TICO_ to generate a circle model from a torch module.
319
+
320
+ Let's assume we have a torch module.
321
+
322
+ ```python
323
+ import tico
324
+ import torch
325
+
326
+ class AddModule(torch.nn.Module):
327
+ def __init__(self):
328
+ super().__init__()
329
+
330
+ def forward(self, x, y):
331
+ return x + y
332
+ ```
333
+
334
+ **NOTE**
335
+ _TICO_ internally uses [torch.export](https://pytorch.org/docs/stable/export.html#torch-export).
336
+ Therefore, the torch module must be 'export'able. Please see
337
+ [this document](https://pytorch.org/docs/stable/export.html#limitations-of-torch-export)
338
+ if you have any trouble to export.
339
+
340
+ #### From torch module
341
+
342
+ You can convert a torch module to a circle model with these steps.
343
+
344
+ ```python
345
+ torch_module = AddModule()
346
+ example_inputs = (torch.ones(4), torch.ones(4))
347
+
348
+ circle_model = tico.convert(torch_module.eval(), example_inputs)
349
+ circle_model.save('add.circle')
350
+ ```
351
+
352
+ **NOTE**
353
+ Please make sure to call `eval()` on the PyTorch module before passing it to our API.
354
+ This ensures the model runs in inference mode, disabling layers like dropout and
355
+ batch normalization updates.
356
+
357
+ **Compile with configuration**
358
+
359
+ ```python
360
+ from test.modules.op.add import AddWithCausalMaskFolded
361
+
362
+ torch_module = AddWithCausalMaskFolded()
363
+ example_inputs = torch_module.get_example_inputs()
364
+
365
+ config = tico.CompileConfigV1()
366
+ config.legalize_causal_mask_value = True
367
+ circle_model = tico.convert(torch_module, example_inputs, config = config)
368
+ circle_model.save('add_causal_mask_m120.circle')
369
+ ```
370
+
371
+ With `legalize_causal_mask_value` option on, causal mask value is converted from
372
+ -inf to -120, creating a more quantization-friendly circle model with the cost of
373
+ slight accuracy drop.
374
+
375
+ #### From .pt2
376
+
377
+ The torch module can be exported and saved as `.pt2` file (from PyTorch 2.1).
378
+
379
+ ```python
380
+ module = AddModule()
381
+ example_inputs = (torch.ones(4), torch.ones(4))
382
+
383
+ exported_program = torch.export.export(module, example_inputs)
384
+ torch.export.save(exported_program, 'add.pt2')
385
+ ```
386
+
387
+ There are two ways to convert `.pt2` file: python api, command line tool.
388
+
389
+ - Python API
390
+
391
+ ```python
392
+ circle_model = tico.convert_from_pt2('add.pt2')
393
+ circle_model.save('add.circle')
394
+ ```
395
+
396
+ - Command Line Tool
397
+
398
+ ```bash
399
+ pt2-to-circle -i add.pt2 -o add.circle
400
+ ```
401
+
402
+ - Command Line Tool with configuration
403
+
404
+ ```bash
405
+ pt2-to-circle -i add.pt2 -o add.circle -c config.yaml
406
+ ```
407
+
408
+ ```yaml
409
+ # config.yaml
410
+
411
+ version: '1.0' # You must specify the config version.
412
+ legalize_causal_mask_value: True
413
+ ```
414
+
415
+ #### Running circle models directly in Python
416
+
417
+ After circle export, you can run the model directly in Python.
418
+
419
+ Note that you should install one-compiler package first.
420
+
421
+ The output types are numpy.ndarray.
422
+
423
+ ```python
424
+ torch_module = AddModule()
425
+ example_inputs = (torch.ones(4), torch.ones(4))
426
+
427
+ circle_model = tico.convert(torch_module, example_inputs)
428
+ circle_model(*example_inputs)
429
+ # numpy.ndarray([2., 2., 2., 2.], dtype=float32)
430
+ ```
431
+
432
+ ### Quantization
433
+
434
+ The `tico.quantization` module provides a unified and modular interface for quantizing
435
+ large language models (LLMs) and other neural networks.
436
+
437
+ It introduces a simple two-step workflow — **prepare** and **convert** — that
438
+ abstracts the details of different quantization algorithms.
439
+
440
+ #### Basic Usage
441
+
442
+ ```python
443
+ from tico.quantization import prepare, convert
444
+ from tico.quantization.config.gptq import GPTQConfig
445
+ import torch
446
+ import torch.nn as nn
447
+
448
+ class LinearModel(nn.Module):
449
+ def __init__(self):
450
+ super().__init__()
451
+ self.linear = nn.Linear(8, 8)
452
+
453
+ def forward(self, x):
454
+ return self.linear(x)
455
+
456
+ model = LinearModel().eval()
457
+
458
+ # 1. Prepare for quantization
459
+ quant_config = GPTQConfig()
460
+ prepared_model = prepare(model, quant_config)
461
+
462
+ # 2. Calibration
463
+ for d in dataset:
464
+ prepared_model(d)
465
+
466
+ # 3. Apply GPTQ
467
+ quantized_model = convert(prepared_model, quant_config)
468
+ ```
469
+
470
+ For detailed documentation, design notes, and contributing guidelines,
471
+ see [tico/quantization/README.md](./tico/quantization/README.md).
472
+
473
+
474
+ ## For Developers
475
+
476
+ ### Testing & Code Formatting
477
+
478
+ Run below commands to configure testing or formatting environment.
479
+
480
+ Refer to the dedicated section to have more fine-grained control.
481
+
482
+ ```bash
483
+ $ ./ccex configure # to set up testing & formatting environment
484
+ $ ./ccex configure format # to set up only formatting environment
485
+ $ ./ccex configure test # to set up only testing environment
486
+ ```
487
+
488
+ **Available options**
489
+ - `--torch_ver <torch version>` To install a specific torch family package(ex. torchvision) version (default: 2.6)
490
+ - Available <torch version>: '2.5', '2.6', 'nightly'
491
+
492
+ ```bash
493
+ $ ./ccex configure # to set up testing & formatting environment with stable2.6.x version
494
+ $ ./ccex configure test # to set up only testing environment with stable 2.6.x version
495
+ $ ./ccex configure test --torch_ver 2.5 # to set up only testing environment with stable 2.5.x version
496
+ $ ./ccex configure test --torch_ver nightly # to set up only testing environment with nightly version
497
+ ```
498
+
499
+ ### Testing
500
+
501
+ #### Test congifure
502
+
503
+ Run below commands to install requirements for testing.
504
+
505
+ **NOTE** `TICO` will be installed in an editable mode.
506
+
507
+ ```bash
508
+ ./ccex configure test
509
+
510
+ # without editable install
511
+ ./ccex configure test --dist
512
+ ```
513
+
514
+ #### Test All
515
+
516
+ Run below commands to run the all unit tests.
517
+
518
+ **NOTE** Unit tests don't include model test.
519
+
520
+ ```bash
521
+ ./ccex test
522
+ # OR
523
+ ./ccex test run-all-tests
524
+ ```
525
+
526
+ #### Test Subset
527
+
528
+ To run subset of `test.modules.*`,
529
+ Run `./ccex test -k <keyword>`
530
+
531
+
532
+ For example, to run tests in specific sub-directory (op, net, ..)
533
+ ```bash
534
+ # To run tests in specific sub-directory (op/, net/ ..)
535
+ ./ccex test -k op
536
+ ./ccex test -k net
537
+
538
+ # To run tests in one file (single/op/add, single/op/sub, ...)
539
+ ./ccex test -k add
540
+ ./ccex test -k sub
541
+
542
+ # To run SimpleAdd test in test/modules/single/op/add.py
543
+ ./ccex test -k SimpleAdd
544
+ ```
545
+
546
+ To see the full debug log, add `-v` or `TICO_LOG=4`.
547
+
548
+ ```bash
549
+ TICO_LOG=4 ./ccex test -k add
550
+ # OR
551
+ ./ccex test -v -k add
552
+ ```
553
+
554
+ #### Test Model
555
+
556
+ If you want to test them locally, you can do so by navigating to each model directory,
557
+ installing the dependencies listed in its `requirements.txt`, and running the tests one by one.
558
+ ```bash
559
+ $ pip install -r test/modules/model/<model_name>/requirements.txt
560
+ # Run test for a single model
561
+ $ ./ccex test -m <model_name>
562
+ # Run models whose names contain "Llama" (e.g., Llama, LlamaDecoderLayer, LlamaWithGQA, etc.)
563
+ # Note that you should use quotes for the wildcard(*) pattern
564
+ $ ./ccex test -m "Llama*"
565
+ ```
566
+
567
+ For example, to run a single model
568
+ ```
569
+ ./ccex test -m InceptionV3
570
+ ```
571
+
572
+ #### Runtime Options
573
+
574
+ By default, `./ccex test` runs all modules with the `circle-interpreter` engine.
575
+ You can override this and run tests using the `onert` runtime instead.
576
+
577
+
578
+ ##### 0. Install ONERT
579
+
580
+ ```bash
581
+ pip install onert
582
+ ```
583
+
584
+ ##### 1. Command-Line Flag
585
+
586
+ Use the `--runtime` (or `-r`) flag to select a runtime:
587
+
588
+ ```bash
589
+ # Run with the default circle-interpreter
590
+ ./ccex test
591
+
592
+ # Run all tests with onert
593
+ ./ccex test --runtime onert
594
+ # or
595
+ ./ccex test -r onert
596
+ ```
597
+
598
+ ##### 2. Environment Variable
599
+
600
+ You can also set the `CCEX_RUNTIME` environment variable:
601
+
602
+ ```bash
603
+ # Temporarily override for one command
604
+ CCEX_RUNTIME=onert ./ccex test
605
+
606
+ # Persist in your shell session
607
+ export CCEX_RUNTIME=onert
608
+ ./ccex test
609
+ ```
610
+
611
+ ##### Supported Runtimes
612
+
613
+ - circle-interpreter (default): uses the Circle interpreter for inference.
614
+ - onert: uses the ONERT package for inference, useful when the Circle interpreter
615
+ cannot run a given module.
616
+
617
+ ### Code Formatting
618
+
619
+ #### Format configure
620
+
621
+ Run below commands to install requirements for formatting.
622
+
623
+ ```bash
624
+ ./ccex configure format
625
+ ```
626
+
627
+ #### Format run
628
+
629
+ ```bash
630
+ ./ccex format
631
+ ```