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.
- tico/__init__.py +2 -2
- tico/_version.py +1 -0
- tico/passes/convert_conv3d_to_conv2d.py +435 -0
- tico/passes/convert_sym_size_to_circle_shape.py +99 -0
- tico/passes/decompose_batch_norm.py +9 -5
- tico/passes/lower_copy.py +95 -0
- tico/passes/ops.py +4 -0
- tico/quantization/algorithm/fpi_gptq/fpi_gptq.py +251 -0
- tico/quantization/algorithm/fpi_gptq/quantizer.py +180 -0
- tico/quantization/algorithm/gptq/gptq.py +231 -11
- tico/quantization/algorithm/gptq/quantizer.py +18 -6
- tico/quantization/config/{pt2e.py → fpi_gptq.py} +11 -4
- tico/quantization/config/gptq.py +27 -4
- tico/quantization/public_interface.py +0 -10
- tico/quantization/wrapq/quantizer.py +2 -0
- tico/quantization/wrapq/wrappers/quant_elementwise.py +51 -11
- tico/serialize/operators/adapters/onert/llama_attention.py +51 -0
- tico/serialize/operators/op_attention.py +58 -0
- tico/serialize/operators/op_circle_shape.py +64 -0
- tico/serialize/operators/op_dequantize_per_channel.py +1 -0
- tico/serialize/operators/op_dequantize_per_tensor.py +1 -0
- tico/serialize/operators/op_transpose_conv.py +66 -50
- tico/utils/convert.py +16 -1
- tico/utils/padding.py +13 -5
- tico/utils/record_input.py +2 -2
- tico/utils/register_custom_op.py +63 -0
- tico/utils/validate_args_kwargs.py +49 -4
- tico-0.2.0.dev260122.dist-info/METADATA +631 -0
- {tico-0.1.0.dev251106.dist-info → tico-0.2.0.dev260122.dist-info}/RECORD +35 -46
- {tico-0.1.0.dev251106.dist-info → tico-0.2.0.dev260122.dist-info}/WHEEL +1 -1
- {tico-0.1.0.dev251106.dist-info → tico-0.2.0.dev260122.dist-info}/entry_points.txt +0 -1
- tico/quantization/algorithm/pt2e/annotation/annotator.py +0 -208
- tico/quantization/algorithm/pt2e/annotation/config.py +0 -26
- tico/quantization/algorithm/pt2e/annotation/op/__init__.py +0 -21
- tico/quantization/algorithm/pt2e/annotation/op/adaptive_avg_pool2d.py +0 -63
- tico/quantization/algorithm/pt2e/annotation/op/add.py +0 -55
- tico/quantization/algorithm/pt2e/annotation/op/conv2d.py +0 -90
- tico/quantization/algorithm/pt2e/annotation/op/div.py +0 -55
- tico/quantization/algorithm/pt2e/annotation/op/linear.py +0 -92
- tico/quantization/algorithm/pt2e/annotation/op/mean.py +0 -51
- tico/quantization/algorithm/pt2e/annotation/op/mul.py +0 -55
- tico/quantization/algorithm/pt2e/annotation/op/relu6.py +0 -51
- tico/quantization/algorithm/pt2e/annotation/op/rsqrt.py +0 -51
- tico/quantization/algorithm/pt2e/annotation/op/sub.py +0 -55
- tico/quantization/algorithm/pt2e/annotation/spec.py +0 -45
- tico/quantization/algorithm/pt2e/annotation/utils.py +0 -88
- tico/quantization/algorithm/pt2e/quantizer.py +0 -81
- tico/quantization/algorithm/pt2e/transformation/__init__.py +0 -1
- tico/quantization/algorithm/pt2e/transformation/convert_scalars_to_attrs.py +0 -58
- tico/quantization/algorithm/pt2e/utils.py +0 -135
- tico/serialize/operators/op_copy.py +0 -187
- tico-0.1.0.dev251106.dist-info/METADATA +0 -392
- /tico/quantization/algorithm/{pt2e → fpi_gptq}/__init__.py +0 -0
- /tico/{quantization/algorithm/pt2e/annotation → serialize/operators/adapters/onert}/__init__.py +0 -0
- {tico-0.1.0.dev251106.dist-info → tico-0.2.0.dev260122.dist-info/licenses}/LICENSE +0 -0
- {tico-0.1.0.dev251106.dist-info → tico-0.2.0.dev260122.dist-info}/top_level.txt +0 -0
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: tico
|
|
3
|
-
Version: 0.1.0.dev251106
|
|
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
|
-
Requires-Dist: tqdm
|
|
17
|
-
|
|
18
|
-
# TICO
|
|
19
|
-
|
|
20
|
-
_TICO_ (Torch IR to Circle [ONE](https://github.com/Samsung/ONE)) is a python library for converting
|
|
21
|
-
Pytorch modules into a circle model that is a lightweight and efficient representation in ONE
|
|
22
|
-
designed for optimized on-device neural network inference.
|
|
23
|
-
|
|
24
|
-
## Table of Contents
|
|
25
|
-
|
|
26
|
-
### For Users
|
|
27
|
-
|
|
28
|
-
- [Installation](#installation)
|
|
29
|
-
- [Getting Started](#getting-started)
|
|
30
|
-
- [From torch module](#from-torch-module)
|
|
31
|
-
- [From .pt2](#from-pt2)
|
|
32
|
-
- [Running circle models directly in Python](#running-circle-models-directly-in-python)
|
|
33
|
-
- [Quantization](#quantization)
|
|
34
|
-
|
|
35
|
-
### For Developers
|
|
36
|
-
|
|
37
|
-
- [Testing & Code Formatting](#testing--code-formatting)
|
|
38
|
-
- [Testing](#testing)
|
|
39
|
-
- [Code Formatting](#code-formatting)
|
|
40
|
-
|
|
41
|
-
## For Users
|
|
42
|
-
|
|
43
|
-
### Installation
|
|
44
|
-
|
|
45
|
-
0. Prerequisites
|
|
46
|
-
|
|
47
|
-
- Python 3.10
|
|
48
|
-
- (Optional) [one-compiler 1.30.0](https://github.com/Samsung/ONE/releases/tag/1.30.0)
|
|
49
|
-
- 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.
|
|
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, 2.7, 2.8, 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
|
-
### Quantization
|
|
193
|
-
|
|
194
|
-
The `tico.quantization` module provides a unified and modular interface for quantizing
|
|
195
|
-
large language models (LLMs) and other neural networks.
|
|
196
|
-
|
|
197
|
-
It introduces a simple two-step workflow — **prepare** and **convert** — that
|
|
198
|
-
abstracts the details of different quantization algorithms.
|
|
199
|
-
|
|
200
|
-
#### Basic Usage
|
|
201
|
-
|
|
202
|
-
```python
|
|
203
|
-
from tico.quantization import prepare, convert
|
|
204
|
-
from tico.quantization.config.gptq import GPTQConfig
|
|
205
|
-
import torch
|
|
206
|
-
import torch.nn as nn
|
|
207
|
-
|
|
208
|
-
class LinearModel(nn.Module):
|
|
209
|
-
def __init__(self):
|
|
210
|
-
super().__init__()
|
|
211
|
-
self.linear = nn.Linear(8, 8)
|
|
212
|
-
|
|
213
|
-
def forward(self, x):
|
|
214
|
-
return self.linear(x)
|
|
215
|
-
|
|
216
|
-
model = LinearModel().eval()
|
|
217
|
-
|
|
218
|
-
# 1. Prepare for quantization
|
|
219
|
-
quant_config = GPTQConfig()
|
|
220
|
-
prepared_model = prepare(model, quant_config)
|
|
221
|
-
|
|
222
|
-
# 2. Calibration
|
|
223
|
-
for d in dataset:
|
|
224
|
-
prepared_model(d)
|
|
225
|
-
|
|
226
|
-
# 3. Apply GPTQ
|
|
227
|
-
quantized_model = convert(prepared_model, quant_config)
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
For detailed documentation, design notes, and contributing guidelines,
|
|
231
|
-
see [tico/quantization/README.md](./tico/quantization/README.md).
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
## For Developers
|
|
235
|
-
|
|
236
|
-
### Testing & Code Formatting
|
|
237
|
-
|
|
238
|
-
Run below commands to configure testing or formatting environment.
|
|
239
|
-
|
|
240
|
-
Refer to the dedicated section to have more fine-grained control.
|
|
241
|
-
|
|
242
|
-
```bash
|
|
243
|
-
$ ./ccex configure # to set up testing & formatting environment
|
|
244
|
-
$ ./ccex configure format # to set up only formatting environment
|
|
245
|
-
$ ./ccex configure test # to set up only testing environment
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
**Available options**
|
|
249
|
-
- `--torch_ver <torch version>` To install a specific torch family package(ex. torchvision) version (default: 2.6)
|
|
250
|
-
- Available <torch version>: '2.5', '2.6', 'nightly'
|
|
251
|
-
|
|
252
|
-
```bash
|
|
253
|
-
$ ./ccex configure # to set up testing & formatting environment with stable2.6.x version
|
|
254
|
-
$ ./ccex configure test # to set up only testing environment with stable 2.6.x version
|
|
255
|
-
$ ./ccex configure test --torch_ver 2.5 # to set up only testing environment with stable 2.5.x version
|
|
256
|
-
$ ./ccex configure test --torch_ver nightly # to set up only testing environment with nightly version
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
### Testing
|
|
260
|
-
|
|
261
|
-
#### Test congifure
|
|
262
|
-
|
|
263
|
-
Run below commands to install requirements for testing.
|
|
264
|
-
|
|
265
|
-
**NOTE** `TICO` will be installed in an editable mode.
|
|
266
|
-
|
|
267
|
-
```bash
|
|
268
|
-
./ccex configure test
|
|
269
|
-
|
|
270
|
-
# without editable install
|
|
271
|
-
./ccex configure test --dist
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
#### Test All
|
|
275
|
-
|
|
276
|
-
Run below commands to run the all unit tests.
|
|
277
|
-
|
|
278
|
-
**NOTE** Unit tests don't include model test.
|
|
279
|
-
|
|
280
|
-
```bash
|
|
281
|
-
./ccex test
|
|
282
|
-
# OR
|
|
283
|
-
./ccex test run-all-tests
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
#### Test Subset
|
|
287
|
-
|
|
288
|
-
To run subset of `test.modules.*`,
|
|
289
|
-
Run `./ccex test -k <keyword>`
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
For example, to run tests in specific sub-directory (op, net, ..)
|
|
293
|
-
```bash
|
|
294
|
-
# To run tests in specific sub-directory (op/, net/ ..)
|
|
295
|
-
./ccex test -k op
|
|
296
|
-
./ccex test -k net
|
|
297
|
-
|
|
298
|
-
# To run tests in one file (single/op/add, single/op/sub, ...)
|
|
299
|
-
./ccex test -k add
|
|
300
|
-
./ccex test -k sub
|
|
301
|
-
|
|
302
|
-
# To run SimpleAdd test in test/modules/single/op/add.py
|
|
303
|
-
./ccex test -k SimpleAdd
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
To see the full debug log, add `-v` or `TICO_LOG=4`.
|
|
307
|
-
|
|
308
|
-
```bash
|
|
309
|
-
TICO_LOG=4 ./ccex test -k add
|
|
310
|
-
# OR
|
|
311
|
-
./ccex test -v -k add
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
#### Test Model
|
|
315
|
-
|
|
316
|
-
If you want to test them locally, you can do so by navigating to each model directory,
|
|
317
|
-
installing the dependencies listed in its `requirements.txt`, and running the tests one by one.
|
|
318
|
-
```bash
|
|
319
|
-
$ pip install -r test/modules/model/<model_name>/requirements.txt
|
|
320
|
-
# Run test for a single model
|
|
321
|
-
$ ./ccex test -m <model_name>
|
|
322
|
-
# Run models whose names contain "Llama" (e.g., Llama, LlamaDecoderLayer, LlamaWithGQA, etc.)
|
|
323
|
-
# Note that you should use quotes for the wildcard(*) pattern
|
|
324
|
-
$ ./ccex test -m "Llama*"
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
For example, to run a single model
|
|
328
|
-
```
|
|
329
|
-
./ccex test -m InceptionV3
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
#### Runtime Options
|
|
333
|
-
|
|
334
|
-
By default, `./ccex test` runs all modules with the `circle-interpreter` engine.
|
|
335
|
-
You can override this and run tests using the `onert` runtime instead.
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
##### 0. Install ONERT
|
|
339
|
-
|
|
340
|
-
```bash
|
|
341
|
-
pip install onert
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
##### 1. Command-Line Flag
|
|
345
|
-
|
|
346
|
-
Use the `--runtime` (or `-r`) flag to select a runtime:
|
|
347
|
-
|
|
348
|
-
```bash
|
|
349
|
-
# Run with the default circle-interpreter
|
|
350
|
-
./ccex test
|
|
351
|
-
|
|
352
|
-
# Run all tests with onert
|
|
353
|
-
./ccex test --runtime onert
|
|
354
|
-
# or
|
|
355
|
-
./ccex test -r onert
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
##### 2. Environment Variable
|
|
359
|
-
|
|
360
|
-
You can also set the `CCEX_RUNTIME` environment variable:
|
|
361
|
-
|
|
362
|
-
```bash
|
|
363
|
-
# Temporarily override for one command
|
|
364
|
-
CCEX_RUNTIME=onert ./ccex test
|
|
365
|
-
|
|
366
|
-
# Persist in your shell session
|
|
367
|
-
export CCEX_RUNTIME=onert
|
|
368
|
-
./ccex test
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
##### Supported Runtimes
|
|
372
|
-
|
|
373
|
-
- circle-interpreter (default): uses the Circle interpreter for inference.
|
|
374
|
-
- onert: uses the ONERT package for inference, useful when the Circle interpreter
|
|
375
|
-
cannot run a given module.
|
|
376
|
-
|
|
377
|
-
### Code Formatting
|
|
378
|
-
|
|
379
|
-
#### Format configure
|
|
380
|
-
|
|
381
|
-
Run below commands to install requirements for formatting.
|
|
382
|
-
|
|
383
|
-
```bash
|
|
384
|
-
./ccex configure format
|
|
385
|
-
```
|
|
386
|
-
|
|
387
|
-
#### Format run
|
|
388
|
-
|
|
389
|
-
```bash
|
|
390
|
-
./ccex format
|
|
391
|
-
```
|
|
392
|
-
|
|
File without changes
|
/tico/{quantization/algorithm/pt2e/annotation → serialize/operators/adapters/onert}/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|