Skip to content

Commit 1ae0d8e

Browse files
ClarkChin08ftian1
authored andcommitted
document revise.
1 parent 170cd1d commit 1ae0d8e

File tree

85 files changed

+2558
-1432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2558
-1432
lines changed

README.md

Lines changed: 244 additions & 280 deletions
Large diffs are not rendered by default.

docs/PTQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ top1, top5 = evaluate(myModel, criterion, data_loader_test, neval_batches=num_ev
284284
print('Evaluation accuracy on %d images, %2.2f'%(num_eval_batches * eval_batch_size, top1.avg))
285285
```
286286
Output:
287-
```
287+
```python
288288
QConfig(activation=functools.partial(<class 'torch.quantization.observer.MinMaxObserver'>, reduce_range=True), weight=functools.partial(<class 'torch.quantization.observer.MinMaxObserver'>, dtype=torch.qint8, qscheme=torch.per_tensor_symmetric))
289289
Post Training Quantization Prepare: Inserting Observers
290290

docs/Quantization.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@ Quantization refers to processes that enable lower precision inference and train
44

55
Quantization methods include the following three classes:
66

7-
* Post-Training Quantization (PTQ)
8-
* Quantization-Aware Training (QAT)
9-
* Dynamic Quantization
7+
* [Post-Training Quantization (PTQ)](./PTQ.md)
8+
* [Quantization-Aware Training (QAT)](./QAT.md)
9+
* [Dynamic Quantization](./dynamic_quantization.md)
1010

11-
Intel® Low Precision Optimization Tool currently supports PTQ and QAT. Using MobileNetV2 as an example, this document provides tutorials for both. It also provides helper functions for evaluation.
11+
> NOTE: Dynamic Quantization currently is only supported with onnxruntime backend.
1212
13-
Dynamic Quantization currently is only supported with onnxruntime backend, please refer to [dynamic quantization](./dynamic_quantization.md) for details.
14-
15-
>Note: These quantization tutorials use [PyTorch examples](https://pytorch.org/tutorials/advanced/static_quantization_tutorial.html#model-architecture) as allowed by PyTorch's [License](https://github.com/pytorch/pytorch/blob/master/LICENSE). Refer to [PyTorch](https://github.com/pytorch/tutorials/blob/master/advanced_source/static_quantization_tutorial.py) for updates.
16-
17-
18-
* See also [PTQ](PTQ.md)
19-
* See also [QAT](QAT.md)

docs/benchmark.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,21 @@ in this example config you can see there is 2 sub-fields named 'accuracy' and 'p
4848
4949
## use user specific dataloader to run benchmark
5050
51-
In this case, you should config your dataloader and lpot will construct an evaluation function to run the benchmarking.
51+
In this case, you should config your dataloader and lpot will construct an evaluation function to run the benchmarking. User can also register postprocess transform and metric to get the accuracy.
5252
5353
```python
5454
dataset = Dataset() # dataset class that implement __getitem__ method or __iter__ method
55-
from lpot import Benchmark
55+
from lpot import Benchmark, common
5656
evaluator = Benchmark(config.yaml)
57-
evaluator.dataloader(dataset, batch_size=batch_size)
58-
results = evaluator(model=input_model)
57+
evaluator.dataloader = common.DataLoader(dataset, batch_size=batch_size)
58+
# user can also register postprocess and metric, this is optional
59+
evaluator.postprocess = common.Postprocess(postprocess_cls)
60+
evaluator.metric = common.Metric(metric_cls)
61+
results = evaluator()
5962

6063
```
6164

62-
###Examples
65+
### Examples
6366

6467
[Benchamrk example](../examples/tensorflow/image_recognition/run_benchmark.sh).
6568

docs/dataloader.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
DataLoader
2+
=========================================
3+
4+
Deep Learning has been encountering larger and larger datasets which are so memory consuming. Before, working with large datasets requires loading them into memory all at once. It is impossible due to the lack of memory, we must figure out an efficient data generation scheme. This is not only about handle the lack of memory in large datasets, also about make the process of loading data faster enough using multi processing/thread. We call the data generation object as 'DataLoader'.
5+
6+
With the importance of DataLoader, different framework have their own DataLoadermodule, as for Intel® Low Precision Optimization Tool, it needs to calibrate the inputs/outputs of each layer of the model, framework specific DataLoader has different features and API that will make it hard to use them same way in the tool. Another request is, the tool also treat batch size as a tuning parameter, that means the tool can dynamically change the batch size to get accuracy target. The third reason is for easy of use, an unified DataLoader API can make it easy to config dataloader in yaml file without any code modification. Considering about all these advantages the tool has implemented an internal DataLoader.
7+
8+
DataLoader takes dataset as input parameter and loads data from dataset when needed.
9+
10+
Dataset is a container which holds all data that should be used by dataloader, and have the ability to be fetched by index or created as an iterator. One can implement a specific Dataset by inhereting from class Dataset with implementing `__iter__` method or `__getitem__` method, while implementing `__getitem__` method, `__len__` method is recommended.
11+
12+
Dataset use Transform as its data process component, Transform contains 3 different part, aimng at different part of the life cycle of data processing, it is:
13+
14+
1. preprocessing
15+
16+
2. postprocessing
17+
18+
3. general
19+
20+
General Transform can be used in both preprocessing and postprocessing, one can also implement a specific transform by inheriting from class Transform with implementing `__call__` method. Usually, DataLoader will use Transform for preprocessing and postprocessing transform is used to give right processed data to metric to update. Transforms also support to compose together to be one and serially implement the transforms.
21+
22+
Transform for preprocessing will be launched in Dataset `__getitem__` or `__next__` method, that means transform is used after dataloader has loaded batched data and before the data given to model for inference. That helps reduce the memory compared with load and process all data at once. Transform for postprocessing is used in evaluation function of internal lpot to process the inferenced data and the processed data is used by metric.
23+
24+
# How to use it
25+
26+
## Config dataloader in yaml file
27+
In this case dataloader will created after the Quantization object initialized. As calibration and evaluation may have different Transform and dataset, you can config different dataloader in yaml file.
28+
29+
```yaml
30+
quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
31+
calibration:
32+
sampling_size: 300 # optional. default value is 100 samples. used to set how many samples in calibration dataset are used.
33+
dataloader:
34+
dataset:
35+
ImageFolder:
36+
root: /path/to/calibration/dataset
37+
transform:
38+
RandomResizedCrop:
39+
size: 224
40+
RandomHorizontalFlip: {}
41+
ToTensor: {}
42+
Normalize:
43+
mean: [0.485, 0.456, 0.406]
44+
std: [0.229, 0.224, 0.225]
45+
46+
evaluation: # optional. required if user doesn't provide eval_func in lpot.Quantization.
47+
accuracy: # optional. required if user doesn't provide eval_func in lpot.Quantization.
48+
metric:
49+
topk: 1
50+
dataloader:
51+
batch_size: 30
52+
dataset:
53+
ImageFolder:
54+
root: /path/to/evaluation/dataset
55+
transform:
56+
Resize:
57+
size: 256
58+
CenterCrop:
59+
size: 224
60+
ToTensor: {}
61+
Normalize:
62+
mean: [0.485, 0.456, 0.406]
63+
std: [0.229, 0.224, 0.225]
64+
performance: # optional. used to benchmark performance of passing model.
65+
configs:
66+
cores_per_instance: 4
67+
num_of_instance: 7
68+
dataloader:
69+
batch_size: 1
70+
dataset:
71+
ImageFolder:
72+
root: /path/to/evaluation/dataset
73+
transform:
74+
Resize:
75+
size: 256
76+
CenterCrop:
77+
size: 224
78+
ToTensor: {}
79+
Normalize:
80+
mean: [0.485, 0.456, 0.406]
81+
std: [0.229, 0.224, 0.225]
82+
```
83+
84+
## Create user specific dataloader
85+
86+
```python
87+
calib_data = mx.io.ImageRecordIter(path_imgrec=dataset,
88+
label_width=1,
89+
preprocess_threads=data_nthreads,
90+
batch_size=batch_size,
91+
data_shape=data_shape,
92+
label_name=label_name,
93+
rand_crop=False,
94+
rand_mirror=False,
95+
shuffle=args.shuffle_dataset,
96+
shuffle_chunk_seed=args.shuffle_chunk_seed,
97+
seed=args.shuffle_seed,
98+
dtype=data_layer_type,
99+
ctx=args.ctx,
100+
**combine_mean_std)
101+
102+
from lpot import Quantization, common
103+
quantizer = Quantization('conf.yaml')
104+
quantizer.model = common.Model(fp32_model)
105+
quantizer.calib_dataloader = calib_data
106+
quantizer.eval_dataloader = calib_data
107+
q_model = quantizer()
108+
```
109+

docs/dataloader_metric.md

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)